diff --git a/src/mimehtml.cpp b/src/mimehtml.cpp index bd4c5ad..6e0789d 100644 --- a/src/mimehtml.cpp +++ b/src/mimehtml.cpp @@ -21,7 +21,7 @@ MimeHtml::MimeHtml(const QString &html) { this->html = html; - this->encoding = PlainText; + this->encoding = _7Bit; this->charset = "utf-8"; } @@ -73,9 +73,22 @@ void MimeHtml::prepare() + this->charset + "\n"; this->header += "Content-Transfer-Encoding: "; - this->header += (this->encoding == PlainText) ? "7bit\n" : "base64\n"; - this->content = (this->encoding == PlainText) ? this->html.toAscii() : QByteArray().append(this->html).toBase64(); + switch (encoding) + { + case _7Bit: + header += "7bit\n"; + content = this->html.toAscii(); + break; + case _8Bit: + header += "8bit\n"; + content = this->html.toUtf8(); + break; + case Base64: + header += "base64\n"; + content = QByteArray().append(this->html).toBase64(); + } + this->content += "\n"; } diff --git a/src/mimemessage.cpp b/src/mimemessage.cpp index 65ea67a..42b4ada 100644 --- a/src/mimemessage.cpp +++ b/src/mimemessage.cpp @@ -54,6 +54,11 @@ void MimeMessage::addPart(MimePart *part) this->parts << part; } +void MimeMessage::useBase64InHeaders(bool use) +{ + this->base64headers = use; +} + const EmailAddress & MimeMessage::getSender() const { return *sender; @@ -82,13 +87,25 @@ const QList & MimeMessage::getParts() const QString MimeMessage::toString() { QString mime; - mime = "From: " + sender->getName() + " <" + sender->getAddress() + ">\n"; + mime = "From: "; + mime += (base64headers) ? ("=?utf-8?B?" + QByteArray().append(sender->getName()).toBase64() + "?=") + : sender->getName(); + mime += " <" + sender->getAddress() + ">\n"; + QList::iterator it; for (it = recipients.begin(); it != recipients.end(); ++it) - mime += "To: " + (*it)->getName() + " <" + (*it)->getAddress() + ">\n"; + { + mime += "To: "; + mime += (base64headers) ? ("=?utf-8?B?" + QByteArray().append((*it)->getName()).toBase64() + "?=") + : (*it)->getName(); + mime += " <" + (*it)->getAddress() + ">\n"; + } - mime += "Subject: " + subject + "\n"; + mime += "Subject: "; + mime += (base64headers) ? ("=?utf-8?B?" + QByteArray().append(subject).toBase64() + "?=") + : subject; + mime += "\n"; QString boundary = "----MIME-part-boundary=" + QByteArray().append(QDateTime::currentDateTime().toString()).toBase64() + "-end"; diff --git a/src/mimemessage.h b/src/mimemessage.h index d449d0a..9220a99 100644 --- a/src/mimemessage.h +++ b/src/mimemessage.h @@ -40,6 +40,8 @@ public: void setSubject(const QString & subject); void addPart(MimePart* part); + void useBase64InHeaders(bool use); + const EmailAddress & getSender() const; const QList & getRecipients() const; const QString & getSubject() const; @@ -63,6 +65,8 @@ protected: QString subject; QList parts; + bool base64headers; + /* [4] --- */ diff --git a/src/mimepart.cpp b/src/mimepart.cpp index 41cfdeb..00f3c35 100644 --- a/src/mimepart.cpp +++ b/src/mimepart.cpp @@ -65,6 +65,7 @@ const QString& MimePart::getContent() const QString MimePart::toString() { prepare(); + return header + "\n" + content; } diff --git a/src/mimepart.h b/src/mimepart.h index ba9ee43..80d6407 100644 --- a/src/mimepart.h +++ b/src/mimepart.h @@ -27,13 +27,12 @@ public: /* [0] Enumerations */ enum Encoding { - PlainText, Base64, _7Bit, - _8Bit, - QuotedPrintable // not implemented + _8Bit }; + /* [0] --- */ diff --git a/src/mimetext.cpp b/src/mimetext.cpp index 8c34509..dd70024 100644 --- a/src/mimetext.cpp +++ b/src/mimetext.cpp @@ -22,7 +22,7 @@ MimeText::MimeText(const QString &text) { this->text = text; this->charset = "utf-8"; - this->encoding = PlainText; + this->encoding = _7Bit; } MimeText::~MimeText() { } @@ -69,13 +69,26 @@ const QString & MimeText::getCharset() const void MimeText::prepare() { - this->header = "Content-Type: text/plain; charset: " + this->header = "Content-Type: text/plain; charset=" + this->charset + "\n"; this->header += "Content-Transfer-Encoding: "; - this->header += (this->encoding == PlainText) ? "7bit\n" : "base64\n"; - this->content = (this->encoding == PlainText) ? this->text.toAscii() : QByteArray().append(this->text).toBase64(); + switch (encoding) + { + case _7Bit: + header += "7bit\n"; + content = this->text.toAscii(); + break; + case _8Bit: + header += "8bit\n"; + content = this->text.toUtf8(); + break; + case Base64: + header += "base64\n"; + content = QByteArray().append(this->text).toBase64(); + } + this->content += "\n"; }