blob: 4dd00d1a3e0cebafc78ec90a476838f34afca0c2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
/*
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.
*/
#include "smtp/mimemultipart.h"
#include <QCryptographicHash>
#include <QRandomGenerator>
#include <QTime>
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;
QRandomGenerator generator;
QCryptographicHash md5(QCryptographicHash::Md5);
md5.addData(QByteArray().append((char)generator.generate()));
cBoundary = md5.result().toHex();
}
void MimeMultiPart::addPart(MimePart *part) { parts.append(part); }
const QList<MimePart *> &MimeMultiPart::getParts() const { return parts; }
void MimeMultiPart::prepare() {
QList<MimePart *>::iterator it;
content.clear();
for (it = parts.begin(); it != parts.end(); it++) {
content += QString("--" + cBoundary + "\r\n").toUtf8();
(*it)->prepare();
content += (*it)->toString().toUtf8();
};
content += QString("--" + cBoundary + "--\r\n").toUtf8();
MimePart::prepare();
}
void MimeMultiPart::setMimeType(const MultiPartType type) {
this->type = type;
this->cType = MULTI_PART_NAMES[type];
}
MimeMultiPart::MultiPartType MimeMultiPart::getMimeType() const { return type; }
|