kmail

kmfolderimap.h

00001 /*
00002  * kmfolderimap.h
00003  *
00004  * Copyright (c) 2001 Kurt Granroth <granroth@kde.org>
00005  * Copyright (c) 2000-2002 Michael Haeckel <haeckel@kde.org>
00006  *
00007  * This file is based on kmacctimap.h by Michael Haeckel which is
00008  * based on popaccount.h by Don Sanders
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 kmfolderimap_h
00025 #define kmfolderimap_h
00026 
00027 #include "kmacctimap.h"
00028 #include "kmfoldermbox.h"
00029 #include "kmmsgbase.h"
00030 
00031 #include "kio/job.h"
00032 #include "kio/global.h"
00033 
00034 #include <kstandarddirs.h>
00035 
00036 #include <qintdict.h>
00037 #include <qdict.h>
00038 template< typename T> class QPtrList;
00039 template< typename T> class QValueList;
00040 
00041 class KMFolderTreeItem;
00042 class KMFolderImap;
00043 class KMSearchPattern;
00044 class KMMessage;
00045 namespace KMail {
00046   class FolderJob;
00047   class ImapJob;
00048   class AttachmentStrategy;
00049   class ImapAccountBase;
00050 }
00051 namespace KPIM {
00052   class ProgressItem;
00053 }
00054 using KMail::FolderJob;
00055 using KMail::ImapJob;
00056 using KMail::AttachmentStrategy;
00057 using KMail::ImapAccountBase;
00058 using KPIM::ProgressItem;
00059 
00060 class KMMsgMetaData
00061 {
00062 public:
00063   KMMsgMetaData(KMMsgStatus aStatus)
00064     :mStatus(aStatus), mSerNum(0) {}
00065   KMMsgMetaData(KMMsgStatus aStatus, Q_UINT32 aSerNum)
00066     :mStatus(aStatus), mSerNum(aSerNum) {}
00067   ~KMMsgMetaData() {};
00068   const KMMsgStatus status() const { return mStatus; }
00069   const Q_UINT32 serNum() const { return mSerNum; }
00070 private:
00071   KMMsgStatus mStatus;
00072   Q_UINT32 mSerNum;
00073 };
00074 
00075 
00076 
00077 class KMFolderImap : public KMFolderMbox
00078 {
00079   Q_OBJECT
00080   friend class ::KMail::ImapJob;
00081 public:
00082 
00083   static QString cacheLocation() {
00084      return locateLocal("data", "kmail/imap" );
00085   }
00086 
00087   enum imapState {
00088     imapNoInformation = 0,
00089     imapListingInProgress = 1,
00090     imapDownloadInProgress = 2,
00091     imapFinished = 3
00092   };
00093 
00094   virtual imapState getContentState() { return mContentState; }
00095   virtual void setContentState(imapState state) { mContentState = state; }
00096 
00097   virtual imapState getSubfolderState() { return mSubfolderState; }
00098   virtual void setSubfolderState(imapState state);
00099 
00103   KMFolderImap(KMFolder* folder, const char* name=0);
00104   virtual ~KMFolderImap();
00105 
00107   virtual KMFolderType folderType() const { return KMFolderTypeImap; }
00108 
00109   virtual KMMessage* getMsg(int idx);
00111   void setImapPath( const QString &path );
00112   QString imapPath() const { return mImapPath; }
00113 
00115   ulong lastUid();
00116 
00118   void setUidValidity(const QString &validity) { mUidValidity = validity; }
00119   QString uidValidity() { return mUidValidity; }
00120 
00122   void setAccount(KMAcctImap *acct);
00123   KMAcctImap* account() const;
00124 
00126   virtual void removeMsg(int i, bool quiet = FALSE);
00127   virtual void removeMsg(const QPtrList<KMMessage>& msgList, bool quiet = FALSE);
00128 
00129   virtual int rename( const QString& newName, KMFolderDir *aParent = 0 );
00130 
00132   virtual void remove();
00133 
00135   virtual void reallyDoClose(const char *owner);
00136 
00138   bool autoExpunge();
00139 
00141   virtual void writeConfig();
00142 
00144   virtual void readConfig();
00145 
00151   virtual bool listDirectory();
00152 
00156   void getFolder(bool force = FALSE);
00157 
00161   void getAndCheckFolder(bool force = FALSE);
00162 
00166   void getMessage(KMFolder * folder, KMMessage * msg);
00167 
00175   void createFolder(const QString &name,
00176       const QString& imapPath = QString::null, bool askUser = true);
00177 
00181   void deleteMessage(KMMessage * msg);
00182   void deleteMessage(const QPtrList<KMMessage>& msgList);
00183 
00188   virtual void setStatus(int idx, KMMsgStatus status, bool toggle);
00189 
00193   virtual void setStatus(QValueList<int>& _ids, KMMsgStatus status, bool toggle);
00194 
00196   static QStringList makeSets( QValueList<ulong>&, bool sort = true);
00197   static QStringList makeSets(const QStringList&, bool sort = true);
00198 
00200   static QPtrList<KMMessage> splitMessageList(const QString& set,
00201                                               QPtrList<KMMessage>& msgList);
00202 
00204   void getUids(QValueList<int>& ids, QValueList<ulong>& uids);
00205 
00207   void getUids(const QPtrList<KMMessage>& msgList, QValueList<ulong>& uids);
00208 
00212   void expungeFolder(KMFolderImap * aFolder, bool quiet);
00213 
00214   virtual int compact( bool ) { expungeFolder(this, false); return 0; };
00215 
00219   void sendFolderComplete(bool success)
00220   { emit folderComplete(this, success); }
00221 
00226   bool processNewMail(bool interactive);
00227 
00232   void setSelected(bool selected) { mIsSelected = selected; }
00233   bool isSelected() { return mIsSelected; }
00234 
00238   static QString encodeFileName(const QString &);
00239   static QString decodeFileName(const QString &);
00240   static QTextCodec * utf7Codec();
00241 
00245   static QString statusToFlags(KMMsgStatus status);
00246 
00250   virtual QString fileName() const {
00251     return encodeFileName( KMFolderMbox::fileName() ); }
00252 
00256    const ulong serNumForUID( ulong uid );
00257 
00262   void saveMsgMetaData( KMMessage* msg, ulong uid = 0 );
00263 
00267   static QValueList<ulong> splitSets(const QString);
00268 
00269   virtual void ignoreJobsForMessage( KMMessage* );
00270 
00274   bool includeInMailCheck() { return mCheckMail; }
00275   void setIncludeInMailCheck( bool check );
00276 
00278   virtual int create();
00279 
00281   virtual bool isAutoExpire() const { return false; }
00282 
00283   void setCheckingValidity( bool val ) { mCheckingValidity = val; }
00284 
00286   KMFolder* trashFolder() const;
00287 
00293   void setAlreadyRemoved(bool removed);
00294 
00296   bool isReadOnly() const { return KMFolderMbox::isReadOnly() || mReadOnly; }
00297 
00302   unsigned int userRights() const { return mUserRights; }
00303 
00305   void setUserRights( unsigned int userRights );
00306 
00312   virtual void search( const KMSearchPattern* );
00313   virtual void search( const KMSearchPattern*, Q_UINT32 serNum );
00314 
00316   virtual bool isMoveable() const;
00317 
00319   void initializeFrom( KMFolderImap* parent, QString path, QString mimeType );
00320 
00321 signals:
00322   void folderComplete(KMFolderImap *folder, bool success);
00323 
00327   void deleted(KMFolderImap*);
00328 
00332   void directoryListingFinished(KMFolderImap*);
00333 
00339   void folderCreationResult( const QString &name, bool success );
00340 
00341 public slots:
00343   virtual void addMsgQuiet(KMMessage *);
00344   virtual void addMsgQuiet(QPtrList<KMMessage>);
00345 
00352   virtual int addMsg(KMMessage* msg, int* index_return = 0);
00353   virtual int addMsg(QPtrList<KMMessage>&, QValueList<int>& index_return);
00354 
00356   void copyMsg(QPtrList<KMMessage>& msgList/*, KMFolder* parent*/);
00357 
00358 
00361   virtual KMMessage* take(int idx);
00362   virtual void take(QPtrList<KMMessage>);
00363 
00367   void slotSimpleData(KIO::Job * job, const QByteArray & data);
00368 
00373   static void flagsToStatus(KMMsgBase *msg, int flags, bool newMsg = TRUE);
00374 
00379   static void seenFlagToStatus( KMMsgBase *msg, int flags, bool newMsg = true );
00380 
00384   void slotCopyMsgResult( KMail::FolderJob* job );
00385 
00389   void slotSearchDone( QValueList<Q_UINT32> serNums,
00390                        const KMSearchPattern* pattern,
00391                        bool complete );
00392 
00396   void slotSearchDone( Q_UINT32 serNum, const KMSearchPattern* pattern, bool matches );
00397 
00402   void slotListResult( const QStringList&, const QStringList&,
00403       const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00404 
00409   void slotCheckNamespace( const QStringList&, const QStringList&,
00410       const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00411 
00412 protected:
00413   virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt,
00414                                   KMFolder *folder, QString partSpecifier,
00415                                   const AttachmentStrategy *as ) const;
00416   virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00417                                   FolderJob::JobType jt, KMFolder *folder ) const;
00418 
00419   void getMessagesResult(KIO::Job * job, bool lastSet);
00420 
00424   virtual int expungeContents();
00425 
00426   void setChildrenState( QString attributes );
00427 
00429   void initInbox();
00430 
00432   KMFolderImap* findParent( const QString& path, const QString& name );
00433 
00435   void checkFolders( const QStringList& folderNames, const QString& ns );
00436 
00437   void finishMailCheck( const char *func, imapState state );
00438 
00439 protected slots:
00440 
00444   void checkValidity();
00445   void slotCheckValidityResult(KIO::Job * job);
00446 
00450   void reallyGetFolder(const QString &startUid = QString::null);
00451 
00455   void slotListFolderResult(KIO::Job * job);
00456   void slotListFolderEntries(KIO::Job * job, const KIO::UDSEntryList & uds);
00457 
00461   void slotGetMessagesResult(KIO::Job * job);
00462   void slotGetLastMessagesResult(KIO::Job * job);
00463   void slotGetMessagesData(KIO::Job * job, const QByteArray & data);
00464 
00468   void slotCreateFolderResult(KIO::Job * job);
00469 
00473   void slotRemoveFolderResult(KIO::Job *job);
00474 
00478   void slotStatResult(KIO::Job *job);
00479 
00484   void slotCompleteMailCheckProgress();
00485 
00489   void slotProcessNewMail( int errorCode, const QString& errorMsg );
00490 
00496   void slotCreatePendingFolders( int errorCode, const QString& errorMsg );
00497 
00501   void slotListNamespaces();
00502 
00503 protected:
00504   QString     mImapPath;
00505   ulong       mLastUid;
00506   imapState   mContentState, mSubfolderState;
00507   bool        mIsSelected;
00508   bool        mCheckFlags;
00509   bool        mReadOnly;
00510   bool        mCheckMail;
00511   mutable QGuardedPtr<KMAcctImap> mAccount;
00512   // the current uidvalidity
00513   QString mUidValidity;
00514   unsigned int mUserRights;
00515 
00516 private:
00517   // if we're checking validity currently
00518   bool        mCheckingValidity;
00519   // uid - metadata cache
00520   QIntDict<KMMsgMetaData> mUidMetaDataMap;
00521   // msgidMD5 - status map
00522   QDict<KMMsgMetaData> mMetaDataMap;
00523   // if the folder should be deleted without server roundtrip
00524   bool        mAlreadyRemoved;
00525   // the progress for mailchecks
00526   QGuardedPtr<ProgressItem> mMailCheckProgressItem;
00527   // the progress for listings
00528   ProgressItem *mListDirProgressItem;
00529   // the progress for addMsg
00530   ProgressItem *mAddMessageProgressItem;
00531   // to-be-added folders
00532   QStringList mFoldersPendingCreation;
00533 
00534   // push all flags to the server instead of just the changed once
00535   // when doing a flag change the next time
00536   // this is needed for migrating local flags from the time where we didn't
00537   // have the ability to store them on the server
00538   bool mUploadAllFlags;
00539 };
00540 
00541 #endif // kmfolderimap_h
KDE Home | KDE Accessibility Home | Description of Access Keys