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 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 
00185   /* Reimplemented from KMFolderMaildir */
00186   virtual KMMessage* take(int idx);
00187   /* Reimplemented from KMFolderMaildir */
00188   virtual int addMsg(KMMessage* msg, int* index_return = 0);
00189   /* internal version that doesn't remove the X-UID header */
00190   virtual int addMsgInternal(KMMessage* msg, bool, int* index_return = 0);
00191   virtual int addMsgKeepUID(KMMessage* msg, int* index_return = 0) {
00192     return addMsgInternal(msg, false, index_return);
00193   }
00194 
00195   /* Reimplemented from KMFolderMaildir */
00196   virtual void removeMsg(int i, bool imapQuiet = false);
00197   virtual void removeMsg(QPtrList<KMMessage> msgList, bool imapQuiet = false)
00198     { FolderStorage::removeMsg(msgList, imapQuiet); }
00199 
00201   bool isReadOnly() const { return KMFolderMaildir::isReadOnly() || mReadOnly; }
00202 
00203 
00207   void sendFolderComplete(bool success)
00208   { emit folderComplete(this, success); }
00209 
00213   void setSilentUpload( bool silent ) { mSilentUpload = silent; }
00214   bool silentUpload() { return mSilentUpload; }
00215 
00216   virtual int createIndexFromContents()
00217     { return KMFolderMaildir::createIndexFromContents(); }
00218 
00219   int createIndexFromContentsRecursive();
00220 
00221   //virtual void holdSyncs( bool hold ) { mHoldSyncs = hold; }
00222 
00228   virtual bool listDirectory();
00229 
00230   virtual void listNamespaces();
00231 
00233   KMFolder* trashFolder() const;
00234 
00239   int userRights() const { return mUserRights; }
00240 
00242   void setUserRights( unsigned int userRights );
00243 
00253   const QuotaInfo quotaInfo() const { return mQuotaInfo; }
00254   void setQuotaInfo( const QuotaInfo & );
00255 
00257   typedef QValueVector<KMail::ACLListEntry> ACLList;
00258   const ACLList& aclList() const { return mACLList; }
00259 
00261   void setACLList( const ACLList& arr );
00262 
00263   // Reimplemented so the mStatusChangedLocally bool can be set
00264   virtual void setStatus( int id, KMMsgStatus status, bool toggle );
00265   virtual void setStatus( QValueList<int>& ids, KMMsgStatus status, bool toggle );
00266 
00267   QString annotationFolderType() const { return mAnnotationFolderType; }
00268 
00269   // For kmailicalifaceimpl only
00270   void updateAnnotationFolderType();
00271 
00280   enum IncidencesFor { IncForNobody, IncForAdmins, IncForReaders };
00281 
00282   IncidencesFor incidencesFor() const { return mIncidencesFor; }
00284   void setIncidencesFor( IncidencesFor incfor );
00285 
00287   virtual bool isMoveable() const;
00288 
00293   QStringList namespacesToList() { return mNamespacesToList; }
00294   void setNamespacesToList( QStringList list ) { mNamespacesToList = list; }
00295 
00300   const QString& imapPathForCreation() { return mImapPathCreation; }
00301   void setImapPathForCreation( const QString& path ) { mImapPathCreation = path; }
00302 
00304   bool isCloseToQuota() const;
00305 
00307   int permanentFlags() const { return mPermanentFlags; }
00308 
00309 
00310   QString folderAttributes() const { return mFolderAttributes; }
00311 
00312 protected slots:
00313   void slotGetMessagesData(KIO::Job * job, const QByteArray & data);
00314   void getMessagesResult(KMail::FolderJob *, bool lastSet);
00315   void slotGetLastMessagesResult(KMail::FolderJob *);
00316   void slotProgress(unsigned long done, unsigned long total);
00317   void slotPutProgress( unsigned long, unsigned long );
00318 
00319   //virtual void slotCheckValidityResult(KIO::Job * job);
00320   void slotSubFolderComplete(KMFolderCachedImap*, bool);
00321 
00322   // Connected to the imap account
00323   void slotConnectionResult( int errorCode, const QString& errorMsg );
00324 
00325   void slotCheckUidValidityResult( KMail::FolderJob* job );
00326   void slotPermanentFlags( int flags );
00327   void slotTestAnnotationResult(KIO::Job *job);
00328   void slotGetAnnotationResult( KIO::Job* );
00329   void slotMultiUrlGetAnnotationResult( KIO::Job* );
00330   void slotSetAnnotationResult(KIO::Job *job);
00331   void slotReceivedUserRights( KMFolder* );
00332   void slotReceivedACL( KMFolder*, KIO::Job*, const KMail::ACLList& );
00333 
00334   void slotMultiSetACLResult(KIO::Job *);
00335   void slotACLChanged( const QString&, int );
00336   void slotAnnotationResult(const QString& entry, const QString& value, bool found);
00337   void slotAnnotationChanged( const QString& entry, const QString& attribute, const QString& value );
00338   void slotDeleteMessagesResult(KMail::FolderJob *);
00339   void slotImapStatusChanged(KMFolder* folder, const QString&, bool);
00340   void slotStorageQuotaResult( const QuotaInfo& );
00341   void slotQuotaResult( KIO::Job* job );
00342 
00343 protected:
00344   /* returns true if there were messages to delete
00345      on the server */
00346   bool deleteMessages();
00347   void listMessages();
00348   void uploadNewMessages();
00349   void uploadFlags();
00350   void uploadSeenFlags();
00351   void createNewFolders();
00352 
00353   void listDirectory2();
00354   void createFoldersNewOnServerAndFinishListing( const QValueVector<int> foldersNewOnServer );
00355 
00356 
00359   virtual QValueList<unsigned long> findNewMessages();
00362   virtual QValueList<KMFolderCachedImap*> findNewFolders();
00363 
00365   virtual bool canRemoveFolder() const;
00366 
00368   virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00369                                   QString partSpecifier, const AttachmentStrategy *as ) const;
00370   virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00371                                   FolderJob::JobType jt, KMFolder *folder ) const;
00372 
00373   virtual void timerEvent( QTimerEvent* );
00374 
00375   /* update progress status */
00376   void newState( int progress, const QString& syncStatus );
00377 
00379   KMFolderCachedImap* findParent( const QString& path, const QString& name );
00380 
00381 
00382 
00383 public slots:
00387   void slotSimpleData(KIO::Job * job, const QByteArray & data);
00388 
00392   void slotTroubleshoot();
00393 
00398   void slotListResult( const QStringList&, const QStringList&,
00399       const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00400 
00405   void slotCheckNamespace( const QStringList&, const QStringList&,
00406       const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00407 
00408 private slots:
00409   void serverSyncInternal();
00410   void slotIncreaseProgress();
00411   void slotUpdateLastUid();
00412   void slotFolderDeletionOnServerFinished();
00413   void slotRescueDone( KMCommand* command );
00414 
00415 signals:
00416   void folderComplete(KMFolderCachedImap *folder, bool success);
00417   void listComplete( KMFolderCachedImap* );
00418 
00422   void syncState( int state, int number );
00423 
00424 private:
00425   void setReadOnly( bool readOnly );
00426   QString state2String( int state ) const;
00427   void rememberDeletion( int );
00432   KMCommand* rescueUnsyncedMessages();
00434   void rescueUnsyncedMessagesAndDeleteFolder( KMFolder *folder, bool root = true );
00435 
00437   enum {
00438     SYNC_STATE_INITIAL,
00439     SYNC_STATE_TEST_ANNOTATIONS,
00440     SYNC_STATE_PUT_MESSAGES,
00441     SYNC_STATE_UPLOAD_FLAGS,
00442     SYNC_STATE_CREATE_SUBFOLDERS,
00443     SYNC_STATE_LIST_NAMESPACES,
00444     SYNC_STATE_LIST_SUBFOLDERS,
00445     SYNC_STATE_LIST_SUBFOLDERS2,
00446     SYNC_STATE_DELETE_SUBFOLDERS,
00447     SYNC_STATE_LIST_MESSAGES,
00448     SYNC_STATE_DELETE_MESSAGES,
00449     SYNC_STATE_EXPUNGE_MESSAGES,
00450     SYNC_STATE_GET_MESSAGES,
00451     SYNC_STATE_HANDLE_INBOX,
00452     SYNC_STATE_GET_USERRIGHTS,
00453     SYNC_STATE_GET_ANNOTATIONS,
00454     SYNC_STATE_SET_ANNOTATIONS,
00455     SYNC_STATE_GET_ACLS,
00456     SYNC_STATE_SET_ACLS,
00457     SYNC_STATE_GET_QUOTA,
00458     SYNC_STATE_FIND_SUBFOLDERS,
00459     SYNC_STATE_SYNC_SUBFOLDERS,
00460     SYNC_STATE_CHECK_UIDVALIDITY,
00461     SYNC_STATE_RENAME_FOLDER
00462   } mSyncState;
00463 
00464   int mProgress;
00465   int mStatusFlagsJobs;
00466 
00467   QString mUidValidity;
00468   QString     mImapPath;
00469   imapState   mContentState, mSubfolderState;
00470   QStringList mSubfolderNames, mSubfolderPaths,
00471               mSubfolderMimeTypes, mSubfolderAttributes;
00472   QString     mFolderAttributes;
00473   QString     mAnnotationFolderType;
00474   IncidencesFor mIncidencesFor;
00475 
00476   bool        mHasInbox;
00477   bool        mIsSelected;
00478   bool        mCheckFlags;
00479   bool        mReadOnly;
00480   mutable QGuardedPtr<KMAcctCachedImap> mAccount;
00481 
00482   QIntDict<int> uidsOnServer;
00483   QValueList<ulong> uidsForDeletionOnServer;
00484   QValueList<KMail::CachedImapJob::MsgForDownload> mMsgsForDownload;
00485   QValueList<ulong> mUidsForDownload;
00486   QStringList       foldersForDeletionOnServer;
00487 
00488   QValueList<KMFolderCachedImap*> mSubfoldersForSync;
00489   KMFolderCachedImap* mCurrentSubfolder;
00490 
00494   QMap<ulong,int> uidMap;
00495   bool uidMapDirty;
00496   void reloadUidMap();
00497   int uidWriteTimer;
00498 
00508   ulong mLastUid;
00513   ulong mTentativeHighestUid;
00514 
00518   bool mFoundAnIMAPDigest;
00519 
00520   int mUserRights, mOldUserRights;
00521   ACLList mACLList;
00522 
00523   bool mSilentUpload;
00524   bool mFolderRemoved;
00525   //bool mHoldSyncs;
00526   bool mRecurse;
00531   bool mStatusChangedLocally;
00533   bool mAnnotationFolderTypeChanged;
00535   bool mIncidencesForChanged;
00536 
00537   QStringList mNamespacesToList;
00538   int mNamespacesToCheck;
00539   bool mPersonalNamespacesCheckDone;
00540   QString mImapPathCreation;
00541 
00542   QuotaInfo mQuotaInfo;
00543   QMap<ulong,void*> mDeletedUIDsSinceLastSync;
00544   bool mAlarmsBlocked;
00545 
00546   QValueList<KMFolder*> mToBeDeletedAfterRescue;
00547   int mRescueCommandCount;
00548 
00549   int mPermanentFlags;
00550 };
00551 
00552 #endif /*kmfoldercachedimap_h*/
KDE Home | KDE Accessibility Home | Description of Access Keys