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 <tdeio/global.h> 00034 00035 namespace KMail { 00036 class AccountManager; 00037 } 00038 class KMFolder; 00039 class TDEConfig/*Base*/; 00040 class KMMessagePart; 00041 class DwBodyPart; 00042 class DwMessage; 00043 class FolderStorage; 00044 template <typename T> class TQValueVector; 00045 00046 namespace TDEIO { 00047 class Job; 00048 } 00049 00050 namespace KPIM { 00051 class ProgressItem; 00052 } 00053 00054 namespace KMail { 00055 struct ACLListEntry; 00056 struct QuotaInfo; 00057 typedef TQValueVector<KMail::ACLListEntry> ACLList; 00058 00059 class AttachmentStrategy; 00060 00061 class ImapAccountBase : public KMail::NetworkAccount { 00062 Q_OBJECT 00063 00064 protected: 00065 ImapAccountBase( AccountManager * parent, const TQString & name, uint id ); 00066 public: 00067 virtual ~ImapAccountBase(); 00068 00070 virtual void init(); 00071 00073 virtual void pseudoAssign( const KMAccount * a ); 00074 00077 bool autoExpunge() const { return mAutoExpunge; } 00078 virtual void setAutoExpunge( bool expunge ); 00079 00081 bool hiddenFolders() const { return mHiddenFolders; } 00082 virtual void setHiddenFolders( bool show ); 00083 00085 bool onlySubscribedFolders() const { return mOnlySubscribedFolders; } 00086 virtual void setOnlySubscribedFolders( bool show ); 00087 00089 bool onlyLocallySubscribedFolders() const { return mOnlyLocallySubscribedFolders; } 00090 virtual void setOnlyLocallySubscribedFolders( bool show ); 00091 00092 00094 bool loadOnDemand() const { return mLoadOnDemand; } 00095 virtual void setLoadOnDemand( bool load ); 00096 00098 bool listOnlyOpenFolders() const { return mListOnlyOpenFolders; } 00099 virtual void setListOnlyOpenFolders( bool only ); 00100 00102 virtual TDEIO::MetaData slaveConfig() const; 00103 00104 virtual void readConfig( TDEConfig& config ); 00105 virtual void writeConfig( TDEConfig& config ); 00106 00110 enum ConnectionState { Error = 0, Connected, Connecting }; 00111 00112 // possible list types 00113 enum ListType { 00114 List, 00115 ListSubscribed, 00116 ListSubscribedNoCheck, 00117 ListFolderOnly, 00118 ListFolderOnlySubscribed 00119 }; 00120 00127 ConnectionState makeConnection(); 00128 00129 // namespace defines 00130 enum imapNamespace { PersonalNS=0, OtherUsersNS=1, SharedNS=2 }; 00131 00132 // map a namespace type to a list of namespaces 00133 typedef TQMap<imapNamespace, TQStringList> nsMap; 00134 00135 // map a namespace to a delimiter 00136 typedef TQMap<TQString, TQString> namespaceDelim; 00137 00138 // map a namespace type to a map with the namespace and the delimiter 00139 typedef TQMap<imapNamespace, namespaceDelim> nsDelimMap; 00140 00144 struct jobData 00145 { 00146 // Needed by TQMap, don't use 00147 jobData() : url(TQString()), parent(0), current(0), total(1), done(0), offset(0), progressItem(0), 00148 onlySubscribed(false), quiet(false), cancellable(false) {} 00149 // Real constructor 00150 jobData( const TQString& _url, KMFolder *_parent = 0, 00151 int _total = 1, int _done = 0, bool _quiet = false, 00152 bool _cancelable = false ) 00153 : url(_url), parent(_parent), current(0), total(_total), done(_done), offset(0), 00154 progressItem(0), quiet(_quiet), cancellable(_cancelable) {} 00155 00156 TQString path; 00157 TQString url; 00158 TQString curNamespace; 00159 TQByteArray data; 00160 TQCString cdata; 00161 TQStringList items; 00162 KMFolder *parent, *current; 00163 TQPtrList<KMMessage> msgList; 00164 int total, done, offset; 00165 KPIM::ProgressItem *progressItem; 00166 bool onlySubscribed, quiet, cancellable; 00167 }; 00168 00169 typedef TQMap<TDEIO::Job *, jobData>::Iterator JobIterator; 00173 void insertJob( TDEIO::Job* job, const jobData& data ) { 00174 mapJobData.insert( job, data ); 00175 } 00179 JobIterator findJob( TDEIO::Job* job ) { return mapJobData.find( job ); } 00180 JobIterator jobsEnd() { return mapJobData.end(); } 00185 void removeJob( JobIterator& it ); 00186 00187 void removeJob( TDEIO::Job* job ); 00188 00196 void changeSubscription(bool subscribe, const TQString& imapPath, bool quiet = false ); 00197 00202 bool locallySubscribedTo( const TQString& imapPath ); 00203 00208 void changeLocalSubscription( const TQString& imapPath, bool subscribe ); 00209 00210 00216 void getUserRights( KMFolder* folder, const TQString& imapPath ); 00217 00223 void getACL( KMFolder* folder, const TQString& imapPath ); 00224 00230 void getStorageQuotaInfo( KMFolder* folder, const TQString& imapPath ); 00231 00236 void setImapStatus( KMFolder* folder, const TQString& path, const TQCString& flags ); 00237 00242 void setImapSeenStatus( KMFolder* folder, const TQString& path, bool seen ); 00243 00247 void slaveDied() { mSlave = 0; killAllJobs(); } 00248 00252 void killAllJobs( bool disconnectSlave=false ) = 0; 00253 00257 virtual void cancelMailCheck(); 00258 00262 enum FolderListType { Single, Recursive }; 00263 void processNewMailInFolder( KMFolder* folder, FolderListType type = Single ); 00264 00268 bool checkingSingleFolder() { return mCheckingSingleFolder; } 00269 00274 void postProcessNewMail( bool setStatusMsg = true ); 00275 00280 bool checkingMail( KMFolder *folder ); 00281 00282 bool checkingMail() { return NetworkAccount::checkingMail(); } 00283 00287 void handleBodyStructure( TQDataStream & stream, KMMessage * msg, 00288 const AttachmentStrategy *as ); 00289 00293 virtual void setFolder(KMFolder*, bool addAccount = false); 00294 00299 bool hasACLSupport() const { return mACLSupport; } 00300 00305 bool hasAnnotationSupport() const { return mAnnotationSupport; } 00306 00310 void setHasNoAnnotationSupport() { mAnnotationSupport = false; } 00311 00316 bool hasQuotaSupport() const { return mQuotaSupport; } 00317 00321 void setHasNoQuotaSupport() { mQuotaSupport = false; } 00322 00327 bool handleJobError( TDEIO::Job* job, const TQString& context, bool abortSync = false ); 00328 00332 virtual FolderStorage* rootFolder() const = 0; 00333 00337 KPIM::ProgressItem* listDirProgressItem(); 00338 00343 virtual unsigned int folderCount() const; 00344 00348 nsMap namespaces() const { return mNamespaces; } 00349 00353 virtual void setNamespaces( nsMap map ) 00354 { mNamespaces = map; } 00355 00360 nsDelimMap namespacesWithDelimiter(); 00361 00365 TQString namespaceForFolder( FolderStorage* ); 00366 00370 TQString addPathToNamespace( const TQString& ns ); 00371 00375 TQString delimiterForNamespace( const TQString& prefix ); 00376 00380 TQString delimiterForFolder( FolderStorage* ); 00381 00385 namespaceDelim namespaceToDelimiter() const 00386 { return mNamespaceToDelimiter; } 00387 00391 void setNamespaceToDelimiter( namespaceDelim map ) 00392 { mNamespaceToDelimiter = map; } 00393 00397 bool isNamespaceFolder( TQString& name ); 00398 00402 bool hasCapability( const TQString& capa ) { 00403 return mCapabilities.contains( capa ); } 00404 00410 TQString createImapPath( FolderStorage* parent, const TQString& folderName ); 00411 00415 TQString createImapPath( const TQString& parent, const TQString& folderName ); 00416 00417 00418 public slots: 00423 void getNamespaces(); 00424 00425 private slots: 00430 void slotSubscriptionResult(TDEIO::Job * job); 00431 00432 protected slots: 00433 virtual void slotCheckQueuedFolders(); 00434 00436 void slotSchedulerSlaveConnected(TDEIO::Slave *aSlave); 00438 void slotSchedulerSlaveError(TDEIO::Slave *aSlave, int, const TQString &errorMsg); 00439 00443 void slotSetStatusResult(TDEIO::Job * job); 00444 00446 void slotGetUserRightsResult( TDEIO::Job* _job ); 00447 00449 void slotGetACLResult( TDEIO::Job* _job ); 00450 00452 void slotGetStorageQuotaInfoResult( TDEIO::Job* _job ); 00453 00457 void slotNoopTimeout(); 00461 void slotIdleTimeout(); 00462 00466 void slotAbortRequested( KPIM::ProgressItem* ); 00467 00471 void slotSimpleResult(TDEIO::Job * job); 00472 00474 void slotNamespaceResult( TDEIO::Job*, const TQString& str ); 00475 00479 void slotSaveNamespaces( const ImapAccountBase::nsDelimMap& map ); 00480 00484 void slotCapabilitiesResult( TDEIO::Job*, const TQString& result ); 00485 00486 protected: 00487 00504 virtual bool handleError( int error, const TQString &errorMsg, TDEIO::Job* job, const TQString& context, bool abortSync = false ); 00505 00507 bool handlePutError( TDEIO::Job* job, jobData& jd, KMFolder* folder ); 00508 00509 virtual TQString protocol() const; 00510 virtual unsigned short int defaultPort() const; 00511 00515 void constructParts( TQDataStream & stream, int count, KMMessagePart* parentKMPart, 00516 DwBodyPart * parent, const DwMessage * dwmsg ); 00517 00519 void migratePrefix(); 00520 00521 // used for writing the blacklist out to the config file 00522 TQStringList locallyBlacklistedFolders() const; 00523 void localBlacklistFromStringList( const TQStringList & ); 00524 TQString prettifyQuotaError( const TQString& _error, TDEIO::Job * job ); 00525 00526 protected: 00527 TQPtrList<TQGuardedPtr<KMFolder> > mOpenFolders; 00528 TQStringList mSubfolderNames, mSubfolderPaths, 00529 mSubfolderMimeTypes, mSubfolderAttributes; 00530 TQMap<TDEIO::Job *, jobData> mapJobData; 00532 TQTimer mIdleTimer; 00534 TQTimer mNoopTimer; 00535 int mTotal, mCountUnread, mCountLastUnread; 00536 TQMap<TQString, int> mUnreadBeforeCheck; 00537 bool mAutoExpunge : 1; 00538 bool mHiddenFolders : 1; 00539 bool mOnlySubscribedFolders : 1; 00540 bool mOnlyLocallySubscribedFolders : 1; 00541 bool mLoadOnDemand : 1; 00542 bool mListOnlyOpenFolders : 1; 00543 bool mProgressEnabled : 1; 00544 00545 bool mErrorDialogIsActive : 1; 00546 bool mPasswordDialogIsActive : 1; 00547 bool mACLSupport : 1; 00548 bool mAnnotationSupport : 1; 00549 bool mQuotaSupport : 1; 00550 bool mSlaveConnected : 1; 00551 bool mSlaveConnectionError : 1; 00552 bool mCheckingSingleFolder : 1; 00553 00554 // folders that should be checked for new mails 00555 TQValueList<TQGuardedPtr<KMFolder> > mMailCheckFolders; 00556 // folders that should be checked after the current check is done 00557 TQValueList<TQGuardedPtr<KMFolder> > mFoldersQueuedForChecking; 00558 // holds messageparts from the bodystructure 00559 TQPtrList<KMMessagePart> mBodyPartList; 00560 // the current message for the bodystructure 00561 KMMessage* mCurrentMsg; 00562 00563 TQGuardedPtr<KPIM::ProgressItem> mListDirProgressItem; 00564 00565 // our namespaces in the form section=namespaceList 00566 nsMap mNamespaces; 00567 00568 // namespace - delimiter map 00569 namespaceDelim mNamespaceToDelimiter; 00570 00571 // old prefix for migration 00572 TQString mOldPrefix; 00573 00574 // capabilities 00575 TQStringList mCapabilities; 00576 00577 std::set<TQString> mLocalSubscriptionBlackList; 00578 00579 signals: 00586 void connectionResult( int errorCode, const TQString& errorMsg ); 00587 00592 void subscriptionChanged(const TQString& imapPath, bool subscribed); 00593 00598 void subscriptionChangeFailed( const TQString &errorMessage ); 00599 00605 void imapStatusChanged( KMFolder*, const TQString& imapPath, bool cont ); 00606 00613 void receivedUserRights( KMFolder* folder ); 00614 00622 void receivedACL( KMFolder* folder, TDEIO::Job* job, const KMail::ACLList& entries ); 00623 00632 void receivedStorageQuotaInfo( KMFolder* folder, TDEIO::Job* job, const KMail::QuotaInfo& entries ); 00633 00637 void namespacesFetched( const ImapAccountBase::nsDelimMap& ); 00638 00642 void namespacesFetched(); 00643 }; 00644 00645 00646 } // namespace KMail 00647 00648 #endif // __KMAIL_IMAPACCOUNTBASE_H__