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 class QComboBox;
00055 class QRadioButton;
00056
00057 namespace KMail {
00058 class AttachmentStrategy;
00059 class ImapAccountBase;
00060 struct ACLListEntry;
00061 }
00062 using KMail::AttachmentStrategy;
00063
00064 class DImapTroubleShootDialog : public KDialogBase
00065 {
00066 Q_OBJECT
00067 public:
00068 enum SelectedOperation {
00069 None = -1,
00070 ReindexCurrent = 0,
00071 ReindexRecursive = 1,
00072 ReindexAll = 2,
00073 RefreshCache
00074 };
00075
00076 DImapTroubleShootDialog( QWidget* parent=0, const char* name=0 );
00077
00078 static int run();
00079
00080 private slots:
00081 void slotDone();
00082
00083 private:
00084 QRadioButton *mIndexButton, *mCacheButton;
00085 QComboBox *mIndexScope;
00086 int rc;
00087 };
00088
00089 class KMFolderCachedImap : public KMFolderMaildir
00090 {
00091 Q_OBJECT
00092
00093 public:
00094 static QString cacheLocation() {
00095 return locateLocal("data", "kmail/dimap" );
00096 }
00097
00101 KMFolderCachedImap(KMFolder* folder, const char* name=0);
00102 virtual ~KMFolderCachedImap();
00103
00105 void reallyDoClose( const char * owner );
00106
00108 void initializeFrom( KMFolderCachedImap* parent );
00109
00110 virtual void readConfig();
00111 virtual void writeConfig();
00112
00113 void writeConfigKeysWhichShouldNotGetOverwrittenByReadConfig();
00114
00116 virtual KMFolderType folderType() const { return KMFolderTypeCachedImap; }
00117
00119 virtual int create();
00120
00122 virtual void remove();
00123
00125 virtual void serverSync( bool recurse );
00126
00128 void resetSyncState();
00129
00130 void checkUidValidity();
00131
00132 enum imapState { imapNoInformation=0, imapInProgress=1, imapFinished=2 };
00133
00134 virtual imapState getContentState() { return mContentState; }
00135 virtual void setContentState(imapState state) { mContentState = state; }
00136
00137 virtual imapState getSubfolderState() { return mSubfolderState; }
00138 virtual void setSubfolderState(imapState state);
00139
00141 void setImapPath(const QString &path);
00142 QString imapPath() const { return mImapPath; }
00143
00145 void setLastUid( ulong uid );
00146 ulong lastUid();
00147
00149 KMMsgBase* findByUID( ulong uid );
00150
00152 void setUidValidity(const QString &validity) { mUidValidity = validity; }
00153 QString uidValidity() const { return mUidValidity; }
00154
00157 void clearUidMap() { uidMap.clear(); }
00158
00160 void setAccount(KMAcctCachedImap *acct);
00161 KMAcctCachedImap* account() const;
00162
00164 QString uidCacheLocation() const;
00165
00167 int readUidCache();
00168
00170 int writeUidCache();
00171
00173 int progress() const { return mProgress; }
00174
00175
00176 virtual int rename(const QString& aName, KMFolderDir *aParent=0);
00177
00178
00179 virtual KMMessage* take(int idx);
00180
00181 virtual int addMsg(KMMessage* msg, int* index_return = 0);
00182
00183 virtual int addMsgInternal(KMMessage* msg, bool, int* index_return = 0);
00184 virtual int addMsgKeepUID(KMMessage* msg, int* index_return = 0) {
00185 return addMsgInternal(msg, false, index_return);
00186 }
00187
00188
00189 virtual void removeMsg(int i, bool imapQuiet = FALSE);
00190 virtual void removeMsg(QPtrList<KMMessage> msgList, bool imapQuiet = FALSE)
00191 { FolderStorage::removeMsg(msgList, imapQuiet); }
00192
00194 bool isReadOnly() const { return KMFolderMaildir::isReadOnly() || mReadOnly; }
00195
00199 void sendFolderComplete(bool success)
00200 { emit folderComplete(this, success); }
00201
00205 void setSilentUpload( bool silent ) { mSilentUpload = silent; }
00206 bool silentUpload() { return mSilentUpload; }
00207
00208 virtual int createIndexFromContents()
00209 { return KMFolderMaildir::createIndexFromContents(); }
00210
00211 int createIndexFromContentsRecursive();
00212
00213
00214
00220 virtual bool listDirectory();
00221
00222 virtual void listNamespaces();
00223
00225 KMFolder* trashFolder() const;
00226
00231 int userRights() const { return mUserRights; }
00232
00234 void setUserRights( unsigned int userRights );
00235
00245 const QuotaInfo quotaInfo() const { return mQuotaInfo; }
00246
00248 typedef QValueVector<KMail::ACLListEntry> ACLList;
00249 const ACLList& aclList() const { return mACLList; }
00250
00252 void setACLList( const ACLList& arr );
00253
00254
00255 virtual void setStatus( int id, KMMsgStatus status, bool toggle );
00256 virtual void setStatus( QValueList<int>& ids, KMMsgStatus status, bool toggle );
00257
00258 QString annotationFolderType() const { return mAnnotationFolderType; }
00259
00260
00261 void updateAnnotationFolderType();
00262
00271 enum IncidencesFor { IncForNobody, IncForAdmins, IncForReaders };
00272
00273 IncidencesFor incidencesFor() const { return mIncidencesFor; }
00275 void setIncidencesFor( IncidencesFor incfor );
00276
00278 virtual bool isMoveable() const;
00279
00284 QStringList namespacesToList() { return mNamespacesToList; }
00285 void setNamespacesToList( QStringList list ) { mNamespacesToList = list; }
00286
00291 const QString& imapPathForCreation() { return mImapPathCreation; }
00292 void setImapPathForCreation( const QString& path ) { mImapPathCreation = path; }
00293
00294 protected slots:
00295 void slotGetMessagesData(KIO::Job * job, const QByteArray & data);
00296 void getMessagesResult(KMail::FolderJob *, bool lastSet);
00297 void slotGetLastMessagesResult(KMail::FolderJob *);
00298 void slotProgress(unsigned long done, unsigned long total);
00299 void slotPutProgress( unsigned long, unsigned long );
00300
00301
00302 void slotSubFolderComplete(KMFolderCachedImap*, bool);
00303
00304
00305 void slotConnectionResult( int errorCode, const QString& errorMsg );
00306
00307 void slotCheckUidValidityResult( KMail::FolderJob* job );
00308 void slotTestAnnotationResult(KIO::Job *job);
00309 void slotGetAnnotationResult( KIO::Job* );
00310 void slotMultiUrlGetAnnotationResult( KIO::Job* );
00311 void slotSetAnnotationResult(KIO::Job *job);
00312 void slotReceivedUserRights( KMFolder* );
00313 void slotReceivedACL( KMFolder*, KIO::Job*, const KMail::ACLList& );
00314
00315 void slotMultiSetACLResult(KIO::Job *);
00316 void slotACLChanged( const QString&, int );
00317 void slotAnnotationResult(const QString& entry, const QString& value, bool found);
00318 void slotAnnotationChanged( const QString& entry, const QString& attribute, const QString& value );
00319 void slotDeleteMessagesResult(KMail::FolderJob *);
00320 void slotImapStatusChanged(KMFolder* folder, const QString&, bool);
00321 void slotStorageQuotaResult( const QuotaInfo& );
00322 void slotQuotaResult( KIO::Job* job );
00323
00324 protected:
00325
00326
00327 bool deleteMessages();
00328 void listMessages();
00329 void uploadNewMessages();
00330 void uploadFlags();
00331 void uploadSeenFlags();
00332 void createNewFolders();
00333
00334 void listDirectory2();
00335 void createFoldersNewOnServerAndFinishListing( const QValueVector<int> foldersNewOnServer );
00336
00337
00340 virtual QValueList<unsigned long> findNewMessages();
00343 virtual QValueList<KMFolderCachedImap*> findNewFolders();
00344
00346 virtual bool canRemoveFolder() const;
00347
00349 virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00350 QString partSpecifier, const AttachmentStrategy *as ) const;
00351 virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00352 FolderJob::JobType jt, KMFolder *folder ) const;
00353
00354 virtual void timerEvent( QTimerEvent* );
00355
00356
00357 void newState( int progress, const QString& syncStatus );
00358
00360 KMFolderCachedImap* findParent( const QString& path, const QString& name );
00361
00362 public slots:
00366 void slotSimpleData(KIO::Job * job, const QByteArray & data);
00367
00371 void slotTroubleshoot();
00372
00377 void slotListResult( const QStringList&, const QStringList&,
00378 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00379
00384 void slotCheckNamespace( const QStringList&, const QStringList&,
00385 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00386
00387 private slots:
00388 void serverSyncInternal();
00389 void slotIncreaseProgress();
00390 void slotUpdateLastUid();
00391 void slotFolderDeletionOnServerFinished();
00392
00393 signals:
00394 void folderComplete(KMFolderCachedImap *folder, bool success);
00395 void listComplete( KMFolderCachedImap* );
00396
00400 void syncState( int state, int number );
00401
00402 private:
00403 void setReadOnly( bool readOnly );
00404 QString state2String( int state ) const;
00405 void rememberDeletion( int );
00406
00408 enum {
00409 SYNC_STATE_INITIAL,
00410 SYNC_STATE_TEST_ANNOTATIONS,
00411 SYNC_STATE_PUT_MESSAGES,
00412 SYNC_STATE_UPLOAD_FLAGS,
00413 SYNC_STATE_CREATE_SUBFOLDERS,
00414 SYNC_STATE_LIST_NAMESPACES,
00415 SYNC_STATE_LIST_SUBFOLDERS,
00416 SYNC_STATE_LIST_SUBFOLDERS2,
00417 SYNC_STATE_DELETE_SUBFOLDERS,
00418 SYNC_STATE_LIST_MESSAGES,
00419 SYNC_STATE_DELETE_MESSAGES,
00420 SYNC_STATE_EXPUNGE_MESSAGES,
00421 SYNC_STATE_GET_MESSAGES,
00422 SYNC_STATE_HANDLE_INBOX,
00423 SYNC_STATE_GET_USERRIGHTS,
00424 SYNC_STATE_GET_ANNOTATIONS,
00425 SYNC_STATE_SET_ANNOTATIONS,
00426 SYNC_STATE_GET_ACLS,
00427 SYNC_STATE_SET_ACLS,
00428 SYNC_STATE_GET_QUOTA,
00429 SYNC_STATE_FIND_SUBFOLDERS,
00430 SYNC_STATE_SYNC_SUBFOLDERS,
00431 SYNC_STATE_CHECK_UIDVALIDITY,
00432 SYNC_STATE_RENAME_FOLDER
00433 } mSyncState;
00434
00435 int mProgress;
00436 int mStatusFlagsJobs;
00437
00438 QString mUidValidity;
00439 QString mImapPath;
00440 imapState mContentState, mSubfolderState;
00441 QStringList mSubfolderNames, mSubfolderPaths,
00442 mSubfolderMimeTypes, mSubfolderAttributes;
00443 QString mAnnotationFolderType;
00444 IncidencesFor mIncidencesFor;
00445
00446 bool mHasInbox;
00447 bool mIsSelected;
00448 bool mCheckFlags;
00449 bool mReadOnly;
00450 mutable QGuardedPtr<KMAcctCachedImap> mAccount;
00451
00452 QIntDict<int> uidsOnServer;
00453 QValueList<ulong> uidsForDeletionOnServer;
00454 QValueList<KMail::CachedImapJob::MsgForDownload> mMsgsForDownload;
00455 QValueList<ulong> mUidsForDownload;
00456 QStringList foldersForDeletionOnServer;
00457
00458 QValueList<KMFolderCachedImap*> mSubfoldersForSync;
00459 KMFolderCachedImap* mCurrentSubfolder;
00460
00464 QMap<ulong,int> uidMap;
00465 bool uidMapDirty;
00466 void reloadUidMap();
00467 int uidWriteTimer;
00468
00478 ulong mLastUid;
00483 ulong mTentativeHighestUid;
00484
00488 bool mFoundAnIMAPDigest;
00489
00490 int mUserRights, mOldUserRights;
00491 ACLList mACLList;
00492
00493 bool mSilentUpload;
00494 bool mFolderRemoved;
00495
00496 bool mRecurse;
00501 bool mStatusChangedLocally;
00503 bool mAnnotationFolderTypeChanged;
00505 bool mIncidencesForChanged;
00506
00507 QStringList mNamespacesToList;
00508 int mNamespacesToCheck;
00509 bool mPersonalNamespacesCheckDone;
00510 QString mImapPathCreation;
00511 QMap<ulong,void*> mDeletedUIDsSinceLastSync;
00512
00513 QuotaInfo mQuotaInfo;
00514 };
00515
00516 #endif