mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-21 05:43:32 -07:00
Merge pull request #4831 from Chocobo1/mail_time
Fix malformed date header in email.
This commit is contained in:
commit
654c8edc6b
2 changed files with 54 additions and 29 deletions
|
@ -58,9 +58,8 @@ namespace
|
||||||
QByteArray hmacMD5(QByteArray key, const QByteArray &msg)
|
QByteArray hmacMD5(QByteArray key, const QByteArray &msg)
|
||||||
{
|
{
|
||||||
const int blockSize = 64; // HMAC-MD5 block size
|
const int blockSize = 64; // HMAC-MD5 block size
|
||||||
if (key.length() > blockSize) { // if key is longer than block size (64), reduce key length with MD5 compression
|
if (key.length() > blockSize) // if key is longer than block size (64), reduce key length with MD5 compression
|
||||||
key = QCryptographicHash::hash(key, QCryptographicHash::Md5);
|
key = QCryptographicHash::hash(key, QCryptographicHash::Md5);
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray innerPadding(blockSize, char(0x36)); // initialize inner padding with char "6"
|
QByteArray innerPadding(blockSize, char(0x36)); // initialize inner padding with char "6"
|
||||||
QByteArray outerPadding(blockSize, char(0x5c)); // initialize outer padding with char "\"
|
QByteArray outerPadding(blockSize, char(0x5c)); // initialize outer padding with char "\"
|
||||||
|
@ -123,15 +122,14 @@ void Smtp::sendMail(const QString &from, const QString &to, const QString &subje
|
||||||
{
|
{
|
||||||
const Preferences* const pref = Preferences::instance();
|
const Preferences* const pref = Preferences::instance();
|
||||||
QTextCodec* latin1 = QTextCodec::codecForName("latin1");
|
QTextCodec* latin1 = QTextCodec::codecForName("latin1");
|
||||||
m_message = "";
|
m_message = "Date: " + getCurrentDateTime().toLatin1() + "\r\n"
|
||||||
m_message += encodeMimeHeader("Date", QDateTime::currentDateTime().toUTC().toString("ddd, d MMM yyyy hh:mm:ss UT"), latin1);
|
+ encodeMimeHeader("From", from, latin1)
|
||||||
m_message += encodeMimeHeader("From", from, latin1);
|
+ encodeMimeHeader("Subject", subject, latin1)
|
||||||
m_message += encodeMimeHeader("Subject", subject, latin1);
|
+ encodeMimeHeader("To", to, latin1)
|
||||||
m_message += encodeMimeHeader("To", to, latin1);
|
+ "MIME-Version: 1.0\r\n"
|
||||||
m_message += "MIME-Version: 1.0\r\n";
|
+ "Content-Type: text/plain; charset=UTF-8\r\n"
|
||||||
m_message += "Content-Type: text/plain; charset=UTF-8\r\n";
|
+ "Content-Transfer-Encoding: base64\r\n"
|
||||||
m_message += "Content-Transfer-Encoding: base64\r\n";
|
+ "\r\n";
|
||||||
m_message += "\r\n";
|
|
||||||
// Encode the body in base64
|
// Encode the body in base64
|
||||||
QString crlf_body = body;
|
QString crlf_body = body;
|
||||||
QByteArray b = crlf_body.replace("\n", "\r\n").toUtf8().toBase64();
|
QByteArray b = crlf_body.replace("\n", "\r\n").toUtf8().toBase64();
|
||||||
|
@ -501,3 +499,29 @@ void Smtp::logError(const QString &msg)
|
||||||
qDebug() << "Email Notification Error:" << msg;
|
qDebug() << "Email Notification Error:" << msg;
|
||||||
Logger::instance()->addMessage(tr("Email Notification Error:") + " " + msg, Log::CRITICAL);
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -102,6 +102,7 @@ namespace Net
|
||||||
void authPlain();
|
void authPlain();
|
||||||
void authLogin();
|
void authLogin();
|
||||||
void logError(const QString &msg);
|
void logError(const QString &msg);
|
||||||
|
QString getCurrentDateTime() const;
|
||||||
|
|
||||||
QByteArray m_message;
|
QByteArray m_message;
|
||||||
#ifndef QT_NO_OPENSSL
|
#ifndef QT_NO_OPENSSL
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue