00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __KMAIL_IMAPACCOUNTBASE_H__
00025 #define __KMAIL_IMAPACCOUNTBASE_H__
00026
00027 #include <set>
00028
00029 #include "networkaccount.h"
00030
00031 #include <qtimer.h>
00032 #include <qguardedptr.h>
00033 #include <kio/global.h>
00034
00035 class AccountManager;
00036 class KMFolder;
00037 class KConfig;
00038 class KMMessagePart;
00039 class DwBodyPart;
00040 class DwMessage;
00041 class FolderStorage;
00042 template <typename T> class QValueVector;
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 QValueVector<KMail::ACLListEntry> ACLList;
00056
00057 class AttachmentStrategy;
00058
00059 class ImapAccountBase : public KMail::NetworkAccount {
00060 Q_OBJECT
00061 protected:
00062 ImapAccountBase( AccountManager * parent, const QString & name, uint id );
00063 public:
00064 virtual ~ImapAccountBase();
00065
00067 virtual void init();
00068
00070 virtual void pseudoAssign( const KMAccount * a );
00071
00074 bool autoExpunge() const { return mAutoExpunge; }
00075 virtual void setAutoExpunge( bool expunge );
00076
00078 bool hiddenFolders() const { return mHiddenFolders; }
00079 virtual void setHiddenFolders( bool show );
00080
00082 bool onlySubscribedFolders() const { return mOnlySubscribedFolders; }
00083 virtual void setOnlySubscribedFolders( bool show );
00084
00086 bool onlyLocallySubscribedFolders() const { return mOnlyLocallySubscribedFolders; }
00087 virtual void setOnlyLocallySubscribedFolders( bool show );
00088
00089
00091 bool loadOnDemand() const { return mLoadOnDemand; }
00092 virtual void setLoadOnDemand( bool load );
00093
00095 bool listOnlyOpenFolders() const { return mListOnlyOpenFolders; }
00096 virtual void setListOnlyOpenFolders( bool only );
00097
00099 virtual KIO::MetaData slaveConfig() const;
00100
00101 virtual void readConfig( KConfig& config );
00102 virtual void writeConfig( KConfig& config );
00103
00107 enum ConnectionState { Error = 0, Connected, Connecting };
00108
00109
00110 enum ListType {
00111 List,
00112 ListSubscribed,
00113 ListSubscribedNoCheck,
00114 ListFolderOnly,
00115 ListFolderOnlySubscribed
00116 };
00117
00124 ConnectionState makeConnection();
00125
00126
00127 enum imapNamespace { PersonalNS=0, OtherUsersNS=1, SharedNS=2 };
00128
00129
00130 typedef QMap<imapNamespace, QStringList> nsMap;
00131
00132
00133 typedef QMap<QString, QString> namespaceDelim;
00134
00135
00136 typedef QMap<imapNamespace, namespaceDelim> nsDelimMap;
00137
00141 struct jobData
00142 {
00143
00144 jobData() : url(QString::null), parent(0), current(0), total(1), done(0), offset(0), progressItem(0),
00145 onlySubscribed(false), quiet(false), cancellable(false) {}
00146
00147 jobData( const QString& _url, KMFolder *_parent = 0,
00148 int _total = 1, int _done = 0, bool _quiet = false,
00149 bool _cancelable = false )
00150 : url(_url), parent(_parent), current(0), total(_total), done(_done), offset(0),
00151 progressItem(0), quiet(_quiet), cancellable(_cancelable) {}
00152
00153 QString path;
00154 QString url;
00155 QString curNamespace;
00156 QByteArray data;
00157 QCString cdata;
00158 QStringList items;
00159 KMFolder *parent, *current;
00160 QPtrList<KMMessage> msgList;
00161 int total, done, offset;
00162 KPIM::ProgressItem *progressItem;
00163 bool onlySubscribed, quiet, cancellable;
00164 };
00165
00166 typedef QMap<KIO::Job *, jobData>::Iterator JobIterator;
00170 void insertJob( KIO::Job* job, const jobData& data ) {
00171 mapJobData.insert( job, data );
00172 }
00176 JobIterator findJob( KIO::Job* job ) { return mapJobData.find( job ); }
00177 JobIterator jobsEnd() { return mapJobData.end(); }
00182 void removeJob( JobIterator& it );
00183
00184 void removeJob( KIO::Job* job );
00185
00191 void changeSubscription(bool subscribe, const QString& imapPath);
00192
00197 bool locallySubscribedTo( const QString& imapPath );
00198
00203 void changeLocalSubscription( const QString& imapPath, bool subscribe );
00204
00205
00211 void getUserRights( KMFolder* folder, const QString& imapPath );
00212
00218 void getACL( KMFolder* folder, const QString& imapPath );
00219
00225 void getStorageQuotaInfo( KMFolder* folder, const QString& imapPath );
00226
00231 void setImapStatus( KMFolder* folder, const QString& path, const QCString& flags );
00232
00237 void setImapSeenStatus( KMFolder* folder, const QString& path, bool seen );
00238
00242 void slaveDied() { mSlave = 0; killAllJobs(); }
00243
00247 void killAllJobs( bool disconnectSlave=false ) = 0;
00248
00252 virtual void cancelMailCheck();
00253
00257 void processNewMailSingleFolder(KMFolder* folder);
00258
00262 bool checkingSingleFolder() { return mCheckingSingleFolder; }
00263
00268 void postProcessNewMail( bool setStatusMsg = true );
00269
00274 bool checkingMail( KMFolder *folder );
00275
00276 bool checkingMail() { return NetworkAccount::checkingMail(); }
00277
00281 void handleBodyStructure( QDataStream & stream, KMMessage * msg,
00282 const AttachmentStrategy *as );
00283
00287 virtual void setFolder(KMFolder*, bool addAccount = false);
00288
00293 bool hasACLSupport() const { return mACLSupport; }
00294
00299 bool hasAnnotationSupport() const { return mAnnotationSupport; }
00300
00304 void setHasNoAnnotationSupport() { mAnnotationSupport = false; }
00305
00310 bool hasQuotaSupport() const { return mQuotaSupport; }
00311
00315 void setHasNoQuotaSupport() { mQuotaSupport = false; }
00316
00321 bool handleJobError( KIO::Job* job, const QString& context, bool abortSync = false );
00322
00326 virtual FolderStorage* const rootFolder() const = 0;
00327
00331 KPIM::ProgressItem* listDirProgressItem();
00332
00337 virtual unsigned int folderCount() const;
00338
00342 nsMap namespaces() const { return mNamespaces; }
00343
00347 virtual void setNamespaces( nsMap map )
00348 { mNamespaces = map; }
00349
00354 nsDelimMap namespacesWithDelimiter();
00355
00359 QString namespaceForFolder( FolderStorage* );
00360
00364 QString addPathToNamespace( const QString& ns );
00365
00369 QString delimiterForNamespace( const QString& prefix );
00370
00374 QString delimiterForFolder( FolderStorage* );
00375
00379 namespaceDelim namespaceToDelimiter() const
00380 { return mNamespaceToDelimiter; }
00381
00385 void setNamespaceToDelimiter( namespaceDelim map )
00386 { mNamespaceToDelimiter = map; }
00387
00391 bool isNamespaceFolder( QString& name );
00392
00396 bool hasCapability( const QString& capa ) {
00397 return mCapabilities.contains( capa ); }
00398
00404 QString createImapPath( FolderStorage* parent, const QString& folderName );
00405
00409 QString createImapPath( const QString& parent, const QString& folderName );
00410
00411
00412 public slots:
00417 void getNamespaces();
00418
00419 private slots:
00424 void slotSubscriptionResult(KIO::Job * job);
00425
00426 protected slots:
00427 virtual void slotCheckQueuedFolders();
00428
00430 void slotSchedulerSlaveConnected(KIO::Slave *aSlave);
00432 void slotSchedulerSlaveError(KIO::Slave *aSlave, int, const QString &errorMsg);
00433
00437 void slotSetStatusResult(KIO::Job * job);
00438
00440 void slotGetUserRightsResult( KIO::Job* _job );
00441
00443 void slotGetACLResult( KIO::Job* _job );
00444
00446 void slotGetStorageQuotaInfoResult( KIO::Job* _job );
00447
00451 void slotNoopTimeout();
00455 void slotIdleTimeout();
00456
00460 void slotAbortRequested( KPIM::ProgressItem* );
00461
00465 void slotSimpleResult(KIO::Job * job);
00466
00468 void slotNamespaceResult( KIO::Job*, const QString& str );
00469
00473 void slotSaveNamespaces( const ImapAccountBase::nsDelimMap& map );
00474
00478 void slotCapabilitiesResult( KIO::Job*, const QString& result );
00479
00480 protected:
00481
00498 virtual bool handleError( int error, const QString &errorMsg, KIO::Job* job, const QString& context, bool abortSync = false );
00499
00501 bool handlePutError( KIO::Job* job, jobData& jd, KMFolder* folder );
00502
00503 virtual QString protocol() const;
00504 virtual unsigned short int defaultPort() const;
00505
00509 void constructParts( QDataStream & stream, int count, KMMessagePart* parentKMPart,
00510 DwBodyPart * parent, const DwMessage * dwmsg );
00511
00513 void migratePrefix();
00514
00515
00516 QStringList locallyBlacklistedFolders() const;
00517 void localBlacklistFromStringList( const QStringList & );
00518 QString prettifyQuotaError( const QString& _error, KIO::Job * job );
00519
00520 protected:
00521 QPtrList<QGuardedPtr<KMFolder> > mOpenFolders;
00522 QStringList mSubfolderNames, mSubfolderPaths,
00523 mSubfolderMimeTypes, mSubfolderAttributes;
00524 QMap<KIO::Job *, jobData> mapJobData;
00526 QTimer mIdleTimer;
00528 QTimer mNoopTimer;
00529 int mTotal, mCountUnread, mCountLastUnread;
00530 QMap<QString, int> mUnreadBeforeCheck;
00531 bool mAutoExpunge : 1;
00532 bool mHiddenFolders : 1;
00533 bool mOnlySubscribedFolders : 1;
00534 bool mOnlyLocallySubscribedFolders : 1;
00535 bool mLoadOnDemand : 1;
00536 bool mListOnlyOpenFolders : 1;
00537 bool mProgressEnabled : 1;
00538
00539 bool mErrorDialogIsActive : 1;
00540 bool mPasswordDialogIsActive : 1;
00541 bool mACLSupport : 1;
00542 bool mAnnotationSupport : 1;
00543 bool mQuotaSupport : 1;
00544 bool mSlaveConnected : 1;
00545 bool mSlaveConnectionError : 1;
00546 bool mCheckingSingleFolder : 1;
00547
00548
00549 QValueList<QGuardedPtr<KMFolder> > mMailCheckFolders;
00550
00551 QValueList<QGuardedPtr<KMFolder> > mFoldersQueuedForChecking;
00552
00553 QPtrList<KMMessagePart> mBodyPartList;
00554
00555 KMMessage* mCurrentMsg;
00556
00557 QGuardedPtr<KPIM::ProgressItem> mListDirProgressItem;
00558
00559
00560 nsMap mNamespaces;
00561
00562
00563 namespaceDelim mNamespaceToDelimiter;
00564
00565
00566 QString mOldPrefix;
00567
00568
00569 QStringList mCapabilities;
00570
00571 std::set<QString> mLocalSubscriptionBlackList;
00572
00573 signals:
00580 void connectionResult( int errorCode, const QString& errorMsg );
00581
00586 void subscriptionChanged(const QString& imapPath, bool subscribed);
00587
00593 void imapStatusChanged( KMFolder*, const QString& imapPath, bool cont );
00594
00600 void receivedUserRights( KMFolder* folder );
00601
00609 void receivedACL( KMFolder* folder, KIO::Job* job, const KMail::ACLList& entries );
00610
00619 void receivedStorageQuotaInfo( KMFolder* folder, KIO::Job* job, const KMail::QuotaInfo& entries );
00620
00624 void namespacesFetched( const ImapAccountBase::nsDelimMap& );
00625
00629 void namespacesFetched();
00630 };
00631
00632
00633 }
00634
00635 #endif // __KMAIL_IMAPACCOUNTBASE_H__