Added Reply-To support

This commit is contained in:
Cedric HT 2016-01-13 15:31:25 +01:00
parent 48c080b9ee
commit c2a734791a
2 changed files with 38 additions and 4 deletions

View File

@ -24,11 +24,12 @@
/* [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)
this->content = new MimeMultiPart(); this->content = new MimeMultiPart();
autoMimeContentCreated = createAutoMimeContent; autoMimeContentCreated = 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;
@ -175,7 +184,7 @@ QString MimeMessage::toString()
/* ---------------------------------- */ /* ---------------------------------- */
/* ------- Recipients / To ---------- */ /* ------- Recipients / To ---------- */
mime += "To:"; mime += "To:";
QList<EmailAddress*>::iterator it; int i; QList<EmailAddress*>::iterator it; int i;
for (i = 0, it = recipientsTo.begin(); it != recipientsTo.end(); ++it, ++i) for (i = 0, it = recipientsTo.begin(); it != recipientsTo.end(); ++it, ++i)
@ -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();

View File

@ -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,11 +79,12 @@ 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;
bool autoMimeContentCreated; bool autoMimeContentCreated;
MimePart::Encoding hEncoding; MimePart::Encoding hEncoding;
/* [4] --- */ /* [4] --- */