Messagelib

itipjob.cpp
1/*
2 SPDX-FileCopyrightText: 2023 Daniel Vrátil <dvratil@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "job/itipjob.h"
8
9#include "contentjobbase_p.h"
10#include "job/multipartjob.h"
11#include "job/singlepartjob.h"
12#include "part/itippart.h"
13
14#include <KLocalizedString>
15#include <KMessageBox>
16
17#include <KMime/Content>
18
19using namespace MessageComposer;
20
21class MessageComposer::ItipJobPrivate : public ContentJobBasePrivate
22{
23public:
24 ItipJobPrivate(ItipJob *qq)
25 : ContentJobBasePrivate(qq)
26 {
27 }
28
29 ContentJobBase *createStandardItipJob();
30 SinglepartJob *createOutlookItipJob();
31 SinglepartJob *createInvitationBodyJob();
32 SinglepartJob *createInvitationJob();
33
34 ItipPart *itipPart = nullptr;
35
36 Q_DECLARE_PUBLIC(ItipJob)
37};
38
39SinglepartJob *ItipJobPrivate::createInvitationBodyJob()
40{
41 auto job = new SinglepartJob; // No parent.
42 job->contentType()->setMimeType("text/plain");
43 job->contentType()->setCharset("utf-8");
44 job->contentType()->setParameter(QByteArrayLiteral("method"), itipPart->method());
45 job->contentTransferEncoding()->setEncoding(KMime::Headers::CEquPr);
46 job->contentDisposition()->setDisposition(KMime::Headers::CDinline);
47 job->setData(KMime::CRLFtoLF(itipPart->invitationBody().toUtf8()));
48 return job;
49}
50
51SinglepartJob *ItipJobPrivate::createInvitationJob()
52{
53 auto job = new SinglepartJob;
54 job->contentType()->setMimeType("text/calendar");
55 job->contentType()->setCharset("utf-8");
56 job->contentType()->setName(QStringLiteral("cal.ics"));
57 job->contentType()->setParameter(QByteArrayLiteral("method"), itipPart->method());
58 job->contentDisposition()->setDisposition(KMime::Headers::CDattachment);
59 job->contentTransferEncoding()->setEncoding(KMime::Headers::CEquPr);
60 job->setData(KMime::CRLFtoLF(itipPart->invitation().toUtf8()));
61 return job;
62}
63
64ContentJobBase *ItipJobPrivate::createStandardItipJob()
65{
66 auto bodyJob = createInvitationBodyJob();
67 if (itipPart->invitation().isEmpty()) {
68 return bodyJob;
69 }
70
71 auto mpJob = new MultipartJob;
72 mpJob->setMultipartSubtype("mixed");
73 mpJob->appendSubjob(bodyJob);
74 mpJob->appendSubjob(createInvitationJob());
75 return mpJob;
76}
77
78SinglepartJob *ItipJobPrivate::createOutlookItipJob()
79{
80 auto job = new SinglepartJob;
81 job->contentType()->setMimeType("text/calendar");
82 job->contentType()->setName(QStringLiteral("cal.ics"));
83 job->contentType()->setParameter(QByteArrayLiteral("method"), QStringLiteral("request"));
84 job->contentType()->setCharset("utf-8");
85
86 if (!itipPart->invitation().isEmpty()) {
87 job->contentDisposition()->setDisposition(KMime::Headers::CDinline);
88 job->contentTransferEncoding()->setEncoding(KMime::Headers::CEquPr);
89 job->setData(KMime::CRLFtoLF(itipPart->invitation().toUtf8()));
90 }
91
92 return job;
93}
94
95ItipJob::ItipJob(ItipPart *itipPart, QObject *parent)
96 : ContentJobBase(*new ItipJobPrivate(this), parent)
97{
98 Q_D(ItipJob);
99 d->itipPart = itipPart;
100}
101
102ItipJob::~ItipJob() = default;
103
104ItipPart *ItipJob::itipPart() const
105{
106 Q_D(const ItipJob);
107 return d->itipPart;
108}
109
110void ItipJob::setItipPart(ItipPart *part)
111{
112 Q_D(ItipJob);
113 d->itipPart = part;
114}
115
116void ItipJob::doStart()
117{
118 Q_D(ItipJob);
119 Q_ASSERT(d->itipPart);
120
121 if (d->itipPart->outlookConformInvitation()) {
122 appendSubjob(d->createOutlookItipJob());
123 } else {
124 appendSubjob(d->createStandardItipJob());
125 }
126
128}
129
130void ItipJob::process()
131{
132 Q_D(ItipJob);
133 // The content has been created by our subjob.
134 Q_ASSERT(d->subjobContents.count() == 1);
135 d->resultContent = d->subjobContents.constFirst();
136 emitResult();
137}
138
139#include "moc_itipjob.cpp"
void emitResult()
void setMimeType(const QByteArray &mimeType)
The ContentJobBase class.
virtual void doStart()
Reimplement to do additional stuff before processing children, such as adding more subjobs.
bool appendSubjob(ContentJobBase *job)
This is meant to be used instead of KCompositeJob::addSubjob(), making it possible to add subjobs fro...
The ItipJob class.
Definition itipjob.h:20
The ItipPart class.
Definition itippart.h:21
The MultipartJob class.
The SinglepartJob class.
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
bool isEmpty() const const
QByteArray toUtf8() const const
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.