7#include "mdnadvicehelper.h"
8#include "mdnadvicedialog.h"
9#include "messagecomposer_debug.h"
10#include <Akonadi/ItemModifyJob>
11#include <KCursorSaver>
12#include <KLazyLocalizedString>
13#include <KLocalizedString>
14#include <MessageComposer/Util>
15#include <MessageViewer/MessageViewerSettings>
21 const char *dontAskAgainID;
24} mdnMessageBoxes[] = {
27 kli18n(
"This message contains a request to return a notification "
28 "about your reception of the message.\n"
29 "You can either ignore the request or let the mail program "
30 "send a \"denied\" or normal response.")},
33 kli18n(
"This message contains a request to send a notification "
34 "about your reception of the message.\n"
35 "It contains a processing instruction that is marked as "
36 "\"required\", but which is unknown to the mail program.\n"
37 "You can either ignore the request or let the mail program "
38 "send a \"failed\" response.")},
39 {
"mdnMultipleAddressesInReceiptTo",
41 kli18n(
"This message contains a request to send a notification "
42 "about your reception of the message,\n"
43 "but it is requested to send the notification to more "
45 "You can either ignore the request or let the mail program "
46 "send a \"denied\" or normal response.")},
47 {
"mdnReturnPathEmpty",
49 kli18n(
"This message contains a request to send a notification "
50 "about your reception of the message,\n"
51 "but there is no return-path set.\n"
52 "You can either ignore the request or let the mail program "
53 "send a \"denied\" or normal response.")},
54 {
"mdnReturnPathNotInReceiptTo",
56 kli18n(
"This message contains a request to send a notification "
57 "about your reception of the message,\n"
58 "but the return-path address differs from the address "
59 "the notification was requested to be sent to.\n"
60 "You can either ignore the request or let the mail program "
61 "send a \"denied\" or normal response.")},
64static const int numMdnMessageBoxes =
sizeof mdnMessageBoxes /
sizeof *mdnMessageBoxes;
66MDNAdviceHelper *MDNAdviceHelper::s_instance =
nullptr;
67MessageComposer::MDNAdvice MDNAdviceHelper::questionIgnoreSend(
const QString &text,
bool canDeny)
69 MessageComposer::MDNAdvice rc = MessageComposer::MDNIgnore;
79MDNAdviceHelper *MDNAdviceHelper::instance()
82 s_instance =
new MDNAdviceHelper;
88QPair<bool, KMime::MDN::SendingMode> MDNAdviceHelper::checkAndSetMDNInfo(
const Akonadi::Item &item, KMime::MDN::DispositionType d,
bool forceSend)
100 return QPair<bool, KMime::MDN::SendingMode>(
false, KMime::MDN::SentAutomatically);
104 KMime::MDN::SendingMode s = KMime::MDN::SentAutomatically;
107 int mode = MessageViewer::MessageViewerSettings::self()->defaultPolicy();
111 if (!mode || (mode < 0) || (mode > 3)) {
114 s = KMime::MDN::SentManually;
117 mode = requestAdviceOnMDN(
"mdnUnknownOption");
118 s = KMime::MDN::SentManually;
124 mode = requestAdviceOnMDN(
"mdnMultipleAddressesInReceiptTo");
125 s = KMime::MDN::SentManually;
129 mode = requestAdviceOnMDN(
"mdnReturnPathEmpty");
130 s = KMime::MDN::SentManually;
133 if (MessageFactoryNG::MDNReturnPathNotInRecieptTo(msg)) {
134 mode = requestAdviceOnMDN(
"mdnReturnPathNotInReceiptTo");
135 s = KMime::MDN::SentManually;
139 if (s != KMime::MDN::SentManually) {
141 mode = requestAdviceOnMDN(
"mdnNormalAsk");
142 s = KMime::MDN::SentManually;
151 if (MessageComposer::Util::findTypeInMessage(msg.
data(),
"message",
"disposition-notification")) {
153 }
else if (mode == 0) {
156 }
else if (mode == 2) {
159 }
else if (mode == 3) {
161 mdnStateAttr->setMDNState(dispositionToSentState(d));
168 i.addAttribute(mdnStateAttr);
170 modify->setIgnorePayload(
true);
171 modify->disableRevisionCheck();
172 return QPair<bool, KMime::MDN::SendingMode>(doSend, s);
178 case KMime::MDN::Displayed:
180 case KMime::MDN::Deleted:
182 case KMime::MDN::Dispatched:
184 case KMime::MDN::Processed:
186 case KMime::MDN::Denied:
188 case KMime::MDN::Failed:
195QPair<QString, bool> MDNAdviceHelper::mdnMessageText(
const char *what)
197 for (
int i = 0; i < numMdnMessageBoxes; ++i) {
198 if (!qstrcmp(what, mdnMessageBoxes[i].dontAskAgainID)) {
199 return {mdnMessageBoxes[i].text.toString(), mdnMessageBoxes[i].canDeny};
205int MDNAdviceHelper::requestAdviceOnMDN(
const char *what)
207 const QPair<QString, bool> mdnInfo = mdnMessageText(what);
208 if (mdnInfo.first.isEmpty()) {
209 qCWarning(MESSAGECOMPOSER_LOG) <<
"didn't find data for message box \"" << what <<
"\"";
210 return MessageComposer::MDNIgnore;
213 const MessageComposer::MDNAdvice answer = questionIgnoreSend(mdnInfo.first, mdnInfo.second);
215 case MessageComposer::MDNSend:
218 case MessageComposer::MDNSendDenied:
223 case MessageComposer::MDNIgnore:
229#include "moc_mdnadvicehelper.cpp"
bool hasAttribute() const
const T * attribute() const
MDNStateAttribute::MDNSentState mdnState() const
Contains various factory methods for creating new messages such as replies, MDNs, forwards,...
static bool MDNRequested(const KMime::Message::Ptr &msg)
When creating MDNs, the user needs to be asked for confirmation in specific cases according to RFC 22...
static bool MDNMDNUnknownOption(const KMime::Message::Ptr &msg)
If the MDN headers contain options that KMail can't parse.
static bool MDNReturnPathEmpty(const KMime::Message::Ptr &msg)
If sending an MDN requires confirmation due to discrepancy between MDN header and Return-Path header.
static bool MDNConfirmMultipleRecipients(const KMime::Message::Ptr &msg)
If sending an MDN requires confirmation due to multiple addresses.
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...