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>
43 #include <boost/shared_ptr.hpp>
45 using namespace MailCommon;
54 {
"mdnNormalAsk",
true,
55 I18N_NOOP(
"This message contains a request to return a notification "
56 "about your reception of the message.\n"
57 "You can either ignore the request or let the mail program "
58 "send a \"denied\" or normal response." ) },
59 {
"mdnUnknownOption",
false,
60 I18N_NOOP(
"This message contains a request to send a notification "
61 "about your reception of the message.\n"
62 "It contains a processing instruction that is marked as "
63 "\"required\", but which is unknown to the mail program.\n"
64 "You can either ignore the request or let the mail program "
65 "send a \"failed\" response." ) },
66 {
"mdnMultipleAddressesInReceiptTo",
true,
67 I18N_NOOP(
"This message contains a request to send a notification "
68 "about your reception of the message,\n"
69 "but it is requested to send the notification to more "
71 "You can either ignore the request or let the mail program "
72 "send a \"denied\" or normal response." ) },
73 {
"mdnReturnPathEmpty",
true,
74 I18N_NOOP(
"This message contains a request to send a notification "
75 "about your reception of the message,\n"
76 "but there is no return-path set.\n"
77 "You can either ignore the request or let the mail program "
78 "send a \"denied\" or normal response." ) },
79 {
"mdnReturnPathNotInReceiptTo",
true,
80 I18N_NOOP(
"This message contains a request to send a notification "
81 "about your reception of the message,\n"
82 "but the return-path address differs from the address "
83 "the notification was requested to be sent to.\n"
84 "You can either ignore the request or let the mail program "
85 "send a \"denied\" or normal response." ) },
92 :
KDialog( parent ), m_result( MessageComposer::MDNIgnore )
94 setCaption( i18n(
"Message Disposition Notification Request" ) );
96 setButtons( KDialog::Yes | KDialog::User1 | KDialog::User2 );
97 setButtonText( KDialog::User2, i18n(
"Send \"&denied\"" ) );
99 setButtons( KDialog::Yes | KDialog::User1 );
101 setButtonText( KDialog::Yes, i18n(
"&Ignore" ) );
102 setButtonText( KDialog::User1, i18n(
"&Send" ) );
103 setEscapeButton( KDialog::Yes );
104 KMessageBox::createKMessageBox(
106 QMessageBox::Question,
111 KMessageBox::NoExec );
123 MessageComposer::MDNAdvice MDNAdviceHelper::questionIgnoreSend(
const QString &
text,
bool canDeny )
125 MessageComposer::MDNAdvice rc = MessageComposer::MDNIgnore;
136 const Akonadi::Item &item, KMime::MDN::DispositionType d,
bool forceSend )
138 KMime::Message::Ptr msg = MessageCore::Util::message( item );
145 if ( item.hasAttribute< MessageCore::MDNStateAttribute >() &&
146 item.attribute< MessageCore::MDNStateAttribute >()->mdnState() != MessageCore::MDNStateAttribute::MDNStateUnknown ) {
148 return QPair< bool, KMime::MDN::SendingMode >(
false, KMime::MDN::SentAutomatically );
150 MessageCore::MDNStateAttribute *mdnStateAttr =
151 new MessageCore::MDNStateAttribute( MessageCore::MDNStateAttribute::MDNStateUnknown );
153 KMime::MDN::SendingMode s = KMime::MDN::SentAutomatically;
156 int mode = MessageViewer::GlobalSettings::self()->defaultPolicy();
160 if ( !mode || mode < 0 || mode > 3 ) {
162 mdnStateAttr->setMDNState( MessageCore::MDNStateAttribute::MDNIgnore );
163 s = KMime::MDN::SentManually;
166 if ( MessageFactory::MDNMDNUnknownOption( msg ) ) {
167 mode = requestAdviceOnMDN(
"mdnUnknownOption" );
168 s = KMime::MDN::SentManually;
173 if ( MessageFactory::MDNConfirmMultipleRecipients( msg ) ) {
174 mode = requestAdviceOnMDN(
"mdnMultipleAddressesInReceiptTo" );
175 s = KMime::MDN::SentManually;
178 if ( MessageFactory::MDNReturnPathEmpty( msg ) ) {
179 mode = requestAdviceOnMDN(
"mdnReturnPathEmpty" );
180 s = KMime::MDN::SentManually;
183 if ( MessageFactory::MDNReturnPathNotInRecieptTo( msg ) ) {
184 mode = requestAdviceOnMDN(
"mdnReturnPathNotInReceiptTo" );
185 s = KMime::MDN::SentManually;
188 if ( MessageFactory::MDNRequested( msg ) ) {
189 if ( s != KMime::MDN::SentManually ) {
191 mode = requestAdviceOnMDN(
"mdnNormalAsk" );
192 s = KMime::MDN::SentManually;
202 if ( MessageViewer::ObjectTreeParser::findType( msg.get(),
204 "disposition-notification",
206 mdnStateAttr->setMDNState( MessageCore::MDNStateAttribute::MDNIgnore );
207 }
else if ( mode == 0 ) {
209 mdnStateAttr->setMDNState( MessageCore::MDNStateAttribute::MDNIgnore );
210 }
else if ( mode == 2 ) {
212 mdnStateAttr->setMDNState( MessageCore::MDNStateAttribute::MDNDenied );
213 }
else if ( mode == 3 ) {
219 Akonadi::Item i( item.id() );
220 i.setRevision( item.revision() );
221 i.setMimeType( item.mimeType() );
222 i.addAttribute( mdnStateAttr );
223 Akonadi::ItemModifyJob *modify =
new Akonadi::ItemModifyJob( i );
224 modify->setIgnorePayload(
true );
225 modify->disableRevisionCheck();
226 return QPair< bool, KMime::MDN::SendingMode >( doSend, s );
230 KMime::MDN::DispositionType d )
233 case KMime::MDN::Displayed:
234 return MessageCore::MDNStateAttribute::MDNDisplayed;
235 case KMime::MDN::Deleted:
236 return MessageCore::MDNStateAttribute::MDNDeleted;
237 case KMime::MDN::Dispatched:
238 return MessageCore::MDNStateAttribute::MDNDispatched;
239 case KMime::MDN::Processed:
240 return MessageCore::MDNStateAttribute::MDNProcessed;
241 case KMime::MDN::Denied:
242 return MessageCore::MDNStateAttribute::MDNDenied;
243 case KMime::MDN::Failed:
244 return MessageCore::MDNStateAttribute::MDNFailed;
246 return MessageCore::MDNStateAttribute::MDNStateUnknown;
250 int MDNAdviceHelper::requestAdviceOnMDN(
const char *what )
255 const MessageViewer::KCursorSaver saver( Qt::ArrowCursor );
257 MessageComposer::MDNAdvice answer;
261 case MessageComposer::MDNSend:
264 case MessageComposer::MDNSendDenied:
269 case MessageComposer::MDNIgnore:
274 kWarning() <<
"didn't find data for message box \"" << what <<
"\"";
275 return MessageComposer::MDNIgnore;
282 m_result = MessageComposer::MDNSend;
287 m_result = MessageComposer::MDNSendDenied;
293 m_result = MessageComposer::MDNIgnore;
301 #include "mdnadvicedialog.moc"
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