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;
00356
00358 bool canDeleteMessages() const;
00359
00364 bool isSystemFolder() const { return mIsSystemFolder; }
00365 void setSystemFolder(bool itIs) { mIsSystemFolder=itIs; }
00366
00368 virtual QString label() const;
00369 void setLabel( const QString& l ) { mLabel = l; }
00370
00372 virtual QString systemLabel() const { return mSystemLabel; }
00373 void setSystemLabel( const QString& l ) { mSystemLabel = l; }
00374
00376 virtual QString prettyURL() const;
00377
00379 void setMailingListEnabled( bool enabled );
00380 bool isMailingListEnabled() const { return mMailingListEnabled; }
00381
00382 void setMailingList( const MailingList& mlist );
00383 MailingList mailingList() const
00384 { return mMailingList; }
00385 QString mailingListPostAddress() const;
00386
00387 void setIdentity(uint identity);
00388 uint identity() const;
00389
00391 QString whoField() const { return mWhoField; }
00392 void setWhoField(const QString& aWhoField);
00393
00395 QString userWhoField(void) { return mUserWhoField; }
00396 void setUserWhoField(const QString &whoField,bool writeConfig=true);
00397
00399 void correctUnreadMsgsCount();
00400
00402 QString idString() const;
00403
00407 void setAutoExpire(bool enabled);
00408
00412 bool isAutoExpire() const { return mExpireMessages; }
00413
00419 void setUnreadExpireAge(int age);
00420
00425 void setUnreadExpireUnits(ExpireUnits units);
00426
00432 void setReadExpireAge(int age);
00433
00438 void setReadExpireUnits(ExpireUnits units);
00439
00444 int getUnreadExpireAge() const { return mUnreadExpireAge; }
00445
00450 int getReadExpireAge() const { return mReadExpireAge; }
00451
00456 ExpireUnits getUnreadExpireUnits() const { return mUnreadExpireUnits; }
00457
00462 ExpireUnits getReadExpireUnits() const { return mReadExpireUnits; }
00463
00464 enum ExpireAction { ExpireDelete, ExpireMove };
00468 ExpireAction expireAction() const { return mExpireAction; }
00469 void setExpireAction( ExpireAction a );
00470
00474 QString expireToFolderId() const { return mExpireToFolderId; }
00475 void setExpireToFolderId( const QString& id );
00476
00481 void expireOldMessages( bool immediate );
00482
00485 int writeIndex( bool createEmptyIndex = false );
00486
00488 void setStatus(int idx, KMMsgStatus status, bool toggle=false);
00489
00491 void setStatus(QValueList<int>& ids, KMMsgStatus status, bool toggle=false);
00492
00494 bool useCustomIcons() const { return mUseCustomIcons; }
00495 void setUseCustomIcons(bool useCustomIcons) { mUseCustomIcons = useCustomIcons; }
00496 QString normalIconPath() const { return mNormalIconPath; }
00497 QString unreadIconPath() const { return mUnreadIconPath; }
00498 void setIconPaths(const QString &normalPath, const QString &unreadPath);
00499
00500 void removeJobs();
00501
00502 void daysToExpire( int& unreadDays, int& readDays );
00503
00508 KMFolder* trashFolder() const;
00509
00514 bool putRepliesInSameFolder() const { return mPutRepliesInSameFolder; }
00515 void setPutRepliesInSameFolder( bool b ) { mPutRepliesInSameFolder = b; }
00516
00521 bool ignoreNewMail() const { return mIgnoreNewMail; }
00522 void setIgnoreNewMail( bool b ) { mIgnoreNewMail = b; }
00523
00524 const KShortcut &shortcut() const { return mShortcut; }
00525 void setShortcut( const KShortcut& );
00526
00528 bool isMoveable() const;
00529
00533 bool moveInProgress() const { return mMoveInProgress; }
00534
00536 void setMoveInProgress( bool b ) { mMoveInProgress = b; }
00537
00538 signals:
00541 void changed();
00542
00545 void closed();
00546
00549 void cleared();
00550
00553 void expunged( KMFolder* );
00554
00556 void iconsChanged();
00557
00559 void nameChanged();
00560
00562 void shortcutChanged( KMFolder * );
00563
00565 void msgRemoved(KMFolder*, Q_UINT32 sernum);
00566
00568 void msgRemoved( int idx, QString msgIdMD5 );
00569 void msgRemoved(KMFolder*);
00570
00572 void msgAdded(int idx);
00573 void msgAdded(KMFolder*, Q_UINT32 sernum);
00574
00576 void msgChanged(KMFolder*, Q_UINT32 sernum, int delta);
00577
00579 void msgHeaderChanged(KMFolder*, int);
00580
00582 void statusMsg(const QString&);
00583
00585 void numUnreadMsgsChanged( KMFolder* );
00586
00588 void removed(KMFolder*, bool);
00589
00591 void viewConfigChanged();
00592
00594 void folderSizeChanged( KMFolder * );
00595
00597 void noContentChanged();
00598
00599 public slots:
00601 int updateIndex();
00602
00605 void reallyAddMsg(KMMessage* aMsg);
00606
00609 void reallyAddCopyOfMsg(KMMessage* aMsg);
00610
00611 private slots:
00613 void slotContentsTypeChanged( KMail::FolderContentsType type );
00615 void slotFolderSizeChanged();
00616
00617 private:
00618 FolderStorage* mStorage;
00619 KMFolderDir* mChild;
00620 bool mIsSystemFolder;
00621 bool mHasIndex :1;
00622 bool mExportsSernums :1;
00623 bool mMoveInProgress :1;
00624
00626 QString mLabel;
00627 QString mSystemLabel;
00628
00630 bool mExpireMessages;
00631 int mUnreadExpireAge;
00632 int mReadExpireAge;
00633 ExpireUnits mUnreadExpireUnits;
00634 ExpireUnits mReadExpireUnits;
00635 ExpireAction mExpireAction;
00636 QString mExpireToFolderId;
00637
00639 bool mUseCustomIcons;
00640 QString mNormalIconPath;
00641 QString mUnreadIconPath;
00642
00644 bool mMailingListEnabled;
00645 MailingList mMailingList;
00646
00647 AccountList* mAcctList;
00648
00649 uint mIdentity;
00650
00652 QString mWhoField, mUserWhoField;
00653
00655 bool mPutRepliesInSameFolder;
00656
00658 bool mIgnoreNewMail;
00659
00661 KShortcut mShortcut;
00662 };
00663
00664
00670 class KMFolderOpener {
00671 KMFolder* mFolder;
00672 const char* const mOwner;
00673 int mOpenRc;
00674
00675 public:
00676 KMFolderOpener( KMFolder* folder, const char* const owner )
00677 : mFolder( folder )
00678 , mOwner( owner )
00679 {
00680 assert( folder );
00681 mOpenRc = folder->open( owner );
00682 }
00683
00684 ~KMFolderOpener()
00685 {
00686 if ( !mOpenRc )
00687 mFolder->close( mOwner );
00688 }
00689
00690 KMFolder* folder() const { return mFolder; }
00691
00692 int openResult() const { return mOpenRc; }
00693
00694 private:
00695
00696 void* operator new( size_t size );
00697 };
00698
00699
00700 #endif