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 QCString& getMsgString(int idx, QCString& mDest);
00188
00190 DwString getDwString(int idx);
00191
00195 void ignoreJobsForMessage( KMMessage* );
00196
00201 FolderJob* createJob( KMMessage *msg, FolderJob::JobType jt = FolderJob::tGetMessage,
00202 KMFolder *folder = 0, QString partSpecifier = QString::null,
00203 const AttachmentStrategy *as = 0 ) const;
00204 FolderJob* createJob( QPtrList<KMMessage>& msgList, const QString& sets,
00205 FolderJob::JobType jt = FolderJob::tGetMessage,
00206 KMFolder *folder = 0 ) const;
00207
00212 const KMMsgBase* getMsgBase(int idx) const;
00213 KMMsgBase* getMsgBase(int idx);
00214
00216 const KMMsgBase* operator[](int idx) const;
00217
00219 KMMsgBase* operator[](int idx);
00220
00223 KMMessage* take(int idx);
00224 void take(QPtrList<KMMessage> msgList);
00225
00232 int addMsg(KMMessage* msg, int* index_return = 0);
00233
00237 int addMsgKeepUID(KMMessage* msg, int* index_return = 0);
00238
00243 int addMsg(QPtrList<KMMessage>&, QValueList<int>& index_return);
00244
00247 void emitMsgAddedSignals(int idx);
00248
00250 void removeMsg(int i, bool imapQuiet = false);
00251 void removeMsg(QPtrList<KMMessage> msgList, bool imapQuiet = false);
00252
00255 int expungeOldMsg(int days);
00256
00261 int moveMsg(KMMessage* msg, int* index_return = 0);
00262 int moveMsg(QPtrList<KMMessage>, int* index_return = 0);
00263
00265 int find(const KMMsgBase* msg) const;
00266 int find( const KMMessage * msg ) const;
00267
00269 int count(bool cache = false) const;
00270
00272 int countUnread();
00273
00276 int countUnreadRecursive();
00277
00280 void msgStatusChanged( const KMMsgStatus oldStatus,
00281 const KMMsgStatus newStatus,
00282 int idx);
00283
00289 int open();
00290
00293 int canAccess();
00294
00297 void close(bool force=false);
00298
00300 void sync();
00301
00303 bool isOpened() const;
00304
00306 void markNewAsUnread();
00307
00309 void markUnreadAsRead();
00310
00315 void remove();
00316
00320 int expunge();
00321
00322 enum CompactOptions { CompactLater, CompactNow, CompactSilentlyNow };
00329 void compact( CompactOptions options );
00330
00333 int rename(const QString& newName, KMFolderDir *aParent = 0);
00334
00338 bool dirty() const;
00339
00341 void setDirty(bool f);
00342
00344 bool needsCompacting() const;
00345 void setNeedsCompacting(bool f);
00346
00355 void quiet(bool beQuiet);
00356
00358 bool isReadOnly() 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 { return mIdentity; }
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
00530 signals:
00533 void changed();
00534
00537 void cleared();
00538
00541 void expunged( KMFolder* );
00542
00544 void iconsChanged();
00545
00547 void nameChanged();
00548
00550 void shortcutChanged( KMFolder * );
00551
00553 void msgRemoved(KMFolder*, Q_UINT32 sernum);
00554
00556 void msgRemoved( int idx, QString msgIdMD5 );
00557 void msgRemoved(KMFolder*);
00558
00560 void msgAdded(int idx);
00561 void msgAdded(KMFolder*, Q_UINT32 sernum);
00562
00564 void msgChanged(KMFolder*, Q_UINT32 sernum, int delta);
00565
00567 void msgHeaderChanged(KMFolder*, int);
00568
00570 void statusMsg(const QString&);
00571
00573 void numUnreadMsgsChanged( KMFolder* );
00574
00576 void removed(KMFolder*, bool);
00577
00579 void viewConfigChanged();
00580
00581 public slots:
00583 int updateIndex();
00584
00587 void reallyAddMsg(KMMessage* aMsg);
00588
00591 void reallyAddCopyOfMsg(KMMessage* aMsg);
00592
00593 private slots:
00595 void slotContentsTypeChanged( KMail::FolderContentsType type );
00596
00597 private:
00598 FolderStorage* mStorage;
00599 KMFolderDir* mChild;
00600 bool mIsSystemFolder;
00601 bool mHasIndex :1;
00602 bool mExportsSernums :1;
00603
00605 QString mLabel;
00606 QString mSystemLabel;
00607
00609 bool mExpireMessages;
00610 int mUnreadExpireAge;
00611 int mReadExpireAge;
00612 ExpireUnits mUnreadExpireUnits;
00613 ExpireUnits mReadExpireUnits;
00614 ExpireAction mExpireAction;
00615 QString mExpireToFolderId;
00616
00618 bool mUseCustomIcons;
00619 QString mNormalIconPath;
00620 QString mUnreadIconPath;
00621
00623 bool mMailingListEnabled;
00624 MailingList mMailingList;
00625
00626 AccountList* mAcctList;
00627
00628 uint mIdentity;
00629
00631 QString mWhoField, mUserWhoField;
00632
00634 bool mPutRepliesInSameFolder;
00635
00637 bool mIgnoreNewMail;
00638
00640 KShortcut mShortcut;
00641 };
00642
00648 class KMFolderCloser {
00649 KMFolder * f;
00650 public:
00651 KMFolderCloser( KMFolder * folder ) : f( folder ) {}
00652 ~KMFolderCloser() {
00653 if ( f ) f->close();
00654 }
00655 KMFolder * folder() const { return f; }
00656 };
00657
00658 #endif