diff --git a/src/mimemessage.cpp b/src/mimemessage.cpp index 14a76c7..f156363 100644 --- a/src/mimemessage.cpp +++ b/src/mimemessage.cpp @@ -140,107 +140,117 @@ const QList & MimeMessage::getParts() const QString MimeMessage::toString() { - QString mime; + QString mimeString; + QTextStream out(&mimeString); + writeToStream(out); + return mimeString; +} +void MimeMessage::writeToStream(QTextStream &out) { /* =========== MIME HEADER ============ */ /* ---------- Sender / From ----------- */ - mime = "From:"; + out << "From:"; if (sender->getName() != "") { switch (hEncoding) { case MimePart::Base64: - mime += " =?utf-8?B?" + QByteArray().append(sender->getName()).toBase64() + "?="; + out << " =?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") + "?="; + out << " =?utf-8?Q?" + QuotedPrintable::encode(QByteArray().append(sender->getName())).replace(' ', "_").replace(':',"=3A") + "?="; break; default: - mime += " " + sender->getName(); + out << " " + sender->getName(); } } - mime += " <" + sender->getAddress() + ">\r\n"; + out << " <" + sender->getAddress() + ">\r\n"; /* ---------------------------------- */ - - /* ------- Recipients / To ---------- */ - mime += "To:"; + /* ------- Recipients / To ---------- */ + out << "To:"; QList::iterator it; int i; for (i = 0, it = recipientsTo.begin(); it != recipientsTo.end(); ++it, ++i) { - if (i != 0) { mime += ","; } + if (i != 0) { out << ","; } if ((*it)->getName() != "") { switch (hEncoding) { case MimePart::Base64: - mime += " =?utf-8?B?" + QByteArray().append((*it)->getName()).toBase64() + "?="; + out << " =?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") + "?="; + out << " =?utf-8?Q?" + QuotedPrintable::encode(QByteArray().append((*it)->getName())).replace(' ', "_").replace(':',"=3A") + "?="; break; default: - mime += " " + (*it)->getName(); + out << " " + (*it)->getName(); } } - mime += " <" + (*it)->getAddress() + ">"; + out << " <" + (*it)->getAddress() + ">"; } - mime += "\r\n"; + out << "\r\n"; /* ---------------------------------- */ /* ------- Recipients / Cc ---------- */ if (recipientsCc.size() != 0) { - mime += "Cc:"; + out << "Cc:"; } for (i = 0, it = recipientsCc.begin(); it != recipientsCc.end(); ++it, ++i) { - if (i != 0) { mime += ","; } + if (i != 0) { out << ","; } if ((*it)->getName() != "") { switch (hEncoding) { case MimePart::Base64: - mime += " =?utf-8?B?" + QByteArray().append((*it)->getName()).toBase64() + "?="; + out << " =?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") + "?="; + out << " =?utf-8?Q?" + QuotedPrintable::encode(QByteArray().append((*it)->getName())).replace(' ', "_").replace(':',"=3A") + "?="; break; default: - mime += " " + (*it)->getName(); + out << " " + (*it)->getName(); } } - mime += " <" + (*it)->getAddress() + ">"; + out << " <" + (*it)->getAddress() + ">"; } if (recipientsCc.size() != 0) { - mime += "\r\n"; + out << "\r\n"; } /* ---------------------------------- */ /* ------------ Subject ------------- */ - mime += "Subject: "; + out << "Subject: "; switch (hEncoding) { case MimePart::Base64: - mime += "=?utf-8?B?" + QByteArray().append(subject).toBase64() + "?="; + out << "=?utf-8?B?" + QByteArray().append(subject).toBase64() + "?="; break; case MimePart::QuotedPrintable: - mime += "=?utf-8?Q?" + QuotedPrintable::encode(QByteArray().append(subject)).replace(' ', "_").replace(':',"=3A") + "?="; + out << "=?utf-8?Q?" + QuotedPrintable::encode(QByteArray().append(subject)).replace(' ', "_").replace(':',"=3A") + "?="; break; default: - mime += subject; + out << subject; } /* ---------------------------------- */ - mime += "\r\n"; - mime += "MIME-Version: 1.0\r\n"; + out << "\r\n"; + out << "MIME-Version: 1.0\r\n"; - mime += content->toString(); - return mime; + out << content->toString(); } +void MimeMessage::writeToDevice(QIODevice &device) { + QTextStream out (&device); + writeToStream(out); + out.flush(); +} + + /* [3] --- */ diff --git a/src/mimemessage.h b/src/mimemessage.h index d0297d1..d136756 100644 --- a/src/mimemessage.h +++ b/src/mimemessage.h @@ -23,6 +23,7 @@ #include "mimemultipart.h" #include "emailaddress.h" #include +#include class MimeMessage : public QObject { @@ -67,6 +68,8 @@ public: /* [3] Public methods */ virtual QString toString(); + virtual void writeToStream(QTextStream &stream); + virtual void writeToDevice(QIODevice &device); /* [3] --- */