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 #include "listjob.h"
00048 using KMail::ListJob;
00049 
00050 #include "mimelib/string.h"
00051 
00052 #include <qptrvector.h>
00053 #include <sys/types.h>
00054 #include <stdio.h>
00055 
00056 class KMMessage;
00057 class KMFolderDir;
00058 class KMAcctList;
00059 class KMMsgDict;
00060 class KMMsgDictREntry;
00061 class QTimer;
00062 
00063 namespace KMail {
00064    class AttachmentStrategy;
00065 }
00066 using KMail::AttachmentStrategy;
00067 
00068 typedef QValueList<Q_UINT32> SerNumList;
00069 
00080 class FolderStorage : public QObject
00081 {
00082   Q_OBJECT
00083 
00084 public:
00085 
00086 
00090   FolderStorage( KMFolder* folder, const char* name=0 );
00091   virtual ~FolderStorage();
00092 
00093   KMFolder* folder() const { return mFolder; }
00094 
00095   void setAcctList( KMAcctList* list ) { mAcctList = list; }
00096   KMAcctList* acctList() const { return mAcctList; }
00097 
00099   virtual KMFolderType folderType() const { return KMFolderTypeUnknown; }
00100 
00102   virtual QString fileName() const;
00104   QString location() const;
00105 
00107   virtual QString indexLocation() const = 0;
00108 
00110   virtual bool noContent() const { return mNoContent; }
00111 
00113   virtual void setNoContent(bool aNoContent)
00114     { mNoContent = aNoContent; }
00115 
00117   virtual bool noChildren() const { return mNoChildren; }
00118 
00120   virtual void setNoChildren( bool aNoChildren );
00121 
00122   enum ChildrenState {
00123     HasChildren,
00124     HasNoChildren,
00125     ChildrenUnknown
00126   };
00129   virtual ChildrenState hasChildren() const { return mHasChildren; }
00130 
00132   virtual void setHasChildren( ChildrenState state )
00133     { mHasChildren = state; }
00134 
00136   virtual void updateChildrenState();
00137 
00139   virtual KMMessage* getMsg(int idx);
00140 
00142   virtual KMMsgInfo* unGetMsg(int idx);
00143 
00145   virtual bool isMessage(int idx);
00146 
00151   virtual KMMessage* readTemporaryMsg(int idx);
00152 
00154   virtual QCString& getMsgString(int idx, QCString& mDest) = 0;
00155 
00157   virtual DwString getDwString(int idx) = 0;
00158 
00162   virtual void ignoreJobsForMessage( KMMessage* );
00163 
00168   virtual FolderJob* createJob( KMMessage *msg, FolderJob::JobType jt = FolderJob::tGetMessage,
00169                                 KMFolder *folder = 0, QString partSpecifier = QString::null,
00170                                 const AttachmentStrategy *as = 0 ) const;
00171   virtual FolderJob* createJob( QPtrList<KMMessage>& msgList, const QString& sets,
00172                                 FolderJob::JobType jt = FolderJob::tGetMessage,
00173                                 KMFolder *folder = 0 ) const;
00174 
00179   virtual const KMMsgBase* getMsgBase(int idx) const = 0;
00180   virtual KMMsgBase* getMsgBase(int idx) = 0;
00181 
00183   virtual const KMMsgBase* operator[](int idx) const { return getMsgBase(idx); }
00184 
00186   virtual KMMsgBase* operator[](int idx) { return getMsgBase(idx); }
00187 
00190   virtual KMMessage* take(int idx);
00191   virtual void take(QPtrList<KMMessage> msgList);
00192 
00199   virtual int addMsg(KMMessage* msg, int* index_return = 0) = 0;
00200 
00204   virtual int addMsgKeepUID(KMMessage* msg, int* index_return = 0) {
00205     return addMsg(msg, index_return);
00206   }
00207 
00210   void emitMsgAddedSignals(int idx);
00211 
00214   virtual bool canAddMsgNow(KMMessage* aMsg, int* aIndex_ret);
00215 
00217   virtual void removeMsg(int i, bool imapQuiet = FALSE);
00218   virtual void removeMsg(const QPtrList<KMMsgBase>& msgList, bool imapQuiet = FALSE);
00219   virtual void removeMsg(const QPtrList<KMMessage>& msgList, bool imapQuiet = FALSE);
00220 
00223   virtual int expungeOldMsg(int days);
00224 
00229   virtual int moveMsg(KMMessage* msg, int* index_return = 0);
00230   virtual int moveMsg(QPtrList<KMMessage>, int* index_return = 0);
00231 
00233   virtual int find(const KMMsgBase* msg) const = 0;
00234   int find( const KMMessage * msg ) const;
00235 
00237   virtual int count(bool cache = false) const;
00238 
00240   virtual int countUnread();
00241 
00244   virtual void msgStatusChanged( const KMMsgStatus oldStatus,
00245                                  const KMMsgStatus newStatus,
00246                  int idx);
00247 
00253   virtual int open() = 0;
00254 
00257   virtual int canAccess() = 0;
00258 
00261   virtual void close(bool force=FALSE) = 0;
00262 
00265   virtual void tryReleasingFolder(KMFolder*) {}
00266 
00268   virtual void sync() = 0;
00269 
00271   bool isOpened() const { return (mOpenCount>0); }
00272 
00274   virtual void markNewAsUnread();
00275 
00277   virtual void markUnreadAsRead();
00278 
00282   virtual int create(bool imap = FALSE) = 0;
00283 
00288   virtual void remove();
00289 
00293   virtual int expunge();
00294 
00299   virtual int compact( bool silent ) = 0;
00300 
00303   virtual int rename(const QString& newName, KMFolderDir *aParent = 0);
00304 
00306   bool autoCreateIndex() const { return mAutoCreateIndex; }
00307 
00310   virtual void setAutoCreateIndex(bool);
00311 
00315   bool dirty() const { return mDirty; }
00316 
00318   void setDirty(bool f);
00319 
00321   bool needsCompacting() const { return needsCompact; }
00322   virtual void setNeedsCompacting(bool f) { needsCompact = f; }
00323 
00332   virtual void quiet(bool beQuiet);
00333 
00335   virtual bool isReadOnly() const = 0;
00336 
00338   QString label() const;
00339 
00341   virtual const char* type() const;
00342 
00344   bool hasAccounts() const { return (mAcctList != 0); }
00345 
00347   virtual void correctUnreadMsgsCount();
00348 
00351   virtual int writeIndex( bool createEmptyIndex = false ) = 0;
00352 
00355   void fillMsgDict(KMMsgDict *dict);
00356 
00358   int writeMsgDict(KMMsgDict *dict = 0);
00359 
00361   int touchMsgDict();
00362 
00364   int appendtoMsgDict(int idx = -1);
00365 
00367   void setRDict(KMMsgDictREntry *rentry);
00368 
00370   KMMsgDictREntry *rDict() const { return mRDict; }
00371 
00373   virtual void setStatus(int idx, KMMsgStatus status, bool toggle=false);
00374 
00376   virtual void setStatus(QValueList<int>& ids, KMMsgStatus status, bool toggle=false);
00377 
00378   void removeJobs();
00379 
00383   static size_t crlf2lf( char* str, const size_t strLen );
00384 
00386   static QString dotEscape(const QString&);
00387 
00389   virtual void readConfig();
00390 
00392   virtual void writeConfig();
00393 
00398   virtual KMFolder* trashFolder() const { return 0; }
00399 
00404   void addJob( FolderJob* ) const;
00405 
00407   bool compactable() const { return mCompactable; }
00408 
00410   virtual void setContentsType( KMail::FolderContentsType type );
00412   KMail::FolderContentsType contentsType() const { return mContentsType; }
00413 
00414 signals:
00417   void changed();
00418 
00421   void cleared();
00422 
00425   void expunged( KMFolder* );
00426 
00428   void nameChanged();
00429 
00431   void readOnlyChanged(KMFolder*);
00432 
00434   void msgRemoved(KMFolder*, Q_UINT32 sernum);
00435 
00437   void msgRemoved(int idx,QString msgIdMD5, QString strippedSubjMD5);
00438   void msgRemoved(KMFolder*);
00439 
00441   void msgAdded(int idx);
00442   void msgAdded(KMFolder*, Q_UINT32 sernum);
00443 
00445   void msgChanged(KMFolder*, Q_UINT32 sernum, int delta);
00446 
00448   void msgHeaderChanged(KMFolder*, int);
00449 
00451   void statusMsg(const QString&);
00452 
00454   void numUnreadMsgsChanged( KMFolder* );
00455 
00457   void removed(KMFolder*, bool);
00458 
00459 public slots:
00461   virtual int updateIndex() = 0;
00462 
00465   virtual void reallyAddMsg(KMMessage* aMsg);
00466 
00469   virtual void reallyAddCopyOfMsg(KMMessage* aMsg);
00470 
00471 protected slots:
00472   virtual void removeJob( QObject* );
00473 
00474 protected:
00480   virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00481                                   QString partSpecifier, const AttachmentStrategy *as ) const = 0;
00482   virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00483                                   FolderJob::JobType jt, KMFolder *folder ) const = 0;
00484 
00488   void headerOfMsgChanged(const KMMsgBase*, int idx);
00489 
00492   virtual KMMessage* readMsg(int idx) = 0;
00493 
00495   virtual bool readIndex() = 0;
00496 
00500   virtual int removeContents() = 0;
00501 
00505   virtual int expungeContents() = 0;
00506 
00507   virtual KMMsgBase* takeIndexEntry( int idx ) = 0;
00508   virtual KMMsgInfo* setIndexEntry( int idx, KMMessage *msg ) = 0;
00509   virtual void clearIndex(bool autoDelete=true, bool syncDict = false) = 0;
00510   virtual void fillDictFromIndex(KMMsgDict *dict) = 0;
00511   virtual void truncateIndex() = 0;
00512 
00513   int mOpenCount;
00514   int mQuiet;
00515   bool mChanged;
00517   bool mAutoCreateIndex;
00519   bool mDirty;
00521   bool mFilesLocked;
00522   KMAcctList* mAcctList;
00523 
00525   int mUnreadMsgs, mGuessedUnreadMsgs;
00526   int mTotalMsgs;
00527   bool mWriteConfigEnabled;
00529   bool needsCompact;
00531   bool mCompactable;
00532   bool mNoContent;
00533   bool mNoChildren;
00534   bool mConvertToUtf8;
00535 
00537   KMMsgDictREntry *mRDict;
00539   mutable QPtrList<FolderJob> mJobList;
00540 
00541   QTimer *mDirtyTimer;
00542   enum { mDirtyTimerInterval = 600000 }; // 10 minutes
00543 
00544   ChildrenState mHasChildren;
00545 
00547   KMail::FolderContentsType mContentsType;
00548 
00549   KMFolder* mFolder;
00550 };
00551 
00552 #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 Wed Mar 23 22:43:41 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003