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
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 { return mIdentity; }
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 cleared();
00543
00546 void expunged( KMFolder* );
00547
00549 void iconsChanged();
00550
00552 void nameChanged();
00553
00555 void shortcutChanged( KMFolder * );
00556
00558 void msgRemoved(KMFolder*, Q_UINT32 sernum);
00559
00561 void msgRemoved( int idx, QString msgIdMD5 );
00562 void msgRemoved(KMFolder*);
00563
00565 void msgAdded(int idx);
00566 void msgAdded(KMFolder*, Q_UINT32 sernum);
00567
00569 void msgChanged(KMFolder*, Q_UINT32 sernum, int delta);
00570
00572 void msgHeaderChanged(KMFolder*, int);
00573
00575 void statusMsg(const QString&);
00576
00578 void numUnreadMsgsChanged( KMFolder* );
00579
00581 void removed(KMFolder*, bool);
00582
00584 void viewConfigChanged();
00585
00587 void folderSizeChanged( KMFolder * );
00588
00589 public slots:
00591 int updateIndex();
00592
00595 void reallyAddMsg(KMMessage* aMsg);
00596
00599 void reallyAddCopyOfMsg(KMMessage* aMsg);
00600
00601 private slots:
00603 void slotContentsTypeChanged( KMail::FolderContentsType type );
00605 void slotFolderSizeChanged();
00606
00607 private:
00608 FolderStorage* mStorage;
00609 KMFolderDir* mChild;
00610 bool mIsSystemFolder;
00611 bool mHasIndex :1;
00612 bool mExportsSernums :1;
00613 bool mMoveInProgress :1;
00614
00616 QString mLabel;
00617 QString mSystemLabel;
00618
00620 bool mExpireMessages;
00621 int mUnreadExpireAge;
00622 int mReadExpireAge;
00623 ExpireUnits mUnreadExpireUnits;
00624 ExpireUnits mReadExpireUnits;
00625 ExpireAction mExpireAction;
00626 QString mExpireToFolderId;
00627
00629 bool mUseCustomIcons;
00630 QString mNormalIconPath;
00631 QString mUnreadIconPath;
00632
00634 bool mMailingListEnabled;
00635 MailingList mMailingList;
00636
00637 AccountList* mAcctList;
00638
00639 uint mIdentity;
00640
00642 QString mWhoField, mUserWhoField;
00643
00645 bool mPutRepliesInSameFolder;
00646
00648 bool mIgnoreNewMail;
00649
00651 KShortcut mShortcut;
00652 };
00653
00654
00660 class KMFolderOpener {
00661 KMFolder* mFolder;
00662 const char* const mOwner;
00663 int mOpenRc;
00664
00665 public:
00666 KMFolderOpener( KMFolder* folder, const char* const owner )
00667 : mFolder( folder )
00668 , mOwner( owner )
00669 {
00670 assert( folder );
00671 mOpenRc = folder->open( owner );
00672 }
00673
00674 ~KMFolderOpener()
00675 {
00676 if ( !mOpenRc )
00677 mFolder->close( mOwner );
00678 }
00679
00680 KMFolder* folder() const { return mFolder; }
00681
00682 int openResult() const { return mOpenRc; }
00683
00684 private:
00685
00686 void* operator new( size_t size );
00687 };
00688
00689
00690 #endif