kmail

kmfoldercachedimap.h

00001 /*
00002  *  kmfoldercachedimap.cpp
00003  *
00004  *  Copyright (c) 2002-2004 Bo Thorsen <bo@sonofthor.dk>
00005  *  Copyright (c) 2002-2003 Steffen Hansen <steffen@klaralvdalens-datakonsult.se>
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; version 2 of the License
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  *  In addition, as a special exception, the copyright holders give
00021  *  permission to link the code of this program with any edition of
00022  *  the Qt library by Trolltech AS, Norway (or with modified versions
00023  *  of Qt that use the same license as Qt), and distribute linked
00024  *  combinations including the two.  You must obey the GNU General
00025  *  Public License in all respects for all of the code used other than
00026  *  Qt.  If you modify this file, you may extend this exception to
00027  *  your version of the file, but you are not obligated to do so.  If
00028  *  you do not wish to do so, delete this exception statement from
00029  *  your version.
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 "kmacctcachedimap.h"
00045 #include "kmfoldertype.h"
00046 #include "folderjob.h"
00047 #include "cachedimapjob.h"
00048 #include "quotajobs.h"
00049 
00050 #include <set>
00051 
00052 using KMail::FolderJob;
00053 using KMail::QuotaInfo;
00054 class KMCommand;
00055 
00056 class QComboBox;
00057 class QRadioButton;
00058 
00059 namespace KMail {
00060   class AttachmentStrategy;
00061   class ImapAccountBase;
00062   struct ACLListEntry;
00063 }
00064 using KMail::AttachmentStrategy;
00065 
00066 class DImapTroubleShootDialog : public KDialogBase
00067 {
00068   Q_OBJECT
00069 public:
00070   enum SelectedOperation {
00071     None = -1,
00072     ReindexCurrent = 0,
00073     ReindexRecursive = 1,
00074     ReindexAll = 2,
00075     RefreshCache
00076   };
00077 
00078   DImapTroubleShootDialog( QWidget* parent=0, const char* name=0 );
00079 
00080   static int run();
00081 
00082 private slots:
00083   void slotDone();
00084   void slotChanged();
00085 private:
00086   QRadioButton *mIndexButton, *mCacheButton;
00087   QComboBox *mIndexScope;
00088   QButtonGroup *mButtonGroup;
00089   int rc;
00090 };
00091 
00092 class KMFolderCachedImap : public KMFolderMaildir
00093 {
00094   Q_OBJECT
00095 
00096 public:
00097   static QString cacheLocation() {
00098      return locateLocal("data", "kmail/dimap" );
00099   }
00100 
00104   KMFolderCachedImap(KMFolder* folder, const char* name=0);
00105   virtual ~KMFolderCachedImap();
00106 
00108   void reallyDoClose(const char* owner);
00109 
00111   void initializeFrom( KMFolderCachedImap* parent );
00112 
00113   virtual void readConfig();
00114   virtual void writeConfig();
00115 
00116   void writeConfigKeysWhichShouldNotGetOverwrittenByReadConfig();
00117 
00119   virtual KMFolderType folderType() const { return KMFolderTypeCachedImap; }
00120 
00122   virtual int create();
00123 
00125   virtual void remove();
00126 
00128   virtual void serverSync( bool recurse, bool quotaOnly = false );
00129 
00131   void resetSyncState( );
00132 
00136   void setAlarmsBlocked( bool blocked );
00138   bool alarmsBlocked() const;
00139 
00140   void checkUidValidity();
00141 
00142   enum imapState { imapNoInformation=0, imapInProgress=1, imapFinished=2 };
00143 
00144   virtual imapState getContentState() const { return mContentState; }
00145   virtual void setContentState(imapState state) { mContentState = state; }
00146 
00147   virtual imapState getSubfolderState() { return mSubfolderState; }
00148   virtual void setSubfolderState(imapState state);
00149 
00151   void setImapPath(const QString &path);
00152   QString imapPath() const { return mImapPath; }
00153 
00155   void setLastUid( ulong uid );
00156   ulong lastUid();
00157 
00159   KMMsgBase* findByUID( ulong uid );
00160 
00162   void setUidValidity(const QString &validity) { mUidValidity = validity; }
00163   QString uidValidity() const { return mUidValidity; }
00164 
00167   void clearUidMap() { uidMap.clear(); }
00168 
00170   void setAccount(KMAcctCachedImap *acct);
00171   KMAcctCachedImap* account() const;
00172 
00174   QString uidCacheLocation() const;
00175 
00177   int readUidCache();
00178 
00180   int writeUidCache();
00181 
00183   int progress() const { return mProgress; }
00184 
00185   /* Reimplemented from KMFolder. Moving is not supported, so aParent must be 0 */
00186   virtual int rename(const QString& aName, KMFolderDir *aParent=0);
00187 
00193   virtual KMMessage* take(int idx);
00194 
00200   void takeTemporarily( int idx );
00201 
00202   /* Reimplemented from KMFolderMaildir */
00203   virtual int addMsg(KMMessage* msg, int* index_return = 0);
00204   /* internal version that doesn't remove the X-UID header */
00205   virtual int addMsgInternal(KMMessage* msg, bool, int* index_return = 0);
00206   virtual int addMsgKeepUID(KMMessage* msg, int* index_return = 0) {
00207     //kdDebug(5006) << "*DEBUG KMFolderCachedImap::addMsgKeepUID()" << endl;
00208     return addMsgInternal(msg, false, index_return);
00209   }
00210 
00211   /* Reimplemented from KMFolderMaildir */
00212   virtual void removeMsg(int i, bool imapQuiet = false);
00213   virtual void removeMsg( const QPtrList<KMMsgBase> & msgList, bool imapQuiet = false)
00214     { FolderStorage::removeMsg(msgList, imapQuiet); }
00215 
00217   bool isReadOnly() const { return KMFolderMaildir::isReadOnly() || mReadOnly; }
00218   bool canDeleteMessages() const;
00219 
00220 
00224   void sendFolderComplete(bool success)
00225   { emit folderComplete(this, success); }
00226 
00230   void setSilentUpload( bool silent ) { mSilentUpload = silent; }
00231   bool silentUpload() { return mSilentUpload; }
00232 
00233   virtual int createIndexFromContents() {
00234     const int result = KMFolderMaildir::createIndexFromContents();
00235     reloadUidMap();
00236     return result;
00237   }
00238 
00239   int createIndexFromContentsRecursive();
00240 
00242   void markForReindexing();
00243 
00244   //virtual void holdSyncs( bool hold ) { mHoldSyncs = hold; }
00245 
00251   virtual bool listDirectory();
00252 
00253   virtual void listNamespaces();
00254 
00256   KMFolder* trashFolder() const;
00257 
00263   int userRights() const { return mUserRights; }
00264   KMail::ACLJobs::ACLFetchState userRightsState() const { return mUserRightsState; }
00265 
00267   void setUserRights( unsigned int userRights, KMail::ACLJobs::ACLFetchState state  );
00268 
00278   const QuotaInfo quotaInfo() const { return mQuotaInfo; }
00279   void setQuotaInfo( const QuotaInfo & );
00280 
00282   typedef QValueVector<KMail::ACLListEntry> ACLList;
00283   const ACLList& aclList() const { return mACLList; }
00284   KMail::ACLJobs::ACLFetchState aclListState() const { return mACLListState; };
00285 
00287   void setACLList( const ACLList& arr );
00288 
00289   // Reimplemented so the mStatusChangedLocally bool can be set
00290   virtual void setStatus( int id, KMMsgStatus status, bool toggle );
00291   virtual void setStatus( QValueList<int>& ids, KMMsgStatus status, bool toggle );
00292 
00293   QString annotationFolderType() const { return mAnnotationFolderType; }
00294 
00295   // For kmailicalifaceimpl only
00296   void updateAnnotationFolderType();
00297 
00306   enum IncidencesFor { IncForNobody, IncForAdmins, IncForReaders };
00307 
00308   IncidencesFor incidencesFor() const { return mIncidencesFor; }
00310   void setIncidencesFor( IncidencesFor incfor );
00311 
00313   bool sharedSeenFlags() const { return mSharedSeenFlags; }
00315   void setSharedSeenFlags( bool b );
00316 
00318   virtual bool isMoveable() const;
00319 
00324   QStringList namespacesToList() { return mNamespacesToList; }
00325   void setNamespacesToList( QStringList list ) { mNamespacesToList = list; }
00326 
00331   const QString& imapPathForCreation() { return mImapPathCreation; }
00332   void setImapPathForCreation( const QString& path ) { mImapPathCreation = path; }
00333 
00335   bool isCloseToQuota() const;
00336 
00338   int permanentFlags() const { return mPermanentFlags; }
00339 
00340 
00341   QString folderAttributes() const { return mFolderAttributes; }
00342 
00343   virtual bool mailCheckInProgress() const;
00344 
00345   bool isInInitialState() const { return mSyncState == SYNC_STATE_INITIAL; }
00346 
00347 protected slots:
00348   void slotGetMessagesData(KIO::Job * job, const QByteArray & data);
00349   void getMessagesResult(KMail::FolderJob *, bool lastSet);
00350   void slotGetLastMessagesResult(KMail::FolderJob *);
00351   void slotProgress(unsigned long done, unsigned long total);
00352   void slotPutProgress( unsigned long, unsigned long );
00353 
00354   //virtual void slotCheckValidityResult(KIO::Job * job);
00355   void slotSubFolderComplete(KMFolderCachedImap*, bool);
00356   void slotSubFolderCloseToQuotaChanged();
00357 
00358   // Connected to the imap account
00359   void slotConnectionResult( int errorCode, const QString& errorMsg );
00360 
00361   void slotCheckUidValidityResult( KMail::FolderJob* job );
00362   void slotPermanentFlags( int flags );
00363   void slotTestAnnotationResult(KIO::Job *job);
00364   void slotGetAnnotationResult( KIO::Job* );
00365   void slotMultiUrlGetAnnotationResult( KIO::Job* );
00366   void slotSetAnnotationResult(KIO::Job *job);
00367   void slotReceivedUserRights( KMFolder* );
00368   void slotReceivedACL( KMFolder*, KIO::Job*, const KMail::ACLList& );
00369 
00370   void slotMultiSetACLResult(KIO::Job *);
00371   void slotACLChanged( const QString&, int );
00372   void slotAnnotationResult(const QString& entry, const QString& value, bool found);
00373   void slotAnnotationChanged( const QString& entry, const QString& attribute, const QString& value );
00374   void slotDeleteMessagesResult(KMail::FolderJob *);
00375   void slotImapStatusChanged(KMFolder* folder, const QString&, bool);
00376   void slotStorageQuotaResult( const QuotaInfo& );
00377   void slotQuotaResult( KIO::Job* job );
00378 
00379 protected:
00380   /* returns true if there were messages to delete
00381      on the server */
00382   bool deleteMessages();
00383   void listMessages();
00384   void uploadNewMessages();
00385   void uploadFlags();
00386   void uploadSeenFlags();
00387   void createNewFolders();
00388 
00389   void listDirectory2();
00390   void createFoldersNewOnServerAndFinishListing( const QValueVector<int> foldersNewOnServer );
00391 
00392 
00395   virtual QValueList<unsigned long> findNewMessages();
00398   virtual QValueList<KMFolderCachedImap*> findNewFolders();
00399 
00401   virtual bool canRemoveFolder() const;
00402 
00404   virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00405                                   QString partSpecifier, const AttachmentStrategy *as ) const;
00406   virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00407                                   FolderJob::JobType jt, KMFolder *folder ) const;
00408 
00409   virtual void timerEvent( QTimerEvent* );
00410 
00411   /* update progress status */
00412   void newState( int progress, const QString& syncStatus );
00413 
00415   KMFolderCachedImap* findParent( const QString& path, const QString& name );
00416 
00417 
00418 
00419 public slots:
00423   void slotSimpleData(KIO::Job * job, const QByteArray & data);
00424 
00428   void slotTroubleshoot();
00429 
00434   void slotListResult( const QStringList&, const QStringList&,
00435       const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00436 
00441   void slotCheckNamespace( const QStringList&, const QStringList&,
00442       const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00443 
00444 private slots:
00445   void serverSyncInternal();
00446   void slotIncreaseProgress();
00447   void slotUpdateLastUid();
00448   void slotFolderDeletionOnServerFinished();
00449   void slotRescueDone( KMCommand* command );
00450   void slotRenameFolderFinished();
00451 
00452 signals:
00453   void folderComplete(KMFolderCachedImap *folder, bool success);
00454   void listComplete( KMFolderCachedImap* );
00455 
00459   void closeToQuotaChanged();
00460 
00461 private:
00462   void setReadOnly( bool readOnly );
00463   QString state2String( int state ) const;
00464   void rememberDeletion( int );
00469   KMCommand* rescueUnsyncedMessages();
00471   void rescueUnsyncedMessagesAndDeleteFolder( KMFolder *folder, bool root = true );
00472 
00477   void disconnectSubFolderSignals();
00478 
00484   void syncNextSubFolder( bool secondSync );
00485 
00489   void buildSubFolderList();
00490 
00492   enum {
00493     SYNC_STATE_INITIAL,
00494     SYNC_STATE_TEST_ANNOTATIONS,
00495     SYNC_STATE_PUT_MESSAGES,
00496     SYNC_STATE_UPLOAD_FLAGS,
00497     SYNC_STATE_CREATE_SUBFOLDERS,
00498     SYNC_STATE_LIST_NAMESPACES,
00499     SYNC_STATE_LIST_SUBFOLDERS,
00500     SYNC_STATE_LIST_SUBFOLDERS2,
00501     SYNC_STATE_DELETE_SUBFOLDERS,
00502     SYNC_STATE_LIST_MESSAGES,
00503     SYNC_STATE_DELETE_MESSAGES,
00504     SYNC_STATE_EXPUNGE_MESSAGES,
00505     SYNC_STATE_GET_MESSAGES,
00506     SYNC_STATE_HANDLE_INBOX,
00507     SYNC_STATE_GET_USERRIGHTS,
00508     SYNC_STATE_GET_ANNOTATIONS,
00509     SYNC_STATE_SET_ANNOTATIONS,
00510     SYNC_STATE_GET_ACLS,
00511     SYNC_STATE_SET_ACLS,
00512     SYNC_STATE_GET_QUOTA,
00513     SYNC_STATE_FIND_SUBFOLDERS,
00514     SYNC_STATE_SYNC_SUBFOLDERS,
00515     SYNC_STATE_CHECK_UIDVALIDITY,
00516     SYNC_STATE_RENAME_FOLDER,
00517     SYNC_STATE_CLOSE,
00518     SYNC_STATE_GET_SUBFOLDER_QUOTA
00519   } mSyncState;
00520 
00521   int mProgress;
00522   int mStatusFlagsJobs;
00523 
00524   QString mUidValidity;
00525   QString     mImapPath;
00526   imapState   mContentState, mSubfolderState;
00527   QStringList mSubfolderNames, mSubfolderPaths,
00528               mSubfolderMimeTypes, mSubfolderAttributes;
00529   QString     mFolderAttributes;
00530   QString     mAnnotationFolderType;
00531   IncidencesFor mIncidencesFor;
00532   bool mSharedSeenFlags;
00533 
00534   bool        mHasInbox;
00535   bool        mIsSelected;
00536   bool        mCheckFlags;
00537   bool        mReadOnly;
00538   mutable QGuardedPtr<KMAcctCachedImap> mAccount;
00539 
00540   QIntDict<int> uidsOnServer;
00541   QValueList<ulong> uidsForDeletionOnServer;
00542   QValueList<KMail::CachedImapJob::MsgForDownload> mMsgsForDownload;
00543   QValueList<ulong> mUidsForDownload;
00544   QStringList       foldersForDeletionOnServer;
00545 
00546   QValueList< QGuardedPtr<KMFolderCachedImap> > mSubfoldersForSync;
00547   KMFolderCachedImap* mCurrentSubfolder;
00548 
00552   QMap<ulong,int> uidMap;
00553   bool uidMapDirty;
00554   void reloadUidMap();
00555   int uidWriteTimer;
00556 
00566   ulong mLastUid;
00571   ulong mTentativeHighestUid;
00572 
00576   bool mFoundAnIMAPDigest;
00577 
00578   int mUserRights, mOldUserRights;
00579   KMail::ACLJobs::ACLFetchState mUserRightsState;
00580   ACLList mACLList;
00581   KMail::ACLJobs::ACLFetchState mACLListState;
00582 
00583   bool mSilentUpload;
00584   bool mFolderRemoved;
00585   //bool mHoldSyncs;
00586   bool mRecurse;
00587   bool mQuotaOnly;
00588 
00590   bool mAnnotationFolderTypeChanged;
00592   bool mIncidencesForChanged;
00594   bool mSharedSeenFlagsChanged;
00595 
00602   std::set<ulong> mUIDsOfLocallyChangedStatuses;
00603 
00608   bool mStatusChangedLocally;
00609 
00610   QStringList mNamespacesToList;
00611   int mNamespacesToCheck;
00612   bool mPersonalNamespacesCheckDone;
00613   QString mImapPathCreation;
00614 
00615   QuotaInfo mQuotaInfo;
00616 
00619   bool mSomeSubFolderCloseToQuotaChanged;
00620 
00621   QMap<ulong,void*> mDeletedUIDsSinceLastSync;
00622   bool mAlarmsBlocked;
00623 
00624   QValueList<KMFolder*> mToBeDeletedAfterRescue;
00625   int mRescueCommandCount;
00626 
00627   QValueList< QGuardedPtr<KMFolderCachedImap> > mNewlyCreatedSubfolders;
00628   int mPermanentFlags;
00629 };
00630 
00631 #endif /*kmfoldercachedimap_h*/
KDE Home | KDE Accessibility Home | Description of Access Keys