kmail

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 <qtimer.h>
00032 #include <qguardedptr.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 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     // possible list types
00110     enum ListType {
00111       List,
00112       ListSubscribed,
00113       ListSubscribedNoCheck,
00114       ListFolderOnly,
00115       ListFolderOnlySubscribed
00116     };
00117 
00124     ConnectionState makeConnection();
00125 
00126     // namespace defines
00127     enum imapNamespace { PersonalNS=0, OtherUsersNS=1, SharedNS=2 };
00128 
00129     // map a namespace type to a list of namespaces
00130     typedef QMap<imapNamespace, QStringList> nsMap;
00131 
00132     // map a namespace to a delimiter
00133     typedef QMap<QString, QString> namespaceDelim;
00134 
00135     // map a namespace type to a map with the namespace and the delimiter
00136     typedef QMap<imapNamespace, namespaceDelim> nsDelimMap;
00137 
00141     struct jobData
00142     {
00143       // Needed by QMap, don't use
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       // Real constructor
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     enum FolderListType { Single, Recursive };
00258     void processNewMailInFolder( KMFolder* folder, FolderListType type = Single );
00259 
00263     bool checkingSingleFolder() { return mCheckingSingleFolder; }
00264 
00269     void postProcessNewMail( bool setStatusMsg = true );
00270 
00275     bool checkingMail( KMFolder *folder );
00276 
00277     bool checkingMail() { return NetworkAccount::checkingMail(); }
00278 
00282     void handleBodyStructure( QDataStream & stream, KMMessage * msg,
00283                               const AttachmentStrategy *as );
00284 
00288     virtual void setFolder(KMFolder*, bool addAccount = false);
00289 
00294     bool hasACLSupport() const { return mACLSupport; }
00295 
00300     bool hasAnnotationSupport() const { return mAnnotationSupport; }
00301 
00305     void setHasNoAnnotationSupport() { mAnnotationSupport = false; }
00306 
00311     bool hasQuotaSupport() const { return mQuotaSupport; }
00312 
00316     void setHasNoQuotaSupport() { mQuotaSupport = false; }
00317 
00322     bool handleJobError( KIO::Job* job, const QString& context, bool abortSync = false );
00323 
00327     virtual FolderStorage* rootFolder() const = 0;
00328 
00332     KPIM::ProgressItem* listDirProgressItem();
00333 
00338     virtual unsigned int folderCount() const;
00339 
00343     nsMap namespaces() const { return mNamespaces; }
00344 
00348     virtual void setNamespaces( nsMap map )
00349     { mNamespaces = map; }
00350 
00355     nsDelimMap namespacesWithDelimiter();
00356 
00360      QString namespaceForFolder( FolderStorage* );
00361 
00365      QString addPathToNamespace( const QString& ns );
00366 
00370      QString delimiterForNamespace( const QString& prefix );
00371 
00375      QString delimiterForFolder( FolderStorage* );
00376 
00380      namespaceDelim namespaceToDelimiter() const
00381      { return mNamespaceToDelimiter; }
00382 
00386      void setNamespaceToDelimiter( namespaceDelim map )
00387      { mNamespaceToDelimiter = map; }
00388 
00392      bool isNamespaceFolder( QString& name );
00393 
00397      bool hasCapability( const QString& capa ) {
00398       return mCapabilities.contains( capa ); }
00399 
00405      QString createImapPath( FolderStorage* parent, const QString& folderName );
00406 
00410      QString createImapPath( const QString& parent, const QString& folderName );
00411 
00412 
00413   public slots:
00418     void getNamespaces();
00419 
00420   private slots:
00425     void slotSubscriptionResult(KIO::Job * job);
00426 
00427   protected slots:
00428     virtual void slotCheckQueuedFolders();
00429 
00431     void slotSchedulerSlaveConnected(KIO::Slave *aSlave);
00433     void slotSchedulerSlaveError(KIO::Slave *aSlave, int, const QString &errorMsg);
00434 
00438     void slotSetStatusResult(KIO::Job * job);
00439 
00441     void slotGetUserRightsResult( KIO::Job* _job );
00442 
00444     void slotGetACLResult( KIO::Job* _job );
00445 
00447     void slotGetStorageQuotaInfoResult( KIO::Job* _job );
00448 
00452     void slotNoopTimeout();
00456     void slotIdleTimeout();
00457 
00461     void slotAbortRequested( KPIM::ProgressItem* );
00462 
00466     void slotSimpleResult(KIO::Job * job);
00467 
00469     void slotNamespaceResult( KIO::Job*, const QString& str );
00470 
00474     void slotSaveNamespaces( const ImapAccountBase::nsDelimMap& map );
00475 
00479     void slotCapabilitiesResult( KIO::Job*, const QString& result );
00480 
00481   protected:
00482 
00499     virtual bool handleError( int error, const QString &errorMsg, KIO::Job* job, const QString& context, bool abortSync = false );
00500 
00502     bool handlePutError( KIO::Job* job, jobData& jd, KMFolder* folder );
00503 
00504     virtual QString protocol() const;
00505     virtual unsigned short int defaultPort() const;
00506 
00510     void constructParts( QDataStream & stream, int count, KMMessagePart* parentKMPart,
00511        DwBodyPart * parent, const DwMessage * dwmsg );
00512 
00514     void migratePrefix();
00515 
00516     // used for writing the blacklist out to the config file
00517     QStringList locallyBlacklistedFolders() const;
00518     void localBlacklistFromStringList( const QStringList & );
00519     QString prettifyQuotaError( const QString& _error, KIO::Job * job );
00520 
00521   protected:
00522     QPtrList<QGuardedPtr<KMFolder> > mOpenFolders;
00523     QStringList mSubfolderNames, mSubfolderPaths,
00524         mSubfolderMimeTypes, mSubfolderAttributes;
00525     QMap<KIO::Job *, jobData> mapJobData;
00527     QTimer mIdleTimer;
00529     QTimer mNoopTimer;
00530     int mTotal, mCountUnread, mCountLastUnread;
00531     QMap<QString, int> mUnreadBeforeCheck;
00532     bool mAutoExpunge : 1;
00533     bool mHiddenFolders : 1;
00534     bool mOnlySubscribedFolders : 1;
00535     bool mOnlyLocallySubscribedFolders : 1;
00536     bool mLoadOnDemand : 1;
00537     bool mListOnlyOpenFolders : 1;
00538     bool mProgressEnabled : 1;
00539 
00540     bool mErrorDialogIsActive : 1;
00541     bool mPasswordDialogIsActive : 1;
00542     bool mACLSupport : 1;
00543     bool mAnnotationSupport : 1;
00544     bool mQuotaSupport : 1;
00545     bool mSlaveConnected : 1;
00546     bool mSlaveConnectionError : 1;
00547     bool mCheckingSingleFolder : 1;
00548 
00549     // folders that should be checked for new mails
00550     QValueList<QGuardedPtr<KMFolder> > mMailCheckFolders;
00551     // folders that should be checked after the current check is done
00552     QValueList<QGuardedPtr<KMFolder> > mFoldersQueuedForChecking;
00553     // holds messageparts from the bodystructure
00554     QPtrList<KMMessagePart> mBodyPartList;
00555     // the current message for the bodystructure
00556     KMMessage* mCurrentMsg;
00557 
00558     QGuardedPtr<KPIM::ProgressItem> mListDirProgressItem;
00559 
00560     // our namespaces in the form section=namespaceList
00561     nsMap mNamespaces;
00562 
00563     // namespace - delimiter map
00564     namespaceDelim mNamespaceToDelimiter;
00565 
00566     // old prefix for migration
00567     QString mOldPrefix;
00568 
00569     // capabilities
00570     QStringList mCapabilities;
00571 
00572     std::set<QString> mLocalSubscriptionBlackList;
00573 
00574   signals:
00581     void connectionResult( int errorCode, const QString& errorMsg );
00582 
00587     void subscriptionChanged(const QString& imapPath, bool subscribed);
00588 
00594     void imapStatusChanged( KMFolder*, const QString& imapPath, bool cont );
00595 
00601     void receivedUserRights( KMFolder* folder );
00602 
00610     void receivedACL( KMFolder* folder, KIO::Job* job, const KMail::ACLList& entries );
00611 
00620     void receivedStorageQuotaInfo( KMFolder* folder, KIO::Job* job, const KMail::QuotaInfo& entries );
00621 
00625     void namespacesFetched( const ImapAccountBase::nsDelimMap& );
00626 
00630     void namespacesFetched();
00631   };
00632 
00633 
00634 } // namespace KMail
00635 
00636 #endif // __KMAIL_IMAPACCOUNTBASE_H__
KDE Home | KDE Accessibility Home | Description of Access Keys