2012-07-24 14:06:55 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2011-2012 - Tőkés Attila
|
|
|
|
|
|
|
|
This file is part of SmtpClient for Qt.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
See the LICENSE file for more details.
|
|
|
|
*/
|
|
|
|
|
2012-07-23 18:01:08 +00:00
|
|
|
#include "mimemultipart.h"
|
|
|
|
#include <QTime>
|
|
|
|
#include <QCryptographicHash>
|
|
|
|
|
|
|
|
const QString MULTI_PART_NAMES[] = {
|
|
|
|
"multipart/mixed", // Mixed
|
|
|
|
"multipart/digest", // Digest
|
|
|
|
"multipart/alternative", // Alternative
|
|
|
|
"multipart/related", // Related
|
|
|
|
"multipart/report", // Report
|
|
|
|
"multipart/signed", // Signed
|
|
|
|
"multipart/encrypted" // Encrypted
|
|
|
|
};
|
|
|
|
|
|
|
|
MimeMultiPart::MimeMultiPart(MultiPartType type)
|
|
|
|
{
|
|
|
|
this->type = type;
|
|
|
|
this->cType = MULTI_PART_NAMES[this->type];
|
|
|
|
this->cEncoding = _8Bit;
|
|
|
|
|
|
|
|
QCryptographicHash md5(QCryptographicHash::Md5);
|
|
|
|
md5.addData(QByteArray().append(qrand()));
|
|
|
|
cBoundary = md5.result().toHex();
|
|
|
|
}
|
|
|
|
|
|
|
|
MimeMultiPart::~MimeMultiPart() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void MimeMultiPart::addPart(MimePart *part) {
|
|
|
|
parts.append(part);
|
|
|
|
}
|
|
|
|
|
|
|
|
const QList<MimePart*> & MimeMultiPart::getParts() const {
|
|
|
|
return parts;
|
|
|
|
}
|
|
|
|
|
2012-09-22 17:59:27 +00:00
|
|
|
void MimeMultiPart::writeContent(QIODevice &device) {
|
2012-07-23 18:01:08 +00:00
|
|
|
QList<MimePart*>::iterator it;
|
|
|
|
|
|
|
|
content = "";
|
|
|
|
for (it = parts.begin(); it != parts.end(); it++) {
|
2012-09-22 17:59:27 +00:00
|
|
|
device.write("--" );
|
|
|
|
device.write(cBoundary.toAscii());
|
|
|
|
device.write("\r\n");
|
|
|
|
(*it)->writeToDevice(device);
|
2012-07-23 18:01:08 +00:00
|
|
|
};
|
|
|
|
|
2012-09-22 17:59:27 +00:00
|
|
|
device.write("--");
|
|
|
|
device.write(cBoundary.toAscii());
|
|
|
|
device.write("--\r\n");
|
2012-07-23 18:01:08 +00:00
|
|
|
}
|
2012-08-09 18:15:17 +00:00
|
|
|
|
2012-09-22 17:59:27 +00:00
|
|
|
|
2012-08-09 18:15:17 +00:00
|
|
|
void MimeMultiPart::setMimeType(const MultiPartType type) {
|
|
|
|
this->type = type;
|
2012-08-09 19:17:07 +00:00
|
|
|
this->cType = MULTI_PART_NAMES[type];
|
2012-08-09 18:15:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MimeMultiPart::MultiPartType MimeMultiPart::getMimeType() const {
|
|
|
|
return type;
|
|
|
|
}
|