Messagelib

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

KDE's Doxygen guidelines are available online.