00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef kmfolderimap_h
00025 #define kmfolderimap_h
00026
00027 #include "kmacctimap.h"
00028 #include "kmfoldermbox.h"
00029 #include "kmmsgbase.h"
00030
00031 #include "kio/job.h"
00032 #include "kio/global.h"
00033
00034 #include <kstandarddirs.h>
00035
00036 #include <qintdict.h>
00037 #include <qdict.h>
00038 template< typename T> class QPtrList;
00039 template< typename T> class QValueList;
00040
00041 class KMFolderTreeItem;
00042 class KMFolderImap;
00043 class KMSearchPattern;
00044 class KMMessage;
00045 namespace KMail {
00046 class FolderJob;
00047 class ImapJob;
00048 class AttachmentStrategy;
00049 class ImapAccountBase;
00050 }
00051 namespace KPIM {
00052 class ProgressItem;
00053 }
00054 using KMail::FolderJob;
00055 using KMail::ImapJob;
00056 using KMail::AttachmentStrategy;
00057 using KMail::ImapAccountBase;
00058 using KPIM::ProgressItem;
00059
00060 class KMMsgMetaData
00061 {
00062 public:
00063 KMMsgMetaData(KMMsgStatus aStatus)
00064 :mStatus(aStatus), mSerNum(0) {}
00065 KMMsgMetaData(KMMsgStatus aStatus, Q_UINT32 aSerNum)
00066 :mStatus(aStatus), mSerNum(aSerNum) {}
00067 ~KMMsgMetaData() {};
00068 const KMMsgStatus status() const { return mStatus; }
00069 const Q_UINT32 serNum() const { return mSerNum; }
00070 private:
00071 KMMsgStatus mStatus;
00072 Q_UINT32 mSerNum;
00073 };
00074
00075
00076
00077 class KMFolderImap : public KMFolderMbox
00078 {
00079 Q_OBJECT
00080 friend class ::KMail::ImapJob;
00081 public:
00082
00083 static QString cacheLocation() {
00084 return locateLocal("data", "kmail/imap" );
00085 }
00086
00087 enum imapState {
00088 imapNoInformation = 0,
00089 imapListingInProgress = 1,
00090 imapDownloadInProgress = 2,
00091 imapFinished = 3
00092 };
00093
00094 virtual imapState getContentState() { return mContentState; }
00095 virtual void setContentState(imapState state) { mContentState = state; }
00096
00097 virtual imapState getSubfolderState() { return mSubfolderState; }
00098 virtual void setSubfolderState(imapState state);
00099
00103 KMFolderImap(KMFolder* folder, const char* name=0);
00104 virtual ~KMFolderImap();
00105
00107 virtual KMFolderType folderType() const { return KMFolderTypeImap; }
00108
00109 virtual KMMessage* getMsg(int idx);
00111 void setImapPath( const QString &path );
00112 QString imapPath() const { return mImapPath; }
00113
00115 ulong lastUid();
00116
00118 void setUidValidity(const QString &validity) { mUidValidity = validity; }
00119 QString uidValidity() { return mUidValidity; }
00120
00122 void setAccount(KMAcctImap *acct);
00123 KMAcctImap* account() const;
00124
00126 virtual void removeMsg(int i, bool quiet = FALSE);
00127 virtual void removeMsg(const QPtrList<KMMessage>& msgList, bool quiet = FALSE);
00128
00129 virtual int rename( const QString& newName, KMFolderDir *aParent = 0 );
00130
00132 virtual void remove();
00133
00137 virtual void close(const char *owner, bool force=FALSE);
00138
00140 bool autoExpunge();
00141
00143 virtual void writeConfig();
00144
00146 virtual void readConfig();
00147
00153 virtual bool listDirectory();
00154
00158 void getFolder(bool force = FALSE);
00159
00163 void getAndCheckFolder(bool force = FALSE);
00164
00168 void getMessage(KMFolder * folder, KMMessage * msg);
00169
00177 void createFolder(const QString &name,
00178 const QString& imapPath = QString::null, bool askUser = true);
00179
00183 void deleteMessage(KMMessage * msg);
00184 void deleteMessage(const QPtrList<KMMessage>& msgList);
00185
00190 virtual void setStatus(int idx, KMMsgStatus status, bool toggle);
00191
00195 virtual void setStatus(QValueList<int>& ids, KMMsgStatus status, bool toggle);
00196
00198 static QStringList makeSets( QValueList<ulong>&, bool sort = true);
00199 static QStringList makeSets(const QStringList&, bool sort = true);
00200
00202 static QPtrList<KMMessage> splitMessageList(const QString& set,
00203 QPtrList<KMMessage>& msgList);
00204
00206 void getUids(QValueList<int>& ids, QValueList<ulong>& uids);
00207
00209 void getUids(const QPtrList<KMMessage>& msgList, QValueList<ulong>& uids);
00210
00214 void expungeFolder(KMFolderImap * aFolder, bool quiet);
00215
00216 virtual int compact( bool ) { expungeFolder(this, false); return 0; };
00217
00221 void sendFolderComplete(bool success)
00222 { emit folderComplete(this, success); }
00223
00228 bool processNewMail(bool interactive);
00229
00234 void setSelected(bool selected) { mIsSelected = selected; }
00235 bool isSelected() { return mIsSelected; }
00236
00240 static QString encodeFileName(const QString &);
00241 static QString decodeFileName(const QString &);
00242 static QTextCodec * utf7Codec();
00243
00247 static QString statusToFlags(KMMsgStatus status);
00248
00252 virtual QString fileName() const {
00253 return encodeFileName( KMFolderMbox::fileName() ); }
00254
00258 const ulong serNumForUID( ulong uid );
00259
00264 void saveMsgMetaData( KMMessage* msg, ulong uid = 0 );
00265
00269 static QValueList<ulong> splitSets(const QString);
00270
00271 virtual void ignoreJobsForMessage( KMMessage* );
00272
00276 bool includeInMailCheck() { return mCheckMail; }
00277 void setIncludeInMailCheck( bool check );
00278
00280 virtual int create();
00281
00283 virtual bool isAutoExpire() const { return false; }
00284
00285 void setCheckingValidity( bool val ) { mCheckingValidity = val; }
00286
00288 KMFolder* trashFolder() const;
00289
00295 void setAlreadyRemoved(bool removed);
00296
00298 bool isReadOnly() const { return KMFolderMbox::isReadOnly() || mReadOnly; }
00299
00304 unsigned int userRights() const { return mUserRights; }
00305
00307 void setUserRights( unsigned int userRights );
00308
00314 virtual void search( const KMSearchPattern* );
00315 virtual void search( const KMSearchPattern*, Q_UINT32 serNum );
00316
00318 virtual bool isMoveable() const;
00319
00321 void initializeFrom( KMFolderImap* parent, QString path, QString mimeType );
00322
00323 signals:
00324 void folderComplete(KMFolderImap *folder, bool success);
00325
00329 void deleted(KMFolderImap*);
00330
00334 void directoryListingFinished(KMFolderImap*);
00335
00341 void folderCreationResult( const QString &name, bool success );
00342
00343 public slots:
00345 virtual void addMsgQuiet(KMMessage *);
00346 virtual void addMsgQuiet(QPtrList<KMMessage>);
00347
00354 virtual int addMsg(KMMessage* msg, int* index_return = 0);
00355 virtual int addMsg(QPtrList<KMMessage>&, QValueList<int>& index_return);
00356
00358 void copyMsg(QPtrList<KMMessage>& msgList);
00359
00360
00363 virtual KMMessage* take(int idx);
00364 virtual void take(QPtrList<KMMessage>);
00365
00369 void slotSimpleData(KIO::Job * job, const QByteArray & data);
00370
00375 static void flagsToStatus(KMMsgBase *msg, int flags, bool newMsg = TRUE);
00376
00380 void slotCopyMsgResult( KMail::FolderJob* job );
00381
00385 void slotSearchDone( QValueList<Q_UINT32> serNums,
00386 const KMSearchPattern* pattern,
00387 bool complete );
00388
00392 void slotSearchDone( Q_UINT32 serNum, const KMSearchPattern* pattern, bool matches );
00393
00398 void slotListResult( const QStringList&, const QStringList&,
00399 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00400
00405 void slotCheckNamespace( const QStringList&, const QStringList&,
00406 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00407
00408 protected:
00409 virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt,
00410 KMFolder *folder, QString partSpecifier,
00411 const AttachmentStrategy *as ) const;
00412 virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00413 FolderJob::JobType jt, KMFolder *folder ) const;
00414
00415 void getMessagesResult(KIO::Job * job, bool lastSet);
00416
00420 virtual int expungeContents();
00421
00422 void setChildrenState( QString attributes );
00423
00425 void initInbox();
00426
00428 KMFolderImap* findParent( const QString& path, const QString& name );
00429
00431 void checkFolders( const QStringList& folderNames, const QString& ns );
00432
00433 void finishMailCheck( const char *func, imapState state );
00434
00435 protected slots:
00436
00440 void checkValidity();
00441 void slotCheckValidityResult(KIO::Job * job);
00442
00446 void reallyGetFolder(const QString &startUid = QString::null);
00447
00451 void slotListFolderResult(KIO::Job * job);
00452 void slotListFolderEntries(KIO::Job * job, const KIO::UDSEntryList & uds);
00453
00457 void slotGetMessagesResult(KIO::Job * job);
00458 void slotGetLastMessagesResult(KIO::Job * job);
00459 void slotGetMessagesData(KIO::Job * job, const QByteArray & data);
00460
00464 void slotCreateFolderResult(KIO::Job * job);
00465
00469 void slotRemoveFolderResult(KIO::Job *job);
00470
00474 void slotStatResult(KIO::Job *job);
00475
00480 void slotCompleteMailCheckProgress();
00481
00485 void slotProcessNewMail( int errorCode, const QString& errorMsg );
00486
00492 void slotCreatePendingFolders( int errorCode, const QString& errorMsg );
00493
00497 void slotListNamespaces();
00498
00499 protected:
00500 QString mImapPath;
00501 ulong mLastUid;
00502 imapState mContentState, mSubfolderState;
00503 bool mIsSelected;
00504 bool mCheckFlags;
00505 bool mReadOnly;
00506 bool mCheckMail;
00507 mutable QGuardedPtr<KMAcctImap> mAccount;
00508
00509 QString mUidValidity;
00510 unsigned int mUserRights;
00511
00512 private:
00513
00514 bool mCheckingValidity;
00515
00516 QIntDict<KMMsgMetaData> mUidMetaDataMap;
00517
00518 QDict<KMMsgMetaData> mMetaDataMap;
00519
00520 bool mAlreadyRemoved;
00521
00522 QGuardedPtr<ProgressItem> mMailCheckProgressItem;
00523
00524 ProgressItem *mListDirProgressItem;
00525
00526 ProgressItem *mAddMessageProgressItem;
00527
00528 QStringList mFoldersPendingCreation;
00529 };
00530
00531 #endif // kmfolderimap_h