kmail

kmfoldercachedimap.h

Go to the documentation of this file.
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 using KMail::FolderJob;
00051 using KMail::QuotaInfo;
00052 class KMCommand;
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 
00133   void setAlarmsBlocked( bool blocked );
00135   bool alarmsBlocked() const;
00136 
00137   void checkUidValidity();
00138 
00139   enum imapState { imapNoInformation=0, imapInProgress=1, imapFinished=2 };
00140 
00141   virtual imapState getContentState() { return mContentState; }
00142   virtual void setContentState(imapState state) { mContentState = state; }
00143 
00144   virtual imapState getSubfolderState() { return mSubfolderState; }
00145   virtual void setSubfolderState(imapState state);
00146 
00148   void setImapPath(const QString &path);
00149   QString imapPath() const { return mImapPath; }
00150 
00152   void setLastUid( ulong uid );
00153   ulong lastUid();
00154 
00156   KMMsgBase* findByUID( ulong uid );
00157 
00159   void setUidValidity(const QString &validity) { mUidValidity = validity; }
00160   QString uidValidity() const { return mUidValidity; }
00161 
00164   void clearUidMap() { uidMap.clear(); }
00165 
00167   void setAccount(KMAcctCachedImap *acct);
00168   KMAcctCachedImap* account() const;
00169 
00171   QString uidCacheLocation() const;
00172 
00174   int readUidCache();
00175 
00177   int writeUidCache();
00178 
00180   int progress() const { return mProgress; }
00181 
00182   /* Reimplemented from KMFolder. Moving is not supported, so aParent must be 0 */
00183   virtual int rename(const QString& aName, KMFolderDir *aParent=0);
00184 
00190   virtual KMMessage* take(int idx);
00191 
00197   void takeTemporarily( int idx );
00198 
00199   /* Reimplemented from KMFolderMaildir */
00200   virtual int addMsg(KMMessage* msg, int* index_return = 0);
00201   /* internal version that doesn't remove the X-UID header */
00202   virtual int addMsgInternal(KMMessage* msg, bool, int* index_return = 0);
00203   virtual int addMsgKeepUID(KMMessage* msg, int* index_return = 0) {
00204     return addMsgInternal(msg, false, index_return);
00205   }
00206 
00207   /* Reimplemented from KMFolderMaildir */
00208   virtual void removeMsg(int i, bool imapQuiet = false);
00209   virtual void removeMsg(QPtrList<KMMessage> msgList, bool imapQuiet = false)
00210     { FolderStorage::removeMsg(msgList, imapQuiet); }
00211 
00213   bool isReadOnly() const { return KMFolderMaildir::isReadOnly() || mReadOnly; }
00214 
00215 
00219   void sendFolderComplete(bool success)
00220   { emit folderComplete(this, success); }
00221 
00225   void setSilentUpload( bool silent ) { mSilentUpload = silent; }
00226   bool silentUpload() { return mSilentUpload; }
00227 
00228   virtual int createIndexFromContents() {
00229     const int result = KMFolderMaildir::createIndexFromContents();
00230     reloadUidMap();
00231     return result;
00232   }
00233 
00234   int createIndexFromContentsRecursive();
00235 
00236   //virtual void holdSyncs( bool hold ) { mHoldSyncs = hold; }
00237 
00243   virtual bool listDirectory();
00244 
00245   virtual void listNamespaces();
00246 
00248   KMFolder* trashFolder() const;
00249 
00254   int userRights() const { return mUserRights; }
00255 
00257   void setUserRights( unsigned int userRights );
00258 
00268   const QuotaInfo quotaInfo() const { return mQuotaInfo; }
00269   void setQuotaInfo( const QuotaInfo & );
00270 
00272   typedef QValueVector<KMail::ACLListEntry> ACLList;
00273   const ACLList& aclList() const { return mACLList; }
00274 
00276   void setACLList( const ACLList& arr );
00277 
00278   // Reimplemented so the mStatusChangedLocally bool can be set
00279   virtual void setStatus( int id, KMMsgStatus status, bool toggle );
00280   virtual void setStatus( QValueList<int>& ids, KMMsgStatus status, bool toggle );
00281 
00282   QString annotationFolderType() const { return mAnnotationFolderType; }
00283 
00284   // For kmailicalifaceimpl only
00285   void updateAnnotationFolderType();
00286 
00295   enum IncidencesFor { IncForNobody, IncForAdmins, IncForReaders };
00296 
00297   IncidencesFor incidencesFor() const { return mIncidencesFor; }
00299   void setIncidencesFor( IncidencesFor incfor );
00300 
00302   virtual bool isMoveable() const;
00303 
00308   QStringList namespacesToList() { return mNamespacesToList; }
00309   void setNamespacesToList( QStringList list ) { mNamespacesToList = list; }
00310 
00315   const QString& imapPathForCreation() { return mImapPathCreation; }
00316   void setImapPathForCreation( const QString& path ) { mImapPathCreation = path; }
00317 
00319   bool isCloseToQuota() const;
00320 
00322   int permanentFlags() const { return mPermanentFlags; }
00323 
00324 
00325   QString folderAttributes() const { return mFolderAttributes; }
00326 
00327 protected slots:
00328   void slotGetMessagesData(KIO::Job * job, const QByteArray & data);
00329   void getMessagesResult(KMail::FolderJob *, bool lastSet);
00330   void slotGetLastMessagesResult(KMail::FolderJob *);
00331   void slotProgress(unsigned long done, unsigned long total);
00332   void slotPutProgress( unsigned long, unsigned long );
00333 
00334   //virtual void slotCheckValidityResult(KIO::Job * job);
00335   void slotSubFolderComplete(KMFolderCachedImap*, bool);
00336 
00337   // Connected to the imap account
00338   void slotConnectionResult( int errorCode, const QString& errorMsg );
00339 
00340   void slotCheckUidValidityResult( KMail::FolderJob* job );
00341   void slotPermanentFlags( int flags );
00342   void slotTestAnnotationResult(KIO::Job *job);
00343   void slotGetAnnotationResult( KIO::Job* );
00344   void slotMultiUrlGetAnnotationResult( KIO::Job* );
00345   void slotSetAnnotationResult(KIO::Job *job);
00346   void slotReceivedUserRights( KMFolder* );
00347   void slotReceivedACL( KMFolder*, KIO::Job*, const KMail::ACLList& );
00348 
00349   void slotMultiSetACLResult(KIO::Job *);
00350   void slotACLChanged( const QString&, int );
00351   void slotAnnotationResult(const QString& entry, const QString& value, bool found);
00352   void slotAnnotationChanged( const QString& entry, const QString& attribute, const QString& value );
00353   void slotDeleteMessagesResult(KMail::FolderJob *);
00354   void slotImapStatusChanged(KMFolder* folder, const QString&, bool);
00355   void slotStorageQuotaResult( const QuotaInfo& );
00356   void slotQuotaResult( KIO::Job* job );
00357 
00358 protected:
00359   /* returns true if there were messages to delete
00360      on the server */
00361   bool deleteMessages();
00362   void listMessages();
00363   void uploadNewMessages();
00364   void uploadFlags();
00365   void uploadSeenFlags();
00366   void createNewFolders();
00367 
00368   void listDirectory2();
00369   void createFoldersNewOnServerAndFinishListing( const QValueVector<int> foldersNewOnServer );
00370 
00371 
00374   virtual QValueList<unsigned long> findNewMessages();
00377   virtual QValueList<KMFolderCachedImap*> findNewFolders();
00378 
00380   virtual bool canRemoveFolder() const;
00381 
00383   virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00384                                   QString partSpecifier, const AttachmentStrategy *as ) const;
00385   virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00386                                   FolderJob::JobType jt, KMFolder *folder ) const;
00387 
00388   virtual void timerEvent( QTimerEvent* );
00389 
00390   /* update progress status */
00391   void newState( int progress, const QString& syncStatus );
00392 
00394   KMFolderCachedImap* findParent( const QString& path, const QString& name );
00395 
00396 
00397 
00398 public slots:
00402   void slotSimpleData(KIO::Job * job, const QByteArray & data);
00403 
00407   void slotTroubleshoot();
00408 
00413   void slotListResult( const QStringList&, const QStringList&,
00414       const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00415 
00420   void slotCheckNamespace( const QStringList&, const QStringList&,
00421       const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00422 
00423 private slots:
00424   void serverSyncInternal();
00425   void slotIncreaseProgress();
00426   void slotUpdateLastUid();
00427   void slotFolderDeletionOnServerFinished();
00428   void slotRescueDone( KMCommand* command );
00429 
00430 signals:
00431   void folderComplete(KMFolderCachedImap *folder, bool success);
00432   void listComplete( KMFolderCachedImap* );
00433 
00437   void syncState( int state, int number );
00438 
00439 private:
00440   void setReadOnly( bool readOnly );
00441   QString state2String( int state ) const;
00442   void rememberDeletion( int );
00447   KMCommand* rescueUnsyncedMessages();
00449   void rescueUnsyncedMessagesAndDeleteFolder( KMFolder *folder, bool root = true );
00450 
00452   enum {
00453     SYNC_STATE_INITIAL,
00454     SYNC_STATE_TEST_ANNOTATIONS,
00455     SYNC_STATE_PUT_MESSAGES,
00456     SYNC_STATE_UPLOAD_FLAGS,
00457     SYNC_STATE_CREATE_SUBFOLDERS,
00458     SYNC_STATE_LIST_NAMESPACES,
00459     SYNC_STATE_LIST_SUBFOLDERS,
00460     SYNC_STATE_LIST_SUBFOLDERS2,
00461     SYNC_STATE_DELETE_SUBFOLDERS,
00462     SYNC_STATE_LIST_MESSAGES,
00463     SYNC_STATE_DELETE_MESSAGES,
00464     SYNC_STATE_EXPUNGE_MESSAGES,
00465     SYNC_STATE_GET_MESSAGES,
00466     SYNC_STATE_HANDLE_INBOX,
00467     SYNC_STATE_GET_USERRIGHTS,
00468     SYNC_STATE_GET_ANNOTATIONS,
00469     SYNC_STATE_SET_ANNOTATIONS,
00470     SYNC_STATE_GET_ACLS,
00471     SYNC_STATE_SET_ACLS,
00472     SYNC_STATE_GET_QUOTA,
00473     SYNC_STATE_FIND_SUBFOLDERS,
00474     SYNC_STATE_SYNC_SUBFOLDERS,
00475     SYNC_STATE_CHECK_UIDVALIDITY,
00476     SYNC_STATE_RENAME_FOLDER
00477   } mSyncState;
00478 
00479   int mProgress;
00480   int mStatusFlagsJobs;
00481 
00482   QString mUidValidity;
00483   QString     mImapPath;
00484   imapState   mContentState, mSubfolderState;
00485   QStringList mSubfolderNames, mSubfolderPaths,
00486               mSubfolderMimeTypes, mSubfolderAttributes;
00487   QString     mFolderAttributes;
00488   QString     mAnnotationFolderType;
00489   IncidencesFor mIncidencesFor;
00490 
00491   bool        mHasInbox;
00492   bool        mIsSelected;
00493   bool        mCheckFlags;
00494   bool        mReadOnly;
00495   mutable QGuardedPtr<KMAcctCachedImap> mAccount;
00496 
00497   QIntDict<int> uidsOnServer;
00498   QValueList<ulong> uidsForDeletionOnServer;
00499   QValueList<KMail::CachedImapJob::MsgForDownload> mMsgsForDownload;
00500   QValueList<ulong> mUidsForDownload;
00501   QStringList       foldersForDeletionOnServer;
00502 
00503   QValueList<KMFolderCachedImap*> mSubfoldersForSync;
00504   KMFolderCachedImap* mCurrentSubfolder;
00505 
00509   QMap<ulong,int> uidMap;
00510   bool uidMapDirty;
00511   void reloadUidMap();
00512   int uidWriteTimer;
00513 
00523   ulong mLastUid;
00528   ulong mTentativeHighestUid;
00529 
00533   bool mFoundAnIMAPDigest;
00534 
00535   int mUserRights, mOldUserRights;
00536   ACLList mACLList;
00537 
00538   bool mSilentUpload;
00539   bool mFolderRemoved;
00540   //bool mHoldSyncs;
00541   bool mRecurse;
00546   bool mStatusChangedLocally;
00548   bool mAnnotationFolderTypeChanged;
00550   bool mIncidencesForChanged;
00551 
00552   QStringList mNamespacesToList;
00553   int mNamespacesToCheck;
00554   bool mPersonalNamespacesCheckDone;
00555   QString mImapPathCreation;
00556 
00557   QuotaInfo mQuotaInfo;
00558   QMap<ulong,void*> mDeletedUIDsSinceLastSync;
00559   bool mAlarmsBlocked;
00560 
00561   QValueList<KMFolder*> mToBeDeletedAfterRescue;
00562   int mRescueCommandCount;
00563 
00564   int mPermanentFlags;
00565 };
00566 
00567 #endif /*kmfoldercachedimap_h*/