kmail Library API Documentation

folderstorage.h

00001 /*
00002     Virtual base class for mail storage.
00003 
00004     This file is part of KMail.
00005 
00006     Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
00007 
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Library General Public
00010     License as published by the Free Software Foundation; either
00011     version 2 of the License, or (at your option) any later version.
00012 
00013     This library is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016     Library General Public License for more details.
00017 
00018     You should have received a copy of the GNU Library General Public License
00019     along with this library; see the file COPYING.LIB.  If not, write to
00020     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00021     Boston, MA 02111-1307, USA.
00022 
00023     In addition, as a special exception, the copyright holders give
00024     permission to link the code of this program with any edition of
00025     the Qt library by Trolltech AS, Norway (or with modified versions
00026     of Qt that use the same license as Qt), and distribute linked
00027     combinations including the two.  You must obey the GNU General
00028     Public License in all respects for all of the code used other than
00029     Qt.  If you modify this file, you may extend this exception to
00030     your version of the file, but you are not obligated to do so.  If
00031     you do not wish to do so, delete this exception statement from
00032     your version.
00033 */
00034 
00035 #ifndef FOLDERSTORAGE_H
00036 #define FOLDERSTORAGE_H
00037 
00038 // for large file support
00039 #include <config.h>
00040 
00041 #include "kmfoldernode.h"
00042 #include "kmfoldertype.h"
00043 #include "kmmsginfo.h"
00044 #include "kmglobal.h"
00045 #include "folderjob.h"
00046 using KMail::FolderJob;
00047 
00048 #include "mimelib/string.h"
00049 
00050 #include <qptrvector.h>
00051 #include <sys/types.h>
00052 #include <stdio.h>
00053 
00054 class KMMessage;
00055 class KMFolderDir;
00056 class KMAcctList;
00057 class KMMsgDict;
00058 class KMMsgDictREntry;
00059 class QTimer;
00060 
00061 namespace KMail {
00062    class AttachmentStrategy;
00063 }
00064 using KMail::AttachmentStrategy;
00065 
00066 typedef QValueList<Q_UINT32> SerNumList;
00067 
00078 class FolderStorage : public QObject
00079 {
00080   Q_OBJECT
00081 
00082 public:
00083 
00084 
00088   FolderStorage( KMFolder* folder, const char* name=0 );
00089   virtual ~FolderStorage();
00090 
00091   KMFolder* folder() const { return mFolder; }
00092 
00093   void setAcctList( KMAcctList* list ) { mAcctList = list; }
00094   KMAcctList* acctList() const { return mAcctList; }
00095 
00097   virtual KMFolderType folderType() const { return KMFolderTypeUnknown; }
00098 
00100   virtual QString fileName() const;
00102   QString location() const;
00103 
00105   virtual QString indexLocation() const = 0;
00106 
00108   virtual bool noContent() const { return mNoContent; }
00109 
00111   virtual void setNoContent(bool aNoContent)
00112     { mNoContent = aNoContent; }
00113 
00115   virtual bool noChildren() const { return mNoChildren; }
00116 
00118   virtual void setNoChildren( bool aNoChildren );
00119 
00120   enum ChildrenState {
00121     HasChildren,
00122     HasNoChildren,
00123     ChildrenUnknown
00124   };
00127   virtual ChildrenState hasChildren() const { return mHasChildren; }
00128 
00130   virtual void setHasChildren( ChildrenState state )
00131     { mHasChildren = state; }
00132 
00134   virtual void updateChildrenState();
00135 
00137   virtual KMMessage* getMsg(int idx);
00138 
00140   virtual KMMsgInfo* unGetMsg(int idx);
00141 
00143   virtual bool isMessage(int idx);
00144 
00149   virtual KMMessage* readTemporaryMsg(int idx);
00150 
00152   virtual QCString& getMsgString(int idx, QCString& mDest) = 0;
00153 
00155   virtual DwString getDwString(int idx) = 0;
00156 
00160   virtual void ignoreJobsForMessage( KMMessage* );
00161 
00166   virtual FolderJob* createJob( KMMessage *msg, FolderJob::JobType jt = FolderJob::tGetMessage,
00167                                 KMFolder *folder = 0, QString partSpecifier = QString::null,
00168                                 const AttachmentStrategy *as = 0 ) const;
00169   virtual FolderJob* createJob( QPtrList<KMMessage>& msgList, const QString& sets,
00170                                 FolderJob::JobType jt = FolderJob::tGetMessage,
00171                                 KMFolder *folder = 0 ) const;
00172 
00177   virtual const KMMsgBase* getMsgBase(int idx) const = 0;
00178   virtual KMMsgBase* getMsgBase(int idx) = 0;
00179 
00181   virtual const KMMsgBase* operator[](int idx) const { return getMsgBase(idx); }
00182 
00184   virtual KMMsgBase* operator[](int idx) { return getMsgBase(idx); }
00185 
00188   virtual KMMessage* take(int idx);
00189   virtual void take(QPtrList<KMMessage> msgList);
00190 
00197   virtual int addMsg(KMMessage* msg, int* index_return = 0) = 0;
00198 
00202   virtual int addMsgKeepUID(KMMessage* msg, int* index_return = 0) {
00203     return addMsg(msg, index_return);
00204   }
00205 
00208   void emitMsgAddedSignals(int idx);
00209 
00212   virtual bool canAddMsgNow(KMMessage* aMsg, int* aIndex_ret);
00213 
00215   virtual void removeMsg(int i, bool imapQuiet = FALSE);
00216   virtual void removeMsg(const QPtrList<KMMsgBase>& msgList, bool imapQuiet = FALSE);
00217   virtual void removeMsg(const QPtrList<KMMessage>& msgList, bool imapQuiet = FALSE);
00218 
00221   virtual int expungeOldMsg(int days);
00222 
00227   virtual int moveMsg(KMMessage* msg, int* index_return = 0);
00228   virtual int moveMsg(QPtrList<KMMessage>, int* index_return = 0);
00229 
00231   virtual int find(const KMMsgBase* msg) const = 0;
00232   int find( const KMMessage * msg ) const;
00233 
00235   virtual int count(bool cache = false) const;
00236 
00238   virtual int countUnread();
00239 
00242   virtual void msgStatusChanged( const KMMsgStatus oldStatus,
00243                                  const KMMsgStatus newStatus,
00244                  int idx);
00245 
00251   virtual int open() = 0;
00252 
00255   virtual int canAccess() = 0;
00256 
00259   virtual void close(bool force=FALSE) = 0;
00260 
00263   virtual void tryReleasingFolder(KMFolder*) {}
00264 
00266   virtual void sync() = 0;
00267 
00269   bool isOpened() const { return (mOpenCount>0); }
00270 
00272   virtual void markNewAsUnread();
00273 
00275   virtual void markUnreadAsRead();
00276 
00280   virtual int create(bool imap = FALSE) = 0;
00281 
00286   virtual void remove();
00287 
00291   virtual int expunge();
00292 
00297   virtual int compact( bool silent ) = 0;
00298 
00301   virtual int rename(const QString& newName, KMFolderDir *aParent = 0);
00302 
00304   bool autoCreateIndex() const { return mAutoCreateIndex; }
00305 
00308   virtual void setAutoCreateIndex(bool);
00309 
00313   bool dirty() const { return mDirty; }
00314 
00316   void setDirty(bool f);
00317 
00319   bool needsCompacting() const { return needsCompact; }
00320   virtual void setNeedsCompacting(bool f) { needsCompact = f; }
00321 
00330   virtual void quiet(bool beQuiet);
00331 
00333   virtual bool isReadOnly() const = 0;
00334 
00336   QString label() const;
00337 
00339   virtual const char* type() const;
00340 
00342   bool hasAccounts() const { return (mAcctList != 0); }
00343 
00345   virtual void correctUnreadMsgsCount();
00346 
00349   virtual int writeIndex( bool createEmptyIndex = false ) = 0;
00350 
00353   void fillMsgDict(KMMsgDict *dict);
00354 
00356   int writeMsgDict(KMMsgDict *dict = 0);
00357 
00359   int touchMsgDict();
00360 
00362   int appendtoMsgDict(int idx = -1);
00363 
00365   void setRDict(KMMsgDictREntry *rentry);
00366 
00368   KMMsgDictREntry *rDict() const { return mRDict; }
00369 
00371   virtual void setStatus(int idx, KMMsgStatus status, bool toggle=false);
00372 
00374   virtual void setStatus(QValueList<int>& ids, KMMsgStatus status, bool toggle=false);
00375 
00376   void removeJobs();
00377 
00381   static size_t crlf2lf( char* str, const size_t strLen );
00382 
00384   static QString dotEscape(const QString&);
00385 
00387   virtual void readConfig();
00388 
00390   virtual void writeConfig();
00391 
00396   virtual KMFolder* trashFolder() const { return 0; }
00397 
00402   void addJob( FolderJob* ) const;
00403 
00405   bool compactable() const { return mCompactable; }
00406 
00408   // If quiet is true, the KMailIcalIface is not informed of the changed. That's usefull
00409   // for folder that are being copied around, should retain their type, but not cause
00410   // conflicts on copy because events are identical in two folders.
00411   virtual void setContentsType( KMail::FolderContentsType type, bool quiet = false );
00413   KMail::FolderContentsType contentsType() const { return mContentsType; }
00414 
00415 signals:
00418   void changed();
00419 
00422   void cleared();
00423 
00426   void expunged( KMFolder* );
00427 
00429   void nameChanged();
00430 
00434   void locationChanged( const QString &, const QString & );
00435 
00438   void contentsTypeChanged( KMail::FolderContentsType type );
00439 
00441   void readOnlyChanged(KMFolder*);
00442 
00444   void msgRemoved(KMFolder*, Q_UINT32 sernum);
00445 
00447   void msgRemoved(int idx,QString msgIdMD5, QString strippedSubjMD5);
00448   void msgRemoved(KMFolder*);
00449 
00451   void msgAdded(int idx);
00452   void msgAdded(KMFolder*, Q_UINT32 sernum);
00453 
00455   void msgChanged(KMFolder*, Q_UINT32 sernum, int delta);
00456 
00458   void msgHeaderChanged(KMFolder*, int);
00459 
00461   void statusMsg(const QString&);
00462 
00464   void numUnreadMsgsChanged( KMFolder* );
00465 
00467   void removed(KMFolder*, bool);
00468 
00469 public slots:
00471   virtual int updateIndex() = 0;
00472 
00475   virtual void reallyAddMsg(KMMessage* aMsg);
00476 
00479   virtual void reallyAddCopyOfMsg(KMMessage* aMsg);
00480 
00481 protected slots:
00482   virtual void removeJob( QObject* );
00483 
00484 protected:
00490   virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00491                                   QString partSpecifier, const AttachmentStrategy *as ) const = 0;
00492   virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00493                                   FolderJob::JobType jt, KMFolder *folder ) const = 0;
00494 
00498   void headerOfMsgChanged(const KMMsgBase*, int idx);
00499 
00502   virtual KMMessage* readMsg(int idx) = 0;
00503 
00505   virtual bool readIndex() = 0;
00506 
00510   virtual int removeContents() = 0;
00511 
00515   virtual int expungeContents() = 0;
00516 
00517   virtual KMMsgBase* takeIndexEntry( int idx ) = 0;
00518   virtual KMMsgInfo* setIndexEntry( int idx, KMMessage *msg ) = 0;
00519   virtual void clearIndex(bool autoDelete=true, bool syncDict = false) = 0;
00520   virtual void fillDictFromIndex(KMMsgDict *dict) = 0;
00521   virtual void truncateIndex() = 0;
00522 
00523   int mOpenCount;
00524   int mQuiet;
00525   bool mChanged;
00527   bool mAutoCreateIndex;
00529   bool mDirty;
00531   bool mFilesLocked;
00532   KMAcctList* mAcctList;
00533 
00535   int mUnreadMsgs, mGuessedUnreadMsgs;
00536   int mTotalMsgs;
00537   bool mWriteConfigEnabled;
00539   bool needsCompact;
00541   bool mCompactable;
00542   bool mNoContent;
00543   bool mNoChildren;
00544   bool mConvertToUtf8;
00545 
00547   KMMsgDictREntry *mRDict;
00549   mutable QPtrList<FolderJob> mJobList;
00550 
00551   QTimer *mDirtyTimer;
00552   enum { mDirtyTimerInterval = 600000 }; // 10 minutes
00553 
00554   ChildrenState mHasChildren;
00555 
00557   KMail::FolderContentsType mContentsType;
00558 
00559   KMFolder* mFolder;
00560 };
00561 
00562 #endif // FOLDERSTORAGE_H
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Aug 23 18:21:11 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003