kmail

kmfolderimap.h
1 /*
2  * kmfolderimap.h
3  *
4  * Copyright (c) 2001 Kurt Granroth <granroth@kde.org>
5  * Copyright (c) 2000-2002 Michael Haeckel <haeckel@kde.org>
6  *
7  * This file is based on kmacctimap.h by Michael Haeckel which is
8  * based on popaccount.h by Don Sanders
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; version 2 of the License
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  */
23 
24 #ifndef kmfolderimap_h
25 #define kmfolderimap_h
26 
27 #include "acljobs.h"
28 #include "kmacctimap.h"
29 #include "kmfoldermbox.h"
30 #include "kmmsgbase.h"
31 
32 #include "tdeio/job.h"
33 #include "tdeio/global.h"
34 
35 #include <kstandarddirs.h>
36 
37 #include <tqintdict.h>
38 #include <tqdict.h>
39 template< typename T> class TQPtrList;
40 template< typename T> class TQValueList;
41 
42 class KMFolderTreeItem;
43 class KMFolderImap;
44 class KMSearchPattern;
45 class KMMessage;
46 namespace KMail {
47  class FolderJob;
48  class ImapJob;
49  class AttachmentStrategy;
50  class ImapAccountBase;
51 }
52 namespace KPIM {
53  class ProgressItem;
54 }
55 using KMail::FolderJob;
56 using KMail::ImapJob;
57 using KMail::AttachmentStrategy;
58 using KMail::ImapAccountBase;
59 using KPIM::ProgressItem;
60 
61 class KMMsgMetaData
62 {
63 public:
64  KMMsgMetaData(KMMsgStatus aStatus)
65  :mStatus(aStatus), mSerNum(0) {}
66  KMMsgMetaData(KMMsgStatus aStatus, TQ_UINT32 aSerNum)
67  :mStatus(aStatus), mSerNum(aSerNum) {}
68  ~KMMsgMetaData() {};
69  KMMsgStatus status() const { return mStatus; }
70  TQ_UINT32 serNum() const { return mSerNum; }
71 private:
72  KMMsgStatus mStatus;
73  TQ_UINT32 mSerNum;
74 };
75 
76 
77 
78 class KMFolderImap : public KMFolderMbox
79 {
80  TQ_OBJECT
81 
82  friend class ::KMail::ImapJob;
83 public:
84 
85  static TQString cacheLocation() {
86  return locateLocal("data", "kmail/imap" );
87  }
88 
89  enum imapState {
90  imapNoInformation = 0,
91  imapListingInProgress = 1,
92  imapDownloadInProgress = 2,
93  imapFinished = 3
94  };
95 
96  virtual imapState getContentState() const { return mContentState; }
97  virtual void setContentState(imapState state) { mContentState = state; }
98 
99  virtual imapState getSubfolderState() { return mSubfolderState; }
100  virtual void setSubfolderState(imapState state);
101 
105  KMFolderImap(KMFolder* folder, const char* name=0);
106  virtual ~KMFolderImap();
107 
109  virtual KMFolderType folderType() const { return KMFolderTypeImap; }
110 
111  virtual KMMessage* getMsg(int idx);
113  void setImapPath( const TQString &path );
114  TQString imapPath() const { return mImapPath; }
115 
117  ulong lastUid();
118 
120  void setUidValidity(const TQString &validity) { mUidValidity = validity; }
121  TQString uidValidity() { return mUidValidity; }
122 
124  void setAccount(KMAcctImap *acct);
125  KMAcctImap* account() const;
126 
128  virtual void removeMsg(int i, bool quiet = FALSE);
129  virtual void removeMsg(const TQPtrList<KMMessage>& msgList, bool quiet = FALSE);
130 
131  virtual int rename( const TQString& newName, KMFolderDir *aParent = 0 );
132 
134  virtual void remove();
135 
137  bool autoExpunge();
138 
140  virtual void writeConfig();
141 
143  virtual void readConfig();
144 
150  virtual bool listDirectory();
151 
155  void getFolder(bool force = FALSE);
156 
160  void getAndCheckFolder(bool force = FALSE);
161 
165  void getMessage(KMFolder * folder, KMMessage * msg);
166 
174  void createFolder(const TQString &name,
175  const TQString& imapPath = TQString(), bool askUser = true);
176 
180  void deleteMessage(KMMessage * msg);
181  void deleteMessage(const TQPtrList<KMMessage>& msgList);
182 
187  virtual void setStatus(int idx, KMMsgStatus status, bool toggle);
188 
192  virtual void setStatus(TQValueList<int>& _ids, KMMsgStatus status, bool toggle);
193 
195  static TQStringList makeSets( TQValueList<ulong>&, bool sort = true);
196  static TQStringList makeSets(const TQStringList&, bool sort = true);
197 
199  static TQPtrList<KMMessage> splitMessageList(const TQString& set,
200  TQPtrList<KMMessage>& msgList);
201 
203  void getUids(TQValueList<int>& ids, TQValueList<ulong>& uids);
204 
206  void getUids(const TQPtrList<KMMessage>& msgList, TQValueList<ulong>& uids);
207 
211  void expungeFolder(KMFolderImap * aFolder, bool quiet);
212 
213  virtual int compact( bool ) { expungeFolder(this, false); return 0; };
214 
218  void sendFolderComplete(bool success)
219  { emit folderComplete(this, success); }
220 
225  bool processNewMail(bool interactive);
226 
231  void setSelected(bool selected) { mIsSelected = selected; }
232  bool isSelected() { return mIsSelected; }
233 
237  static TQString encodeFileName(const TQString &);
238  static TQString decodeFileName(const TQString &);
239  static TQTextCodec * utf7Codec();
240 
244  static TQString statusToFlags(KMMsgStatus status, int supportedFalgs);
245 
249  virtual TQString fileName() const {
250  return encodeFileName( KMFolderMbox::fileName() ); }
251 
255  ulong serNumForUID( ulong uid );
256 
261  void saveMsgMetaData( KMMessage* msg, ulong uid = 0 );
262 
266  static TQValueList<ulong> splitSets(const TQString);
267 
268  virtual void ignoreJobsForMessage( KMMessage* );
269 
273  bool includeInMailCheck() { return mCheckMail; }
274  void setIncludeInMailCheck( bool check );
275 
277  virtual int create();
278 
280  virtual bool isAutoExpire() const { return false; }
281 
283  virtual void reallyDoClose(const char* owner);
284 
285  void setCheckingValidity( bool val ) { mCheckingValidity = val; }
286 
288  KMFolder* trashFolder() const;
289 
295  void setAlreadyRemoved(bool removed);
296 
298  bool isReadOnly() const { return KMFolderMbox::isReadOnly() || mReadOnly; }
299  bool canDeleteMessages() const;
300 
306  unsigned int userRights() const { return mUserRights; }
307  KMail::ACLJobs::ACLFetchState userRightsState() const { return mUserRightsState; }
308 
310  void setUserRights( unsigned int userRights, KMail::ACLJobs::ACLFetchState userRightsState );
311 
317  virtual void search( const KMSearchPattern* );
318  virtual void search( const KMSearchPattern*, TQ_UINT32 serNum );
319 
321  virtual bool isMoveable() const;
322 
324  void initializeFrom( KMFolderImap* parent, TQString path, TQString mimeType );
325 
327  int permanentFlags() const { return mPermanentFlags; }
328 
329  virtual bool mailCheckInProgress() const;
330 
331 signals:
332  void folderComplete(KMFolderImap *folder, bool success);
333 
337  void deleted(KMFolderImap*);
338 
342  void directoryListingFinished(KMFolderImap*);
343 
349  void folderCreationResult( const TQString &name, bool success );
350 
351 public slots:
353  virtual void addMsgQuiet(KMMessage *);
354  virtual void addMsgQuiet(TQPtrList<KMMessage>);
355 
362  virtual int addMsg(KMMessage* msg, int* index_return = 0);
363  virtual int addMsg(TQPtrList<KMMessage>&, TQValueList<int>& index_return);
364 
366  void copyMsg(TQPtrList<KMMessage>& msgList/*, KMFolder* parent*/);
367 
368 
371  virtual KMMessage* take(int idx);
372  virtual void take(TQPtrList<KMMessage>);
373 
377  void slotSimpleData(TDEIO::Job * job, const TQByteArray & data);
378 
383  static void flagsToStatus(KMMsgBase *msg, int flags, bool newMsg = TRUE, int supportedFalgs = 31 );
384 
389  static void seenFlagToStatus( KMMsgBase *msg, int flags, bool newMsg = true );
390 
394  void slotCopyMsgResult( KMail::FolderJob* job );
395 
399  void slotSearchDone( TQValueList<TQ_UINT32> serNums,
400  const KMSearchPattern* pattern,
401  bool complete );
402 
406  void slotSearchDone( TQ_UINT32 serNum, const KMSearchPattern* pattern, bool matches );
407 
412  void slotListResult( const TQStringList&, const TQStringList&,
413  const TQStringList&, const TQStringList&, const ImapAccountBase::jobData& );
414 
419  void slotCheckNamespace( const TQStringList&, const TQStringList&,
420  const TQStringList&, const TQStringList&, const ImapAccountBase::jobData& );
421 
422 protected:
423  virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt,
424  KMFolder *folder, TQString partSpecifier,
425  const AttachmentStrategy *as ) const;
426  virtual FolderJob* doCreateJob( TQPtrList<KMMessage>& msgList, const TQString& sets,
427  FolderJob::JobType jt, KMFolder *folder ) const;
428 
429  void getMessagesResult(TDEIO::Job * job, bool lastSet);
430 
434  virtual int expungeContents();
435 
436  void setChildrenState( TQString attributes );
437 
439  void initInbox();
440 
442  KMFolderImap* findParent( const TQString& path, const TQString& name );
443 
445  void checkFolders( const TQStringList& folderNames, const TQString& ns );
446 
447  void finishMailCheck( const char *func, imapState state );
448 
449 protected slots:
450 
454  void checkValidity();
455  void slotCheckValidityResult(TDEIO::Job * job);
456 
460  void reallyGetFolder(const TQString &startUid = TQString());
461 
465  void slotListFolderResult(TDEIO::Job * job);
466  void slotListFolderEntries(TDEIO::Job * job, const TDEIO::UDSEntryList & uds);
467 
471  void slotGetMessagesResult(TDEIO::Job * job);
472  void slotGetLastMessagesResult(TDEIO::Job * job);
473  void slotGetMessagesData(TDEIO::Job * job, const TQByteArray & data);
474 
478  void slotCreateFolderResult(TDEIO::Job * job);
479 
483  void slotRemoveFolderResult(TDEIO::Job *job);
484 
488  void slotStatResult(TDEIO::Job *job);
489 
494  void slotCompleteMailCheckProgress();
495 
499  void slotProcessNewMail( int errorCode, const TQString& errorMsg );
500 
506  void slotCreatePendingFolders( int errorCode, const TQString& errorMsg );
507 
511  void slotListNamespaces();
512 
513 protected:
514  TQString mImapPath;
515  ulong mLastUid;
516  imapState mContentState, mSubfolderState;
517  bool mIsSelected;
518  bool mCheckFlags;
519  bool mReadOnly;
520  bool mCheckMail;
521  mutable TQGuardedPtr<KMAcctImap> mAccount;
522  // the current uidvalidity
523  TQString mUidValidity;
524  unsigned int mUserRights;
525  KMail::ACLJobs::ACLFetchState mUserRightsState;
526 
527 private:
528  // if we're checking validity currently
529  bool mCheckingValidity;
530  // uid - metadata cache
531  TQIntDict<KMMsgMetaData> mUidMetaDataMap;
532  // msgidMD5 - status map
533  TQDict<KMMsgMetaData> mMetaDataMap;
534  // if the folder should be deleted without server roundtrip
535  bool mAlreadyRemoved;
536  // the progress for mailchecks
537  TQGuardedPtr<ProgressItem> mMailCheckProgressItem;
538  // the progress for listings
539  ProgressItem *mListDirProgressItem;
540  // the progress for addMsg
541  ProgressItem *mAddMessageProgressItem;
542  // to-be-added folders
543  TQStringList mFoldersPendingCreation;
544 
545  // push all flags to the server instead of just the changed once
546  // when doing a flag change the next time
547  // this is needed for migrating local flags from the time where we didn't
548  // have the ability to store them on the server
549  bool mUploadAllFlags;
550 
551  // PERMANENTFLAGS part of SELECT response, needed to determine if custom flags can be
552  // stored on the server
553  int mPermanentFlags;
554 };
555 
556 #endif // kmfolderimap_h
KMail list that manages the contents of one directory that may contain folders and/or other directori...
Definition: kmfolderdir.h:16
Mail folder.
Definition: kmfolder.h:69
This is a Mime Message.
Definition: kmmessage.h:68
This class is an abstraction of a search over messages.
folderdiaquotatab.h
Definition: aboutdata.cpp:40