commit
12c810ada9
@ -16,8 +16,6 @@ TEMPLATE = lib
|
|||||||
DEFINES += SMTP_BUILD
|
DEFINES += SMTP_BUILD
|
||||||
win32:CONFIG += dll
|
win32:CONFIG += dll
|
||||||
|
|
||||||
QMAKE_CXXFLAGS += -fPIC
|
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
src/emailaddress.cpp \
|
src/emailaddress.cpp \
|
||||||
src/mimeattachment.cpp \
|
src/mimeattachment.cpp \
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
/* [1] Constructors and Destructors */
|
/* [1] Constructors and Destructors */
|
||||||
MimeMessage::MimeMessage(bool createAutoMimeContent) :
|
MimeMessage::MimeMessage(bool createAutoMimeContent) :
|
||||||
|
replyTo(Q_NULLPTR),
|
||||||
hEncoding(MimePart::_8Bit)
|
hEncoding(MimePart::_8Bit)
|
||||||
{
|
{
|
||||||
if (createAutoMimeContent)
|
if (createAutoMimeContent)
|
||||||
@ -58,6 +59,10 @@ void MimeMessage::setContent(MimePart *content) {
|
|||||||
this->content = content;
|
this->content = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MimeMessage::setReplyTo(EmailAddress* rto) {
|
||||||
|
replyTo = rto;
|
||||||
|
}
|
||||||
|
|
||||||
void MimeMessage::setSender(EmailAddress* e)
|
void MimeMessage::setSender(EmailAddress* e)
|
||||||
{
|
{
|
||||||
this->sender = e;
|
this->sender = e;
|
||||||
@ -127,6 +132,10 @@ const QList<EmailAddress*> & MimeMessage::getRecipients(RecipientType type) cons
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const EmailAddress* MimeMessage::getReplyTo() const {
|
||||||
|
return replyTo;
|
||||||
|
}
|
||||||
|
|
||||||
const QString & MimeMessage::getSubject() const
|
const QString & MimeMessage::getSubject() const
|
||||||
{
|
{
|
||||||
return subject;
|
return subject;
|
||||||
@ -245,9 +254,31 @@ QString MimeMessage::toString()
|
|||||||
default:
|
default:
|
||||||
mime += subject;
|
mime += subject;
|
||||||
}
|
}
|
||||||
|
mime += "\r\n";
|
||||||
|
/* ---------------------------------- */
|
||||||
|
|
||||||
|
/* ---------- Reply-To -------------- */
|
||||||
|
if (replyTo) {
|
||||||
|
mime += "Reply-To: ";
|
||||||
|
if (replyTo->getName() != "")
|
||||||
|
{
|
||||||
|
switch (hEncoding)
|
||||||
|
{
|
||||||
|
case MimePart::Base64:
|
||||||
|
mime += " =?utf-8?B?" + QByteArray().append(replyTo->getName()).toBase64() + "?=";
|
||||||
|
break;
|
||||||
|
case MimePart::QuotedPrintable:
|
||||||
|
mime += " =?utf-8?Q?" + QuotedPrintable::encode(QByteArray().append(replyTo->getName())).replace(' ', "_").replace(':',"=3A") + "?=";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
mime += " " + replyTo->getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mime += " <" + replyTo->getAddress() + ">\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
/* ---------------------------------- */
|
/* ---------------------------------- */
|
||||||
|
|
||||||
mime += "\r\n";
|
|
||||||
mime += "MIME-Version: 1.0\r\n";
|
mime += "MIME-Version: 1.0\r\n";
|
||||||
|
|
||||||
mime += content->toString();
|
mime += content->toString();
|
||||||
|
@ -53,6 +53,7 @@ public:
|
|||||||
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 setHeaderEncoding(MimePart::Encoding);
|
void setHeaderEncoding(MimePart::Encoding);
|
||||||
|
|
||||||
@ -60,6 +61,7 @@ public:
|
|||||||
const QList<EmailAddress*> & getRecipients(RecipientType type = To) const;
|
const QList<EmailAddress*> & getRecipients(RecipientType type = To) const;
|
||||||
const QString & getSubject() const;
|
const QString & getSubject() const;
|
||||||
const QList<MimePart*> & getParts() const;
|
const QList<MimePart*> & getParts() const;
|
||||||
|
const EmailAddress* getReplyTo() const;
|
||||||
|
|
||||||
MimePart& getContent();
|
MimePart& getContent();
|
||||||
void setContent(MimePart *content);
|
void setContent(MimePart *content);
|
||||||
@ -77,6 +79,7 @@ protected:
|
|||||||
/* [4] Protected members */
|
/* [4] Protected members */
|
||||||
|
|
||||||
EmailAddress* sender;
|
EmailAddress* sender;
|
||||||
|
EmailAddress* replyTo;
|
||||||
QList<EmailAddress*> recipientsTo, recipientsCc, recipientsBcc;
|
QList<EmailAddress*> recipientsTo, recipientsCc, recipientsBcc;
|
||||||
QString subject;
|
QString subject;
|
||||||
MimePart *content;
|
MimePart *content;
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
/* [1] Constructors and destructors */
|
/* [1] Constructors and destructors */
|
||||||
|
|
||||||
SmtpClient::SmtpClient(const QString & host, int port, ConnectionType connectionType) :
|
SmtpClient::SmtpClient(const QString & host, int port, ConnectionType connectionType) :
|
||||||
|
socket(NULL),
|
||||||
name("localhost"),
|
name("localhost"),
|
||||||
authMethod(AuthPlain),
|
authMethod(AuthPlain),
|
||||||
connectionTimeout(5000),
|
connectionTimeout(5000),
|
||||||
@ -44,7 +45,10 @@ SmtpClient::SmtpClient(const QString & host, int port, ConnectionType connection
|
|||||||
this, SLOT(socketReadyRead()));
|
this, SLOT(socketReadyRead()));
|
||||||
}
|
}
|
||||||
|
|
||||||
SmtpClient::~SmtpClient() {}
|
SmtpClient::~SmtpClient() {
|
||||||
|
if (socket)
|
||||||
|
delete socket;
|
||||||
|
}
|
||||||
|
|
||||||
/* [1] --- */
|
/* [1] --- */
|
||||||
|
|
||||||
@ -80,6 +84,9 @@ void SmtpClient::setConnectionType(ConnectionType ct)
|
|||||||
{
|
{
|
||||||
this->connectionType = ct;
|
this->connectionType = ct;
|
||||||
|
|
||||||
|
if (socket)
|
||||||
|
delete socket;
|
||||||
|
|
||||||
switch (connectionType)
|
switch (connectionType)
|
||||||
{
|
{
|
||||||
case TcpConnection:
|
case TcpConnection:
|
||||||
@ -325,7 +332,7 @@ bool SmtpClient::login(const QString &user, const QString &password, AuthMethod
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (ResponseTimeoutException e)
|
catch (ResponseTimeoutException)
|
||||||
{
|
{
|
||||||
// Responce Timeout exceeded
|
// Responce Timeout exceeded
|
||||||
emit smtpError(AuthenticationFailedError);
|
emit smtpError(AuthenticationFailedError);
|
||||||
@ -421,7 +428,7 @@ void SmtpClient::quit()
|
|||||||
|
|
||||||
/* [4] Protected methods */
|
/* [4] Protected methods */
|
||||||
|
|
||||||
void SmtpClient::waitForResponse() throw (ResponseTimeoutException)
|
void SmtpClient::waitForResponse()
|
||||||
{
|
{
|
||||||
do {
|
do {
|
||||||
if (!socket->waitForReadyRead(responseTimeout))
|
if (!socket->waitForReadyRead(responseTimeout))
|
||||||
@ -448,7 +455,7 @@ void SmtpClient::waitForResponse() throw (ResponseTimeoutException)
|
|||||||
} while (true);
|
} while (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SmtpClient::sendMessage(const QString &text) throw (SendMessageTimeoutException)
|
void SmtpClient::sendMessage(const QString &text)
|
||||||
{
|
{
|
||||||
socket->write(text.toUtf8() + "\r\n");
|
socket->write(text.toUtf8() + "\r\n");
|
||||||
if (! socket->waitForBytesWritten(sendMessageTimeout))
|
if (! socket->waitForBytesWritten(sendMessageTimeout))
|
||||||
@ -463,11 +470,11 @@ void SmtpClient::sendMessage(const QString &text) throw (SendMessageTimeoutExcep
|
|||||||
|
|
||||||
/* [5] Slots for the socket's signals */
|
/* [5] Slots for the socket's signals */
|
||||||
|
|
||||||
void SmtpClient::socketStateChanged(QAbstractSocket::SocketState state)
|
void SmtpClient::socketStateChanged(QAbstractSocket::SocketState /*state*/)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void SmtpClient::socketError(QAbstractSocket::SocketError socketError)
|
void SmtpClient::socketError(QAbstractSocket::SocketError /*socketError*/)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ public:
|
|||||||
|
|
||||||
/* [1] Constructors and Destructors */
|
/* [1] Constructors and Destructors */
|
||||||
|
|
||||||
SmtpClient(const QString & host = "locahost", int port = 25, ConnectionType ct = TcpConnection);
|
SmtpClient(const QString & host = "localhost", int port = 25, ConnectionType ct = TcpConnection);
|
||||||
|
|
||||||
~SmtpClient();
|
~SmtpClient();
|
||||||
|
|
||||||
@ -154,9 +154,9 @@ protected:
|
|||||||
|
|
||||||
/* [5] Protected methods */
|
/* [5] Protected methods */
|
||||||
|
|
||||||
void waitForResponse() throw (ResponseTimeoutException);
|
void waitForResponse();
|
||||||
|
|
||||||
void sendMessage(const QString &text) throw (SendMessageTimeoutException);
|
void sendMessage(const QString &text);
|
||||||
|
|
||||||
/* [5] --- */
|
/* [5] --- */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user