Browse Source

SMTP: Send the IP of the configured Network Interface. Relates to #1845.

adaptive-webui-19844
sledgehammer999 10 years ago
parent
commit
487ca568b8
  1. 25
      src/smtp.cpp

25
src/smtp.cpp

@ -79,13 +79,34 @@ 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";
if (address.isEmpty()) {
foreach (const QHostAddress& addr, QNetworkInterface::allAddresses()) { foreach (const QHostAddress& addr, QNetworkInterface::allAddresses()) {
if (addr == QHostAddress::LocalHost || addr == QHostAddress::LocalHostIPv6) if (addr == QHostAddress::LocalHost || addr == QHostAddress::LocalHostIPv6
|| (!listen_ipv6 && (addr.protocol() == QAbstractSocket::IPv6Protocol)))
continue; continue;
address = addr.toString().toLatin1(); address = addr.toString().toLatin1();
break; 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…
Cancel
Save