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     return addMsgInternal(msg, false, index_return);
00208   }
00209 
00210   /* Reimplemented from KMFolderMaildir */
00211   virtual void removeMsg(int i, bool imapQuiet = false);
00212   virtual void removeMsg(QPtrList<KMMessage> msgList, bool imapQuiet = false)
00213     { FolderStorage::removeMsg(msgList, imapQuiet); }
00214 
00216   bool isReadOnly() const { return KMFolderMaildir::isReadOnly() || mReadOnly; }
00217   bool canDeleteMessages() const;
00218 
00219 
00223   void sendFolderComplete(bool success)
00224   { emit folderComplete(this, success); }
00225 
00229   void setSilentUpload( bool silent ) { mSilentUpload = silent; }
00230   bool silentUpload() { return mSilentUpload; }
00231 
00232   virtual int createIndexFromContents() {
00233     const int result = KMFolderMaildir::createIndexFromContents();
00234     reloadUidMap();
00235     return result;
00236   }
00237 
00238   int createIndexFromContentsRecursive();
00239 
00240   //virtual void holdSyncs( bool hold ) { mHoldSyncs = hold; }
00241 
00247   virtual bool listDirectory();
00248 
00249   virtual void listNamespaces();
00250 
00252   KMFolder* trashFolder() const;
00253 
00258   int userRights() const { return mUserRights; }
00259 
00261   void setUserRights( unsigned int userRights );
00262 
00272   const QuotaInfo quotaInfo() const { return mQuotaInfo; }
00273   void setQuotaInfo( const QuotaInfo & );
00274 
00276   typedef QValueVector<KMail::ACLListEntry> ACLList;
00277   const ACLList& aclList() const { return mACLList; }
00278 
00280   void setACLList( const ACLList& arr );
00281 
00282   // Reimplemented so the mStatusChangedLocally bool can be set
00283   virtual void setStatus( int id, KMMsgStatus status, bool toggle );
00284   virtual void setStatus( QValueList<int>& ids, KMMsgStatus status, bool toggle );
00285 
00286   QString annotationFolderType() const { return mAnnotationFolderType; }
00287 
00288   // For kmailicalifaceimpl only
00289   void updateAnnotationFolderType();
00290 
00299   enum IncidencesFor { IncForNobody, IncForAdmins, IncForReaders };
00300 
00301   IncidencesFor incidencesFor() const { return mIncidencesFor; }
00303   void setIncidencesFor( IncidencesFor incfor );
00304 
00306   bool sharedSeenFlags() const { return mSharedSeenFlags; }
00308   void setSharedSeenFlags( bool b );
00309 
00311   virtual bool isMoveable() const;
00312 
00317   QStringList namespacesToList() { return mNamespacesToList; }
00318   void setNamespacesToList( QStringList list ) { mNamespacesToList = list; }
00319 
00324   const QString& imapPathForCreation() { return mImapPathCreation; }
00325   void setImapPathForCreation( const QString& path ) { mImapPathCreation = path; }
00326 
00328   bool isCloseToQuota() const;
00329 
00331   int permanentFlags() const { return mPermanentFlags; }
00332 
00333 
00334   QString folderAttributes() const { return mFolderAttributes; }
00335 
00336   virtual bool mailCheckInProgress() const;
00337 
00338 protected slots:
00339   void slotGetMessagesData(KIO::Job * job, const QByteArray & data);
00340   void getMessagesResult(KMail::FolderJob *, bool lastSet);
00341   void slotGetLastMessagesResult(KMail::FolderJob *);
00342   void slotProgress(unsigned long done, unsigned long total);
00343   void slotPutProgress( unsigned long, unsigned long );
00344 
00345   //virtual void slotCheckValidityResult(KIO::Job * job);
00346   void slotSubFolderComplete(KMFolderCachedImap*, bool);
00347   void slotSubFolderCloseToQuotaChanged();
00348 
00349   // Connected to the imap account
00350   void slotConnectionResult( int errorCode, const QString& errorMsg );
00351 
00352   void slotCheckUidValidityResult( KMail::FolderJob* job );
00353   void slotPermanentFlags( int flags );
00354   void slotTestAnnotationResult(KIO::Job *job);
00355   void slotGetAnnotationResult( KIO::Job* );
00356   void slotMultiUrlGetAnnotationResult( KIO::Job* );
00357   void slotSetAnnotationResult(KIO::Job *job);
00358   void slotReceivedUserRights( KMFolder* );
00359   void slotReceivedACL( KMFolder*, KIO::Job*, const KMail::ACLList& );
00360 
00361   void slotMultiSetACLResult(KIO::Job *);
00362   void slotACLChanged( const QString&, int );
00363   void slotAnnotationResult(const QString& entry, const QString& value, bool found);
00364   void slotAnnotationChanged( const QString& entry, const QString& attribute, const QString& value );
00365   void slotDeleteMessagesResult(KMail::FolderJob *);
00366   void slotImapStatusChanged(KMFolder* folder, const QString&, bool);
00367   void slotStorageQuotaResult( const QuotaInfo& );
00368   void slotQuotaResult( KIO::Job* job );
00369 
00370 protected:
00371   /* returns true if there were messages to delete
00372      on the server */
00373   bool deleteMessages();
00374   void listMessages();
00375   void uploadNewMessages();
00376   void uploadFlags();
00377   void uploadSeenFlags();
00378   void createNewFolders();
00379 
00380   void listDirectory2();
00381   void createFoldersNewOnServerAndFinishListing( const QValueVector<int> foldersNewOnServer );
00382 
00383 
00386   virtual QValueList<unsigned long> findNewMessages();
00389   virtual QValueList<KMFolderCachedImap*> findNewFolders();
00390 
00392   virtual bool canRemoveFolder() const;
00393 
00395   virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00396                                   QString partSpecifier, const AttachmentStrategy *as ) const;
00397   virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00398                                   FolderJob::JobType jt, KMFolder *folder ) const;
00399 
00400   virtual void timerEvent( QTimerEvent* );
00401 
00402   /* update progress status */
00403   void newState( int progress, const QString& syncStatus );
00404 
00406   KMFolderCachedImap* findParent( const QString& path, const QString& name );
00407 
00408 
00409 
00410 public slots:
00414   void slotSimpleData(KIO::Job * job, const QByteArray & data);
00415 
00419   void slotTroubleshoot();
00420 
00425   void slotListResult( const QStringList&, const QStringList&,
00426       const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00427 
00432   void slotCheckNamespace( const QStringList&, const QStringList&,
00433       const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00434 
00435 private slots:
00436   void serverSyncInternal();
00437   void slotIncreaseProgress();
00438   void slotUpdateLastUid();
00439   void slotFolderDeletionOnServerFinished();
00440   void slotRescueDone( KMCommand* command );
00441   void slotRenameFolderFinished();
00442 
00443 signals:
00444   void folderComplete(KMFolderCachedImap *folder, bool success);
00445   void listComplete( KMFolderCachedImap* );
00446 
00450   void closeToQuotaChanged();
00451 
00452 private:
00453   void setReadOnly( bool readOnly );
00454   QString state2String( int state ) const;
00455   void rememberDeletion( int );
00460   KMCommand* rescueUnsyncedMessages();
00462   void rescueUnsyncedMessagesAndDeleteFolder( KMFolder *folder, bool root = true );
00463 
00468   void disconnectSubFolderSignals();
00469 
00475   void syncNextSubFolder( bool secondSync );
00476 
00480   void buildSubFolderList();
00481 
00483   enum {
00484     SYNC_STATE_INITIAL,
00485     SYNC_STATE_TEST_ANNOTATIONS,
00486     SYNC_STATE_PUT_MESSAGES,
00487     SYNC_STATE_UPLOAD_FLAGS,
00488     SYNC_STATE_CREATE_SUBFOLDERS,
00489     SYNC_STATE_LIST_NAMESPACES,
00490     SYNC_STATE_LIST_SUBFOLDERS,
00491     SYNC_STATE_LIST_SUBFOLDERS2,
00492     SYNC_STATE_DELETE_SUBFOLDERS,
00493     SYNC_STATE_LIST_MESSAGES,
00494     SYNC_STATE_DELETE_MESSAGES,
00495     SYNC_STATE_EXPUNGE_MESSAGES,
00496     SYNC_STATE_GET_MESSAGES,
00497     SYNC_STATE_HANDLE_INBOX,
00498     SYNC_STATE_GET_USERRIGHTS,
00499     SYNC_STATE_GET_ANNOTATIONS,
00500     SYNC_STATE_SET_ANNOTATIONS,
00501     SYNC_STATE_GET_ACLS,
00502     SYNC_STATE_SET_ACLS,
00503     SYNC_STATE_GET_QUOTA,
00504     SYNC_STATE_FIND_SUBFOLDERS,
00505     SYNC_STATE_SYNC_SUBFOLDERS,
00506     SYNC_STATE_CHECK_UIDVALIDITY,
00507     SYNC_STATE_RENAME_FOLDER,
00508     SYNC_STATE_CLOSE,
00509     SYNC_STATE_GET_SUBFOLDER_QUOTA
00510   } mSyncState;
00511 
00512   int mProgress;
00513   int mStatusFlagsJobs;
00514 
00515   QString mUidValidity;
00516   QString     mImapPath;
00517   imapState   mContentState, mSubfolderState;
00518   QStringList mSubfolderNames, mSubfolderPaths,
00519               mSubfolderMimeTypes, mSubfolderAttributes;
00520   QString     mFolderAttributes;
00521   QString     mAnnotationFolderType;
00522   IncidencesFor mIncidencesFor;
00523   bool mSharedSeenFlags;
00524 
00525   bool        mHasInbox;
00526   bool        mIsSelected;
00527   bool        mCheckFlags;
00528   bool        mReadOnly;
00529   mutable QGuardedPtr<KMAcctCachedImap> mAccount;
00530 
00531   QIntDict<int> uidsOnServer;
00532   QValueList<ulong> uidsForDeletionOnServer;
00533   QValueList<KMail::CachedImapJob::MsgForDownload> mMsgsForDownload;
00534   QValueList<ulong> mUidsForDownload;
00535   QStringList       foldersForDeletionOnServer;
00536 
00537   QValueList< QGuardedPtr<KMFolderCachedImap> > mSubfoldersForSync;
00538   KMFolderCachedImap* mCurrentSubfolder;
00539 
00543   QMap<ulong,int> uidMap;
00544   bool uidMapDirty;
00545   void reloadUidMap();
00546   int uidWriteTimer;
00547 
00557   ulong mLastUid;
00562   ulong mTentativeHighestUid;
00563 
00567   bool mFoundAnIMAPDigest;
00568 
00569   int mUserRights, mOldUserRights;
00570   ACLList mACLList;
00571 
00572   bool mSilentUpload;
00573   bool mFolderRemoved;
00574   //bool mHoldSyncs;
00575   bool mRecurse;
00576   bool mQuotaOnly;
00577 
00579   bool mAnnotationFolderTypeChanged;
00581   bool mIncidencesForChanged;
00583   bool mSharedSeenFlagsChanged;
00584 
00591   std::set<ulong> mUIDsOfLocallyChangedStatuses;
00592 
00597   bool mStatusChangedLocally;
00598 
00599   QStringList mNamespacesToList;
00600   int mNamespacesToCheck;
00601   bool mPersonalNamespacesCheckDone;
00602   QString mImapPathCreation;
00603 
00604   QuotaInfo mQuotaInfo;
00605 
00608   bool mSomeSubFolderCloseToQuotaChanged;
00609 
00610   QMap<ulong,void*> mDeletedUIDsSinceLastSync;
00611   bool mAlarmsBlocked;
00612 
00613   QValueList<KMFolder*> mToBeDeletedAfterRescue;
00614   int mRescueCommandCount;
00615 
00616   QValueList< QGuardedPtr<KMFolderCachedImap> > mNewlyCreatedSubfolders;
00617   int mPermanentFlags;
00618 };
00619 
00620 #endif /*kmfoldercachedimap_h*/
KDE Home | KDE Accessibility Home | Description of Access Keys