Repair and adjust the SMTP library.
This commit is contained in:
parent
a0b5b56e8f
commit
39acbb05c1
@ -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);
|
void setAddress(const QString &address);
|
||||||
|
|
||||||
const QString & getName() const;
|
[[nodiscard]] const QString &getName() const;
|
||||||
const QString & getAddress() const;
|
|
||||||
|
[[nodiscard]] const QString &getAddress() const;
|
||||||
|
|
||||||
/* [2] --- */
|
/* [2] --- */
|
||||||
|
|
||||||
|
@ -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(const QByteArray &stream, const QString &fileName);
|
||||||
|
|
||||||
~MimeAttachment();
|
~MimeAttachment() override;
|
||||||
|
|
||||||
/* [1] --- */
|
/* [1] --- */
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ protected:
|
|||||||
|
|
||||||
/* [2] Protected methods */
|
/* [2] Protected methods */
|
||||||
|
|
||||||
virtual void prepare();
|
void prepare() override;
|
||||||
|
|
||||||
/* [2] --- */
|
/* [2] --- */
|
||||||
};
|
};
|
||||||
|
@ -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;
|
||||||
|
@ -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] --- */
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ protected:
|
|||||||
|
|
||||||
/* [4] Protected methods */
|
/* [4] Protected methods */
|
||||||
|
|
||||||
virtual void prepare();
|
void prepare() override;
|
||||||
|
|
||||||
/* [4] --- */
|
/* [4] --- */
|
||||||
|
|
||||||
|
@ -23,15 +23,15 @@
|
|||||||
|
|
||||||
#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] --- */
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ public:
|
|||||||
|
|
||||||
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] --- */
|
||||||
};
|
};
|
||||||
|
@ -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] --- */
|
||||||
};
|
};
|
||||||
|
@ -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,8 +37,9 @@ public:
|
|||||||
|
|
||||||
/* [1] Constructors and Destructors */
|
/* [1] Constructors and Destructors */
|
||||||
|
|
||||||
MimeMessage(bool createAutoMimeConent = true);
|
explicit MimeMessage(bool createAutoMimeConent = true);
|
||||||
~MimeMessage();
|
|
||||||
|
~MimeMessage() override;
|
||||||
|
|
||||||
/* [1] --- */
|
/* [1] --- */
|
||||||
|
|
||||||
@ -47,25 +47,37 @@ public:
|
|||||||
/* [2] Getters and Setters */
|
/* [2] Getters and Setters */
|
||||||
|
|
||||||
void setSender(EmailAddress *e);
|
void setSender(EmailAddress *e);
|
||||||
|
|
||||||
void addRecipient(EmailAddress *rcpt, RecipientType type = To);
|
void addRecipient(EmailAddress *rcpt, RecipientType type = To);
|
||||||
|
|
||||||
void addTo(EmailAddress *rcpt);
|
void addTo(EmailAddress *rcpt);
|
||||||
|
|
||||||
void addCc(EmailAddress *rcpt);
|
void addCc(EmailAddress *rcpt);
|
||||||
|
|
||||||
void addBcc(EmailAddress *rcpt);
|
void addBcc(EmailAddress *rcpt);
|
||||||
|
|
||||||
void setSubject(const QString &subject);
|
void setSubject(const QString &subject);
|
||||||
|
|
||||||
void addPart(MimePart *part);
|
void addPart(MimePart *part);
|
||||||
|
|
||||||
void setReplyTo(EmailAddress *rto);
|
void setReplyTo(EmailAddress *rto);
|
||||||
|
|
||||||
void setInReplyTo(const QString &inReplyTo);
|
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,7 +92,7 @@ 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;
|
||||||
|
@ -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] --- */
|
||||||
|
|
||||||
|
@ -28,41 +28,51 @@ 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();
|
||||||
|
|
||||||
|
@ -23,14 +23,14 @@
|
|||||||
|
|
||||||
#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] --- */
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ public:
|
|||||||
|
|
||||||
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] --- */
|
||||||
|
|
||||||
|
@ -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:
|
||||||
|
@ -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,46 +56,57 @@ 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();
|
||||||
@ -113,6 +120,7 @@ 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);
|
||||||
@ -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] --- */
|
||||||
|
@ -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
|
||||||
|
@ -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] --- */
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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] --- */
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
MimeInlineFile::MimeInlineFile(QFile *f) : MimeFile(f) {}
|
MimeInlineFile::MimeInlineFile(QFile *f) : MimeFile(f) {}
|
||||||
|
|
||||||
MimeInlineFile::~MimeInlineFile() {}
|
MimeInlineFile::~MimeInlineFile() = default;
|
||||||
|
|
||||||
/* [1] --- */
|
/* [1] --- */
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ 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";
|
||||||
}
|
}
|
||||||
/* ---------------------------------- */
|
/* ---------------------------------- */
|
||||||
|
@ -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); }
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ MimePart::MimePart() {
|
|||||||
cBoundary = "";
|
cBoundary = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
MimePart::~MimePart() { return; }
|
MimePart::~MimePart() = default;
|
||||||
|
|
||||||
/* [1] --- */
|
/* [1] --- */
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ MimeText::MimeText(const QString &txt) {
|
|||||||
this->cEncoding = _8Bit;
|
this->cEncoding = _8Bit;
|
||||||
}
|
}
|
||||||
|
|
||||||
MimeText::~MimeText() {}
|
MimeText::~MimeText() = default;
|
||||||
|
|
||||||
/* [1] --- */
|
/* [1] --- */
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
@ -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] --- */
|
||||||
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user