Browse Source

Fix malformed date header in email. Closes #4828.

adaptive-webui-19844
Chocobo1 9 years ago
parent
commit
41fe85b624
  1. 28
      src/base/net/smtp.cpp
  2. 1
      src/base/net/smtp.h

28
src/base/net/smtp.cpp

@ -124,7 +124,7 @@ void Smtp::sendMail(const QString &from, const QString &to, const QString &subje @@ -124,7 +124,7 @@ void Smtp::sendMail(const QString &from, const QString &to, const QString &subje
const Preferences* const pref = Preferences::instance();
QTextCodec* latin1 = QTextCodec::codecForName("latin1");
m_message = "";
m_message += encodeMimeHeader("Date", QDateTime::currentDateTime().toUTC().toString("ddd, d MMM yyyy hh:mm:ss UT"), latin1);
m_message += "Date: " + getCurrentDateTime().toLatin1() + "\r\n";
m_message += encodeMimeHeader("From", from, latin1);
m_message += encodeMimeHeader("Subject", subject, latin1);
m_message += encodeMimeHeader("To", to, latin1);
@ -501,3 +501,29 @@ void Smtp::logError(const QString &msg) @@ -501,3 +501,29 @@ void Smtp::logError(const QString &msg)
qDebug() << "Email Notification Error:" << msg;
Logger::instance()->addMessage(tr("Email Notification Error:") + " " + msg, Log::CRITICAL);
}
QString Smtp::getCurrentDateTime() const
{
// return date & time in the format specified in RFC 2822, section 3.3
const QDateTime nowDateTime = QDateTime::currentDateTime();
const QDate nowDate = nowDateTime.date();
const QLocale eng(QLocale::English);
QString timeStr = nowDateTime.time().toString("HH:mm:ss");
QString weekDayStr = eng.dayName(nowDate.dayOfWeek(), QLocale::ShortFormat);
QString dayStr = QString::number(nowDate.day());
QString monthStr = eng.monthName(nowDate.month(), QLocale::ShortFormat);
QString yearStr = QString::number(nowDate.year());
QDateTime tmp = nowDateTime;
tmp.setTimeSpec(Qt::UTC);
int timeOffsetHour = nowDateTime.secsTo(tmp) / 3600;
int timeOffsetMin = nowDateTime.secsTo(tmp) / 60 - (60 * timeOffsetHour);
int timeOffset = timeOffsetHour * 100 + timeOffsetMin;
char buf[6] = {0};
std::snprintf(buf, sizeof(buf), "%+05d", timeOffset);
QString timeOffsetStr = buf;
QString ret = weekDayStr + ", " + dayStr + " " + monthStr + " " + yearStr + " " + timeStr + " " + timeOffsetStr;
return ret;
}

1
src/base/net/smtp.h

@ -102,6 +102,7 @@ namespace Net @@ -102,6 +102,7 @@ namespace Net
void authPlain();
void authLogin();
void logError(const QString &msg);
QString getCurrentDateTime() const;
QByteArray m_message;
#ifndef QT_NO_OPENSSL

Loading…
Cancel
Save