1
0

Repair and adjust the SMTP library.

This commit is contained in:
Saturneric 2021-07-15 01:23:44 +08:00
parent a0b5b56e8f
commit 39acbb05c1
25 changed files with 858 additions and 817 deletions

View File

@ -23,27 +23,29 @@
#include "smtpexports.h" #include "smtpexports.h"
class SMTP_EXPORT EmailAddress : public QObject class SMTP_EXPORT EmailAddress : public QObject {
{ Q_OBJECT
Q_OBJECT
public: public:
/* [1] Constructors and Destructors */ /* [1] Constructors and Destructors */
EmailAddress(); EmailAddress() = default;
EmailAddress(const QString & address, const QString & name="");
~EmailAddress(); explicit EmailAddress(const QString &address, const QString &name = "");
~EmailAddress() override;
/* [1] --- */ /* [1] --- */
/* [2] Getters and Setters */ /* [2] Getters and Setters */
void setName(const QString & name); void setName(const QString &name);
void setAddress(const QString & address);
const QString & getName() const; void setAddress(const QString &address);
const QString & getAddress() const;
[[nodiscard]] const QString &getName() const;
[[nodiscard]] const QString &getAddress() const;
/* [2] --- */ /* [2] --- */

View File

@ -25,17 +25,17 @@
#include "smtpexports.h" #include "smtpexports.h"
class SMTP_EXPORT MimeAttachment : public MimeFile class SMTP_EXPORT MimeAttachment : public MimeFile {
{ Q_OBJECT
Q_OBJECT
public: public:
/* [1] Constructors and Destructors */ /* [1] Constructors and Destructors */
MimeAttachment(QFile* file); explicit MimeAttachment(QFile *file);
MimeAttachment(const QByteArray& stream, const QString& fileName);
~MimeAttachment(); MimeAttachment(const QByteArray &stream, const QString &fileName);
~MimeAttachment() override;
/* [1] --- */ /* [1] --- */
@ -43,7 +43,7 @@ protected:
/* [2] Protected methods */ /* [2] Protected methods */
virtual void prepare(); void prepare() override;
/* [2] --- */ /* [2] --- */
}; };

View File

@ -24,16 +24,16 @@
#include "smtpexports.h" #include "smtpexports.h"
class SMTP_EXPORT MimeContentFormatter : public QObject class SMTP_EXPORT MimeContentFormatter : public QObject {
{ Q_OBJECT
Q_OBJECT
public: public:
MimeContentFormatter (int max_length = 76); explicit MimeContentFormatter(int max_length = 76);
void setMaxLength(int l); void setMaxLength(int l);
int getMaxLength() const;
QString format(const QString &content, bool quotedPrintable = false) const; [[nodiscard]] int getMaxLength() const;
[[nodiscard]] QString format(const QString &content, bool quotedPrintable = false) const;
protected: protected:
int max_length; int max_length;

View File

@ -24,16 +24,17 @@
#include "smtpexports.h" #include "smtpexports.h"
class SMTP_EXPORT MimeFile : public MimePart class SMTP_EXPORT MimeFile : public MimePart {
{ Q_OBJECT
Q_OBJECT
public: public:
/* [1] Constructors and Destructors */ /* [1] Constructors and Destructors */
MimeFile(const QByteArray& stream, const QString& fileName); MimeFile(const QByteArray &stream, const QString &fileName);
MimeFile(QFile *f);
~MimeFile(); explicit MimeFile(QFile *f);
~MimeFile() override;
/* [1] --- */ /* [1] --- */
@ -46,14 +47,14 @@ protected:
/* [3] Protected members */ /* [3] Protected members */
QFile* file; QFile *file;
/* [3] --- */ /* [3] --- */
/* [4] Protected methods */ /* [4] Protected methods */
virtual void prepare(); void prepare() override;
/* [4] --- */ /* [4] --- */

View File

@ -23,24 +23,24 @@
#include "smtpexports.h" #include "smtpexports.h"
class SMTP_EXPORT MimeHtml : public MimeText class SMTP_EXPORT MimeHtml : public MimeText {
{ Q_OBJECT
Q_OBJECT
public: public:
/* [1] Constructors and Destructors */ /* [1] Constructors and Destructors */
MimeHtml(const QString &html = ""); explicit MimeHtml(const QString &html = "");
~MimeHtml();
~MimeHtml() override;
/* [1] --- */ /* [1] --- */
/* [2] Getters and Setters */ /* [2] Getters and Setters */
void setHtml(const QString & html); void setHtml(const QString &html);
const QString& getHtml() const; [[nodiscard]] const QString &getHtml() const;
/* [2] --- */ /* [2] --- */
@ -53,7 +53,7 @@ protected:
/* [4] Protected methods */ /* [4] Protected methods */
virtual void prepare(); void prepare() override;
/* [4] --- */ /* [4] --- */
}; };

View File

@ -23,14 +23,14 @@
#include "smtpexports.h" #include "smtpexports.h"
class SMTP_EXPORT MimeInlineFile : public MimeFile class SMTP_EXPORT MimeInlineFile : public MimeFile {
{
public: public:
/* [1] Constructors and Destructors */ /* [1] Constructors and Destructors */
MimeInlineFile(QFile *f); explicit MimeInlineFile(QFile *f);
~MimeInlineFile();
~MimeInlineFile() override;
/* [1] --- */ /* [1] --- */
@ -48,7 +48,7 @@ protected:
/* [4] Protected methods */ /* [4] Protected methods */
virtual void prepare(); void prepare() override;
/* [4] --- */ /* [4] --- */
}; };

View File

@ -26,8 +26,7 @@
#include "smtpexports.h" #include "smtpexports.h"
class SMTP_EXPORT MimeMessage : public QObject class SMTP_EXPORT MimeMessage : public QObject {
{
public: public:
enum RecipientType { enum RecipientType {
@ -38,34 +37,47 @@ public:
/* [1] Constructors and Destructors */ /* [1] Constructors and Destructors */
MimeMessage(bool createAutoMimeConent = true); explicit MimeMessage(bool createAutoMimeConent = true);
~MimeMessage();
~MimeMessage() override;
/* [1] --- */ /* [1] --- */
/* [2] Getters and Setters */ /* [2] Getters and Setters */
void setSender(EmailAddress* e); void setSender(EmailAddress *e);
void addRecipient(EmailAddress* rcpt, RecipientType type = To);
void addTo(EmailAddress* rcpt);
void addCc(EmailAddress* rcpt);
void addBcc(EmailAddress* rcpt);
void setSubject(const QString & subject);
void addPart(MimePart* part);
void setReplyTo(EmailAddress* rto);
void setInReplyTo(const QString& inReplyTo); void addRecipient(EmailAddress *rcpt, RecipientType type = To);
void addTo(EmailAddress *rcpt);
void addCc(EmailAddress *rcpt);
void addBcc(EmailAddress *rcpt);
void setSubject(const QString &subject);
void addPart(MimePart *part);
void setReplyTo(EmailAddress *rto);
void setInReplyTo(const QString &inReplyTo);
void setHeaderEncoding(MimePart::Encoding); void setHeaderEncoding(MimePart::Encoding);
const EmailAddress & getSender() const; [[nodiscard]] const EmailAddress &getSender() const;
const QList<EmailAddress*> & getRecipients(RecipientType type = To) const;
const QString & getSubject() const; [[nodiscard]] const QList<EmailAddress *> &getRecipients(RecipientType type = To) const;
const QList<MimePart*> & getParts() const;
const EmailAddress* getReplyTo() const; [[nodiscard]] const QString &getSubject() const;
[[nodiscard]] const QList<MimePart *> &getParts() const;
[[nodiscard]] const EmailAddress *getReplyTo() const;
MimePart &getContent();
MimePart& getContent();
void setContent(MimePart *content); void setContent(MimePart *content);
/* [2] --- */ /* [2] --- */
@ -80,9 +92,9 @@ protected:
/* [4] Protected members */ /* [4] Protected members */
EmailAddress* sender; EmailAddress *sender{};
EmailAddress* replyTo; EmailAddress *replyTo;
QList<EmailAddress*> recipientsTo, recipientsCc, recipientsBcc; QList<EmailAddress *> recipientsTo, recipientsCc, recipientsBcc;
QString subject; QString subject;
QString mInReplyTo; QString mInReplyTo;
MimePart *content; MimePart *content;

View File

@ -24,7 +24,7 @@
#include "smtpexports.h" #include "smtpexports.h"
class SMTP_EXPORT MimeMultiPart : public MimePart { class SMTP_EXPORT MimeMultiPart : public MimePart {
Q_OBJECT Q_OBJECT
public: public:
/* [0] Enums */ /* [0] Enums */
enum MultiPartType { enum MultiPartType {
@ -40,18 +40,19 @@ public:
/* [0] --- */ /* [0] --- */
/* [1] Constructors and Destructors */ /* [1] Constructors and Destructors */
MimeMultiPart(const MultiPartType type = Related); explicit MimeMultiPart(MultiPartType type = Related);
~MimeMultiPart(); ~MimeMultiPart() override;
/* [1] --- */ /* [1] --- */
/* [2] Getters and Setters */ /* [2] Getters and Setters */
void setMimeType(const MultiPartType type); void setMimeType(MultiPartType type);
MultiPartType getMimeType() const;
const QList<MimePart *> &getParts() const; [[nodiscard]] MultiPartType getMimeType() const;
[[nodiscard]] const QList<MimePart *> &getParts() const;
/* [2] --- */ /* [2] --- */
@ -59,7 +60,7 @@ public:
void addPart(MimePart *part); void addPart(MimePart *part);
virtual void prepare(); void prepare() override;
/* [3] --- */ /* [3] --- */

View File

@ -25,44 +25,54 @@
#include "smtpexports.h" #include "smtpexports.h"
class SMTP_EXPORT MimePart : public QObject { class SMTP_EXPORT MimePart : public QObject {
Q_OBJECT Q_OBJECT
public: public:
/* [0] Enumerations */ /* [0] Enumerations */
enum Encoding { _7Bit, _8Bit, Base64, QuotedPrintable }; enum Encoding {
_7Bit, _8Bit, Base64, QuotedPrintable
};
/* [0] --- */ /* [0] --- */
/* [1] Constructors and Destructors */ /* [1] Constructors and Destructors */
MimePart(); MimePart();
~MimePart();
~MimePart() override;
/* [1] --- */ /* [1] --- */
/* [2] Getters and Setters */ /* [2] Getters and Setters */
const QString &getHeader() const; [[nodiscard]] const QString &getHeader() const;
const QByteArray &getContent() const;
[[nodiscard]] const QByteArray &getContent() const;
void setContent(const QByteArray &content); void setContent(const QByteArray &content);
void setHeader(const QString &header); void setHeader(const QString &header);
void addHeaderLine(const QString &line); void addHeaderLine(const QString &line);
void setContentId(const QString &cId); void setContentId(const QString &cId);
const QString &getContentId() const;
[[nodiscard]] const QString &getContentId() const;
void setContentName(const QString &cName); void setContentName(const QString &cName);
const QString &getContentName() const;
[[nodiscard]] const QString &getContentName() const;
void setContentType(const QString &cType); void setContentType(const QString &cType);
const QString &getContentType() const;
[[nodiscard]] const QString &getContentType() const;
void setCharset(const QString &charset); void setCharset(const QString &charset);
const QString &getCharset() const;
[[nodiscard]] const QString &getCharset() const;
void setEncoding(Encoding enc); void setEncoding(Encoding enc);
Encoding getEncoding() const;
[[nodiscard]] Encoding getEncoding() const;
MimeContentFormatter &getContentFormatter(); MimeContentFormatter &getContentFormatter();

View File

@ -23,23 +23,23 @@
#include "smtpexports.h" #include "smtpexports.h"
class SMTP_EXPORT MimeText : public MimePart class SMTP_EXPORT MimeText : public MimePart {
{
public: public:
/* [1] Constructors and Destructors */ /* [1] Constructors and Destructors */
MimeText(const QString &text = ""); explicit MimeText(const QString &text = "");
~MimeText();
~MimeText() override;
/* [1] --- */ /* [1] --- */
/* [2] Getters and Setters*/ /* [2] Getters and Setters*/
void setText(const QString & text); void setText(const QString &text);
const QString & getText() const; [[nodiscard]] const QString &getText() const;
/* [2] --- */ /* [2] --- */
@ -53,7 +53,7 @@ protected:
/* [4] Protected methods */ /* [4] Protected methods */
void prepare(); void prepare() override;
/* [4] --- */ /* [4] --- */

View File

@ -24,12 +24,12 @@
#include "smtpexports.h" #include "smtpexports.h"
class SMTP_EXPORT QuotedPrintable : public QObject class SMTP_EXPORT QuotedPrintable : public QObject {
{ Q_OBJECT
Q_OBJECT
public: public:
static QString encode(const QByteArray &input); static QString encode(const QByteArray &input);
static QByteArray decode(const QString &input); static QByteArray decode(const QString &input);
private: private:

View File

@ -25,21 +25,18 @@
#include "mimemessage.h" #include "mimemessage.h"
#include "smtpexports.h" #include "smtpexports.h"
class SMTP_EXPORT SmtpClient : public QObject class SMTP_EXPORT SmtpClient : public QObject {
{ Q_OBJECT
Q_OBJECT
public: public:
/* [0] Enumerations */ /* [0] Enumerations */
enum AuthMethod enum AuthMethod {
{
AuthPlain, AuthPlain,
AuthLogin AuthLogin
}; };
enum SmtpError enum SmtpError {
{
ConnectionTimeoutError, ConnectionTimeoutError,
ResponseTimeoutError, ResponseTimeoutError,
SendDataTimeoutError, SendDataTimeoutError,
@ -48,8 +45,7 @@ public:
ClientError // 5xx smtp error ClientError // 5xx smtp error
}; };
enum ConnectionType enum ConnectionType {
{
TcpConnection, TcpConnection,
SslConnection, SslConnection,
TlsConnection // STARTTLS TlsConnection // STARTTLS
@ -60,49 +56,60 @@ public:
/* [1] Constructors and Destructors */ /* [1] Constructors and Destructors */
SmtpClient(const QString & host = "localhost", int port = 25, ConnectionType ct = TcpConnection); explicit SmtpClient(const QString &host = "localhost", int port = 25, ConnectionType ct = TcpConnection);
~SmtpClient(); ~SmtpClient() override;
/* [1] --- */ /* [1] --- */
/* [2] Getters and Setters */ /* [2] Getters and Setters */
const QString& getHost() const; [[nodiscard]] const QString &getHost() const;
void setHost(const QString &host); void setHost(const QString &host);
int getPort() const; [[nodiscard]] int getPort() const;
void setPort(int port); void setPort(int port);
const QString& getName() const; [[nodiscard]] const QString &getName() const;
void setName(const QString &name); void setName(const QString &name);
ConnectionType getConnectionType() const; [[nodiscard]] ConnectionType getConnectionType() const;
void setConnectionType(ConnectionType ct); void setConnectionType(ConnectionType ct);
const QString & getUser() const; [[nodiscard]] const QString &getUser() const;
void setUser(const QString &user); void setUser(const QString &user);
const QString & getPassword() const; [[nodiscard]] const QString &getPassword() const;
void setPassword(const QString &password); void setPassword(const QString &password);
SmtpClient::AuthMethod getAuthMethod() const; [[nodiscard]] SmtpClient::AuthMethod getAuthMethod() const;
void setAuthMethod(AuthMethod method); void setAuthMethod(AuthMethod method);
const QString & getResponseText() const; [[nodiscard]] const QString &getResponseText() const;
int getResponseCode() const;
[[nodiscard]] int getResponseCode() const;
[[nodiscard]] int getConnectionTimeout() const;
int getConnectionTimeout() const;
void setConnectionTimeout(int msec); void setConnectionTimeout(int msec);
int getResponseTimeout() const; [[nodiscard]] int getResponseTimeout() const;
void setResponseTimeout(int msec); void setResponseTimeout(int msec);
int getSendMessageTimeout() const; [[nodiscard]] int getSendMessageTimeout() const;
void setSendMessageTimeout(int msec); void setSendMessageTimeout(int msec);
QTcpSocket* getSocket(); QTcpSocket *getSocket();
/* [2] --- */ /* [2] --- */
@ -113,9 +120,10 @@ public:
bool connectToHost(); bool connectToHost();
bool login(); bool login();
bool login(const QString &user, const QString &password, AuthMethod method = AuthLogin); bool login(const QString &user, const QString &password, AuthMethod method = AuthLogin);
bool sendMail(MimeMessage& email); bool sendMail(MimeMessage &email);
void quit(); void quit();
@ -146,8 +154,11 @@ protected:
int responseCode; int responseCode;
class ResponseTimeoutException {}; class ResponseTimeoutException : public std::exception {
class SendMessageTimeoutException {}; };
class SendMessageTimeoutException : public std::exception {
};
/* [4] --- */ /* [4] --- */
@ -165,7 +176,9 @@ protected slots:
/* [6] Protected slots */ /* [6] Protected slots */
void socketStateChanged(QAbstractSocket::SocketState state); void socketStateChanged(QAbstractSocket::SocketState state);
void socketError(QAbstractSocket::SocketError error); void socketError(QAbstractSocket::SocketError error);
void socketReadyRead(); void socketReadyRead();
/* [6] --- */ /* [6] --- */

View File

@ -2,9 +2,9 @@
#define SMTPEXPORTS_H #define SMTPEXPORTS_H
#ifdef SMTP_BUILD #ifdef SMTP_BUILD
#define SMTP_EXPORT Q_DECL_EXPORT #define SMTP_EXPORT
#else #else
#define SMTP_EXPORT Q_DECL_IMPORT #define SMTP_EXPORT
#endif #endif
#endif // SMTPEXPORTS_H #endif // SMTPEXPORTS_H

View File

@ -22,11 +22,12 @@
/* [1] Constructors and Destructors */ /* [1] Constructors and Destructors */
MimeAttachment::MimeAttachment(QFile *file) : MimeFile(file) {} MimeAttachment::MimeAttachment(QFile *file) : MimeFile(file) {}
MimeAttachment::MimeAttachment(const QByteArray &stream, MimeAttachment::MimeAttachment(const QByteArray &stream,
const QString &fileName) const QString &fileName)
: MimeFile(stream, fileName) {} : MimeFile(stream, fileName) {}
MimeAttachment::~MimeAttachment() {} MimeAttachment::~MimeAttachment() = default;
/* [1] --- */ /* [1] --- */

View File

@ -27,7 +27,7 @@ QString MimeContentFormatter::format(const QString &content,
QString out; QString out;
int chars = 0; int chars = 0;
for (int i = 0; i < content.length(); ++i) { for (auto i : content) {
chars++; chars++;
if (!quotedPrintable) { if (!quotedPrintable) {
if (chars > max_length) { if (chars > max_length) {
@ -35,20 +35,20 @@ QString MimeContentFormatter::format(const QString &content,
chars = 1; chars = 1;
} }
} else { } else {
if (content[i] == '\n') { // new line if (i == '\n') { // new line
out.append(content[i]); out.append(i);
chars = 0; chars = 0;
continue; continue;
} }
if ((chars > max_length - 1) || if ((chars > max_length - 1) ||
((content[i] == '=') && (chars > max_length - 3))) { ((i == '=') && (chars > max_length - 3))) {
out.append('='); out.append('=');
out.append("\r\n"); out.append("\r\n");
chars = 1; chars = 1;
} }
} }
out.append(content[i]); out.append(i);
} }
return out; return out;

View File

@ -31,13 +31,12 @@ MimeFile::MimeFile(QFile *file) {
MimeFile::MimeFile(const QByteArray &stream, const QString &fileName) { MimeFile::MimeFile(const QByteArray &stream, const QString &fileName) {
this->cEncoding = Base64; this->cEncoding = Base64;
this->cType = "application/octet-stream"; this->cType = "application/octet-stream";
this->file = 0; this->file = nullptr;
this->cName = fileName; this->cName = fileName;
this->content = stream; this->content = stream;
} }
MimeFile::~MimeFile() { MimeFile::~MimeFile() {
if (file)
delete file; delete file;
} }

View File

@ -24,7 +24,7 @@ MimeHtml::MimeHtml(const QString &html) : MimeText(html) {
this->cType = "text/html"; this->cType = "text/html";
} }
MimeHtml::~MimeHtml() {} MimeHtml::~MimeHtml() = default;
/* [1] --- */ /* [1] --- */

View File

@ -22,7 +22,7 @@
MimeInlineFile::MimeInlineFile(QFile *f) : MimeFile(f) {} MimeInlineFile::MimeInlineFile(QFile *f) : MimeFile(f) {}
MimeInlineFile::~MimeInlineFile() {} MimeInlineFile::~MimeInlineFile() = default;
/* [1] --- */ /* [1] --- */

View File

@ -87,7 +87,7 @@ void MimeMessage::setSubject(const QString &subject) {
void MimeMessage::addPart(MimePart *part) { void MimeMessage::addPart(MimePart *part) {
if (typeid(*content) == typeid(MimeMultiPart)) { if (typeid(*content) == typeid(MimeMultiPart)) {
((MimeMultiPart *)content)->addPart(part); ((MimeMultiPart *) content)->addPart(part);
}; };
} }
@ -120,9 +120,9 @@ const QString &MimeMessage::getSubject() const { return subject; }
const QList<MimePart *> &MimeMessage::getParts() const { const QList<MimePart *> &MimeMessage::getParts() const {
if (typeid(*content) == typeid(MimeMultiPart)) { if (typeid(*content) == typeid(MimeMultiPart)) {
return ((MimeMultiPart *)content)->getParts(); return ((MimeMultiPart *) content)->getParts();
} else { } else {
QList<MimePart *> *res = new QList<MimePart *>(); auto *res = new QList<MimePart *>();
res->append(content); res->append(content);
return *res; return *res;
} }
@ -194,7 +194,7 @@ QString MimeMessage::toString() {
/* ---------------------------------- */ /* ---------------------------------- */
/* ------- Recipients / Cc ---------- */ /* ------- Recipients / Cc ---------- */
if (recipientsCc.size() != 0) { if (!recipientsCc.empty()) {
mime += "Cc:"; mime += "Cc:";
} }
for (i = 0, it = recipientsCc.begin(); it != recipientsCc.end(); ++it, ++i) { for (i = 0, it = recipientsCc.begin(); it != recipientsCc.end(); ++it, ++i) {
@ -223,7 +223,7 @@ QString MimeMessage::toString() {
} }
mime += " <" + (*it)->getAddress() + ">"; mime += " <" + (*it)->getAddress() + ">";
} }
if (recipientsCc.size() != 0) { if (!recipientsCc.empty()) {
mime += "\r\n"; mime += "\r\n";
} }
/* ---------------------------------- */ /* ---------------------------------- */

View File

@ -39,11 +39,11 @@ MimeMultiPart::MimeMultiPart(MultiPartType type) {
QRandomGenerator generator; QRandomGenerator generator;
QCryptographicHash md5(QCryptographicHash::Md5); QCryptographicHash md5(QCryptographicHash::Md5);
md5.addData(QByteArray().append(generator.generate())); md5.addData(QByteArray().append((char) generator.generate()));
cBoundary = md5.result().toHex(); cBoundary = md5.result().toHex();
} }
MimeMultiPart::~MimeMultiPart() {} MimeMultiPart::~MimeMultiPart() = default;
void MimeMultiPart::addPart(MimePart *part) { parts.append(part); } void MimeMultiPart::addPart(MimePart *part) { parts.append(part); }

View File

@ -27,7 +27,7 @@ MimePart::MimePart() {
cBoundary = ""; cBoundary = "";
} }
MimePart::~MimePart() { return; } MimePart::~MimePart() = default;
/* [1] --- */ /* [1] --- */

View File

@ -27,7 +27,7 @@ MimeText::MimeText(const QString &txt) {
this->cEncoding = _8Bit; this->cEncoding = _8Bit;
} }
MimeText::~MimeText() {} MimeText::~MimeText() = default;
/* [1] --- */ /* [1] --- */

View File

@ -25,8 +25,8 @@ QString QuotedPrintable::encode(const QByteArray &input) {
const char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', const char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
for (int i = 0; i < input.length(); ++i) { for (char i : input) {
byte = input[i]; byte = i;
if ((byte == 0x20) || ((byte >= 33) && (byte <= 126) && (byte != 61))) { if ((byte == 0x20) || ((byte >= 33) && (byte <= 126) && (byte != 61))) {
output.append(byte); output.append(byte);

View File

@ -110,7 +110,9 @@ void SmtpClient::setConnectionTimeout(int msec) { connectionTimeout = msec; }
int SmtpClient::getResponseTimeout() const { return responseTimeout; } int SmtpClient::getResponseTimeout() const { return responseTimeout; }
void SmtpClient::setResponseTimeout(int msec) { responseTimeout = msec; } void SmtpClient::setResponseTimeout(int msec) { responseTimeout = msec; }
int SmtpClient::getSendMessageTimeout() const { return sendMessageTimeout; } int SmtpClient::getSendMessageTimeout() const { return sendMessageTimeout; }
void SmtpClient::setSendMessageTimeout(int msec) { sendMessageTimeout = msec; } void SmtpClient::setSendMessageTimeout(int msec) { sendMessageTimeout = msec; }
/* [2] --- */ /* [2] --- */
@ -124,7 +126,7 @@ bool SmtpClient::connectToHost() {
socket->connectToHost(host, port); socket->connectToHost(host, port);
break; break;
case SslConnection: case SslConnection:
((QSslSocket *)socket)->connectToHostEncrypted(host, port); ((QSslSocket *) socket)->connectToHostEncrypted(host, port);
break; break;
} }
@ -171,10 +173,10 @@ bool SmtpClient::connectToHost() {
return false; return false;
}; };
((QSslSocket *)socket)->startClientEncryption(); ((QSslSocket *) socket)->startClientEncryption();
if (!((QSslSocket *)socket)->waitForEncrypted(connectionTimeout)) { if (!((QSslSocket *) socket)->waitForEncrypted(connectionTimeout)) {
qDebug() << ((QSslSocket *)socket)->errorString(); qDebug() << ((QSslSocket *) socket)->errorString();
emit smtpError(ConnectionTimeoutError); emit smtpError(ConnectionTimeoutError);
return false; return false;
} }
@ -209,9 +211,9 @@ bool SmtpClient::login(const QString &user, const QString &password,
if (method == AuthPlain) { if (method == AuthPlain) {
// Sending command: AUTH PLAIN base64('\0' + username + '\0' + password) // Sending command: AUTH PLAIN base64('\0' + username + '\0' + password)
sendMessage("AUTH PLAIN " + QByteArray() sendMessage("AUTH PLAIN " + QByteArray()
.append((char)0) .append((char) 0)
.append(user.toUtf8()) .append(user.toUtf8())
.append((char)0) .append((char) 0)
.append(password.toUtf8()) .append(password.toUtf8())
.toBase64()); .toBase64());
@ -369,7 +371,7 @@ void SmtpClient::waitForResponse() {
responseText = socket->readLine(); responseText = socket->readLine();
// Extract the respose code from the server's responce (first 3 digits) // Extract the respose code from the server's responce (first 3 digits)
responseCode = responseText.left(3).toInt(); responseCode = responseText.leftRef(3).toInt();
if (responseCode / 100 == 4) if (responseCode / 100 == 4)
emit smtpError(ServerError); emit smtpError(ServerError);