kmail

kmfolder.h

Go to the documentation of this file.
00001 /* -*- mode: C++ -*-
00002  * kmail: KDE mail client
00003  * Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  *
00019  */
00020 #ifndef kmfolder_h
00021 #define kmfolder_h
00022 
00023 // for large file support
00024 #include <config.h>
00025 
00026 #include "kmfoldernode.h"
00027 #include "kmfoldertype.h"
00028 #include "kmmsginfo.h"
00029 #include "kmglobal.h"
00030 #include "kmkernel.h"
00031 #include "folderjob.h"
00032 using KMail::FolderJob;
00033 #include "mailinglist-magic.h"
00034 using KMail::MailingList;
00035 #include "kmaccount.h" // for AccountList
00036 
00037 #include "mimelib/string.h"
00038 
00039 #include <qptrvector.h>
00040 #include <sys/types.h>
00041 #include <stdio.h>
00042 #include <kshortcut.h>
00043 
00044 class KMMessage;
00045 class KMFolderDir;
00046 class QTimer;
00047 class FolderStorage;
00048 class KMFolderTreeItem;
00049 class KMFolderJob;
00050 
00051 namespace KMail {
00052    class AttachmentStrategy;
00053 }
00054 using KMail::AttachmentStrategy;
00055 
00056 typedef QValueList<Q_UINT32> SerNumList;
00057 
00068 class KMFolder: public KMFolderNode
00069 {
00070   Q_OBJECT
00071   friend class ::KMFolderJob;
00072 public:
00073 
00089   KMFolder( KMFolderDir* parent, const QString& name,
00090                 KMFolderType aFolderType, bool withIndex = true,
00091                 bool exportedSernums = true );
00092   ~KMFolder();
00093 
00095   bool isMainInbox() {
00096     return this == KMKernel::self()->inboxFolder();
00097   }
00099   bool isOutbox() {
00100     return this == KMKernel::self()->outboxFolder();
00101   }
00104   bool isSent() {
00105     return KMKernel::self()->folderIsSentMailFolder( this );
00106   }
00109   bool isTrash() {
00110     return KMKernel::self()->folderIsTrash( this );
00111   }
00114   bool isDrafts() {
00115     return KMKernel::self()->folderIsDrafts( this );
00116   }
00119   bool isTemplates() {
00120     return KMKernel::self()->folderIsTemplates( this );
00121   }
00122 
00123   void setAcctList( AccountList* list ) { mAcctList = list; }
00124   AccountList* acctList() { return mAcctList; }
00125 
00127   bool hasAccounts() const { return (mAcctList != 0); }
00128 
00130   void readConfig( KConfig* config );
00131 
00133   void writeConfig( KConfig* config ) const;
00134 
00135   FolderStorage* storage() { return mStorage; }
00137   const FolderStorage* storage() const { return mStorage; }
00138 
00140   KMFolderType folderType() const;
00141 
00143   QString fileName() const;
00144 
00146   QString location() const;
00147 
00149   QString indexLocation() const;
00150 
00152   QString subdirLocation() const;
00153 
00156   KMFolderDir* child() const
00157     { return mChild; }
00158 
00160   KMFolderDir* createChildFolder();
00161 
00163   void setChild( KMFolderDir* aChild );
00164 
00166   bool noContent() const;
00167 
00169   void setNoContent(bool aNoContent);
00170 
00172   bool noChildren() const;
00173 
00175   void setNoChildren(bool aNoChildren);
00176 
00178   KMMessage* getMsg(int idx);
00179 
00181   KMMsgInfo* unGetMsg(int idx);
00182 
00184   bool isMessage(int idx);
00185 
00187   DwString getDwString(int idx);
00188 
00192   void ignoreJobsForMessage( KMMessage* );
00193 
00198   FolderJob* createJob( KMMessage *msg, FolderJob::JobType jt = FolderJob::tGetMessage,
00199                         KMFolder *folder = 0, QString partSpecifier = QString::null,
00200                         const AttachmentStrategy *as = 0 ) const;
00201   FolderJob* createJob( QPtrList<KMMessage>& msgList, const QString& sets,
00202                         FolderJob::JobType jt = FolderJob::tGetMessage,
00203                         KMFolder *folder = 0 ) const;
00204 
00209   const KMMsgBase* getMsgBase(int idx) const;
00210   KMMsgBase* getMsgBase(int idx);
00211 
00213   const KMMsgBase* operator[](int idx) const;
00214 
00216   KMMsgBase* operator[](int idx);
00217 
00220   KMMessage* take(int idx);
00221   void take(QPtrList<KMMessage> msgList);
00222 
00229   int addMsg(KMMessage* msg, int* index_return = 0);
00230 
00234   int addMsgKeepUID(KMMessage* msg, int* index_return = 0);
00235 
00240   int addMsg(QPtrList<KMMessage>&, QValueList<int>& index_return);
00241 
00244   void emitMsgAddedSignals(int idx);
00245 
00247   void removeMsg(int i, bool imapQuiet = false);
00248   void removeMsg(QPtrList<KMMessage> msgList, bool imapQuiet = false);
00249 
00252   int expungeOldMsg(int days);
00253 
00258   int moveMsg(KMMessage* msg, int* index_return = 0);
00259   int moveMsg(QPtrList<KMMessage>, int* index_return = 0);
00260 
00262   int find(const KMMsgBase* msg) const;
00263   int find( const KMMessage * msg ) const;
00264 
00266   int count(bool cache = false) const;
00267 
00269   int countUnread();
00270 
00273   int countUnreadRecursive();
00274 
00277   void msgStatusChanged( const KMMsgStatus oldStatus,
00278                          const KMMsgStatus newStatus,
00279                          int idx);
00280 
00286   int open(const char *owner);
00287 
00290   int canAccess();
00291 
00294   void close(const char *owner, bool force=false);
00295 
00297   void sync();
00298 
00300   bool isOpened() const;
00301 
00303   void markNewAsUnread();
00304 
00306   void markUnreadAsRead();
00307 
00312   void remove();
00313 
00317   int expunge();
00318 
00319   enum CompactOptions { CompactLater, CompactNow, CompactSilentlyNow };
00326   void compact( CompactOptions options );
00327 
00330   int rename(const QString& newName, KMFolderDir *aParent = 0);
00331 
00335   bool dirty() const;
00336 
00338   void setDirty(bool f);
00339 
00341   bool needsCompacting() const;
00342   void setNeedsCompacting(bool f);
00343 
00352   void quiet(bool beQuiet);
00353 
00355   bool isReadOnly() const;
00356 
00361   bool isSystemFolder() const { return mIsSystemFolder; }
00362   void setSystemFolder(bool itIs) { mIsSystemFolder=itIs; }
00363 
00365   virtual QString label() const;
00366   void setLabel( const QString& l ) { mLabel = l; }
00367 
00369   virtual QString systemLabel() const { return mSystemLabel; }
00370   void setSystemLabel( const QString& l ) { mSystemLabel = l; }
00371 
00373   virtual QString prettyURL() const;
00374 
00376   void setMailingListEnabled( bool enabled );
00377   bool isMailingListEnabled() const { return mMailingListEnabled; }
00378 
00379   void setMailingList( const MailingList& mlist );
00380   MailingList mailingList() const
00381   { return mMailingList; }
00382   QString mailingListPostAddress() const;
00383 
00384   void setIdentity(uint identity);
00385   uint identity() const;
00386 
00388   QString whoField() const { return mWhoField; }
00389   void setWhoField(const QString& aWhoField);
00390 
00392   QString userWhoField(void) { return mUserWhoField; }
00393   void setUserWhoField(const QString &whoField,bool writeConfig=true);
00394 
00396   void correctUnreadMsgsCount();
00397 
00399   QString idString() const;
00400 
00404   void setAutoExpire(bool enabled);
00405 
00409   bool isAutoExpire() const { return mExpireMessages; }
00410 
00416   void setUnreadExpireAge(int age);
00417 
00422   void setUnreadExpireUnits(ExpireUnits units);
00423 
00429   void setReadExpireAge(int age);
00430 
00435   void setReadExpireUnits(ExpireUnits units);
00436 
00441   int getUnreadExpireAge() const { return mUnreadExpireAge; }
00442 
00447   int getReadExpireAge() const { return mReadExpireAge; }
00448 
00453   ExpireUnits getUnreadExpireUnits() const { return mUnreadExpireUnits; }
00454 
00459   ExpireUnits getReadExpireUnits() const { return mReadExpireUnits; }
00460 
00461   enum ExpireAction { ExpireDelete, ExpireMove };
00465   ExpireAction expireAction() const { return mExpireAction; }
00466   void setExpireAction( ExpireAction a );
00467 
00471   QString expireToFolderId() const { return mExpireToFolderId; }
00472   void setExpireToFolderId( const QString& id );
00473 
00478   void expireOldMessages( bool immediate );
00479 
00482   int writeIndex( bool createEmptyIndex = false );
00483 
00485   void setStatus(int idx, KMMsgStatus status, bool toggle=false);
00486 
00488   void setStatus(QValueList<int>& ids, KMMsgStatus status, bool toggle=false);
00489 
00491   bool useCustomIcons() const { return mUseCustomIcons; }
00492   void setUseCustomIcons(bool useCustomIcons) { mUseCustomIcons = useCustomIcons; }
00493   QString normalIconPath() const { return mNormalIconPath; }
00494   QString unreadIconPath() const { return mUnreadIconPath; }
00495   void setIconPaths(const QString &normalPath, const QString &unreadPath);
00496 
00497   void removeJobs();
00498 
00499   void daysToExpire( int& unreadDays, int& readDays );
00500 
00505   KMFolder* trashFolder() const;
00506 
00511   bool putRepliesInSameFolder() const { return mPutRepliesInSameFolder; }
00512   void setPutRepliesInSameFolder( bool b ) { mPutRepliesInSameFolder = b; }
00513 
00518   bool ignoreNewMail() const { return mIgnoreNewMail; }
00519   void setIgnoreNewMail( bool b ) { mIgnoreNewMail = b; }
00520 
00521   const KShortcut &shortcut() const { return mShortcut; }
00522   void setShortcut( const KShortcut& );
00523 
00525   bool isMoveable() const;
00526 
00530   bool moveInProgress() const { return mMoveInProgress; }
00531 
00533   void setMoveInProgress( bool b ) { mMoveInProgress = b; }
00534 
00535 signals:
00538   void changed();
00539 
00542   void closed();
00543 
00546   void cleared();
00547 
00550   void expunged( KMFolder* );
00551 
00553   void iconsChanged();
00554 
00556   void nameChanged();
00557 
00559   void shortcutChanged( KMFolder * );
00560 
00562   void msgRemoved(KMFolder*, Q_UINT32 sernum);
00563 
00565   void msgRemoved( int idx, QString msgIdMD5 );
00566   void msgRemoved(KMFolder*);
00567 
00569   void msgAdded(int idx);
00570   void msgAdded(KMFolder*, Q_UINT32 sernum);
00571 
00573   void msgChanged(KMFolder*, Q_UINT32 sernum, int delta);
00574 
00576   void msgHeaderChanged(KMFolder*, int);
00577 
00579   void statusMsg(const QString&);
00580 
00582   void numUnreadMsgsChanged( KMFolder* );
00583 
00585   void removed(KMFolder*, bool);
00586 
00588   void viewConfigChanged();
00589 
00591   void folderSizeChanged( KMFolder * );
00592 
00593 public slots:
00595   int updateIndex();
00596 
00599   void reallyAddMsg(KMMessage* aMsg);
00600 
00603   void reallyAddCopyOfMsg(KMMessage* aMsg);
00604 
00605 private slots:
00607   void slotContentsTypeChanged( KMail::FolderContentsType type );
00609   void slotFolderSizeChanged();
00610 
00611 private:
00612   FolderStorage* mStorage;
00613   KMFolderDir* mChild;
00614   bool mIsSystemFolder;
00615   bool mHasIndex :1;
00616   bool mExportsSernums :1;
00617   bool mMoveInProgress :1;
00618 
00620   QString mLabel;
00621   QString mSystemLabel;
00622 
00624   bool         mExpireMessages;          // true if old messages are expired
00625   int          mUnreadExpireAge;         // Given in unreadExpireUnits
00626   int          mReadExpireAge;           // Given in readExpireUnits
00627   ExpireUnits  mUnreadExpireUnits;
00628   ExpireUnits  mReadExpireUnits;
00629   ExpireAction mExpireAction;
00630   QString      mExpireToFolderId;
00631 
00633   bool mUseCustomIcons;
00634   QString mNormalIconPath;
00635   QString mUnreadIconPath;
00636 
00638   bool                mMailingListEnabled;
00639   MailingList         mMailingList;
00640 
00641   AccountList* mAcctList;
00642 
00643   uint mIdentity;
00644 
00646   QString mWhoField, mUserWhoField;
00647 
00649   bool mPutRepliesInSameFolder;
00650 
00652   bool mIgnoreNewMail;
00653 
00655   KShortcut mShortcut;
00656 };
00657 
00658 
00664 class KMFolderOpener {
00665   KMFolder* mFolder;
00666   const char* const mOwner;
00667   int mOpenRc;
00668 
00669 public:
00670   KMFolderOpener( KMFolder* folder, const char* const owner )
00671    : mFolder( folder )
00672    , mOwner( owner )
00673   {
00674     assert( folder ); //change if that's not what you want
00675     mOpenRc = folder->open( owner );
00676   }
00677 
00678   ~KMFolderOpener()
00679   {
00680     if ( !mOpenRc )
00681       mFolder->close( mOwner );
00682   }
00683 
00684   KMFolder* folder() const { return mFolder; }
00685 
00686   int openResult() const { return mOpenRc; }
00687 
00688 private:
00689   //we forbid construction on the heap as good as we can
00690   void* operator new( size_t size );
00691 };
00692 
00693 
00694 #endif /*kmfolder_h*/