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
14using namespace MessageCore;
15using KMime::Content;
16
17class Q_DECL_HIDDEN MessageCore::AttachmentFromMimeContentJob::AttachmentFromMimeContentJobPrivate
18{
19public:
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
42void 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
71 emitResult(); // Success.
72}
73
74#include "moc_attachmentfrommimecontentjob.cpp"
void emitResult()
AttachmentFromMimeContentJob(const KMime::Content *content, QObject *parent=nullptr)
Creates a new job.
void setMimeContent(const KMime::Content *content)
Sets the mime content to load the attachment from.
~AttachmentFromMimeContentJob() override
Destroys the job.
const KMime::Content * mimeContent() const
Returns the mime content to load the attachment from.
A base class for jobs to load attachments from different sources.
AttachmentPart::Ptr attachmentPart() const
Returns the loaded attachment.
void setAttachmentPart(const AttachmentPart::Ptr &part)
Subclasses use this method to set the loaded part.
A class that encapsulates an attachment.
QSharedPointer< AttachmentPart > Ptr
Defines a pointer to an attachment object.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.