00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef kmfolder_h
00021 #define kmfolder_h
00022
00023
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"
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;
00357 bool isWritable() const;
00358
00360 bool canDeleteMessages() const;
00361
00366 bool isSystemFolder() const { return mIsSystemFolder; }
00367 void setSystemFolder(bool itIs) { mIsSystemFolder=itIs; }
00368
00370 virtual QString label() const;
00371 void setLabel( const QString& l ) { mLabel = l; }
00372
00374 virtual QString systemLabel() const { return mSystemLabel; }
00375 void setSystemLabel( const QString& l ) { mSystemLabel = l; }
00376
00378 virtual QString prettyURL() const;
00379
00381 void setMailingListEnabled( bool enabled );
00382 bool isMailingListEnabled() const { return mMailingListEnabled; }
00383
00384 void setMailingList( const MailingList& mlist );
00385 MailingList mailingList() const
00386 { return mMailingList; }
00387 QString mailingListPostAddress() const;
00388
00389 void setIdentity(uint identity);
00390 uint identity() const;
00391
00393 QString whoField() const { return mWhoField; }
00394 void setWhoField(const QString& aWhoField);
00395
00397 QString userWhoField(void) { return mUserWhoField; }
00398 void setUserWhoField(const QString &whoField,bool writeConfig=true);
00399
00401 void correctUnreadMsgsCount();
00402
00404 QString idString() const;
00405
00409 void setAutoExpire(bool enabled);
00410
00414 bool isAutoExpire() const { return mExpireMessages; }
00415
00421 void setUnreadExpireAge(int age);
00422
00427 void setUnreadExpireUnits(ExpireUnits units);
00428
00434 void setReadExpireAge(int age);
00435
00440 void setReadExpireUnits(ExpireUnits units);
00441
00446 int getUnreadExpireAge() const { return mUnreadExpireAge; }
00447
00452 int getReadExpireAge() const { return mReadExpireAge; }
00453
00458 ExpireUnits getUnreadExpireUnits() const { return mUnreadExpireUnits; }
00459
00464 ExpireUnits getReadExpireUnits() const { return mReadExpireUnits; }
00465
00466 enum ExpireAction { ExpireDelete, ExpireMove };
00470 ExpireAction expireAction() const { return mExpireAction; }
00471 void setExpireAction( ExpireAction a );
00472
00476 QString expireToFolderId() const { return mExpireToFolderId; }
00477 void setExpireToFolderId( const QString& id );
00478
00483 void expireOldMessages( bool immediate );
00484
00487 int writeIndex( bool createEmptyIndex = false );
00488
00490 void setStatus(int idx, KMMsgStatus status, bool toggle=false);
00491
00493 void setStatus(QValueList<int>& ids, KMMsgStatus status, bool toggle=false);
00494
00496 bool useCustomIcons() const { return mUseCustomIcons; }
00497 void setUseCustomIcons(bool useCustomIcons) { mUseCustomIcons = useCustomIcons; }
00498 QString normalIconPath() const { return mNormalIconPath; }
00499 QString unreadIconPath() const { return mUnreadIconPath; }
00500 void setIconPaths(const QString &normalPath, const QString &unreadPath);
00501
00502 void removeJobs();
00503
00504 void daysToExpire( int& unreadDays, int& readDays );
00505
00510 KMFolder* trashFolder() const;
00511
00516 bool putRepliesInSameFolder() const { return mPutRepliesInSameFolder; }
00517 void setPutRepliesInSameFolder( bool b ) { mPutRepliesInSameFolder = b; }
00518
00523 bool ignoreNewMail() const { return mIgnoreNewMail; }
00524 void setIgnoreNewMail( bool b ) { mIgnoreNewMail = b; }
00525
00526 const KShortcut &shortcut() const { return mShortcut; }
00527 void setShortcut( const KShortcut& );
00528
00530 bool isMoveable() const;
00531
00535 bool moveInProgress() const { return mMoveInProgress; }
00536
00538 void setMoveInProgress( bool b ) { mMoveInProgress = b; }
00539
00540 signals:
00543 void changed();
00544
00547 void closed();
00548
00551 void cleared();
00552
00555 void expunged( KMFolder* );
00556
00558 void iconsChanged();
00559
00561 void nameChanged();
00562
00564 void shortcutChanged( KMFolder * );
00565
00567 void msgRemoved(KMFolder*, Q_UINT32 sernum);
00568
00570 void msgRemoved( int idx, QString msgIdMD5 );
00571 void msgRemoved(KMFolder*);
00572
00574 void msgAdded(int idx);
00575 void msgAdded(KMFolder*, Q_UINT32 sernum);
00576
00578 void msgChanged(KMFolder*, Q_UINT32 sernum, int delta);
00579
00581 void msgHeaderChanged(KMFolder*, int);
00582
00584 void statusMsg(const QString&);
00585
00587 void numUnreadMsgsChanged( KMFolder* );
00588
00590 void removed(KMFolder*, bool);
00591
00593 void viewConfigChanged();
00594
00596 void folderSizeChanged( KMFolder * );
00597
00599 void noContentChanged();
00600
00601 public slots:
00603 int updateIndex();
00604
00607 void reallyAddMsg(KMMessage* aMsg);
00608
00611 void reallyAddCopyOfMsg(KMMessage* aMsg);
00612
00613 private slots:
00615 void slotContentsTypeChanged( KMail::FolderContentsType type );
00617 void slotFolderSizeChanged();
00618
00619 private:
00620 FolderStorage* mStorage;
00621 KMFolderDir* mChild;
00622 bool mIsSystemFolder;
00623 bool mHasIndex :1;
00624 bool mExportsSernums :1;
00625 bool mMoveInProgress :1;
00626
00628 QString mLabel;
00629 QString mSystemLabel;
00630
00632 bool mExpireMessages;
00633 int mUnreadExpireAge;
00634 int mReadExpireAge;
00635 ExpireUnits mUnreadExpireUnits;
00636 ExpireUnits mReadExpireUnits;
00637 ExpireAction mExpireAction;
00638 QString mExpireToFolderId;
00639
00641 bool mUseCustomIcons;
00642 QString mNormalIconPath;
00643 QString mUnreadIconPath;
00644
00646 bool mMailingListEnabled;
00647 MailingList mMailingList;
00648
00649 AccountList* mAcctList;
00650
00651 uint mIdentity;
00652
00654 QString mWhoField, mUserWhoField;
00655
00657 bool mPutRepliesInSameFolder;
00658
00660 bool mIgnoreNewMail;
00661
00663 KShortcut mShortcut;
00664 };
00665
00666
00672 class KMFolderOpener {
00673 KMFolder* mFolder;
00674 const char* const mOwner;
00675 int mOpenRc;
00676
00677 public:
00678 KMFolderOpener( KMFolder* folder, const char* const owner )
00679 : mFolder( folder )
00680 , mOwner( owner )
00681 {
00682 assert( folder );
00683 mOpenRc = folder->open( owner );
00684 }
00685
00686 ~KMFolderOpener()
00687 {
00688 if ( !mOpenRc )
00689 mFolder->close( mOwner );
00690 }
00691
00692 KMFolder* folder() const { return mFolder; }
00693
00694 int openResult() const { return mOpenRc; }
00695
00696 private:
00697
00698 void* operator new( size_t size );
00699 };
00700
00701
00702 #endif