The header's encoding can be now selected.
The subject, sender's and the recipient's names can be also ecoded with base64 and quoted-printable. See the MimeMessage::setHeaderEncoding() function.
This commit is contained in:
parent
2b7f475766
commit
735fa2f4dd
@ -17,6 +17,7 @@
|
||||
#include "mimemessage.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include "quotedprintable.h"
|
||||
|
||||
/* [1] Constructors and Destructors */
|
||||
|
||||
@ -54,9 +55,9 @@ void MimeMessage::addPart(MimePart *part)
|
||||
this->parts << part;
|
||||
}
|
||||
|
||||
void MimeMessage::useBase64InHeaders(bool use)
|
||||
void MimeMessage::setHeaderEncoding(MimePart::Encoding hEnc)
|
||||
{
|
||||
this->base64headers = use;
|
||||
this->hEncoding = hEnc;
|
||||
}
|
||||
|
||||
const EmailAddress & MimeMessage::getSender() const
|
||||
@ -87,24 +88,69 @@ const QList<MimePart*> & MimeMessage::getParts() const
|
||||
QString MimeMessage::toString()
|
||||
{
|
||||
QString mime;
|
||||
|
||||
/* =========== MIME HEADER ============ */
|
||||
|
||||
/* ---------- Sender / From ----------- */
|
||||
mime = "From:";
|
||||
mime += (base64headers) ? ("=?utf-8?B?" + QByteArray().append(sender->getName()).toBase64() + "?=")
|
||||
: sender->getName();
|
||||
if (sender->getName() != "")
|
||||
{
|
||||
switch (hEncoding)
|
||||
{
|
||||
case MimePart::Base64:
|
||||
mime += " =?utf-8?B?" + QByteArray().append(sender->getName()).toBase64() + "?=";
|
||||
break;
|
||||
case MimePart::QuotedPrintable:
|
||||
mime += " =?utf-8?Q?" + QuotedPrintable::encode(QByteArray().append(sender->getName())).replace(' ', "_").replace(':',"=3A") + "?=";
|
||||
break;
|
||||
default:
|
||||
mime += " " + sender->getName();
|
||||
}
|
||||
}
|
||||
mime += " <" + sender->getAddress() + ">\n";
|
||||
/* ---------------------------------- */
|
||||
|
||||
|
||||
/* ------- Recipients / To ---------- */
|
||||
QList<EmailAddress*>::iterator it;
|
||||
for (it = recipients.begin(); it != recipients.end(); ++it)
|
||||
{
|
||||
mime += "To:";
|
||||
mime += (base64headers) ? ("=?utf-8?B?" + QByteArray().append((*it)->getName()).toBase64() + "?=")
|
||||
: (*it)->getName();
|
||||
|
||||
if ((*it)->getName() != "")
|
||||
{
|
||||
switch (hEncoding)
|
||||
{
|
||||
case MimePart::Base64:
|
||||
mime += " =?utf-8?B?" + QByteArray().append((*it)->getName()).toBase64() + "?=";
|
||||
break;
|
||||
case MimePart::QuotedPrintable:
|
||||
mime += " =?utf-8?Q?" + QuotedPrintable::encode(QByteArray().append((*it)->getName())).replace(' ', "_").replace(':',"=3A") + "?=";
|
||||
break;
|
||||
default:
|
||||
mime += " " + (*it)->getName();
|
||||
}
|
||||
}
|
||||
mime += " <" + (*it)->getAddress() + ">\n";
|
||||
}
|
||||
/* ---------------------------------- */
|
||||
|
||||
/* ------------ Subject ------------- */
|
||||
mime += "Subject: ";
|
||||
mime += (base64headers) ? ("=?utf-8?B?" + QByteArray().append(subject).toBase64() + "?=")
|
||||
: subject;
|
||||
|
||||
switch (hEncoding)
|
||||
{
|
||||
case MimePart::Base64:
|
||||
mime += "=?utf-8?B?" + QByteArray().append(subject).toBase64() + "?=";
|
||||
break;
|
||||
case MimePart::QuotedPrintable:
|
||||
mime += "=?utf-8?Q?" + QuotedPrintable::encode(QByteArray().append(subject)).replace(' ', "_").replace(':',"=3A") + "?=";
|
||||
break;
|
||||
default:
|
||||
mime += subject;
|
||||
}
|
||||
/* ---------------------------------- */
|
||||
|
||||
mime += "\n";
|
||||
|
||||
QString boundary = "----MIME-part-boundary=" + QByteArray().append(QDateTime::currentDateTime().toString()).toBase64() + "-end";
|
||||
@ -112,14 +158,20 @@ QString MimeMessage::toString()
|
||||
mime += "MIME-Version: 1.0\n";
|
||||
mime += "Content-type: multipart/mixed; boundary=\"" + boundary + "\"\n\n";
|
||||
|
||||
/* ====== END OF MIME HEADER ======== */
|
||||
|
||||
boundary = "--" + boundary;
|
||||
|
||||
/* ========== MIME BODY ============= */
|
||||
|
||||
QList<MimePart*>::iterator i;
|
||||
for (i = parts.begin(); i != parts.end(); ++i)
|
||||
mime += boundary + "\n" + (*i)->toString();
|
||||
|
||||
mime += boundary + "--\n";
|
||||
|
||||
/* ====== END OF MIME BODY ========= */
|
||||
|
||||
return mime;
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ public:
|
||||
void setSubject(const QString & subject);
|
||||
void addPart(MimePart* part);
|
||||
|
||||
void useBase64InHeaders(bool use);
|
||||
void setHeaderEncoding(MimePart::Encoding);
|
||||
|
||||
const EmailAddress & getSender() const;
|
||||
const QList<EmailAddress*> & getRecipients() const;
|
||||
@ -65,7 +65,7 @@ protected:
|
||||
QString subject;
|
||||
QList<MimePart*> parts;
|
||||
|
||||
bool base64headers;
|
||||
MimePart::Encoding hEncoding;
|
||||
|
||||
/* [4] --- */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user