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
00135 bool autoExpunge();
00136
00138 virtual void writeConfig();
00139
00141 virtual void readConfig();
00142
00148 virtual bool listDirectory();
00149
00153 void getFolder(bool force = FALSE);
00154
00158 void getAndCheckFolder(bool force = FALSE);
00159
00163 void getMessage(KMFolder * folder, KMMessage * msg);
00164
00172 void createFolder(const QString &name,
00173 const QString& imapPath = QString::null, bool askUser = true);
00174
00178 void deleteMessage(KMMessage * msg);
00179 void deleteMessage(const QPtrList<KMMessage>& msgList);
00180
00185 virtual void setStatus(int idx, KMMsgStatus status, bool toggle);
00186
00190 virtual void setStatus(QValueList<int>& _ids, KMMsgStatus status, bool toggle);
00191
00193 static QStringList makeSets( QValueList<ulong>&, bool sort = true);
00194 static QStringList makeSets(const QStringList&, bool sort = true);
00195
00197 static QPtrList<KMMessage> splitMessageList(const QString& set,
00198 QPtrList<KMMessage>& msgList);
00199
00201 void getUids(QValueList<int>& ids, QValueList<ulong>& uids);
00202
00204 void getUids(const QPtrList<KMMessage>& msgList, QValueList<ulong>& uids);
00205
00209 void expungeFolder(KMFolderImap * aFolder, bool quiet);
00210
00211 virtual int compact( bool ) { expungeFolder(this, false); return 0; };
00212
00216 void sendFolderComplete(bool success)
00217 { emit folderComplete(this, success); }
00218
00223 bool processNewMail(bool interactive);
00224
00229 void setSelected(bool selected) { mIsSelected = selected; }
00230 bool isSelected() { return mIsSelected; }
00231
00235 static QString encodeFileName(const QString &);
00236 static QString decodeFileName(const QString &);
00237 static QTextCodec * utf7Codec();
00238
00242 static QString statusToFlags(KMMsgStatus status, int supportedFalgs);
00243
00247 virtual QString fileName() const {
00248 return encodeFileName( KMFolderMbox::fileName() ); }
00249
00253 const ulong serNumForUID( ulong uid );
00254
00259 void saveMsgMetaData( KMMessage* msg, ulong uid = 0 );
00260
00264 static QValueList<ulong> splitSets(const QString);
00265
00266 virtual void ignoreJobsForMessage( KMMessage* );
00267
00271 bool includeInMailCheck() { return mCheckMail; }
00272 void setIncludeInMailCheck( bool check );
00273
00275 virtual int create();
00276
00278 virtual bool isAutoExpire() const { return false; }
00279
00281 virtual void reallyDoClose(const char* owner);
00282
00283 void setCheckingValidity( bool val ) { mCheckingValidity = val; }
00284
00286 KMFolder* trashFolder() const;
00287
00293 void setAlreadyRemoved(bool removed);
00294
00296 bool isReadOnly() const { return KMFolderMbox::isReadOnly() || mReadOnly; }
00297
00302 unsigned int userRights() const { return mUserRights; }
00303
00305 void setUserRights( unsigned int userRights );
00306
00312 virtual void search( const KMSearchPattern* );
00313 virtual void search( const KMSearchPattern*, Q_UINT32 serNum );
00314
00316 virtual bool isMoveable() const;
00317
00319 void initializeFrom( KMFolderImap* parent, QString path, QString mimeType );
00320
00322 int permanentFlags() const { return mPermanentFlags; }
00323
00324 signals:
00325 void folderComplete(KMFolderImap *folder, bool success);
00326
00330 void deleted(KMFolderImap*);
00331
00335 void directoryListingFinished(KMFolderImap*);
00336
00342 void folderCreationResult( const QString &name, bool success );
00343
00344 public slots:
00346 virtual void addMsgQuiet(KMMessage *);
00347 virtual void addMsgQuiet(QPtrList<KMMessage>);
00348
00355 virtual int addMsg(KMMessage* msg, int* index_return = 0);
00356 virtual int addMsg(QPtrList<KMMessage>&, QValueList<int>& index_return);
00357
00359 void copyMsg(QPtrList<KMMessage>& msgList);
00360
00361
00364 virtual KMMessage* take(int idx);
00365 virtual void take(QPtrList<KMMessage>);
00366
00370 void slotSimpleData(KIO::Job * job, const QByteArray & data);
00371
00376 static void flagsToStatus(KMMsgBase *msg, int flags, bool newMsg = TRUE, int supportedFalgs = 31 );
00377
00382 static void seenFlagToStatus( KMMsgBase *msg, int flags, bool newMsg = true );
00383
00387 void slotCopyMsgResult( KMail::FolderJob* job );
00388
00392 void slotSearchDone( QValueList<Q_UINT32> serNums,
00393 const KMSearchPattern* pattern,
00394 bool complete );
00395
00399 void slotSearchDone( Q_UINT32 serNum, const KMSearchPattern* pattern, bool matches );
00400
00405 void slotListResult( const QStringList&, const QStringList&,
00406 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00407
00412 void slotCheckNamespace( const QStringList&, const QStringList&,
00413 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00414
00415 protected:
00416 virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt,
00417 KMFolder *folder, QString partSpecifier,
00418 const AttachmentStrategy *as ) const;
00419 virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00420 FolderJob::JobType jt, KMFolder *folder ) const;
00421
00422 void getMessagesResult(KIO::Job * job, bool lastSet);
00423
00427 virtual int expungeContents();
00428
00429 void setChildrenState( QString attributes );
00430
00432 void initInbox();
00433
00435 KMFolderImap* findParent( const QString& path, const QString& name );
00436
00438 void checkFolders( const QStringList& folderNames, const QString& ns );
00439
00440 void finishMailCheck( const char *func, imapState state );
00441
00442 protected slots:
00443
00447 void checkValidity();
00448 void slotCheckValidityResult(KIO::Job * job);
00449
00453 void reallyGetFolder(const QString &startUid = QString::null);
00454
00458 void slotListFolderResult(KIO::Job * job);
00459 void slotListFolderEntries(KIO::Job * job, const KIO::UDSEntryList & uds);
00460
00464 void slotGetMessagesResult(KIO::Job * job);
00465 void slotGetLastMessagesResult(KIO::Job * job);
00466 void slotGetMessagesData(KIO::Job * job, const QByteArray & data);
00467
00471 void slotCreateFolderResult(KIO::Job * job);
00472
00476 void slotRemoveFolderResult(KIO::Job *job);
00477
00481 void slotStatResult(KIO::Job *job);
00482
00487 void slotCompleteMailCheckProgress();
00488
00492 void slotProcessNewMail( int errorCode, const QString& errorMsg );
00493
00499 void slotCreatePendingFolders( int errorCode, const QString& errorMsg );
00500
00504 void slotListNamespaces();
00505
00506 protected:
00507 QString mImapPath;
00508 ulong mLastUid;
00509 imapState mContentState, mSubfolderState;
00510 bool mIsSelected;
00511 bool mCheckFlags;
00512 bool mReadOnly;
00513 bool mCheckMail;
00514 mutable QGuardedPtr<KMAcctImap> mAccount;
00515
00516 QString mUidValidity;
00517 unsigned int mUserRights;
00518
00519 private:
00520
00521 bool mCheckingValidity;
00522
00523 QIntDict<KMMsgMetaData> mUidMetaDataMap;
00524
00525 QDict<KMMsgMetaData> mMetaDataMap;
00526
00527 bool mAlreadyRemoved;
00528
00529 QGuardedPtr<ProgressItem> mMailCheckProgressItem;
00530
00531 ProgressItem *mListDirProgressItem;
00532
00533 ProgressItem *mAddMessageProgressItem;
00534
00535 QStringList mFoldersPendingCreation;
00536
00537
00538
00539
00540
00541 bool mUploadAllFlags;
00542
00543
00544
00545 int mPermanentFlags;
00546 };
00547
00548 #endif // kmfolderimap_h