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. 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…
Cancel
Save