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
21 : ContentJobBasePrivate(qq)
28 bool obvoscate =
false;
33ProtectedHeadersJob::ProtectedHeadersJob(
QObject *parent)
38ProtectedHeadersJob::~ProtectedHeadersJob() =
default;
46 d->content->assemble();
50void ProtectedHeadersJob::setSkeletonMessage(
KMime::Message *skeletonMessage)
54 d->skeletonMessage = skeletonMessage;
57void ProtectedHeadersJob::setObvoscate(
bool obvoscate)
61 d->obvoscate = obvoscate;
64void ProtectedHeadersJob::doStart()
67 Q_ASSERT(d->resultContent ==
nullptr);
68 Q_ASSERT(d->skeletonMessage);
71 if (d->obvoscate && subject) {
74 auto ct = cjob->contentType();
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());
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()
110 if (!d->content || !d->content->hasContent()) {
111 Q_ASSERT(d->subjobContents.size() == 1);
112 d->content = d->subjobContents.constFirst();
116 const auto headers = d->skeletonMessage->headers();
117 for (
const auto &header : headers) {
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);
140 copyHeader->from7BitString(header->as7BitString(
false));
141 d->content->appendHeader(copyHeader);
144 if (d->obvoscate && subject) {
145 subject->from7BitString(
"...");
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)