mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-13 16:28:06 +00:00
SMTP: send the local hostname as FQDN. See discussion in #1845 for more info.
This commit is contained in:
parent
f9aee5e3ab
commit
5528f60a15
42
src/smtp.cpp
42
src/smtp.cpp
@ -45,6 +45,7 @@
|
|||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QHostAddress>
|
#include <QHostAddress>
|
||||||
|
#include <QHostInfo>
|
||||||
#include <QNetworkInterface>
|
#include <QNetworkInterface>
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
|
|
||||||
@ -77,40 +78,13 @@ QByteArray hmacMD5(QByteArray key, const QByteArray &msg)
|
|||||||
return QCryptographicHash::hash(total, QCryptographicHash::Md5);
|
return QCryptographicHash::hash(total, QCryptographicHash::Md5);
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray determineLocalAddress()
|
QByteArray determineFQDN()
|
||||||
{
|
{
|
||||||
const Preferences* const pref = Preferences::instance();
|
QString hostname = QHostInfo::localHostName();
|
||||||
const QString iface_name = pref->getNetworkInterface();
|
if (hostname.isEmpty())
|
||||||
const bool use_ipv6 = pref->getListenIPv6();
|
hostname = "localhost";
|
||||||
QByteArray address = "127.0.0.1";
|
|
||||||
|
|
||||||
if (iface_name.isEmpty()) {
|
return hostname.toLocal8Bit();
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return address;
|
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@ -332,7 +306,7 @@ QByteArray Smtp::encode_mime_header(const QString& key, const QString& value, QT
|
|||||||
|
|
||||||
void Smtp::ehlo()
|
void Smtp::ehlo()
|
||||||
{
|
{
|
||||||
QByteArray address = determineLocalAddress();
|
QByteArray address = determineFQDN();
|
||||||
socket->write("ehlo " + address + "\r\n");
|
socket->write("ehlo " + address + "\r\n");
|
||||||
socket->flush();
|
socket->flush();
|
||||||
state = EhloSent;
|
state = EhloSent;
|
||||||
@ -340,7 +314,7 @@ void Smtp::ehlo()
|
|||||||
|
|
||||||
void Smtp::helo()
|
void Smtp::helo()
|
||||||
{
|
{
|
||||||
QByteArray address = determineLocalAddress();
|
QByteArray address = determineFQDN();
|
||||||
socket->write("helo " + address + "\r\n");
|
socket->write("helo " + address + "\r\n");
|
||||||
socket->flush();
|
socket->flush();
|
||||||
state = HeloSent;
|
state = HeloSent;
|
||||||
|
Loading…
Reference in New Issue
Block a user