mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-25 18:56:34 +03:00
SMTP: Send the IP of the configured Network Interface. Relates to #1845.
This commit is contained in:
parent
54bf386794
commit
487ca568b8
1 changed files with 27 additions and 6 deletions
33
src/smtp.cpp
33
src/smtp.cpp
|
@ -79,12 +79,33 @@ QByteArray hmacMD5(QByteArray key, const QByteArray &msg)
|
|||
|
||||
QByteArray determineLocalAddress()
|
||||
{
|
||||
const Preferences* const pref = Preferences::instance();
|
||||
const QString iface_name = pref->getNetworkInterface();
|
||||
const bool listen_ipv6 = pref->getListenIPv6();
|
||||
QByteArray address = "127.0.0.1";
|
||||
foreach (const QHostAddress& addr, QNetworkInterface::allAddresses()) {
|
||||
if (addr == QHostAddress::LocalHost || addr == QHostAddress::LocalHostIPv6)
|
||||
continue;
|
||||
address = addr.toString().toLatin1();
|
||||
break;
|
||||
|
||||
if (address.isEmpty()) {
|
||||
foreach (const QHostAddress& addr, QNetworkInterface::allAddresses()) {
|
||||
if (addr == QHostAddress::LocalHost || addr == QHostAddress::LocalHostIPv6
|
||||
|| (!listen_ipv6 && (addr.protocol() == QAbstractSocket::IPv6Protocol)))
|
||||
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
|
||||
|| (!listen_ipv6 && (entry.ip().protocol() == QAbstractSocket::IPv6Protocol)))
|
||||
continue;
|
||||
|
||||
address = entry.ip().toString().toLatin1();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return address;
|
||||
|
@ -115,7 +136,7 @@ Smtp::~Smtp() {
|
|||
}
|
||||
|
||||
void Smtp::sendMail(const QString &from, const QString &to, const QString &subject, const QString &body) {
|
||||
Preferences* const pref = Preferences::instance();
|
||||
const Preferences* const pref = Preferences::instance();
|
||||
QTextCodec* latin1 = QTextCodec::codecForName("latin1");
|
||||
message = "";
|
||||
message += encode_mime_header("Date", QDateTime::currentDateTime().toUTC().toString("ddd, d MMM yyyy hh:mm:ss UT"), latin1);
|
||||
|
|
Loading…
Reference in a new issue