00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef kmfoldercachedimap_h
00033 #define kmfoldercachedimap_h
00034
00035 #include <kdialogbase.h>
00036 #include <kstandarddirs.h>
00037 #include <qvaluelist.h>
00038 #include <qvaluevector.h>
00039 #include <qptrlist.h>
00040 #include <qdialog.h>
00041
00042 #include "kmfoldermaildir.h"
00043 #include "kmfolderimap.h"
00044 #include "kmacctimap.h"
00045 #include "kmfoldertype.h"
00046 #include "folderjob.h"
00047 #include "cachedimapjob.h"
00048 #include "quotajobs.h"
00049
00050 using KMail::FolderJob;
00051 using KMail::QuotaInfo;
00052 class KMAcctCachedImap;
00053
00054 namespace KMail {
00055 class AttachmentStrategy;
00056 class ImapAccountBase;
00057 struct ACLListEntry;
00058 }
00059 using KMail::AttachmentStrategy;
00060
00061 class DImapTroubleShootDialog : public KDialogBase
00062 {
00063 Q_OBJECT
00064 public:
00065 DImapTroubleShootDialog( QWidget* parent=0, const char* name=0 );
00066
00067 static int run();
00068
00069 private slots:
00070 void slotRebuildIndex();
00071 void slotRebuildCache();
00072
00073 private:
00074 int rc;
00075 };
00076
00077 class KMFolderCachedImap : public KMFolderMaildir
00078 {
00079 Q_OBJECT
00080
00081 public:
00082 static QString cacheLocation() {
00083 return locateLocal("data", "kmail/dimap" );
00084 }
00085
00089 KMFolderCachedImap(KMFolder* folder, const char* name=0);
00090 virtual ~KMFolderCachedImap();
00091
00093 void initializeFrom( KMFolderCachedImap* parent );
00094
00095 virtual void readConfig();
00096 virtual void writeConfig();
00097
00098 void writeConfigKeysWhichShouldNotGetOverwrittenByReadConfig();
00099
00101 virtual KMFolderType folderType() const { return KMFolderTypeCachedImap; }
00102
00104 virtual int create();
00105
00107 virtual void remove();
00108
00110 virtual void serverSync( bool recurse );
00111
00113 void resetSyncState();
00114
00115 void checkUidValidity();
00116
00117 enum imapState { imapNoInformation=0, imapInProgress=1, imapFinished=2 };
00118
00119 virtual imapState getContentState() { return mContentState; }
00120 virtual void setContentState(imapState state) { mContentState = state; }
00121
00122 virtual imapState getSubfolderState() { return mSubfolderState; }
00123 virtual void setSubfolderState(imapState state);
00124
00126 void setImapPath(const QString &path);
00127 QString imapPath() const { return mImapPath; }
00128
00130 void setLastUid( ulong uid );
00131 ulong lastUid();
00132
00134 KMMsgBase* findByUID( ulong uid );
00135
00137 void setUidValidity(const QString &validity) { mUidValidity = validity; }
00138 QString uidValidity() const { return mUidValidity; }
00139
00142 void clearUidMap() { uidMap.clear(); }
00143
00145 void setAccount(KMAcctCachedImap *acct);
00146 KMAcctCachedImap* account() const;
00147
00149 QString uidCacheLocation() const;
00150
00152 int readUidCache();
00153
00155 int writeUidCache();
00156
00158 int progress() const { return mProgress; }
00159
00160
00161 virtual int rename(const QString& aName, KMFolderDir *aParent=0);
00162
00163
00164 virtual KMMessage* take(int idx);
00165
00166 virtual int addMsg(KMMessage* msg, int* index_return = 0);
00167
00168 virtual int addMsgInternal(KMMessage* msg, bool, int* index_return = 0);
00169 virtual int addMsgKeepUID(KMMessage* msg, int* index_return = 0) {
00170 return addMsgInternal(msg, false, index_return);
00171 }
00172
00173
00174 virtual void removeMsg(int i, bool imapQuiet = FALSE);
00175 virtual void removeMsg(QPtrList<KMMessage> msgList, bool imapQuiet = FALSE)
00176 { FolderStorage::removeMsg(msgList, imapQuiet); }
00177
00179 bool isReadOnly() const { return KMFolderMaildir::isReadOnly() || mReadOnly; }
00180
00184 void sendFolderComplete(bool success)
00185 { emit folderComplete(this, success); }
00186
00190 void setSilentUpload( bool silent ) { mSilentUpload = silent; }
00191 bool silentUpload() { return mSilentUpload; }
00192
00193 virtual int createIndexFromContents()
00194 { return KMFolderMaildir::createIndexFromContents(); }
00195
00196
00197
00203 virtual bool listDirectory();
00204
00205 virtual void listNamespaces();
00206
00208 KMFolder* trashFolder() const;
00209
00214 int userRights() const { return mUserRights; }
00215
00217 void setUserRights( unsigned int userRights );
00218
00228 const QuotaInfo quotaInfo() const { return mQuotaInfo; }
00229
00231 typedef QValueVector<KMail::ACLListEntry> ACLList;
00232 const ACLList& aclList() const { return mACLList; }
00233
00235 void setACLList( const ACLList& arr );
00236
00237
00238 virtual void setStatus( int id, KMMsgStatus status, bool toggle );
00239 virtual void setStatus( QValueList<int>& ids, KMMsgStatus status, bool toggle );
00240
00241 QString annotationFolderType() const { return mAnnotationFolderType; }
00242
00243
00244 void updateAnnotationFolderType();
00245
00254 enum IncidencesFor { IncForNobody, IncForAdmins, IncForReaders };
00255
00256 IncidencesFor incidencesFor() const { return mIncidencesFor; }
00258 void setIncidencesFor( IncidencesFor incfor );
00259
00261 virtual bool isMoveable() const;
00262
00267 QStringList namespacesToList() { return mNamespacesToList; }
00268 void setNamespacesToList( QStringList list ) { mNamespacesToList = list; }
00269
00274 const QString& imapPathForCreation() { return mImapPathCreation; }
00275 void setImapPathForCreation( const QString& path ) { mImapPathCreation = path; }
00276
00277 protected slots:
00278 void slotGetMessagesData(KIO::Job * job, const QByteArray & data);
00279 void getMessagesResult(KMail::FolderJob *, bool lastSet);
00280 void slotGetLastMessagesResult(KMail::FolderJob *);
00281 void slotProgress(unsigned long done, unsigned long total);
00282 void slotPutProgress( unsigned long, unsigned long );
00283
00284
00285 void slotSubFolderComplete(KMFolderCachedImap*, bool);
00286
00287
00288 void slotConnectionResult( int errorCode, const QString& errorMsg );
00289
00290 void slotCheckUidValidityResult( KMail::FolderJob* job );
00291 void slotTestAnnotationResult(KIO::Job *job);
00292 void slotGetAnnotationResult( KIO::Job* );
00293 void slotSetAnnotationResult(KIO::Job *job);
00294 void slotReceivedUserRights( KMFolder* );
00295 void slotReceivedACL( KMFolder*, KIO::Job*, const KMail::ACLList& );
00296
00297 void slotMultiSetACLResult(KIO::Job *);
00298 void slotACLChanged( const QString&, int );
00299 void slotAnnotationResult(const QString& entry, const QString& value, bool found);
00300 void slotAnnotationChanged( const QString& entry, const QString& attribute, const QString& value );
00301 void slotDeleteMessagesResult(KMail::FolderJob *);
00302 void slotImapStatusChanged(KMFolder* folder, const QString&, bool);
00303 void slotStorageQuotaResult( const QuotaInfo& );
00304 void slotQuotaResult( KIO::Job* job );
00305
00306 protected:
00307
00308
00309 bool deleteMessages();
00310 void listMessages();
00311 void uploadNewMessages();
00312 void uploadFlags();
00313 void createNewFolders();
00314
00315 void listDirectory2();
00316
00317
00320 virtual QValueList<unsigned long> findNewMessages();
00323 virtual QValueList<KMFolderCachedImap*> findNewFolders();
00324
00326 virtual bool canRemoveFolder() const;
00327
00329 virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00330 QString partSpecifier, const AttachmentStrategy *as ) const;
00331 virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00332 FolderJob::JobType jt, KMFolder *folder ) const;
00333
00334 virtual void timerEvent( QTimerEvent* );
00335
00336
00337 void newState( int progress, const QString& syncStatus );
00338
00340 KMFolderCachedImap* findParent( const QString& path, const QString& name );
00341
00342 public slots:
00346 void slotSimpleData(KIO::Job * job, const QByteArray & data);
00347
00351 void slotTroubleshoot();
00352
00357 void slotListResult( const QStringList&, const QStringList&,
00358 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00359
00364 void slotCheckNamespace( const QStringList&, const QStringList&,
00365 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00366
00367 private slots:
00368 void serverSyncInternal();
00369 void slotIncreaseProgress();
00370 void slotUpdateLastUid();
00371 void slotFolderDeletionOnServerFinished();
00372
00373 signals:
00374 void folderComplete(KMFolderCachedImap *folder, bool success);
00375 void listComplete( KMFolderCachedImap* );
00376
00380 void syncState( int state, int number );
00381
00382 private:
00383 void setReadOnly( bool readOnly );
00384 QString state2String( int state ) const;
00385
00387 enum {
00388 SYNC_STATE_INITIAL,
00389 SYNC_STATE_TEST_ANNOTATIONS,
00390 SYNC_STATE_PUT_MESSAGES,
00391 SYNC_STATE_UPLOAD_FLAGS,
00392 SYNC_STATE_CREATE_SUBFOLDERS,
00393 SYNC_STATE_LIST_NAMESPACES,
00394 SYNC_STATE_LIST_SUBFOLDERS,
00395 SYNC_STATE_LIST_SUBFOLDERS2,
00396 SYNC_STATE_DELETE_SUBFOLDERS,
00397 SYNC_STATE_LIST_MESSAGES,
00398 SYNC_STATE_DELETE_MESSAGES,
00399 SYNC_STATE_EXPUNGE_MESSAGES,
00400 SYNC_STATE_GET_MESSAGES,
00401 SYNC_STATE_HANDLE_INBOX,
00402 SYNC_STATE_GET_USERRIGHTS,
00403 SYNC_STATE_GET_ANNOTATIONS,
00404 SYNC_STATE_SET_ANNOTATIONS,
00405 SYNC_STATE_GET_ACLS,
00406 SYNC_STATE_SET_ACLS,
00407 SYNC_STATE_GET_QUOTA,
00408 SYNC_STATE_FIND_SUBFOLDERS,
00409 SYNC_STATE_SYNC_SUBFOLDERS,
00410 SYNC_STATE_CHECK_UIDVALIDITY,
00411 SYNC_STATE_RENAME_FOLDER
00412 } mSyncState;
00413
00414 int mProgress;
00415 int mStatusFlagsJobs;
00416
00417 QString mUidValidity;
00418 QString mImapPath;
00419 imapState mContentState, mSubfolderState;
00420 QStringList mSubfolderNames, mSubfolderPaths,
00421 mSubfolderMimeTypes, mSubfolderAttributes;
00422 QString mAnnotationFolderType;
00423 IncidencesFor mIncidencesFor;
00424
00425 bool mHasInbox;
00426 bool mIsSelected;
00427 bool mCheckFlags;
00428 bool mReadOnly;
00429 mutable QGuardedPtr<KMAcctCachedImap> mAccount;
00430
00431 QIntDict<int> uidsOnServer;
00432 QValueList<ulong> uidsForDeletionOnServer;
00433 QValueList<KMail::CachedImapJob::MsgForDownload> mMsgsForDownload;
00434 QValueList<ulong> mUidsForDownload;
00435 QStringList foldersForDeletionOnServer;
00436
00437 QValueList<KMFolderCachedImap*> mSubfoldersForSync;
00438 KMFolderCachedImap* mCurrentSubfolder;
00439
00443 QMap<ulong,int> uidMap;
00444 bool uidMapDirty;
00445 void reloadUidMap();
00446 int uidWriteTimer;
00447
00457 ulong mLastUid;
00462 ulong mTentativeHighestUid;
00463
00467 bool mFoundAnIMAPDigest;
00468
00469 int mUserRights;
00470 ACLList mACLList;
00471
00472 bool mSilentUpload;
00473 bool mFolderRemoved;
00474
00475 bool mRecurse;
00480 bool mStatusChangedLocally;
00482 bool mAnnotationFolderTypeChanged;
00484 bool mIncidencesForChanged;
00485
00486 QStringList mNamespacesToList;
00487 int mNamespacesToCheck;
00488 bool mPersonalNamespacesCheckDone;
00489 QString mImapPathCreation;
00490
00491 QuotaInfo mQuotaInfo;
00492 };
00493
00494 #endif