Browse Source

SMTP: send the local hostname as FQDN. See discussion in #1845 for more info.

adaptive-webui-19844
sledgehammer999 10 years ago
parent
commit
5528f60a15
  1. 42
      src/smtp.cpp

42
src/smtp.cpp

@ -45,6 +45,7 @@ @@ -45,6 +45,7 @@
#include <QTextCodec>
#include <QDebug>
#include <QHostAddress>
#include <QHostInfo>
#include <QNetworkInterface>
#include <QCryptographicHash>
@ -77,40 +78,13 @@ QByteArray hmacMD5(QByteArray key, const QByteArray &msg) @@ -77,40 +78,13 @@ QByteArray hmacMD5(QByteArray key, const QByteArray &msg)
return QCryptographicHash::hash(total, QCryptographicHash::Md5);
}
QByteArray determineLocalAddress()
QByteArray determineFQDN()
{
const Preferences* const pref = Preferences::instance();
const QString iface_name = pref->getNetworkInterface();
const bool use_ipv6 = pref->getListenIPv6();
QByteArray address = "127.0.0.1";
if (iface_name.isEmpty()) {
foreach (const QHostAddress& addr, QNetworkInterface::allAddresses()) {
if (addr == QHostAddress::LocalHost || addr == QHostAddress::LocalHostIPv6
|| (!use_ipv6 && (addr.protocol() == QAbstractSocket::IPv6Protocol))
|| (use_ipv6 && (addr.protocol() == QAbstractSocket::IPv4Protocol)))
continue;
address = addr.toString().toLatin1();
break;
}
}
else {
const QNetworkInterface network_iface = QNetworkInterface::interfaceFromName(iface_name);
if (!network_iface.isValid())
return address;
foreach (const QNetworkAddressEntry &entry, network_iface.addressEntries()) {
if (entry.ip() == QHostAddress::LocalHost || entry.ip() == QHostAddress::LocalHostIPv6
|| (!use_ipv6 && (entry.ip().protocol() == QAbstractSocket::IPv6Protocol))
|| (use_ipv6 && (entry.ip().protocol() == QAbstractSocket::IPv4Protocol)))
continue;
address = entry.ip().toString().toLatin1();
break;
}
}
QString hostname = QHostInfo::localHostName();
if (hostname.isEmpty())
hostname = "localhost";
return address;
return hostname.toLocal8Bit();
}
} // namespace
@ -332,7 +306,7 @@ QByteArray Smtp::encode_mime_header(const QString& key, const QString& value, QT @@ -332,7 +306,7 @@ QByteArray Smtp::encode_mime_header(const QString& key, const QString& value, QT
void Smtp::ehlo()
{
QByteArray address = determineLocalAddress();
QByteArray address = determineFQDN();
socket->write("ehlo " + address + "\r\n");
socket->flush();
state = EhloSent;
@ -340,7 +314,7 @@ void Smtp::ehlo() @@ -340,7 +314,7 @@ void Smtp::ehlo()
void Smtp::helo()
{
QByteArray address = determineLocalAddress();
QByteArray address = determineFQDN();
socket->write("helo " + address + "\r\n");
socket->flush();
state = HeloSent;

Loading…
Cancel
Save