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 
19 using namespace MessageComposer;
20 
21 class MessageComposer::ItipJobPrivate : public ContentJobBasePrivate
22 {
23 public:
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 
39 SinglepartJob *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(QStringLiteral("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 
51 SinglepartJob *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"), "utf-8");
57  job->contentType()->setParameter(QStringLiteral("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 
64 ContentJobBase *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 
78 SinglepartJob *ItipJobPrivate::createOutlookItipJob()
79 {
80  auto job = new SinglepartJob;
81  job->contentType()->setMimeType("text/calendar");
82  job->contentType()->setName(QStringLiteral("cal.ics"), "utf-8");
83  job->contentType()->setParameter(QStringLiteral("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 
95 ItipJob::ItipJob(ItipPart *itipPart, QObject *parent)
96  : ContentJobBase(*new ItipJobPrivate(this), parent)
97 {
98  Q_D(ItipJob);
99  d->itipPart = itipPart;
100 }
101 
102 ItipJob::~ItipJob() = default;
103 
104 ItipPart *ItipJob::itipPart() const
105 {
106  Q_D(const ItipJob);
107  return d->itipPart;
108 }
109 
110 void ItipJob::setItipPart(ItipPart *part)
111 {
112  Q_D(ItipJob);
113  d->itipPart = part;
114 }
115 
116 void 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 
127  ContentJobBase::doStart();
128 }
129 
130 void 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"
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
The ItipJob class.
Definition: itipjob.h:19
void setMimeType(const QByteArray &mimeType)
The SinglepartJob class.
Definition: singlepartjob.h:31
The ItipPart class.
Definition: itippart.h:20
The MultipartJob class.
Definition: multipartjob.h:19
The ContentJobBase class.
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Thu Feb 15 2024 03:55:20 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.