Messagelib

multipartjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Constantin Berzan <[email protected]>
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 
14 using namespace MessageComposer;
15 
16 class MessageComposer::MultipartJobPrivate : public ContentJobBasePrivate
17 {
18 public:
19  MultipartJobPrivate(MultipartJob *qq)
20  : ContentJobBasePrivate(qq)
21  {
22  }
23 
24  QByteArray subtype;
25 };
26 
27 MultipartJob::MultipartJob(QObject *parent)
28  : ContentJobBase(*new MultipartJobPrivate(this), parent)
29 {
30 }
31 
32 MultipartJob::~MultipartJob() = default;
33 
34 QByteArray MultipartJob::multipartSubtype() const
35 {
36  Q_D(const MultipartJob);
37  return d->subtype;
38 }
39 
40 void MultipartJob::setMultipartSubtype(const QByteArray &subtype)
41 {
42  Q_D(MultipartJob);
43  d->subtype = subtype;
44 }
45 
46 void MultipartJob::process()
47 {
48  Q_D(MultipartJob);
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->addContent(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 }
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
The MultipartJob class.
Definition: multipartjob.h:19
The ContentJobBase class.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Dec 5 2021 23:04:54 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.