Messagelib

attachmentfrommimecontentjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Constantin Berzan <[email protected]>
3 
4  Based on KMail code by:
5  SPDX-FileCopyrightText: 1997 Markus Wuebben <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #include "attachmentfrommimecontentjob.h"
11 
12 #include "messagecore_debug.h"
13 #include <KMime/Content>
14 
15 using namespace MessageCore;
16 using KMime::Content;
17 
18 class Q_DECL_HIDDEN MessageCore::AttachmentFromMimeContentJob::AttachmentFromMimeContentJobPrivate
19 {
20 public:
21  const Content *mMimeContent = nullptr;
22 };
23 
25  : AttachmentLoadJob(parent)
26  , d(new AttachmentFromMimeContentJobPrivate)
27 {
28  d->mMimeContent = content;
29 }
30 
32 
34 {
35  return d->mMimeContent;
36 }
37 
39 {
40  d->mMimeContent = content;
41 }
42 
43 void AttachmentFromMimeContentJob::doStart()
44 {
45  // Create the AttachmentPart.
46  Q_ASSERT(attachmentPart() == nullptr);
47 
49  auto content = const_cast<Content *>(d->mMimeContent);
50  part->setData(content->decodedContent());
51 
52  // Get the details from the MIME headers.
53  if (auto ct = content->contentType(false)) {
54  part->setMimeType(ct->mimeType());
55  part->setName(ct->name());
56  }
57 
58  if (auto ct = content->contentTransferEncoding(false)) {
59  part->setEncoding(ct->encoding());
60  }
61 
62  if (auto ct = content->contentDisposition(false)) {
63  part->setFileName(ct->filename());
64  part->setInline(ct->disposition() == KMime::Headers::CDinline);
65  }
66 
67  if (auto ct = content->contentDescription(false)) {
68  part->setDescription(ct->asUnicodeString());
69  }
70 
71  setAttachmentPart(part);
72  emitResult(); // Success.
73 }
const KMime::Content * mimeContent() const
Returns the mime content to load the attachment from.
void emitResult()
A base class for jobs to load attachments from different sources.
void setMimeContent(const KMime::Content *content)
Sets the mime content to load the attachment from.
AttachmentFromMimeContentJob(const KMime::Content *content, QObject *parent=nullptr)
Creates a new job.
A class that encapsulates an attachment.
~AttachmentFromMimeContentJob() override
Destroys the job.
QSharedPointer< AttachmentPart > Ptr
Defines a pointer to an attachment object.
void setAttachmentPart(const AttachmentPart::Ptr &part)
Subclasses use this method to set the loaded part.
AttachmentPart::Ptr attachmentPart() const
Returns the loaded attachment.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Nov 26 2021 23:16:41 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.