7#include "job/protectedheadersjob.h"
9#include "contentjobbase_p.h"
10#include "job/singlepartjob.h"
12#include <KMime/Content>
13#include <KMime/Message>
17class MessageComposer::ProtectedHeadersJobPrivate :
public ContentJobBasePrivate
20 ProtectedHeadersJobPrivate(ProtectedHeadersJob *qq)
21 : ContentJobBasePrivate(qq)
25 KMime::Content *content =
nullptr;
26 KMime::Message *skeletonMessage =
nullptr;
28 bool obvoscate =
false;
30 Q_DECLARE_PUBLIC(ProtectedHeadersJob)
33ProtectedHeadersJob::ProtectedHeadersJob(
QObject *parent)
38ProtectedHeadersJob::~ProtectedHeadersJob() =
default;
42 Q_D(ProtectedHeadersJob);
46 d->content->assemble();
50void ProtectedHeadersJob::setSkeletonMessage(KMime::Message *skeletonMessage)
52 Q_D(ProtectedHeadersJob);
54 d->skeletonMessage = skeletonMessage;
57void ProtectedHeadersJob::setObvoscate(
bool obvoscate)
59 Q_D(ProtectedHeadersJob);
61 d->obvoscate = obvoscate;
64void ProtectedHeadersJob::doStart()
66 Q_D(ProtectedHeadersJob);
67 Q_ASSERT(d->resultContent ==
nullptr);
68 Q_ASSERT(d->skeletonMessage);
70 auto subject = d->skeletonMessage->header<KMime::Headers::Subject>();
71 if (d->obvoscate && subject) {
73 auto cjob =
new SinglepartJob;
74 auto ct = cjob->contentType();
75 ct->setMimeType(
"text/plain");
76 ct->setCharset(subject->rfc2047Charset());
77 ct->setParameter(QByteArrayLiteral(
"protected-headers"), QStringLiteral(
"v1"));
78 cjob->contentDisposition()->setDisposition(KMime::Headers::contentDisposition::CDinline);
79 cjob->setData(subject->type() + QByteArray(
": ") + subject->asUnicodeString().toUtf8());
82 auto mixedPart =
new KMime::Content();
83 const QByteArray boundary = KMime::multiPartBoundary();
84 mixedPart->contentType()->setMimeType(
"multipart/mixed");
85 mixedPart->contentType(
false)->setBoundary(boundary);
86 mixedPart->appendContent(cjob->content());
90 if (!d->content || !d->content->hasContent()) {
91 Q_ASSERT(d->subjobContents.size() == 1);
92 d->content = d->subjobContents.constFirst();
95 mixedPart->appendContent(d->content);
96 d->content = mixedPart;
104void ProtectedHeadersJob::process()
106 Q_D(ProtectedHeadersJob);
110 if (!d->content || !d->content->hasContent()) {
111 Q_ASSERT(d->subjobContents.size() == 1);
112 d->content = d->subjobContents.constFirst();
115 auto subject = d->skeletonMessage->header<KMime::Headers::Subject>();
116 const auto headers = d->skeletonMessage->headers();
117 for (
const auto &header : headers) {
118 const QByteArray headerType(header->type());
119 if (headerType.startsWith(
"X-KMail-")) {
122 if (headerType ==
"Bcc") {
125 if (headerType.startsWith(
"Content-")) {
133 if (header->as7BitString().length() > 70) {
136 auto copyHeader = KMime::Headers::createHeader(headerType);
138 copyHeader =
new KMime::Headers::Generic(headerType.constData(), headerType.size());
140 copyHeader->from7BitString(header->as7BitString(
false));
141 d->content->appendHeader(copyHeader);
144 if (d->obvoscate && subject) {
145 subject->from7BitString(
"...");
147 auto contentType = d->content->header<KMime::Headers::ContentType>();
148 contentType->setParameter(QByteArrayLiteral(
"protected-headers"), QStringLiteral(
"v1"));
150 d->resultContent = d->content;
155#include "moc_protectedheadersjob.cpp"
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...
KMime::Content * content() const
Get the resulting KMime::Content that the ContentJobBase has generated.
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)