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 initializeFrom( KMFolderCachedImap* parent );
00106
00107 virtual void readConfig();
00108 virtual void writeConfig();
00109
00110 void writeConfigKeysWhichShouldNotGetOverwrittenByReadConfig();
00111
00113 virtual KMFolderType folderType() const { return KMFolderTypeCachedImap; }
00114
00116 virtual int create();
00117
00119 virtual void remove();
00120
00122 virtual void serverSync( bool recurse );
00123
00125 void resetSyncState();
00126
00127 void checkUidValidity();
00128
00129 enum imapState { imapNoInformation=0, imapInProgress=1, imapFinished=2 };
00130
00131 virtual imapState getContentState() { return mContentState; }
00132 virtual void setContentState(imapState state) { mContentState = state; }
00133
00134 virtual imapState getSubfolderState() { return mSubfolderState; }
00135 virtual void setSubfolderState(imapState state);
00136
00138 void setImapPath(const QString &path);
00139 QString imapPath() const { return mImapPath; }
00140
00142 void setLastUid( ulong uid );
00143 ulong lastUid();
00144
00146 KMMsgBase* findByUID( ulong uid );
00147
00149 void setUidValidity(const QString &validity) { mUidValidity = validity; }
00150 QString uidValidity() const { return mUidValidity; }
00151
00154 void clearUidMap() { uidMap.clear(); }
00155
00157 void setAccount(KMAcctCachedImap *acct);
00158 KMAcctCachedImap* account() const;
00159
00161 QString uidCacheLocation() const;
00162
00164 int readUidCache();
00165
00167 int writeUidCache();
00168
00170 int progress() const { return mProgress; }
00171
00172
00173 virtual int rename(const QString& aName, KMFolderDir *aParent=0);
00174
00175
00176 virtual KMMessage* take(int idx);
00177
00178 virtual int addMsg(KMMessage* msg, int* index_return = 0);
00179
00180 virtual int addMsgInternal(KMMessage* msg, bool, int* index_return = 0);
00181 virtual int addMsgKeepUID(KMMessage* msg, int* index_return = 0) {
00182 return addMsgInternal(msg, false, index_return);
00183 }
00184
00185
00186 virtual void removeMsg(int i, bool imapQuiet = FALSE);
00187 virtual void removeMsg(QPtrList<KMMessage> msgList, bool imapQuiet = FALSE)
00188 { FolderStorage::removeMsg(msgList, imapQuiet); }
00189
00191 bool isReadOnly() const { return KMFolderMaildir::isReadOnly() || mReadOnly; }
00192
00196 void sendFolderComplete(bool success)
00197 { emit folderComplete(this, success); }
00198
00202 void setSilentUpload( bool silent ) { mSilentUpload = silent; }
00203 bool silentUpload() { return mSilentUpload; }
00204
00205 virtual int createIndexFromContents()
00206 { return KMFolderMaildir::createIndexFromContents(); }
00207
00208 int createIndexFromContentsRecursive();
00209
00210
00211
00217 virtual bool listDirectory();
00218
00219 virtual void listNamespaces();
00220
00222 KMFolder* trashFolder() const;
00223
00228 int userRights() const { return mUserRights; }
00229
00231 void setUserRights( unsigned int userRights );
00232
00242 const QuotaInfo quotaInfo() const { return mQuotaInfo; }
00243
00245 typedef QValueVector<KMail::ACLListEntry> ACLList;
00246 const ACLList& aclList() const { return mACLList; }
00247
00249 void setACLList( const ACLList& arr );
00250
00251
00252 virtual void setStatus( int id, KMMsgStatus status, bool toggle );
00253 virtual void setStatus( QValueList<int>& ids, KMMsgStatus status, bool toggle );
00254
00255 QString annotationFolderType() const { return mAnnotationFolderType; }
00256
00257
00258 void updateAnnotationFolderType();
00259
00268 enum IncidencesFor { IncForNobody, IncForAdmins, IncForReaders };
00269
00270 IncidencesFor incidencesFor() const { return mIncidencesFor; }
00272 void setIncidencesFor( IncidencesFor incfor );
00273
00275 virtual bool isMoveable() const;
00276
00281 QStringList namespacesToList() { return mNamespacesToList; }
00282 void setNamespacesToList( QStringList list ) { mNamespacesToList = list; }
00283
00288 const QString& imapPathForCreation() { return mImapPathCreation; }
00289 void setImapPathForCreation( const QString& path ) { mImapPathCreation = path; }
00290
00291 protected slots:
00292 void slotGetMessagesData(KIO::Job * job, const QByteArray & data);
00293 void getMessagesResult(KMail::FolderJob *, bool lastSet);
00294 void slotGetLastMessagesResult(KMail::FolderJob *);
00295 void slotProgress(unsigned long done, unsigned long total);
00296 void slotPutProgress( unsigned long, unsigned long );
00297
00298
00299 void slotSubFolderComplete(KMFolderCachedImap*, bool);
00300
00301
00302 void slotConnectionResult( int errorCode, const QString& errorMsg );
00303
00304 void slotCheckUidValidityResult( KMail::FolderJob* job );
00305 void slotTestAnnotationResult(KIO::Job *job);
00306 void slotGetAnnotationResult( KIO::Job* );
00307 void slotMultiUrlGetAnnotationResult( KIO::Job* );
00308 void slotSetAnnotationResult(KIO::Job *job);
00309 void slotReceivedUserRights( KMFolder* );
00310 void slotReceivedACL( KMFolder*, KIO::Job*, const KMail::ACLList& );
00311
00312 void slotMultiSetACLResult(KIO::Job *);
00313 void slotACLChanged( const QString&, int );
00314 void slotAnnotationResult(const QString& entry, const QString& value, bool found);
00315 void slotAnnotationChanged( const QString& entry, const QString& attribute, const QString& value );
00316 void slotDeleteMessagesResult(KMail::FolderJob *);
00317 void slotImapStatusChanged(KMFolder* folder, const QString&, bool);
00318 void slotStorageQuotaResult( const QuotaInfo& );
00319 void slotQuotaResult( KIO::Job* job );
00320
00321 protected:
00322
00323
00324 bool deleteMessages();
00325 void listMessages();
00326 void uploadNewMessages();
00327 void uploadFlags();
00328 void createNewFolders();
00329
00330 void listDirectory2();
00331 void createFoldersNewOnServerAndFinishListing( const QValueVector<int> foldersNewOnServer );
00332
00333
00336 virtual QValueList<unsigned long> findNewMessages();
00339 virtual QValueList<KMFolderCachedImap*> findNewFolders();
00340
00342 virtual bool canRemoveFolder() const;
00343
00345 virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00346 QString partSpecifier, const AttachmentStrategy *as ) const;
00347 virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00348 FolderJob::JobType jt, KMFolder *folder ) const;
00349
00350 virtual void timerEvent( QTimerEvent* );
00351
00352
00353 void newState( int progress, const QString& syncStatus );
00354
00356 KMFolderCachedImap* findParent( const QString& path, const QString& name );
00357
00358 public slots:
00362 void slotSimpleData(KIO::Job * job, const QByteArray & data);
00363
00367 void slotTroubleshoot();
00368
00373 void slotListResult( const QStringList&, const QStringList&,
00374 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00375
00380 void slotCheckNamespace( const QStringList&, const QStringList&,
00381 const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00382
00383 private slots:
00384 void serverSyncInternal();
00385 void slotIncreaseProgress();
00386 void slotUpdateLastUid();
00387 void slotFolderDeletionOnServerFinished();
00388
00389 signals:
00390 void folderComplete(KMFolderCachedImap *folder, bool success);
00391 void listComplete( KMFolderCachedImap* );
00392
00396 void syncState( int state, int number );
00397
00398 private:
00399 void setReadOnly( bool readOnly );
00400 QString state2String( int state ) const;
00401
00403 enum {
00404 SYNC_STATE_INITIAL,
00405 SYNC_STATE_TEST_ANNOTATIONS,
00406 SYNC_STATE_PUT_MESSAGES,
00407 SYNC_STATE_UPLOAD_FLAGS,
00408 SYNC_STATE_CREATE_SUBFOLDERS,
00409 SYNC_STATE_LIST_NAMESPACES,
00410 SYNC_STATE_LIST_SUBFOLDERS,
00411 SYNC_STATE_LIST_SUBFOLDERS2,
00412 SYNC_STATE_DELETE_SUBFOLDERS,
00413 SYNC_STATE_LIST_MESSAGES,
00414 SYNC_STATE_DELETE_MESSAGES,
00415 SYNC_STATE_EXPUNGE_MESSAGES,
00416 SYNC_STATE_GET_MESSAGES,
00417 SYNC_STATE_HANDLE_INBOX,
00418 SYNC_STATE_GET_USERRIGHTS,
00419 SYNC_STATE_GET_ANNOTATIONS,
00420 SYNC_STATE_SET_ANNOTATIONS,
00421 SYNC_STATE_GET_ACLS,
00422 SYNC_STATE_SET_ACLS,
00423 SYNC_STATE_GET_QUOTA,
00424 SYNC_STATE_FIND_SUBFOLDERS,
00425 SYNC_STATE_SYNC_SUBFOLDERS,
00426 SYNC_STATE_CHECK_UIDVALIDITY,
00427 SYNC_STATE_RENAME_FOLDER
00428 } mSyncState;
00429
00430 int mProgress;
00431 int mStatusFlagsJobs;
00432
00433 QString mUidValidity;
00434 QString mImapPath;
00435 imapState mContentState, mSubfolderState;
00436 QStringList mSubfolderNames, mSubfolderPaths,
00437 mSubfolderMimeTypes, mSubfolderAttributes;
00438 QString mAnnotationFolderType;
00439 IncidencesFor mIncidencesFor;
00440
00441 bool mHasInbox;
00442 bool mIsSelected;
00443 bool mCheckFlags;
00444 bool mReadOnly;
00445 mutable QGuardedPtr<KMAcctCachedImap> mAccount;
00446
00447 QIntDict<int> uidsOnServer;
00448 QValueList<ulong> uidsForDeletionOnServer;
00449 QValueList<KMail::CachedImapJob::MsgForDownload> mMsgsForDownload;
00450 QValueList<ulong> mUidsForDownload;
00451 QStringList foldersForDeletionOnServer;
00452
00453 QValueList<KMFolderCachedImap*> mSubfoldersForSync;
00454 KMFolderCachedImap* mCurrentSubfolder;
00455
00459 QMap<ulong,int> uidMap;
00460 bool uidMapDirty;
00461 void reloadUidMap();
00462 int uidWriteTimer;
00463
00473 ulong mLastUid;
00478 ulong mTentativeHighestUid;
00479
00483 bool mFoundAnIMAPDigest;
00484
00485 int mUserRights, mOldUserRights;
00486 ACLList mACLList;
00487
00488 bool mSilentUpload;
00489 bool mFolderRemoved;
00490
00491 bool mRecurse;
00496 bool mStatusChangedLocally;
00498 bool mAnnotationFolderTypeChanged;
00500 bool mIncidencesForChanged;
00501
00502 QStringList mNamespacesToList;
00503 int mNamespacesToCheck;
00504 bool mPersonalNamespacesCheckDone;
00505 QString mImapPathCreation;
00506
00507 QuotaInfo mQuotaInfo;
00508 };
00509
00510 #endif