1 // -*- mode: C++; c-file-style: "gnu" -*-
6 #include "kmail_export.h"
7 #include <kmime/kmime_message.h>
8 #include "messageviewer/viewer.h"
9 #include "messageviewer/editorwatcher.h"
10 #include "messageviewer/headerstrategy.h"
11 #include "messageviewer/headerstyle.h"
12 using MessageViewer::EditorWatcher
;
13 #include <akonadi/kmime/messagestatus.h>
14 #include <messagelist/core/view.h>
15 using Akonadi::MessageStatus
;
17 #include <ktemporaryfile.h>
22 #include <akonadi/item.h>
23 #include <akonadi/itemfetchscope.h>
24 #include <akonadi/collection.h>
25 class KProgressDialog
;
28 namespace MailCommon
{
29 class FolderCollection
;
33 template <typename T
> class QSharedPointer
;
35 namespace KIO
{ class Job
; }
39 namespace GpgME
{ class Error
; }
40 namespace Kleo
{ class SpecialJob
; }
42 typedef QMap
<KMime::Content
*, Akonadi::Item
> PartNodeMessageMap
;
43 /// Small helper structure which encapsulates the KMMessage created when creating a reply, and
45 class KMAIL_EXPORT KMCommand
: public QObject
50 enum Result
{ Undefined
, OK
, Canceled
, Failed
};
52 // Trival constructor, don't retrieve any messages
53 KMCommand( QWidget
*parent
= 0 );
54 KMCommand( QWidget
*parent
, const Akonadi::Item
& );
55 // Retrieve all messages in msgList when start is called.
56 KMCommand( QWidget
*parent
, const QList
<Akonadi::Item
> &msgList
);
57 // Retrieve the single message msgBase when start is called.
61 /** Returns the result of the command. Only call this method from the slot
62 connected to completed().
64 Result
result() const;
67 // Retrieve messages then calls execute
72 /// @param result The status of the command.
73 void messagesTransfered( KMCommand::Result result
);
75 /// Emitted when the command has completed.
76 void completed( KMCommand
*command
);
79 /** Allows to configure how much data should be retrieved of the messages. */
80 Akonadi::ItemFetchScope
& fetchScope() { return mFetchScope
; }
82 // Returns list of messages retrieved
83 const QList
<Akonadi::Item
> retrievedMsgs() const;
84 // Returns the single message retrieved
85 Akonadi::Item
retrievedMessage() const;
86 // Returns the parent widget
87 QWidget
*parentWidget() const;
89 bool deletesItself() const { return mDeletesItself
; }
90 /** Specify whether the subclass takes care of the deletion of the object.
91 By default the base class will delete the object.
92 @param deletesItself true if the subclass takes care of deletion, false
93 if the base class should take care of deletion
95 void setDeletesItself( bool deletesItself
)
96 { mDeletesItself
= deletesItself
; }
98 bool emitsCompletedItself() const { return mEmitsCompletedItself
; }
99 /** Specify whether the subclass takes care of emitting the completed()
100 signal. By default the base class will emit this signal.
101 @param emitsCompletedItself true if the subclass emits the completed
102 signal, false if the base class should emit
105 void setEmitsCompletedItself( bool emitsCompletedItself
)
106 { mEmitsCompletedItself
= emitsCompletedItself
; }
108 /** Use this to set the result of the command.
109 @param result The result of the command.
111 void setResult( Result result
)
112 { mResult
= result
; }
115 // execute should be implemented by derived classes
116 virtual Result
execute() = 0;
118 /** transfers the list of (imap)-messages
119 * this is a necessary preparation for e.g. forwarding */
120 void transferSelectedMsgs();
123 void slotPostTransfer( KMCommand::Result result
);
124 /** the msg has been transferred */
125 void slotMsgTransfered(const Akonadi::Item::List
& msgs
);
126 /** the KMImapJob is finished */
127 void slotJobFinished();
128 /** the transfer was canceled */
129 void slotTransferCancelled();
132 QList
<Akonadi::Item
> mRetrievedMsgs
;
135 // ProgressDialog for transferring messages
136 KProgressDialog
* mProgressDialog
;
137 //Currently only one async command allowed at a time
138 static int mCountJobs
;
141 bool mDeletesItself
: 1;
142 bool mEmitsCompletedItself
: 1;
145 QList
<Akonadi::Item
> mMsgList
;
146 Akonadi::ItemFetchScope mFetchScope
;
149 class KMAIL_EXPORT KMMailtoComposeCommand
: public KMCommand
154 explicit KMMailtoComposeCommand( const KUrl
&url
, const Akonadi::Item
&msg
=Akonadi::Item() );
157 virtual Result
execute();
160 Akonadi::Item mMessage
;
163 class KMAIL_EXPORT KMMailtoReplyCommand
: public KMCommand
168 KMMailtoReplyCommand( QWidget
*parent
, const KUrl
&url
,
169 const Akonadi::Item
&msg
, const QString
&selection
);
172 virtual Result
execute();
178 class KMAIL_EXPORT KMMailtoForwardCommand
: public KMCommand
183 KMMailtoForwardCommand( QWidget
*parent
, const KUrl
&url
,const Akonadi::Item
& msg
);
186 virtual Result
execute();
191 class KMAIL_EXPORT KMAddBookmarksCommand
: public KMCommand
196 KMAddBookmarksCommand( const KUrl
&url
, QWidget
*parent
);
199 virtual Result
execute();
204 class KMAIL_EXPORT KMUrlSaveCommand
: public KMCommand
209 KMUrlSaveCommand( const KUrl
&url
, QWidget
*parent
);
212 void slotUrlSaveResult( KJob
*job
);
215 virtual Result
execute();
220 class KMAIL_EXPORT KMEditMsgCommand
: public KMCommand
225 KMEditMsgCommand( QWidget
*parent
, const Akonadi::Item
&msg
, bool deleteFromSource
= true );
227 void slotDeleteItem( KJob
*job
);
229 virtual Result
execute();
230 bool mDeleteFromSource
;
233 class KMAIL_EXPORT KMUseTemplateCommand
: public KMCommand
238 KMUseTemplateCommand( QWidget
*parent
, const Akonadi::Item
&msg
);
241 virtual Result
execute();
244 class KMAIL_EXPORT KMSaveMsgCommand
: public KMCommand
249 KMSaveMsgCommand( QWidget
*parent
, const QList
<Akonadi::Item
> &msgList
);
250 KMSaveMsgCommand( QWidget
*parent
, const Akonadi::Item
& msg
);
254 virtual Result
execute();
260 class KMAIL_EXPORT KMOpenMsgCommand
: public KMCommand
265 explicit KMOpenMsgCommand( QWidget
*parent
, const KUrl
& url
= KUrl(),
266 const QString
& encoding
= QString() );
269 virtual Result
execute();
272 void slotDataArrived( KIO::Job
*job
, const QByteArray
& data
);
273 void slotResult( KJob
*job
);
276 static const int MAX_CHUNK_SIZE
= 64*1024;
279 KIO::TransferJob
*mJob
;
280 const QString mEncoding
;
283 class KMAIL_EXPORT KMSaveAttachmentsCommand
: public KMCommand
287 /** Use this to save all attachments of the given message.
288 @param parent The parent widget of the command used for message boxes.
289 @param msg The message of which the attachments should be saved.
291 KMSaveAttachmentsCommand( QWidget
*parent
, const Akonadi::Item
&msg
);
292 /** Use this to save all attachments of the given messages.
293 @param parent The parent widget of the command used for message boxes.
294 @param msgs The messages of which the attachments should be saved.
296 KMSaveAttachmentsCommand( QWidget
*parent
, const QList
<Akonadi::Item
>& msgs
);
299 virtual Result
execute();
302 class KMAIL_EXPORT KMReplyToCommand
: public KMCommand
307 KMReplyToCommand( QWidget
*parent
, const Akonadi::Item
&msg
,
308 const QString
&selection
= QString() );
311 virtual Result
execute();
317 class KMAIL_EXPORT KMNoQuoteReplyToCommand
: public KMCommand
322 KMNoQuoteReplyToCommand( QWidget
*parent
, const Akonadi::Item
&msg
);
325 virtual Result
execute();
328 class KMReplyListCommand
: public KMCommand
333 KMReplyListCommand( QWidget
*parent
, const Akonadi::Item
&msg
,
334 const QString
&selection
= QString() );
337 virtual Result
execute();
343 class KMAIL_EXPORT KMReplyToAllCommand
: public KMCommand
348 KMReplyToAllCommand( QWidget
*parent
, const Akonadi::Item
&msg
,
349 const QString
&selection
= QString() );
352 virtual Result
execute();
358 class KMAIL_EXPORT KMReplyAuthorCommand
: public KMCommand
363 KMReplyAuthorCommand( QWidget
*parent
, const Akonadi::Item
&msg
,
364 const QString
&selection
= QString() );
367 virtual Result
execute();
373 class KMAIL_EXPORT KMForwardCommand
: public KMCommand
378 KMForwardCommand( QWidget
*parent
, const QList
<Akonadi::Item
> &msgList
,
380 KMForwardCommand( QWidget
*parent
, const Akonadi::Item
& msg
,
384 virtual Result
execute();
390 class KMAIL_EXPORT KMForwardAttachedCommand
: public KMCommand
395 KMForwardAttachedCommand( QWidget
*parent
, const QList
<Akonadi::Item
> &msgList
,
396 uint identity
= 0, KMail::Composer
*win
= 0 );
397 KMForwardAttachedCommand( QWidget
*parent
, const Akonadi::Item
& msg
,
398 uint identity
= 0, KMail::Composer
*win
= 0 );
401 virtual Result
execute();
404 QPointer
<KMail::Composer
> mWin
;
407 class KMAIL_EXPORT KMRedirectCommand
: public KMCommand
412 KMRedirectCommand( QWidget
*parent
, const Akonadi::Item
&msg
);
415 virtual Result
execute();
418 class KMAIL_EXPORT KMCustomReplyToCommand
: public KMCommand
423 KMCustomReplyToCommand( QWidget
*parent
, const Akonadi::Item
&msg
,
424 const QString
&selection
,
425 const QString
&tmpl
);
428 virtual Result
execute();
435 class KMAIL_EXPORT KMCustomReplyAllToCommand
: public KMCommand
440 KMCustomReplyAllToCommand( QWidget
*parent
, const Akonadi::Item
&msg
,
441 const QString
&selection
,
442 const QString
&tmpl
);
445 virtual Result
execute();
452 class KMAIL_EXPORT KMCustomForwardCommand
: public KMCommand
457 KMCustomForwardCommand( QWidget
*parent
, const QList
<Akonadi::Item
> &msgList
,
458 uint identity
, const QString
&tmpl
);
459 KMCustomForwardCommand( QWidget
*parent
, const Akonadi::Item
& msg
,
460 uint identity
, const QString
&tmpl
);
463 virtual Result
execute();
469 class KMAIL_EXPORT KMPrintCommand
: public KMCommand
474 KMPrintCommand( QWidget
*parent
, const Akonadi::Item
&msg
,
475 MessageViewer::HeaderStyle
*headerStyle
= 0,
476 const MessageViewer::HeaderStrategy
*headerStrategy
= 0,
477 bool htmlOverride
= false,
478 bool htmlLoadExtOverride
= false,
479 bool useFixedFont
= false,
480 const QString
& encoding
= QString() );
482 void setOverrideFont( const QFont
& );
483 void setAttachmentStrategy( const MessageViewer::AttachmentStrategy
*strategy
);
486 virtual Result
execute();
488 MessageViewer::HeaderStyle
*mHeaderStyle
;
489 const MessageViewer::HeaderStrategy
*mHeaderStrategy
;
490 const MessageViewer::AttachmentStrategy
*mAttachmentStrategy
;
492 bool mHtmlLoadExtOverride
;
498 class KMAIL_EXPORT KMSetStatusCommand
: public KMCommand
504 KMSetStatusCommand( const MessageStatus
& status
, const Akonadi::Item::List
&items
,
508 void slotModifyItemDone( KJob
* job
);
511 virtual Result
execute();
512 MessageStatus mStatus
;
516 /** This command is used to set or toggle a tag for a list of messages. If toggle is
517 true then the tag is deleted if it is already applied.
519 class KMAIL_EXPORT KMSetTagCommand
: public KMCommand
524 enum SetTagMode
{ AddIfNotExisting
, Toggle
};
526 KMSetTagCommand( const QString
&tagLabel
, const QList
<Akonadi::Item
> &item
,
527 SetTagMode mode
=AddIfNotExisting
);
530 virtual Result
execute();
533 QList
<Akonadi::Item
> mItem
;
537 /* This command is used to create a filter based on the user's
538 decision, e.g. filter by From header */
539 class KMAIL_EXPORT KMFilterCommand
: public KMCommand
544 KMFilterCommand( const QByteArray
&field
, const QString
&value
);
547 virtual Result
execute();
554 /* This command is used to apply a single filter (AKA ad-hoc filter)
555 to a set of messages */
556 class KMAIL_EXPORT KMFilterActionCommand
: public KMCommand
561 KMFilterActionCommand( QWidget
*parent
,
562 const QList
<Akonadi::Item
> &msgList
, MailCommon::MailFilter
*filter
);
565 virtual Result
execute();
566 MailCommon::MailFilter
*mFilter
;
570 class KMAIL_EXPORT KMMetaFilterActionCommand
: public QObject
575 KMMetaFilterActionCommand( MailCommon::MailFilter
*filter
, KMMainWidget
*main
);
581 MailCommon::MailFilter
*mFilter
;
582 KMMainWidget
*mMainWidget
;
586 class KMAIL_EXPORT KMMailingListFilterCommand
: public KMCommand
591 KMMailingListFilterCommand( QWidget
*parent
, const Akonadi::Item
&msg
);
594 virtual Result
execute();
598 class KMAIL_EXPORT KMCopyCommand
: public KMCommand
603 KMCopyCommand( const Akonadi::Collection
&destFolder
, const QList
<Akonadi::Item
> &msgList
);
604 KMCopyCommand( const Akonadi::Collection
& destFolder
, const Akonadi::Item
&msg
);
607 void slotCopyResult( KJob
* job
);
609 virtual Result
execute();
611 Akonadi::Collection mDestFolder
;
612 QList
<Akonadi::Item
> mMsgList
;
618 class KMAIL_EXPORT KMMoveCommand
: public KMCommand
623 KMMoveCommand( const Akonadi::Collection
& destFolder
, const QList
<Akonadi::Item
> &msgList
, MessageList::Core::MessageItemSetReference ref
);
624 KMMoveCommand( const Akonadi::Collection
& destFolder
, const Akonadi::Item
& msg
, MessageList::Core::MessageItemSetReference ref
= MessageList::Core::MessageItemSetReference() );
625 Akonadi::Collection
destFolder() const { return mDestFolder
; }
627 MessageList::Core::MessageItemSetReference
refSet() const { return mRef
; }
630 void slotMoveCanceled();
631 void slotMoveResult( KJob
* job
);
633 void setDestFolder( const Akonadi::Collection
& folder
) { mDestFolder
= folder
; }
636 void moveDone( KMMoveCommand
* );
639 virtual Result
execute();
640 void completeMove( Result result
);
642 Akonadi::Collection mDestFolder
;
643 KPIM::ProgressItem
*mProgressItem
;
644 MessageList::Core::MessageItemSetReference mRef
;
645 bool mCompleteWithAddedMsg
;
648 class KMAIL_EXPORT KMTrashMsgCommand
: public KMMoveCommand
653 KMTrashMsgCommand( const Akonadi::Collection
& srcFolder
, const QList
<Akonadi::Item
> &msgList
,MessageList::Core::MessageItemSetReference ref
);
654 KMTrashMsgCommand( const Akonadi::Collection
& srcFolder
, const Akonadi::Item
& msg
,MessageList::Core::MessageItemSetReference ref
);
657 static Akonadi::Collection
findTrashFolder( const Akonadi::Collection
& srcFolder
);
661 class KMAIL_EXPORT KMResendMessageCommand
: public KMCommand
666 explicit KMResendMessageCommand( QWidget
*parent
, const Akonadi::Item
& msg
= Akonadi::Item() );
669 virtual Result
execute();
672 // TODO: Remove this class. There is no reason why the mailing list stuff should be based
673 // on KMCommand, they should instead be utilty methods.
674 class KMAIL_EXPORT KMMailingListCommand
: public KMCommand
678 KMMailingListCommand( QWidget
*parent
, const QSharedPointer
<MailCommon::FolderCollection
> &parentFolder
);
680 virtual Result
execute();
682 virtual KUrl::List
urls() const =0;
684 QSharedPointer
<MailCommon::FolderCollection
> mFolder
;
687 class KMAIL_EXPORT KMMailingListPostCommand
: public KMMailingListCommand
691 KMMailingListPostCommand( QWidget
*parent
, const QSharedPointer
<MailCommon::FolderCollection
> &parentFolder
);
693 virtual KUrl::List
urls() const;
696 class KMAIL_EXPORT KMMailingListSubscribeCommand
: public KMMailingListCommand
700 KMMailingListSubscribeCommand( QWidget
*parent
, const QSharedPointer
<MailCommon::FolderCollection
> &parentFolder
);
702 virtual KUrl::List
urls() const;
705 class KMAIL_EXPORT KMMailingListUnsubscribeCommand
: public KMMailingListCommand
709 KMMailingListUnsubscribeCommand( QWidget
*parent
, const QSharedPointer
<MailCommon::FolderCollection
> &parentFolder
);
711 virtual KUrl::List
urls() const;
714 class KMAIL_EXPORT KMMailingListArchivesCommand
: public KMMailingListCommand
718 KMMailingListArchivesCommand( QWidget
*parent
, const QSharedPointer
<MailCommon::FolderCollection
> &parentFolder
);
720 virtual KUrl::List
urls() const;
723 class KMAIL_EXPORT KMMailingListHelpCommand
: public KMMailingListCommand
727 KMMailingListHelpCommand( QWidget
*parent
, const QSharedPointer
<MailCommon::FolderCollection
> &parentFolder
);
729 virtual KUrl::List
urls() const;
732 #endif /*KMCommands_h*/