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 "networkaccount.h"
00028 
00029 #include <qtimer.h>
00030 #include <qguardedptr.h>
00031 #include <kio/global.h>
00032 
00033 class AccountManager;
00034 class KMFolder;
00035 class KConfig/*Base*/;
00036 class KMMessagePart;
00037 class DwBodyPart;
00038 class DwMessage;
00039 class FolderStorage;
00040 template <typename T> class QValueVector;
00041 
00042 namespace KIO {
00043   class Job;
00044 }
00045 
00046 namespace KPIM {
00047   class ProgressItem;
00048 }
00049 
00050 namespace KMail {
00051   struct ACLListEntry;
00052   struct QuotaInfo;
00053   typedef QValueVector<KMail::ACLListEntry> ACLList;
00054 
00055   class AttachmentStrategy;
00056 
00057   class ImapAccountBase : public KMail::NetworkAccount {
00058     Q_OBJECT
00059   protected:
00060     ImapAccountBase( AccountManager * parent, const QString & name, uint id );
00061   public:
00062     virtual ~ImapAccountBase();
00063 
00065     virtual void init();
00066 
00068     virtual void pseudoAssign( const KMAccount * a );
00069 
00072     bool autoExpunge() const { return mAutoExpunge; }
00073     virtual void setAutoExpunge( bool expunge );
00074 
00076     bool hiddenFolders() const { return mHiddenFolders; }
00077     virtual void setHiddenFolders( bool show );
00078 
00080     bool onlySubscribedFolders() const { return mOnlySubscribedFolders; }
00081     virtual void setOnlySubscribedFolders( bool show );
00082 
00084     bool loadOnDemand() const { return mLoadOnDemand; }
00085     virtual void setLoadOnDemand( bool load );
00086 
00088     bool listOnlyOpenFolders() const { return mListOnlyOpenFolders; }
00089     virtual void setListOnlyOpenFolders( bool only );
00090 
00092     virtual KIO::MetaData slaveConfig() const;
00093 
00094     virtual void readConfig( KConfig& config );
00095     virtual void writeConfig( KConfig& config );
00096 
00100     enum ConnectionState { Error = 0, Connected, Connecting };
00101 
00102     // possible list types
00103     enum ListType { 
00104       List, 
00105       ListSubscribed, 
00106       ListSubscribedNoCheck, 
00107       ListFolderOnly,
00108       ListFolderOnlySubscribed
00109     };
00110 
00117     ConnectionState makeConnection();
00118 
00119     // namespace defines
00120     enum imapNamespace { PersonalNS=0, OtherUsersNS=1, SharedNS=2 };
00121 
00122     // map a namespace type to a list of namespaces
00123     typedef QMap<imapNamespace, QStringList> nsMap;
00124 
00125     // map a namespace to a delimiter
00126     typedef QMap<QString, QString> namespaceDelim;
00127 
00128     // map a namespace type to a map with the namespace and the delimiter
00129     typedef QMap<imapNamespace, namespaceDelim> nsDelimMap;
00130 
00134     struct jobData
00135     {
00136       // Needed by QMap, don't use
00137       jobData() : url(QString::null), parent(0), total(1), done(0), offset(0), progressItem(0),
00138                   onlySubscribed(false), quiet(false), cancellable(false) {}
00139       // Real constructor
00140       jobData( const QString& _url, KMFolder *_parent = 0,
00141           int _total = 1, int _done = 0, bool _quiet = false,
00142           bool _cancelable = false )
00143         : url(_url), parent(_parent), total(_total), done(_done), offset(0),
00144           progressItem(0), quiet(_quiet), cancellable(_cancelable) {}
00145 
00146       // Return "url" in a form that can be displayed in HTML (w/o password)
00147       QString htmlURL() const;
00148 
00149       QString path;
00150       QString url;
00151       QString curNamespace;
00152       QByteArray data;
00153       QCString cdata;
00154       QStringList items;
00155       KMFolder *parent;
00156       QPtrList<KMMessage> msgList;
00157       int total, done, offset;
00158       KPIM::ProgressItem *progressItem;
00159       bool onlySubscribed, quiet, cancellable;
00160     };
00161 
00162     typedef QMap<KIO::Job *, jobData>::Iterator JobIterator;
00166     void insertJob( KIO::Job* job, const jobData& data ) {
00167       mapJobData.insert( job, data );
00168     }
00172     JobIterator findJob( KIO::Job* job ) { return mapJobData.find( job ); }
00173     JobIterator jobsEnd() { return mapJobData.end(); }
00178     void removeJob( JobIterator& it );
00179 
00180     void removeJob( KIO::Job* job );
00181 
00187     void changeSubscription(bool subscribe, const QString& imapPath);
00188 
00194     void getUserRights( KMFolder* folder, const QString& imapPath );
00195 
00201     void getACL( KMFolder* folder, const QString& imapPath );
00202 
00208     void getStorageQuotaInfo( KMFolder* folder, const QString& imapPath );
00209 
00214     void setImapStatus( KMFolder* folder, const QString& path, const QCString& flags );
00215 
00219     void slaveDied() { mSlave = 0; killAllJobs(); }
00220 
00224     void killAllJobs( bool disconnectSlave=false ) = 0;
00225 
00229     virtual void cancelMailCheck();
00230 
00234     void processNewMailSingleFolder(KMFolder* folder);
00235 
00239     bool checkingSingleFolder() { return mCheckingSingleFolder; }
00240 
00245     void postProcessNewMail( bool setStatusMsg = true );
00246 
00251     bool checkingMail( KMFolder *folder );
00252 
00253     bool checkingMail() { return NetworkAccount::checkingMail(); }
00254 
00258     void handleBodyStructure( QDataStream & stream, KMMessage * msg,
00259                               const AttachmentStrategy *as );
00260 
00264     virtual void setFolder(KMFolder*, bool addAccount = false);
00265 
00270     bool hasACLSupport() const { return mACLSupport; }
00271 
00276     bool hasAnnotationSupport() const { return mAnnotationSupport; }
00277 
00281     void setHasNoAnnotationSupport() { mAnnotationSupport = false; }
00282 
00287     bool hasQuotaSupport() const { return mQuotaSupport; }
00288 
00292     void setHasNoQuotaSupport() { mQuotaSupport = false; }
00293 
00298     bool handleJobError( KIO::Job* job, const QString& context, bool abortSync = false );
00299 
00303     virtual FolderStorage* const rootFolder() const = 0;
00304 
00308     KPIM::ProgressItem* listDirProgressItem();
00309 
00314     virtual unsigned int folderCount() const;
00315 
00319     nsMap namespaces() const { return mNamespaces; }
00320 
00324     virtual void setNamespaces( nsMap map ) 
00325     { mNamespaces = map; }
00326 
00331     nsDelimMap namespacesWithDelimiter();
00332 
00336      QString namespaceForFolder( FolderStorage* );
00337 
00341      QString addPathToNamespace( const QString& ns );
00342 
00346      QString delimiterForNamespace( const QString& prefix );
00347 
00351      QString delimiterForFolder( FolderStorage* );
00352 
00356      namespaceDelim namespaceToDelimiter() const
00357      { return mNamespaceToDelimiter; }
00358 
00362      void setNamespaceToDelimiter( namespaceDelim map )
00363      { mNamespaceToDelimiter = map; } 
00364 
00368      bool isNamespaceFolder( QString& name );
00369 
00373      bool hasCapability( const QString& capa ) {
00374       return mCapabilities.contains( capa ); }
00375 
00381      QString createImapPath( FolderStorage* parent, const QString& folderName );
00382 
00386      QString createImapPath( const QString& parent, const QString& folderName );
00387 
00388 
00389   public slots:
00394     void getNamespaces();
00395 
00396   private slots:
00401     void slotSubscriptionResult(KIO::Job * job);
00402 
00403   protected slots:
00404     virtual void slotCheckQueuedFolders();
00405 
00407     void slotSchedulerSlaveConnected(KIO::Slave *aSlave);
00409     void slotSchedulerSlaveError(KIO::Slave *aSlave, int, const QString &errorMsg);
00410 
00414     void slotSetStatusResult(KIO::Job * job);
00415 
00417     void slotGetUserRightsResult( KIO::Job* _job );
00418 
00420     void slotGetACLResult( KIO::Job* _job );
00421 
00423     void slotGetStorageQuotaInfoResult( KIO::Job* _job );
00424 
00428     void slotNoopTimeout();
00432     void slotIdleTimeout();
00433 
00437     void slotAbortRequested( KPIM::ProgressItem* );
00438 
00442     void slotSimpleResult(KIO::Job * job);
00443 
00445     void slotNamespaceResult( KIO::Job*, const QString& str );
00446 
00450     void slotSaveNamespaces( const ImapAccountBase::nsDelimMap& map );
00451 
00455     void slotCapabilitiesResult( KIO::Job*, const QString& result );
00456 
00457   protected:
00458 
00475     virtual bool handleError( int error, const QString &errorMsg, KIO::Job* job, const QString& context, bool abortSync = false );
00476 
00478     bool handlePutError( KIO::Job* job, jobData& jd, KMFolder* folder );
00479 
00480     virtual QString protocol() const;
00481     virtual unsigned short int defaultPort() const;
00482 
00486     void constructParts( QDataStream & stream, int count, KMMessagePart* parentKMPart,
00487        DwBodyPart * parent, const DwMessage * dwmsg );
00488 
00490     void migratePrefix();
00491 
00492 
00493   protected:
00494     QPtrList<QGuardedPtr<KMFolder> > mOpenFolders;
00495     QStringList mSubfolderNames, mSubfolderPaths,
00496         mSubfolderMimeTypes, mSubfolderAttributes;
00497     QMap<KIO::Job *, jobData> mapJobData;
00499     QTimer mIdleTimer;
00501     QTimer mNoopTimer;
00502     int mTotal, mCountUnread, mCountLastUnread;
00503     QMap<QString, int> mUnreadBeforeCheck;
00504     bool mAutoExpunge : 1;
00505     bool mHiddenFolders : 1;
00506     bool mOnlySubscribedFolders : 1;
00507     bool mLoadOnDemand : 1;
00508     bool mListOnlyOpenFolders : 1;
00509     bool mProgressEnabled : 1;
00510 
00511     bool mErrorDialogIsActive : 1;
00512     bool mPasswordDialogIsActive : 1;
00513     bool mACLSupport : 1;
00514     bool mAnnotationSupport : 1;
00515     bool mQuotaSupport : 1;
00516     bool mSlaveConnected : 1;
00517     bool mSlaveConnectionError : 1;
00518     bool mCheckingSingleFolder : 1;
00519 
00520     // folders that should be checked for new mails
00521     QValueList<QGuardedPtr<KMFolder> > mMailCheckFolders;
00522     // folders that should be checked after the current check is done
00523     QValueList<QGuardedPtr<KMFolder> > mFoldersQueuedForChecking;
00524     // holds messageparts from the bodystructure
00525     QPtrList<KMMessagePart> mBodyPartList;
00526     // the current message for the bodystructure
00527     KMMessage* mCurrentMsg;
00528 
00529     QGuardedPtr<KPIM::ProgressItem> mListDirProgressItem;
00530 
00531     // our namespaces in the form section=namespaceList
00532     nsMap mNamespaces;
00533 
00534     // namespace - delimiter map
00535     namespaceDelim mNamespaceToDelimiter;
00536 
00537     // old prefix for migration
00538     QString mOldPrefix;
00539 
00540     // capabilities
00541     QStringList mCapabilities;
00542 
00543   signals:
00550     void connectionResult( int errorCode, const QString& errorMsg );
00551 
00556     void subscriptionChanged(const QString& imapPath, bool subscribed);
00557 
00563     void imapStatusChanged( KMFolder*, const QString& imapPath, bool cont );
00564 
00570     void receivedUserRights( KMFolder* folder );
00571 
00579     void receivedACL( KMFolder* folder, KIO::Job* job, const KMail::ACLList& entries );
00580 
00589     void receivedStorageQuotaInfo( KMFolder* folder, KIO::Job* job, const KMail::QuotaInfo& entries );
00590 
00594     void namespacesFetched( const ImapAccountBase::nsDelimMap& );
00595 
00599     void namespacesFetched();
00600   };
00601 
00602 
00603 } // namespace KMail
00604 
00605 #endif // __KMAIL_IMAPACCOUNTBASE_H__
KDE Home | KDE Accessibility Home | Description of Access Keys