Messagelib

multipartjob.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Constantin Berzan <exit3219@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "job/multipartjob.h"
8#include "contentjobbase_p.h"
9
10#include "messagecomposer_debug.h"
11
12#include <KMime/Content>
13
14using namespace MessageComposer;
15
16class MessageComposer::MultipartJobPrivate : public ContentJobBasePrivate
17{
18public:
19 MultipartJobPrivate(MultipartJob *qq)
20 : ContentJobBasePrivate(qq)
21 {
22 }
23
24 QByteArray subtype;
25};
26
27MultipartJob::MultipartJob(QObject *parent)
28 : ContentJobBase(*new MultipartJobPrivate(this), parent)
29{
30}
31
32MultipartJob::~MultipartJob() = default;
33
34QByteArray MultipartJob::multipartSubtype() const
35{
36 Q_D(const MultipartJob);
37 return d->subtype;
38}
39
40void MultipartJob::setMultipartSubtype(const QByteArray &subtype)
41{
43 d->subtype = subtype;
44}
45
46void MultipartJob::process()
47{
49 Q_ASSERT(d->resultContent == nullptr); // Not processed before.
50 Q_ASSERT(!d->subtype.isEmpty());
51 d->resultContent = new KMime::Content;
52 auto contentType = d->resultContent->contentType(true);
53 contentType->setMimeType("multipart/" + d->subtype);
54 contentType->setBoundary(KMime::multiPartBoundary());
55 d->resultContent->contentTransferEncoding()->setEncoding(KMime::Headers::CE7Bit);
56 d->resultContent->setPreamble("This is a multi-part message in MIME format.\n");
57 for (KMime::Content *c : std::as_const(d->subjobContents)) {
58 d->resultContent->appendContent(c);
59 if (c->contentTransferEncoding()->encoding() == KMime::Headers::CE8Bit) {
60 d->resultContent->contentTransferEncoding()->setEncoding(KMime::Headers::CE8Bit);
61 break;
62 }
63 }
64 qCDebug(MESSAGECOMPOSER_LOG) << "Created" << d->resultContent->contentType()->mimeType() << "content with" << d->resultContent->contents().count()
65 << "subjobContents.";
66 emitResult();
67}
68
69#include "moc_multipartjob.cpp"
void emitResult()
const Headers::ContentType * contentType() const
void setMimeType(const QByteArray &mimeType)
The ContentJobBase class.
The MultipartJob class.
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:05:10 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.