22 #include <messagecore/helpers/messagehelpers.h>
23 #include <messagecore/misc/mdnstateattribute.h>
25 #include <messagecomposer/helper/messagefactory.h>
26 using MessageComposer::MessageFactory;
28 #include <messageviewer/settings/globalsettings.h>
30 #include <messageviewer/utils/kcursorsaver.h>
32 #include <messageviewer/viewer/objecttreeparser.h>
34 #include <Akonadi/ItemFetchJob>
35 #include <Akonadi/ItemModifyJob>
39 #include <KMessageBox>
44 #include <boost/shared_ptr.hpp>
47 using namespace MailCommon;
56 {
"mdnNormalAsk",
true,
57 I18N_NOOP(
"This message contains a request to return a notification "
58 "about your reception of the message.\n"
59 "You can either ignore the request or let the mail program "
60 "send a \"denied\" or normal response." ) },
61 {
"mdnUnknownOption",
false,
62 I18N_NOOP(
"This message contains a request to send a notification "
63 "about your reception of the message.\n"
64 "It contains a processing instruction that is marked as "
65 "\"required\", but which is unknown to the mail program.\n"
66 "You can either ignore the request or let the mail program "
67 "send a \"failed\" response." ) },
68 {
"mdnMultipleAddressesInReceiptTo",
true,
69 I18N_NOOP(
"This message contains a request to send a notification "
70 "about your reception of the message,\n"
71 "but it is requested to send the notification to more "
73 "You can either ignore the request or let the mail program "
74 "send a \"denied\" or normal response." ) },
75 {
"mdnReturnPathEmpty",
true,
76 I18N_NOOP(
"This message contains a request to send a notification "
77 "about your reception of the message,\n"
78 "but there is no return-path set.\n"
79 "You can either ignore the request or let the mail program "
80 "send a \"denied\" or normal response." ) },
81 {
"mdnReturnPathNotInReceiptTo",
true,
82 I18N_NOOP(
"This message contains a request to send a notification "
83 "about your reception of the message,\n"
84 "but the return-path address differs from the address "
85 "the notification was requested to be sent to.\n"
86 "You can either ignore the request or let the mail program "
87 "send a \"denied\" or normal response." ) },
94 :
KDialog( parent ), m_result( MessageComposer::MDNIgnore )
96 setCaption( i18n(
"Message Disposition Notification Request" ) );
98 setButtons( KDialog::Yes | KDialog::User1 | KDialog::User2 );
99 setButtonText( KDialog::User2, i18n(
"Send \"&denied\"" ) );
101 setButtons( KDialog::Yes | KDialog::User1 );
103 setButtonText( KDialog::Yes, i18n(
"&Ignore" ) );
104 setButtonText( KDialog::User1, i18n(
"&Send" ) );
105 setEscapeButton( KDialog::Yes );
106 KMessageBox::createKMessageBox(
108 QMessageBox::Question,
113 KMessageBox::NoExec );
125 MessageComposer::MDNAdvice MDNAdviceHelper::questionIgnoreSend(
const QString &
text,
bool canDeny )
127 MessageComposer::MDNAdvice rc = MessageComposer::MDNIgnore;
138 const Akonadi::Item &item, KMime::MDN::DispositionType d,
bool forceSend )
140 KMime::Message::Ptr msg = MessageCore::Util::message( item );
147 if ( item.hasAttribute< MessageCore::MDNStateAttribute >() &&
148 item.attribute< MessageCore::MDNStateAttribute >()->mdnState() != MessageCore::MDNStateAttribute::MDNStateUnknown ) {
152 MessageCore::MDNStateAttribute *mdnStateAttr =
153 new MessageCore::MDNStateAttribute( MessageCore::MDNStateAttribute::MDNStateUnknown );
155 KMime::MDN::SendingMode s = KMime::MDN::SentAutomatically;
158 int mode = MessageViewer::GlobalSettings::self()->defaultPolicy();
162 if ( !mode || mode < 0 || mode > 3 ) {
164 mdnStateAttr->setMDNState( MessageCore::MDNStateAttribute::MDNIgnore );
165 s = KMime::MDN::SentManually;
168 if ( MessageFactory::MDNMDNUnknownOption( msg ) ) {
169 mode = requestAdviceOnMDN(
"mdnUnknownOption" );
170 s = KMime::MDN::SentManually;
175 if ( MessageFactory::MDNConfirmMultipleRecipients( msg ) ) {
176 mode = requestAdviceOnMDN(
"mdnMultipleAddressesInReceiptTo" );
177 s = KMime::MDN::SentManually;
180 if ( MessageFactory::MDNReturnPathEmpty( msg ) ) {
181 mode = requestAdviceOnMDN(
"mdnReturnPathEmpty" );
182 s = KMime::MDN::SentManually;
185 if ( MessageFactory::MDNReturnPathNotInRecieptTo( msg ) ) {
186 mode = requestAdviceOnMDN(
"mdnReturnPathNotInReceiptTo" );
187 s = KMime::MDN::SentManually;
190 if ( MessageFactory::MDNRequested( msg ) ) {
191 if ( s != KMime::MDN::SentManually ) {
193 mode = requestAdviceOnMDN(
"mdnNormalAsk" );
194 s = KMime::MDN::SentManually;
204 if ( MessageViewer::ObjectTreeParser::findType( msg.get(),
206 "disposition-notification",
208 mdnStateAttr->setMDNState( MessageCore::MDNStateAttribute::MDNIgnore );
209 }
else if ( mode == 0 ) {
211 mdnStateAttr->setMDNState( MessageCore::MDNStateAttribute::MDNIgnore );
212 }
else if ( mode == 2 ) {
214 mdnStateAttr->setMDNState( MessageCore::MDNStateAttribute::MDNDenied );
215 }
else if ( mode == 3 ) {
221 Akonadi::Item i( item.id() );
222 i.setRevision( item.revision() );
223 i.setMimeType( item.mimeType() );
224 i.addAttribute( mdnStateAttr );
225 Akonadi::ItemModifyJob *modify =
new Akonadi::ItemModifyJob( i );
226 modify->setIgnorePayload(
true );
227 modify->disableRevisionCheck();
232 KMime::MDN::DispositionType d )
235 case KMime::MDN::Displayed:
236 return MessageCore::MDNStateAttribute::MDNDisplayed;
237 case KMime::MDN::Deleted:
238 return MessageCore::MDNStateAttribute::MDNDeleted;
239 case KMime::MDN::Dispatched:
240 return MessageCore::MDNStateAttribute::MDNDispatched;
241 case KMime::MDN::Processed:
242 return MessageCore::MDNStateAttribute::MDNProcessed;
243 case KMime::MDN::Denied:
244 return MessageCore::MDNStateAttribute::MDNDenied;
245 case KMime::MDN::Failed:
246 return MessageCore::MDNStateAttribute::MDNFailed;
248 return MessageCore::MDNStateAttribute::MDNStateUnknown;
252 int MDNAdviceHelper::requestAdviceOnMDN(
const char *what )
257 const MessageViewer::KCursorSaver saver( Qt::ArrowCursor );
259 MessageComposer::MDNAdvice answer;
263 case MessageComposer::MDNSend:
266 case MessageComposer::MDNSendDenied:
271 case MessageComposer::MDNIgnore:
276 kWarning() <<
"didn't find data for message box \"" << what <<
"\"";
277 return MessageComposer::MDNIgnore;
284 m_result = MessageComposer::MDNSend;
289 m_result = MessageComposer::MDNSendDenied;
295 m_result = MessageComposer::MDNIgnore;
MessageComposer::MDNAdvice result() const
static const struct @0 mdnMessageBoxes[]
void slotButtonClicked(int button)
MessageCore::MDNStateAttribute::MDNSentState dispositionToSentState(KMime::MDN::DispositionType d)
QPair< bool, KMime::MDN::SendingMode > checkAndSetMDNInfo(const Akonadi::Item &item, KMime::MDN::DispositionType d, bool forceSend=false)
Checks the MDN headers to see if the user needs to be asked for any confirmations.
static const int numMdnMessageBoxes
MDNAdviceDialog(const QString &text, bool canDeny, QWidget *parent=0)
const char * dontAskAgainID