Browse Source

Merge pull request #14547 from glassez/codec

Don't use deprecated QTextCodec
adaptive-webui-19844
Vladimir Golovnev 4 years ago committed by GitHub
parent
commit
04827188f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      src/base/net/smtp.cpp
  2. 2
      src/base/net/smtp.h

20
src/base/net/smtp.cpp

@ -37,7 +37,6 @@
#include <QDebug> #include <QDebug>
#include <QHostInfo> #include <QHostInfo>
#include <QStringList> #include <QStringList>
#include <QTextCodec>
#ifndef QT_NO_OPENSSL #ifndef QT_NO_OPENSSL
#include <QSslSocket> #include <QSslSocket>
@ -89,6 +88,14 @@ namespace
return hostname.toLocal8Bit(); return hostname.toLocal8Bit();
} }
bool canEncodeAsLatin1(const QStringView string)
{
return std::none_of(string.cbegin(), string.cend(), [](const QChar &ch)
{
return ch > QChar(0xff);
});
}
} // namespace } // namespace
using namespace Net; using namespace Net;
@ -137,11 +144,10 @@ 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)
{ {
const Preferences *const pref = Preferences::instance(); const Preferences *const pref = Preferences::instance();
QTextCodec *latin1 = QTextCodec::codecForName("latin1");
m_message = "Date: " + getCurrentDateTime().toLatin1() + "\r\n" m_message = "Date: " + getCurrentDateTime().toLatin1() + "\r\n"
+ encodeMimeHeader("From", from, latin1) + encodeMimeHeader("From", from)
+ encodeMimeHeader("Subject", subject, latin1) + encodeMimeHeader("Subject", subject)
+ encodeMimeHeader("To", to, latin1) + encodeMimeHeader("To", to)
+ "MIME-Version: 1.0\r\n" + "MIME-Version: 1.0\r\n"
+ "Content-Type: text/plain; charset=UTF-8\r\n" + "Content-Type: text/plain; charset=UTF-8\r\n"
+ "Content-Transfer-Encoding: base64\r\n" + "Content-Transfer-Encoding: base64\r\n"
@ -312,12 +318,12 @@ void Smtp::readyRead()
} }
} }
QByteArray Smtp::encodeMimeHeader(const QString &key, const QString &value, const QTextCodec *latin1, const QByteArray &prefix) QByteArray Smtp::encodeMimeHeader(const QString &key, const QString &value, const QByteArray &prefix)
{ {
QByteArray rv = ""; QByteArray rv = "";
QByteArray line = key.toLatin1() + ": "; QByteArray line = key.toLatin1() + ": ";
if (!prefix.isEmpty()) line += prefix; if (!prefix.isEmpty()) line += prefix;
if (!value.contains("=?") && latin1->canEncode(value)) if (!value.contains("=?") && canEncodeAsLatin1(value))
{ {
bool firstWord = true; bool firstWord = true;
for (const QByteArray &word : asConst(value.toLatin1().split(' '))) for (const QByteArray &word : asConst(value.toLatin1().split(' ')))

2
src/base/net/smtp.h

@ -88,7 +88,7 @@ namespace Net
AuthCramMD5 AuthCramMD5
}; };
QByteArray encodeMimeHeader(const QString &key, const QString &value, const QTextCodec *latin1, const QByteArray &prefix = {}); QByteArray encodeMimeHeader(const QString &key, const QString &value, const QByteArray &prefix = {});
void ehlo(); void ehlo();
void helo(); void helo();
void parseEhloResponse(const QByteArray &code, bool continued, const QString &line); void parseEhloResponse(const QByteArray &code, bool continued, const QString &line);

Loading…
Cancel
Save