mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-25 22:14:32 +00:00
SMTP: Send the IP of the configured Network Interface. Relates to #1845.
This commit is contained in:
parent
54bf386794
commit
487ca568b8
33
src/smtp.cpp
33
src/smtp.cpp
@ -79,12 +79,33 @@ QByteArray hmacMD5(QByteArray key, const QByteArray &msg)
|
|||||||
|
|
||||||
QByteArray determineLocalAddress()
|
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";
|
QByteArray address = "127.0.0.1";
|
||||||
foreach (const QHostAddress& addr, QNetworkInterface::allAddresses()) {
|
|
||||||
if (addr == QHostAddress::LocalHost || addr == QHostAddress::LocalHostIPv6)
|
if (address.isEmpty()) {
|
||||||
continue;
|
foreach (const QHostAddress& addr, QNetworkInterface::allAddresses()) {
|
||||||
address = addr.toString().toLatin1();
|
if (addr == QHostAddress::LocalHost || addr == QHostAddress::LocalHostIPv6
|
||||||
break;
|
|| (!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;
|
return address;
|
||||||
@ -115,7 +136,7 @@ Smtp::~Smtp() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Smtp::sendMail(const QString &from, const QString &to, const QString &subject, const QString &body) {
|
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");
|
QTextCodec* latin1 = QTextCodec::codecForName("latin1");
|
||||||
message = "";
|
message = "";
|
||||||
message += encode_mime_header("Date", QDateTime::currentDateTime().toUTC().toString("ddd, d MMM yyyy hh:mm:ss UT"), latin1);
|
message += encode_mime_header("Date", QDateTime::currentDateTime().toUTC().toString("ddd, d MMM yyyy hh:mm:ss UT"), latin1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user