imapaccountbase.h
00001 /* -*- c++ -*- 00002 * imapaccountbase.h 00003 * 00004 * Copyright (c) 2000-2002 Michael Haeckel <haeckel@kde.org> 00005 * Copyright (c) 2002 Marc Mutz <mutz@kde.org> 00006 * 00007 * This file is based on work on pop3 and imap account implementations 00008 * by Don Sanders <sanders@kde.org> and Michael Haeckel <haeckel@kde.org> 00009 * 00010 * This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; version 2 of the License 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00022 */ 00023 00024 #ifndef __KMAIL_IMAPACCOUNTBASE_H__ 00025 #define __KMAIL_IMAPACCOUNTBASE_H__ 00026 00027 #include <set> 00028 00029 #include "networkaccount.h" 00030 00031 #include <tqtimer.h> 00032 #include <tqguardedptr.h> 00033 #include <kio/global.h> 00034 00035 class AccountManager; 00036 class KMFolder; 00037 class KConfig/*Base*/; 00038 class KMMessagePart; 00039 class DwBodyPart; 00040 class DwMessage; 00041 class FolderStorage; 00042 template <typename T> class TQValueVector; 00043 00044 namespace KIO { 00045 class Job; 00046 } 00047 00048 namespace KPIM { 00049 class ProgressItem; 00050 } 00051 00052 namespace KMail { 00053 struct ACLListEntry; 00054 struct QuotaInfo; 00055 typedef TQValueVector<KMail::ACLListEntry> ACLList; 00056 00057 class AttachmentStrategy; 00058 00059 class ImapAccountBase : public KMail::NetworkAccount { 00060 Q_OBJECT 00061 TQ_OBJECT 00062 protected: 00063 ImapAccountBase( AccountManager * parent, const TQString & name, uint id ); 00064 public: 00065 virtual ~ImapAccountBase(); 00066 00068 virtual void init(); 00069 00071 virtual void pseudoAssign( const KMAccount * a ); 00072 00075 bool autoExpunge() const { return mAutoExpunge; } 00076 virtual void setAutoExpunge( bool expunge ); 00077 00079 bool hiddenFolders() const { return mHiddenFolders; } 00080 virtual void setHiddenFolders( bool show ); 00081 00083 bool onlySubscribedFolders() const { return mOnlySubscribedFolders; } 00084 virtual void setOnlySubscribedFolders( bool show ); 00085 00087 bool onlyLocallySubscribedFolders() const { return mOnlyLocallySubscribedFolders; } 00088 virtual void setOnlyLocallySubscribedFolders( bool show ); 00089 00090 00092 bool loadOnDemand() const { return mLoadOnDemand; } 00093 virtual void setLoadOnDemand( bool load ); 00094 00096 bool listOnlyOpenFolders() const { return mListOnlyOpenFolders; } 00097 virtual void setListOnlyOpenFolders( bool only ); 00098 00100 virtual KIO::MetaData slaveConfig() const; 00101 00102 virtual void readConfig( KConfig& config ); 00103 virtual void writeConfig( KConfig& config ); 00104 00108 enum ConnectionState { Error = 0, Connected, Connecting }; 00109 00110 // possible list types 00111 enum ListType { 00112 List, 00113 ListSubscribed, 00114 ListSubscribedNoCheck, 00115 ListFolderOnly, 00116 ListFolderOnlySubscribed 00117 }; 00118 00125 ConnectionState makeConnection(); 00126 00127 // namespace defines 00128 enum imapNamespace { PersonalNS=0, OtherUsersNS=1, SharedNS=2 }; 00129 00130 // map a namespace type to a list of namespaces 00131 typedef TQMap<imapNamespace, TQStringList> nsMap; 00132 00133 // map a namespace to a delimiter 00134 typedef TQMap<TQString, TQString> namespaceDelim; 00135 00136 // map a namespace type to a map with the namespace and the delimiter 00137 typedef TQMap<imapNamespace, namespaceDelim> nsDelimMap; 00138 00142 struct jobData 00143 { 00144 // Needed by TQMap, don't use 00145 jobData() : url(TQString()), parent(0), current(0), total(1), done(0), offset(0), progressItem(0), 00146 onlySubscribed(false), quiet(false), cancellable(false) {} 00147 // Real constructor 00148 jobData( const TQString& _url, KMFolder *_parent = 0, 00149 int _total = 1, int _done = 0, bool _quiet = false, 00150 bool _cancelable = false ) 00151 : url(_url), parent(_parent), current(0), total(_total), done(_done), offset(0), 00152 progressItem(0), quiet(_quiet), cancellable(_cancelable) {} 00153 00154 TQString path; 00155 TQString url; 00156 TQString curNamespace; 00157 TQByteArray data; 00158 TQCString cdata; 00159 TQStringList items; 00160 KMFolder *parent, *current; 00161 TQPtrList<KMMessage> msgList; 00162 int total, done, offset; 00163 KPIM::ProgressItem *progressItem; 00164 bool onlySubscribed, quiet, cancellable; 00165 }; 00166 00167 typedef TQMap<KIO::Job *, jobData>::Iterator JobIterator; 00171 void insertJob( KIO::Job* job, const jobData& data ) { 00172 mapJobData.insert( job, data ); 00173 } 00177 JobIterator findJob( KIO::Job* job ) { return mapJobData.find( job ); } 00178 JobIterator jobsEnd() { return mapJobData.end(); } 00183 void removeJob( JobIterator& it ); 00184 00185 void removeJob( KIO::Job* job ); 00186 00194 void changeSubscription(bool subscribe, const TQString& imapPath, bool quiet = false ); 00195 00200 bool locallySubscribedTo( const TQString& imapPath ); 00201 00206 void changeLocalSubscription( const TQString& imapPath, bool subscribe ); 00207 00208 00214 void getUserRights( KMFolder* folder, const TQString& imapPath ); 00215 00221 void getACL( KMFolder* folder, const TQString& imapPath ); 00222 00228 void getStorageQuotaInfo( KMFolder* folder, const TQString& imapPath ); 00229 00234 void setImapStatus( KMFolder* folder, const TQString& path, const TQCString& flags ); 00235 00240 void setImapSeenStatus( KMFolder* folder, const TQString& path, bool seen ); 00241 00245 void slaveDied() { mSlave = 0; killAllJobs(); } 00246 00250 void killAllJobs( bool disconnectSlave=false ) = 0; 00251 00255 virtual void cancelMailCheck(); 00256 00260 enum FolderListType { Single, Recursive }; 00261 void processNewMailInFolder( KMFolder* folder, FolderListType type = Single ); 00262 00266 bool checkingSingleFolder() { return mCheckingSingleFolder; } 00267 00272 void postProcessNewMail( bool setStatusMsg = true ); 00273 00278 bool checkingMail( KMFolder *folder ); 00279 00280 bool checkingMail() { return NetworkAccount::checkingMail(); } 00281 00285 void handleBodyStructure( TQDataStream & stream, KMMessage * msg, 00286 const AttachmentStrategy *as ); 00287 00291 virtual void setFolder(KMFolder*, bool addAccount = false); 00292 00297 bool hasACLSupport() const { return mACLSupport; } 00298 00303 bool hasAnnotationSupport() const { return mAnnotationSupport; } 00304 00308 void setHasNoAnnotationSupport() { mAnnotationSupport = false; } 00309 00314 bool hasQuotaSupport() const { return mQuotaSupport; } 00315 00319 void setHasNoQuotaSupport() { mQuotaSupport = false; } 00320 00325 bool handleJobError( KIO::Job* job, const TQString& context, bool abortSync = false ); 00326 00330 virtual FolderStorage* rootFolder() const = 0; 00331 00335 KPIM::ProgressItem* listDirProgressItem(); 00336 00341 virtual unsigned int folderCount() const; 00342 00346 nsMap namespaces() const { return mNamespaces; } 00347 00351 virtual void setNamespaces( nsMap map ) 00352 { mNamespaces = map; } 00353 00358 nsDelimMap namespacesWithDelimiter(); 00359 00363 TQString namespaceForFolder( FolderStorage* ); 00364 00368 TQString addPathToNamespace( const TQString& ns ); 00369 00373 TQString delimiterForNamespace( const TQString& prefix ); 00374 00378 TQString delimiterForFolder( FolderStorage* ); 00379 00383 namespaceDelim namespaceToDelimiter() const 00384 { return mNamespaceToDelimiter; } 00385 00389 void setNamespaceToDelimiter( namespaceDelim map ) 00390 { mNamespaceToDelimiter = map; } 00391 00395 bool isNamespaceFolder( TQString& name ); 00396 00400 bool hasCapability( const TQString& capa ) { 00401 return mCapabilities.contains( capa ); } 00402 00408 TQString createImapPath( FolderStorage* parent, const TQString& folderName ); 00409 00413 TQString createImapPath( const TQString& parent, const TQString& folderName ); 00414 00415 00416 public slots: 00421 void getNamespaces(); 00422 00423 private slots: 00428 void slotSubscriptionResult(KIO::Job * job); 00429 00430 protected slots: 00431 virtual void slotCheckQueuedFolders(); 00432 00434 void slotSchedulerSlaveConnected(KIO::Slave *aSlave); 00436 void slotSchedulerSlaveError(KIO::Slave *aSlave, int, const TQString &errorMsg); 00437 00441 void slotSetStatusResult(KIO::Job * job); 00442 00444 void slotGetUserRightsResult( KIO::Job* _job ); 00445 00447 void slotGetACLResult( KIO::Job* _job ); 00448 00450 void slotGetStorageQuotaInfoResult( KIO::Job* _job ); 00451 00455 void slotNoopTimeout(); 00459 void slotIdleTimeout(); 00460 00464 void slotAbortRequested( KPIM::ProgressItem* ); 00465 00469 void slotSimpleResult(KIO::Job * job); 00470 00472 void slotNamespaceResult( KIO::Job*, const TQString& str ); 00473 00477 void slotSaveNamespaces( const ImapAccountBase::nsDelimMap& map ); 00478 00482 void slotCapabilitiesResult( KIO::Job*, const TQString& result ); 00483 00484 protected: 00485 00502 virtual bool handleError( int error, const TQString &errorMsg, KIO::Job* job, const TQString& context, bool abortSync = false ); 00503 00505 bool handlePutError( KIO::Job* job, jobData& jd, KMFolder* folder ); 00506 00507 virtual TQString protocol() const; 00508 virtual unsigned short int defaultPort() const; 00509 00513 void constructParts( TQDataStream & stream, int count, KMMessagePart* parentKMPart, 00514 DwBodyPart * parent, const DwMessage * dwmsg ); 00515 00517 void migratePrefix(); 00518 00519 // used for writing the blacklist out to the config file 00520 TQStringList locallyBlacklistedFolders() const; 00521 void localBlacklistFromStringList( const TQStringList & ); 00522 TQString prettifyQuotaError( const TQString& _error, KIO::Job * job ); 00523 00524 protected: 00525 TQPtrList<TQGuardedPtr<KMFolder> > mOpenFolders; 00526 TQStringList mSubfolderNames, mSubfolderPaths, 00527 mSubfolderMimeTypes, mSubfolderAttributes; 00528 TQMap<KIO::Job *, jobData> mapJobData; 00530 TQTimer mIdleTimer; 00532 TQTimer mNoopTimer; 00533 int mTotal, mCountUnread, mCountLastUnread; 00534 TQMap<TQString, int> mUnreadBeforeCheck; 00535 bool mAutoExpunge : 1; 00536 bool mHiddenFolders : 1; 00537 bool mOnlySubscribedFolders : 1; 00538 bool mOnlyLocallySubscribedFolders : 1; 00539 bool mLoadOnDemand : 1; 00540 bool mListOnlyOpenFolders : 1; 00541 bool mProgressEnabled : 1; 00542 00543 bool mErrorDialogIsActive : 1; 00544 bool mPasswordDialogIsActive : 1; 00545 bool mACLSupport : 1; 00546 bool mAnnotationSupport : 1; 00547 bool mQuotaSupport : 1; 00548 bool mSlaveConnected : 1; 00549 bool mSlaveConnectionError : 1; 00550 bool mCheckingSingleFolder : 1; 00551 00552 // folders that should be checked for new mails 00553 TQValueList<TQGuardedPtr<KMFolder> > mMailCheckFolders; 00554 // folders that should be checked after the current check is done 00555 TQValueList<TQGuardedPtr<KMFolder> > mFoldersQueuedForChecking; 00556 // holds messageparts from the bodystructure 00557 TQPtrList<KMMessagePart> mBodyPartList; 00558 // the current message for the bodystructure 00559 KMMessage* mCurrentMsg; 00560 00561 TQGuardedPtr<KPIM::ProgressItem> mListDirProgressItem; 00562 00563 // our namespaces in the form section=namespaceList 00564 nsMap mNamespaces; 00565 00566 // namespace - delimiter map 00567 namespaceDelim mNamespaceToDelimiter; 00568 00569 // old prefix for migration 00570 TQString mOldPrefix; 00571 00572 // capabilities 00573 TQStringList mCapabilities; 00574 00575 std::set<TQString> mLocalSubscriptionBlackList; 00576 00577 signals: 00584 void connectionResult( int errorCode, const TQString& errorMsg ); 00585 00590 void subscriptionChanged(const TQString& imapPath, bool subscribed); 00591 00596 void subscriptionChangeFailed( const TQString &errorMessage ); 00597 00603 void imapStatusChanged( KMFolder*, const TQString& imapPath, bool cont ); 00604 00611 void receivedUserRights( KMFolder* folder ); 00612 00620 void receivedACL( KMFolder* folder, KIO::Job* job, const KMail::ACLList& entries ); 00621 00630 void receivedStorageQuotaInfo( KMFolder* folder, KIO::Job* job, const KMail::QuotaInfo& entries ); 00631 00635 void namespacesFetched( const ImapAccountBase::nsDelimMap& ); 00636 00640 void namespacesFetched(); 00641 }; 00642 00643 00644 } // namespace KMail 00645 00646 #endif // __KMAIL_IMAPACCOUNTBASE_H__