mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 05:13:30 -07:00
SMTP: Send the IP of the configured Network Interface. Relates to #1845.
Conflicts: src/smtp.cpp
This commit is contained in:
parent
3b9dc7add2
commit
82768e2098
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()
|
QByteArray determineLocalAddress()
|
||||||
{
|
{
|
||||||
|
const Preferences pref;
|
||||||
|
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 pref;
|
const Preferences pref;
|
||||||
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…
Add table
Add a link
Reference in a new issue