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
00049 using KMail::FolderJob;
00050 class KMAcctCachedImap;
00051
00052 namespace KMail {
00053 class AttachmentStrategy;
00054 class ImapAccountBase;
00055 struct ACLListEntry;
00056 }
00057 using KMail::AttachmentStrategy;
00058
00059 class DImapTroubleShootDialog : public KDialogBase
00060 {
00061 Q_OBJECT
00062 public:
00063 DImapTroubleShootDialog( QWidget* parent=0, const char* name=0 );
00064
00065 static int run();
00066
00067 private slots:
00068 void slotRebuildIndex();
00069 void slotRebuildCache();
00070
00071 private:
00072 int rc;
00073 };
00074
00075 class KMFolderCachedImap : public KMFolderMaildir
00076 {
00077 Q_OBJECT
00078
00079 public:
00080 static QString cacheLocation() {
00081 return locateLocal("data", "kmail/dimap" );
00082 }
00083
00087 KMFolderCachedImap(KMFolder* folder, const char* name=0);
00088 virtual ~KMFolderCachedImap();
00089
00091 void initializeFrom( KMFolderCachedImap* parent );
00092
00093 virtual void readConfig();
00094 virtual void writeConfig();
00095
00096 void writeAnnotationConfig();
00097
00099 virtual KMFolderType folderType() const { return KMFolderTypeCachedImap; }
00100
00102 virtual int create();
00103
00105 virtual void remove();
00106
00108 virtual void serverSync( bool recurse );
00109
00111 void resetSyncState();
00112
00113 void checkUidValidity();
00114
00115 enum imapState { imapNoInformation=0, imapInProgress=1, imapFinished=2 };
00116
00117 virtual imapState getContentState() { return mContentState; }
00118 virtual void setContentState(imapState state) { mContentState = state; }
00119
00120 virtual imapState getSubfolderState() { return mSubfolderState; }
00121 virtual void setSubfolderState(imapState state);
00122
00124 void setImapPath(const QString &path);
00125 QString imapPath() const { return mImapPath; }
00126
00128 void setLastUid( ulong uid );
00129 ulong lastUid();
00130
00132 KMMsgBase* findByUID( ulong uid );
00133
00135 void setUidValidity(const QString &validity) { mUidValidity = validity; }
00136 QString uidValidity() const { return mUidValidity; }
00137
00140 void clearUidMap() { uidMap.clear(); }
00141
00143 void setAccount(KMAcctCachedImap *acct);
00144 KMAcctCachedImap* account() const;
00145
00147 QString uidCacheLocation() const;
00148
00150 int readUidCache();
00151
00153 int writeUidCache();
00154
00156 int progress() const { return mProgress; }
00157
00158
00159 virtual int rename(const QString& aName, KMFolderDir *aParent=0);
00160
00161
00162 virtual KMMessage* take(int idx);
00163
00164 virtual int addMsg(KMMessage* msg, int* index_return = 0);
00165
00166 virtual int addMsgInternal(KMMessage* msg, bool, int* index_return = 0);
00167 virtual int addMsgKeepUID(KMMessage* msg, int* index_return = 0) {
00168 return addMsgInternal(msg, false, index_return);
00169 }
00170
00171
00172 virtual void removeMsg(int i, bool imapQuiet = FALSE);
00173 virtual void removeMsg(QPtrList<KMMessage> msgList, bool imapQuiet = FALSE)
00174 { FolderStorage::removeMsg(msgList, imapQuiet); }
00175
00177 bool isReadOnly() const { return KMFolderMaildir::isReadOnly() || mReadOnly; }
00178
00182 void sendFolderComplete(bool success)
00183 { emit folderComplete(this, success); }
00184
00188 void setSilentUpload( bool silent ) { mSilentUpload = silent; }
00189 bool silentUpload() { return mSilentUpload; }
00190
00191 virtual int createIndexFromContents()
00192 { return KMFolderMaildir::createIndexFromContents(); }
00193
00194
00195
00201 virtual bool listDirectory();
00202
00203 virtual void listNamespaces();
00204
00206 KMFolder* trashFolder() const;
00207
00212 int userRights() const { return mUserRights; }
00213
00215 void setUserRights( unsigned int userRights );
00216
00218 typedef QValueVector<KMail::ACLListEntry> ACLList;
00219 const ACLList& aclList() const { return mACLList; }
00220
00222 void setACLList( const ACLList& arr );
00223
00224
00225 virtual void setStatus( int id, KMMsgStatus status, bool toggle );
00226 virtual void setStatus( QValueList<int>& ids, KMMsgStatus status, bool toggle );
00227
00228 QString annotationFolderType() const { return mAnnotationFolderType; }
00229
00230
00231 void updateAnnotationFolderType();
00232
00241 enum IncidencesFor { IncForNobody, IncForAdmins, IncForReaders };
00242
00243 IncidencesFor incidencesFor() const { return mIncidencesFor; }
00245 void setIncidencesFor( IncidencesFor incfor );
00246
00248 virtual bool isMoveable() const;
00249
00254 QStringList namespacesToList() { return mNamespacesToList; }
00255 void setNamespacesToList( QStringList list ) { mNamespacesToList = list; }
00256
00261 const QString& imapPathForCreation() { return mImapPathCreation; }
00262 void setImapPathForCreation( const QString& path ) { mImapPathCreation = path; }
00263
00264 protected slots:
00265 void slotGetMessagesData(KIO::Job * job, const QByteArray & data);
00266 void getMessagesResult(KMail::FolderJob *, bool lastSet);
00267 void slotGetLastMessagesResult(KMail::FolderJob *);
00268 void slotProgress(unsigned long done, unsigned long total);
00269 void slotPutProgress( unsigned long, unsigned long );
00270
00271
00272 void slotSubFolderComplete(KMFolderCachedImap*, bool);
00273
00274
00275 void slotConnectionResult( int errorCode, const QString& errorMsg );
00276
00277 void slotCheckUidValidityResult( KMail::FolderJob* job );
00278 void slotTestAnnotationResult(KIO::Job *job);
00279 void slotGetAnnotationResult( KIO::Job* );
00280 void slotSetAnnotationResult(KIO::Job *job);
00281 void slotReceivedUserRights( KMFolder* );
00282 void slotReceivedACL( KMFolder*, KIO::Job*, const KMail::ACLList& );
00283
00284 void slotMultiSetACLResult(KIO::Job *);
00285 void slotACLChanged( const QString&, int );
00286 void slotAnnotationResult(const QString& entry, const QString& value, bool found);
00287 void slotAnnotationChanged( const QString& entry, const QString& attribute, const QString& value );
00288 void slotDeleteMessagesResult(KMail::FolderJob *);
00289 void slotImapStatusChanged(KMFolder* folder, const QString&, bool);
00290
00291 protected:
00292
00293
00294 bool deleteMessages();
00295 void listMessages();
00296 void uploadNewMessages();
00297 void uploadFlags();
00298 void createNewFolders();
00299
00300 void listDirectory2();
00301
00302
00305 virtual QValueList<unsigned long> findNewMessages();
00308 virtual QValueList<KMFolderCachedImap*> findNewFolders();
00309
00311 virtual bool canRemoveFolder() const;
00312
00314 virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00315 QString partSpecifier, const AttachmentStrategy *as ) const;
00316 virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00317 FolderJob::JobType jt, KMFolder *folder ) const;
00318
00319 virtual void timerEvent( QTimerEvent* );
00320
00321
00322 void newState( int progress, const QString& syncStatus );
00323
00325 KMFolderCachedImap* findParent( const QString& path, const QString& name );
00326
00327 public slots:
00331 void slotSimpleData(KIO::Job * job, const QByteArray & data);
00332
00336 void slotTroubleshoot();
00337
00342 void slotListResult( const QStringList&, const QStringList&,
00343 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00344
00349 void slotCheckNamespace( const QStringList&, const QStringList&,
00350 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00351
00352 private slots:
00353 void serverSyncInternal();
00354 void slotIncreaseProgress();
00355 void slotUpdateLastUid();
00356 void slotFolderDeletionOnServerFinished();
00357
00358 signals:
00359 void folderComplete(KMFolderCachedImap *folder, bool success);
00360 void listComplete( KMFolderCachedImap* );
00361
00365 void syncState( int state, int number );
00366
00367 private:
00368 void setReadOnly( bool readOnly );
00369 QString state2String( int state ) const;
00370
00372 enum {
00373 SYNC_STATE_INITIAL,
00374 SYNC_STATE_TEST_ANNOTATIONS,
00375 SYNC_STATE_PUT_MESSAGES,
00376 SYNC_STATE_UPLOAD_FLAGS,
00377 SYNC_STATE_CREATE_SUBFOLDERS,
00378 SYNC_STATE_LIST_NAMESPACES,
00379 SYNC_STATE_LIST_SUBFOLDERS,
00380 SYNC_STATE_LIST_SUBFOLDERS2,
00381 SYNC_STATE_DELETE_SUBFOLDERS,
00382 SYNC_STATE_LIST_MESSAGES,
00383 SYNC_STATE_DELETE_MESSAGES,
00384 SYNC_STATE_EXPUNGE_MESSAGES,
00385 SYNC_STATE_GET_MESSAGES,
00386 SYNC_STATE_HANDLE_INBOX,
00387 SYNC_STATE_GET_USERRIGHTS,
00388 SYNC_STATE_GET_ANNOTATIONS,
00389 SYNC_STATE_SET_ANNOTATIONS,
00390 SYNC_STATE_GET_ACLS,
00391 SYNC_STATE_SET_ACLS,
00392 SYNC_STATE_FIND_SUBFOLDERS,
00393 SYNC_STATE_SYNC_SUBFOLDERS,
00394 SYNC_STATE_CHECK_UIDVALIDITY,
00395 SYNC_STATE_RENAME_FOLDER
00396 } mSyncState;
00397
00398 int mProgress;
00399 int mStatusFlagsJobs;
00400
00401 QString mUidValidity;
00402 QString mImapPath;
00403 imapState mContentState, mSubfolderState;
00404 QStringList mSubfolderNames, mSubfolderPaths,
00405 mSubfolderMimeTypes, mSubfolderAttributes;
00406 QString mAnnotationFolderType;
00407 IncidencesFor mIncidencesFor;
00408
00409 bool mHasInbox;
00410 bool mIsSelected;
00411 bool mCheckFlags;
00412 bool mReadOnly;
00413 mutable QGuardedPtr<KMAcctCachedImap> mAccount;
00414
00415 QIntDict<int> uidsOnServer;
00416 QValueList<ulong> uidsForDeletionOnServer;
00417 QValueList<KMail::CachedImapJob::MsgForDownload> mMsgsForDownload;
00418 QValueList<ulong> mUidsForDownload;
00419 QStringList foldersForDeletionOnServer;
00420
00421 QValueList<KMFolderCachedImap*> mSubfoldersForSync;
00422 KMFolderCachedImap* mCurrentSubfolder;
00423
00427 QMap<ulong,int> uidMap;
00428 bool uidMapDirty;
00429 void reloadUidMap();
00430 int uidWriteTimer;
00431
00441 ulong mLastUid;
00446 ulong mTentativeHighestUid;
00447
00451 bool mFoundAnIMAPDigest;
00452
00453 int mUserRights;
00454 ACLList mACLList;
00455
00456 bool mSilentUpload;
00457 bool mFolderRemoved;
00458
00459 bool mRecurse;
00464 bool mStatusChangedLocally;
00466 bool mAnnotationFolderTypeChanged;
00468 bool mIncidencesForChanged;
00469
00470 QStringList mNamespacesToList;
00471 int mNamespacesToCheck;
00472 bool mPersonalNamespacesCheckDone;
00473 QString mImapPathCreation;
00474 };
00475
00476 #endif