First step of stream based implementation.
This commit is contained in:
parent
28666c2603
commit
24ca613e47
@ -140,107 +140,117 @@ const QList<MimePart*> & MimeMessage::getParts() const
|
|||||||
|
|
||||||
QString MimeMessage::toString()
|
QString MimeMessage::toString()
|
||||||
{
|
{
|
||||||
QString mime;
|
QString mimeString;
|
||||||
|
QTextStream out(&mimeString);
|
||||||
|
writeToStream(out);
|
||||||
|
return mimeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MimeMessage::writeToStream(QTextStream &out) {
|
||||||
/* =========== MIME HEADER ============ */
|
/* =========== MIME HEADER ============ */
|
||||||
|
|
||||||
/* ---------- Sender / From ----------- */
|
/* ---------- Sender / From ----------- */
|
||||||
mime = "From:";
|
out << "From:";
|
||||||
if (sender->getName() != "")
|
if (sender->getName() != "")
|
||||||
{
|
{
|
||||||
switch (hEncoding)
|
switch (hEncoding)
|
||||||
{
|
{
|
||||||
case MimePart::Base64:
|
case MimePart::Base64:
|
||||||
mime += " =?utf-8?B?" + QByteArray().append(sender->getName()).toBase64() + "?=";
|
out << " =?utf-8?B?" + QByteArray().append(sender->getName()).toBase64() + "?=";
|
||||||
break;
|
break;
|
||||||
case MimePart::QuotedPrintable:
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
mime += " " + sender->getName();
|
out << " " + sender->getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mime += " <" + sender->getAddress() + ">\r\n";
|
out << " <" + sender->getAddress() + ">\r\n";
|
||||||
/* ---------------------------------- */
|
/* ---------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
/* ------- Recipients / To ---------- */
|
/* ------- Recipients / To ---------- */
|
||||||
mime += "To:";
|
out << "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)
|
||||||
{
|
{
|
||||||
if (i != 0) { mime += ","; }
|
if (i != 0) { out << ","; }
|
||||||
|
|
||||||
if ((*it)->getName() != "")
|
if ((*it)->getName() != "")
|
||||||
{
|
{
|
||||||
switch (hEncoding)
|
switch (hEncoding)
|
||||||
{
|
{
|
||||||
case MimePart::Base64:
|
case MimePart::Base64:
|
||||||
mime += " =?utf-8?B?" + QByteArray().append((*it)->getName()).toBase64() + "?=";
|
out << " =?utf-8?B?" + QByteArray().append((*it)->getName()).toBase64() + "?=";
|
||||||
break;
|
break;
|
||||||
case MimePart::QuotedPrintable:
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
mime += " " + (*it)->getName();
|
out << " " + (*it)->getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mime += " <" + (*it)->getAddress() + ">";
|
out << " <" + (*it)->getAddress() + ">";
|
||||||
}
|
}
|
||||||
mime += "\r\n";
|
out << "\r\n";
|
||||||
/* ---------------------------------- */
|
/* ---------------------------------- */
|
||||||
|
|
||||||
/* ------- Recipients / Cc ---------- */
|
/* ------- Recipients / Cc ---------- */
|
||||||
if (recipientsCc.size() != 0) {
|
if (recipientsCc.size() != 0) {
|
||||||
mime += "Cc:";
|
out << "Cc:";
|
||||||
}
|
}
|
||||||
for (i = 0, it = recipientsCc.begin(); it != recipientsCc.end(); ++it, ++i)
|
for (i = 0, it = recipientsCc.begin(); it != recipientsCc.end(); ++it, ++i)
|
||||||
{
|
{
|
||||||
if (i != 0) { mime += ","; }
|
if (i != 0) { out << ","; }
|
||||||
|
|
||||||
if ((*it)->getName() != "")
|
if ((*it)->getName() != "")
|
||||||
{
|
{
|
||||||
switch (hEncoding)
|
switch (hEncoding)
|
||||||
{
|
{
|
||||||
case MimePart::Base64:
|
case MimePart::Base64:
|
||||||
mime += " =?utf-8?B?" + QByteArray().append((*it)->getName()).toBase64() + "?=";
|
out << " =?utf-8?B?" + QByteArray().append((*it)->getName()).toBase64() + "?=";
|
||||||
break;
|
break;
|
||||||
case MimePart::QuotedPrintable:
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
mime += " " + (*it)->getName();
|
out << " " + (*it)->getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mime += " <" + (*it)->getAddress() + ">";
|
out << " <" + (*it)->getAddress() + ">";
|
||||||
}
|
}
|
||||||
if (recipientsCc.size() != 0) {
|
if (recipientsCc.size() != 0) {
|
||||||
mime += "\r\n";
|
out << "\r\n";
|
||||||
}
|
}
|
||||||
/* ---------------------------------- */
|
/* ---------------------------------- */
|
||||||
|
|
||||||
/* ------------ Subject ------------- */
|
/* ------------ Subject ------------- */
|
||||||
mime += "Subject: ";
|
out << "Subject: ";
|
||||||
|
|
||||||
|
|
||||||
switch (hEncoding)
|
switch (hEncoding)
|
||||||
{
|
{
|
||||||
case MimePart::Base64:
|
case MimePart::Base64:
|
||||||
mime += "=?utf-8?B?" + QByteArray().append(subject).toBase64() + "?=";
|
out << "=?utf-8?B?" + QByteArray().append(subject).toBase64() + "?=";
|
||||||
break;
|
break;
|
||||||
case MimePart::QuotedPrintable:
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
mime += subject;
|
out << subject;
|
||||||
}
|
}
|
||||||
/* ---------------------------------- */
|
/* ---------------------------------- */
|
||||||
|
|
||||||
mime += "\r\n";
|
out << "\r\n";
|
||||||
mime += "MIME-Version: 1.0\r\n";
|
out << "MIME-Version: 1.0\r\n";
|
||||||
|
|
||||||
mime += content->toString();
|
out << content->toString();
|
||||||
return mime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MimeMessage::writeToDevice(QIODevice &device) {
|
||||||
|
QTextStream out (&device);
|
||||||
|
writeToStream(out);
|
||||||
|
out.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* [3] --- */
|
/* [3] --- */
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "mimemultipart.h"
|
#include "mimemultipart.h"
|
||||||
#include "emailaddress.h"
|
#include "emailaddress.h"
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QTextStream>
|
||||||
|
|
||||||
class MimeMessage : public QObject
|
class MimeMessage : public QObject
|
||||||
{
|
{
|
||||||
@ -67,6 +68,8 @@ public:
|
|||||||
/* [3] Public methods */
|
/* [3] Public methods */
|
||||||
|
|
||||||
virtual QString toString();
|
virtual QString toString();
|
||||||
|
virtual void writeToStream(QTextStream &stream);
|
||||||
|
virtual void writeToDevice(QIODevice &device);
|
||||||
|
|
||||||
/* [3] --- */
|
/* [3] --- */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user