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   typedef QValueVector<KMail::ACLListEntry> ACLList;
00053 
00054   class AttachmentStrategy;
00055 
00056   class ImapAccountBase : public KMail::NetworkAccount {
00057     Q_OBJECT
00058   protected:
00059     ImapAccountBase( AccountManager * parent, const QString & name, uint id );
00060   public:
00061     virtual ~ImapAccountBase();
00062 
00064     virtual void init();
00065 
00067     virtual void pseudoAssign( const KMAccount * a );
00068 
00071     bool autoExpunge() const { return mAutoExpunge; }
00072     virtual void setAutoExpunge( bool expunge );
00073 
00075     bool hiddenFolders() const { return mHiddenFolders; }
00076     virtual void setHiddenFolders( bool show );
00077 
00079     bool onlySubscribedFolders() const { return mOnlySubscribedFolders; }
00080     virtual void setOnlySubscribedFolders( bool show );
00081 
00083     bool loadOnDemand() const { return mLoadOnDemand; }
00084     virtual void setLoadOnDemand( bool load );
00085 
00087     bool listOnlyOpenFolders() const { return mListOnlyOpenFolders; }
00088     virtual void setListOnlyOpenFolders( bool only );
00089 
00091     virtual KIO::MetaData slaveConfig() const;
00092 
00093     virtual void readConfig( KConfig& config );
00094     virtual void writeConfig( KConfig& config );
00095 
00099     enum ConnectionState { Error = 0, Connected, Connecting };
00100 
00101     // possible list types
00102     enum ListType { 
00103       List, 
00104       ListSubscribed, 
00105       ListSubscribedNoCheck, 
00106       ListFolderOnly,
00107       ListFolderOnlySubscribed
00108     };
00109 
00116     ConnectionState makeConnection();
00117 
00118     // namespace defines
00119     enum imapNamespace { PersonalNS=0, OtherUsersNS=1, SharedNS=2 };
00120 
00121     // map a namespace type to a list of namespaces
00122     typedef QMap<imapNamespace, QStringList> nsMap;
00123 
00124     // map a namespace to a delimiter
00125     typedef QMap<QString, QString> namespaceDelim;
00126 
00127     // map a namespace type to a map with the namespace and the delimiter
00128     typedef QMap<imapNamespace, namespaceDelim> nsDelimMap;
00129 
00133     struct jobData
00134     {
00135       // Needed by QMap, don't use
00136       jobData() : url(QString::null), parent(0), total(1), done(0), offset(0), progressItem(0),
00137                   onlySubscribed(false), quiet(false), cancellable(false) {}
00138       // Real constructor
00139       jobData( const QString& _url, KMFolder *_parent = 0,
00140           int _total = 1, int _done = 0, bool _quiet = false,
00141           bool _cancelable = false )
00142         : url(_url), parent(_parent), total(_total), done(_done), offset(0),
00143           progressItem(0), quiet(_quiet), cancellable(_cancelable) {}
00144 
00145       // Return "url" in a form that can be displayed in HTML (w/o password)
00146       QString htmlURL() const;
00147 
00148       QString path;
00149       QString url;
00150       QString curNamespace;
00151       QByteArray data;
00152       QCString cdata;
00153       QStringList items;
00154       KMFolder *parent;
00155       QPtrList<KMMessage> msgList;
00156       int total, done, offset;
00157       KPIM::ProgressItem *progressItem;
00158       bool onlySubscribed, quiet, cancellable;
00159     };
00160 
00161     typedef QMap<KIO::Job *, jobData>::Iterator JobIterator;
00165     void insertJob( KIO::Job* job, const jobData& data ) {
00166       mapJobData.insert( job, data );
00167     }
00171     JobIterator findJob( KIO::Job* job ) { return mapJobData.find( job ); }
00172     JobIterator jobsEnd() { return mapJobData.end(); }
00177     void removeJob( JobIterator& it );
00178 
00179     void removeJob( KIO::Job* job );
00180 
00186     void changeSubscription(bool subscribe, const QString& imapPath);
00187 
00193     void getUserRights( KMFolder* folder, const QString& imapPath );
00194 
00200     void getACL( KMFolder* folder, const QString& imapPath );
00201 
00206     void setImapStatus( KMFolder* folder, const QString& path, const QCString& flags );
00207 
00211     void slaveDied() { mSlave = 0; killAllJobs(); }
00212 
00216     void killAllJobs( bool disconnectSlave=false ) = 0;
00217 
00221     virtual void cancelMailCheck();
00222 
00226     void processNewMailSingleFolder(KMFolder* folder);
00227 
00231     bool checkingSingleFolder() { return mCheckingSingleFolder; }
00232 
00237     void postProcessNewMail( bool setStatusMsg = true );
00238 
00243     bool checkingMail( KMFolder *folder );
00244 
00245     bool checkingMail() { return NetworkAccount::checkingMail(); }
00246 
00250     void handleBodyStructure( QDataStream & stream, KMMessage * msg,
00251                               const AttachmentStrategy *as );
00252 
00256     virtual void setFolder(KMFolder*, bool addAccount = false);
00257 
00262     bool hasACLSupport() const { return mACLSupport; }
00263 
00268     bool hasAnnotationSupport() const { return mAnnotationSupport; }
00269 
00273     void setHasNoAnnotationSupport() { mAnnotationSupport = false; }
00274 
00279     bool handleJobError( KIO::Job* job, const QString& context, bool abortSync = false );
00280 
00284     virtual FolderStorage* const rootFolder() const = 0;
00285 
00289     KPIM::ProgressItem* listDirProgressItem();
00290 
00295     virtual unsigned int folderCount() const;
00296 
00300     nsMap namespaces() const { return mNamespaces; }
00301 
00305     virtual void setNamespaces( nsMap map ) 
00306     { mNamespaces = map; }
00307 
00312     nsDelimMap namespacesWithDelimiter();
00313 
00317      QString namespaceForFolder( FolderStorage* );
00318 
00322      QString addPathToNamespace( const QString& ns );
00323 
00327      QString delimiterForNamespace( const QString& prefix );
00328 
00332      QString delimiterForFolder( FolderStorage* );
00333 
00337      namespaceDelim namespaceToDelimiter() const
00338      { return mNamespaceToDelimiter; }
00339 
00343      void setNamespaceToDelimiter( namespaceDelim map )
00344      { mNamespaceToDelimiter = map; } 
00345 
00349      bool isNamespaceFolder( QString& name );
00350 
00354      bool hasCapability( const QString& capa ) {
00355       return mCapabilities.contains( capa ); }
00356 
00362      QString createImapPath( FolderStorage* parent, const QString& folderName );
00363 
00367      QString createImapPath( const QString& parent, const QString& folderName );
00368 
00369 
00370   public slots:
00375     void getNamespaces();
00376 
00377   private slots:
00382     void slotSubscriptionResult(KIO::Job * job);
00383 
00384   protected slots:
00385     virtual void slotCheckQueuedFolders();
00386 
00388     void slotSchedulerSlaveConnected(KIO::Slave *aSlave);
00390     void slotSchedulerSlaveError(KIO::Slave *aSlave, int, const QString &errorMsg);
00391 
00395     void slotSetStatusResult(KIO::Job * job);
00396 
00398     void slotGetUserRightsResult( KIO::Job* _job );
00399 
00401     void slotGetACLResult( KIO::Job* _job );
00402 
00406     void slotNoopTimeout();
00410     void slotIdleTimeout();
00411 
00415     void slotAbortRequested( KPIM::ProgressItem* );
00416 
00420     void slotSimpleResult(KIO::Job * job);
00421 
00423     void slotNamespaceResult( KIO::Job*, const QString& str );
00424 
00428     void slotSaveNamespaces( const ImapAccountBase::nsDelimMap& map );
00429 
00433     void slotCapabilitiesResult( KIO::Job*, const QString& result );
00434 
00435   protected:
00436 
00453     virtual bool handleError( int error, const QString &errorMsg, KIO::Job* job, const QString& context, bool abortSync = false );
00454 
00456     bool handlePutError( KIO::Job* job, jobData& jd, KMFolder* folder );
00457 
00458     virtual QString protocol() const;
00459     virtual unsigned short int defaultPort() const;
00460 
00464     void constructParts( QDataStream & stream, int count, KMMessagePart* parentKMPart,
00465        DwBodyPart * parent, const DwMessage * dwmsg );
00466 
00468     void migratePrefix();
00469 
00470 
00471   protected:
00472     QPtrList<QGuardedPtr<KMFolder> > mOpenFolders;
00473     QStringList mSubfolderNames, mSubfolderPaths,
00474         mSubfolderMimeTypes, mSubfolderAttributes;
00475     QMap<KIO::Job *, jobData> mapJobData;
00477     QTimer mIdleTimer;
00479     QTimer mNoopTimer;
00480     int mTotal, mCountUnread, mCountLastUnread;
00481     QMap<QString, int> mUnreadBeforeCheck;
00482     bool mAutoExpunge : 1;
00483     bool mHiddenFolders : 1;
00484     bool mOnlySubscribedFolders : 1;
00485     bool mLoadOnDemand : 1;
00486     bool mListOnlyOpenFolders : 1;
00487     bool mProgressEnabled : 1;
00488 
00489     bool mErrorDialogIsActive : 1;
00490     bool mPasswordDialogIsActive : 1;
00491     bool mACLSupport : 1;
00492     bool mAnnotationSupport : 1;
00493     bool mSlaveConnected : 1;
00494     bool mSlaveConnectionError : 1;
00495     bool mCheckingSingleFolder : 1;
00496 
00497     // folders that should be checked for new mails
00498     QValueList<QGuardedPtr<KMFolder> > mMailCheckFolders;
00499     // folders that should be checked after the current check is done
00500     QValueList<QGuardedPtr<KMFolder> > mFoldersQueuedForChecking;
00501     // holds messageparts from the bodystructure
00502     QPtrList<KMMessagePart> mBodyPartList;
00503     // the current message for the bodystructure
00504     KMMessage* mCurrentMsg;
00505 
00506     QGuardedPtr<KPIM::ProgressItem> mListDirProgressItem;
00507 
00508     // our namespaces in the form section=namespaceList
00509     nsMap mNamespaces;
00510 
00511     // namespace - delimiter map
00512     namespaceDelim mNamespaceToDelimiter;
00513 
00514     // old prefix for migration
00515     QString mOldPrefix;
00516 
00517     // capabilities
00518     QStringList mCapabilities;
00519 
00520   signals:
00527     void connectionResult( int errorCode, const QString& errorMsg );
00528 
00533     void subscriptionChanged(const QString& imapPath, bool subscribed);
00534 
00540     void imapStatusChanged( KMFolder*, const QString& imapPath, bool cont );
00541 
00547     void receivedUserRights( KMFolder* folder );
00548 
00556     void receivedACL( KMFolder* folder, KIO::Job* job, const KMail::ACLList& entries );
00557 
00561     void namespacesFetched( const ImapAccountBase::nsDelimMap& );
00562 
00566     void namespacesFetched();
00567   };
00568 
00569 
00570 } // namespace KMail
00571 
00572 #endif // __KMAIL_IMAPACCOUNTBASE_H__
KDE Home | KDE Accessibility Home | Description of Access Keys