00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
#ifndef FOLDERSTORAGE_H
00036
#define FOLDERSTORAGE_H
00037
00038
00039
#include <config.h>
00040
00041
#include "kmfoldernode.h"
00042
#include "kmfoldertype.h"
00043
#include "kmmsginfo.h"
00044
#include "kmglobal.h"
00045
#include "folderjob.h"
00046
using KMail::FolderJob;
00047
#include "listjob.h"
00048
using KMail::ListJob;
00049
00050
#include "mimelib/string.h"
00051
00052
#include <qptrvector.h>
00053
#include <sys/types.h>
00054
#include <stdio.h>
00055
00056
class KMMessage;
00057
class KMFolderDir;
00058
class KMAcctList;
00059
class KMMsgDict;
00060
class KMMsgDictREntry;
00061
class QTimer;
00062
00063
namespace KMail {
00064
class AttachmentStrategy;
00065 }
00066
using KMail::AttachmentStrategy;
00067
00068
typedef QValueList<Q_UINT32> SerNumList;
00069
00080 class FolderStorage :
public QObject
00081 {
00082 Q_OBJECT
00083
00084
public:
00085
00086
00090
FolderStorage(
KMFolder* folder,
const char* name=0 );
00091
virtual ~
FolderStorage();
00092
00093
KMFolder* folder()
const {
return mFolder; }
00094
00095
void setAcctList( KMAcctList* list ) { mAcctList = list; }
00096 KMAcctList* acctList()
const {
return mAcctList; }
00097
00099 virtual KMFolderType
folderType()
const {
return KMFolderTypeUnknown; }
00100
00102
virtual QString fileName() const;
00104
QString location() const;
00105
00107 virtual
QString indexLocation() const = 0;
00108
00110 virtual
bool noContent()
const {
return mNoContent; }
00111
00113 virtual void setNoContent(
bool aNoContent)
00114 { mNoContent = aNoContent; }
00115
00117 virtual bool noChildren()
const {
return mNoChildren; }
00118
00120
virtual void setNoChildren(
bool aNoChildren );
00121
00122
enum ChildrenState {
00123 HasChildren,
00124 HasNoChildren,
00125 ChildrenUnknown
00126 };
00129 virtual ChildrenState
hasChildren()
const {
return mHasChildren; }
00130
00132 virtual void setHasChildren( ChildrenState state )
00133 { mHasChildren = state; }
00134
00136
virtual void updateChildrenState();
00137
00139
virtual KMMessage*
getMsg(
int idx);
00140
00142
virtual KMMsgInfo*
unGetMsg(
int idx);
00143
00145
virtual bool isMessage(
int idx);
00146
00148
virtual QCString&
getMsgString(
int idx,
QCString& mDest) = 0;
00149
00151
virtual DwString
getDwString(
int idx) = 0;
00152
00156
virtual void ignoreJobsForMessage( KMMessage* );
00157
00162
virtual FolderJob*
createJob( KMMessage *msg, FolderJob::JobType jt = FolderJob::tGetMessage,
00163
KMFolder *folder = 0,
QString partSpecifier = QString::null,
00164
const AttachmentStrategy *as = 0 )
const;
00165
virtual FolderJob*
createJob(
QPtrList<KMMessage>& msgList,
const QString& sets,
00166 FolderJob::JobType jt = FolderJob::tGetMessage,
00167
KMFolder *folder = 0 )
const;
00168
00173
virtual const KMMsgBase*
getMsgBase(
int idx)
const = 0;
00174
virtual KMMsgBase*
getMsgBase(
int idx) = 0;
00175
00177 virtual const KMMsgBase*
operator[](
int idx)
const {
return getMsgBase(idx); }
00178
00180 virtual KMMsgBase*
operator[](
int idx) {
return getMsgBase(idx); }
00181
00184
virtual KMMessage*
take(
int idx);
00185
virtual void take(
QPtrList<KMMessage> msgList);
00186
00193
virtual int addMsg(KMMessage* msg,
int* index_return = 0) = 0;
00194
00198 virtual int addMsgKeepUID(KMMessage* msg,
int* index_return = 0) {
00199
return addMsg(msg, index_return);
00200 }
00201
00204
void emitMsgAddedSignals(
int idx);
00205
00208
virtual bool canAddMsgNow(KMMessage* aMsg,
int* aIndex_ret);
00209
00211
virtual void removeMsg(
int i,
bool imapQuiet = FALSE);
00212
virtual void removeMsg(
const QPtrList<KMMsgBase>& msgList,
bool imapQuiet = FALSE);
00213
virtual void removeMsg(
const QPtrList<KMMessage>& msgList,
bool imapQuiet = FALSE);
00214
00217
virtual int expungeOldMsg(
int days);
00218
00223
virtual int moveMsg(KMMessage* msg,
int* index_return = 0);
00224
virtual int moveMsg(
QPtrList<KMMessage>,
int* index_return = 0);
00225
00227
virtual int find(
const KMMsgBase* msg)
const = 0;
00228
int find(
const KMMessage * msg )
const;
00229
00231
virtual int count(
bool cache =
false)
const;
00232
00234
virtual int countUnread();
00235
00238
virtual void msgStatusChanged(
const KMMsgStatus oldStatus,
00239
const KMMsgStatus newStatus,
00240
int idx);
00241
00247
virtual int open() = 0;
00248
00251
virtual int canAccess() = 0;
00252
00255
virtual void close(
bool force=FALSE) = 0;
00256
00259 virtual void tryReleasingFolder(
KMFolder*) {}
00260
00262
virtual void sync() = 0;
00263
00265 bool isOpened()
const {
return (mOpenCount>0); }
00266
00268
virtual void markNewAsUnread();
00269
00271
virtual void markUnreadAsRead();
00272
00276
virtual int create(
bool imap = FALSE) = 0;
00277
00282
virtual void remove();
00283
00287
virtual int expunge();
00288
00293
virtual int compact(
bool silent ) = 0;
00294
00297
virtual int rename(
const QString& newName,
KMFolderDir *aParent = 0);
00298
00300 bool autoCreateIndex()
const {
return mAutoCreateIndex; }
00301
00304
virtual void setAutoCreateIndex(
bool);
00305
00309 bool dirty()
const {
return mDirty; }
00310
00312
void setDirty(
bool f);
00313
00315 bool needsCompacting()
const {
return needsCompact; }
00316
virtual void setNeedsCompacting(
bool f) { needsCompact = f; }
00317
00326
virtual void quiet(
bool beQuiet);
00327
00329
virtual bool isReadOnly() const = 0;
00330
00332
QString label() const;
00333
00335 virtual const
char* type() const;
00336
00338 bool hasAccounts()
const {
return (mAcctList != 0); }
00339
00341
virtual void correctUnreadMsgsCount();
00342
00345
virtual int writeIndex(
bool createEmptyIndex =
false ) = 0;
00346
00349
void fillMsgDict(KMMsgDict *dict);
00350
00352
int writeMsgDict(KMMsgDict *dict = 0);
00353
00355
int touchMsgDict();
00356
00358
int appendtoMsgDict(
int idx = -1);
00359
00361
void setRDict(KMMsgDictREntry *rentry);
00362
00364 KMMsgDictREntry *
rDict()
const {
return mRDict; }
00365
00367
virtual void setStatus(
int idx, KMMsgStatus status,
bool toggle=
false);
00368
00370
virtual void setStatus(
QValueList<int>& ids, KMMsgStatus status,
bool toggle=
false);
00371
00372
void removeJobs();
00373
00377
static size_t
crlf2lf(
char* str,
const size_t strLen );
00378
00380
static QString dotEscape(
const QString&);
00381
00383
virtual void readConfig();
00384
00386
virtual void writeConfig();
00387
00392 virtual KMFolder*
trashFolder()
const {
return 0; }
00393
00398
void addJob( FolderJob* ) const;
00399
00401 bool compactable()
const {
return mCompactable; }
00402
00404
virtual void setContentsType( KMail::FolderContentsType type );
00406 KMail::FolderContentsType
contentsType()
const {
return mContentsType; }
00407
00408 signals:
00411
void changed();
00412
00415
void cleared();
00416
00419
void expunged();
00420
00422
void nameChanged();
00423
00425
void msgRemoved(
KMFolder*, Q_UINT32 sernum);
00426
00428
void msgRemoved(
int idx,
QString msgIdMD5,
QString strippedSubjMD5);
00429
void msgRemoved(
KMFolder*);
00430
00432
void msgAdded(
int idx);
00433
void msgAdded(
KMFolder*, Q_UINT32 sernum);
00434
00436
void msgChanged(
KMFolder*, Q_UINT32 sernum,
int delta);
00437
00439
void msgHeaderChanged(
KMFolder*,
int);
00440
00442
void statusMsg(
const QString&);
00443
00445
void numUnreadMsgsChanged(
KMFolder* );
00446
00448
void removed(
KMFolder*,
bool);
00449
00450
public slots:
00452
virtual int updateIndex() = 0;
00453
00456
virtual void reallyAddMsg(KMMessage* aMsg);
00457
00460
virtual void reallyAddCopyOfMsg(KMMessage* aMsg);
00461
00462
protected slots:
00463
virtual void removeJob(
QObject* );
00464
00465
protected:
00471
virtual FolderJob*
doCreateJob( KMMessage *msg, FolderJob::JobType jt,
KMFolder *folder,
00472
QString partSpecifier,
const AttachmentStrategy *as )
const = 0;
00473
virtual FolderJob*
doCreateJob(
QPtrList<KMMessage>& msgList,
const QString& sets,
00474 FolderJob::JobType jt,
KMFolder *folder )
const = 0;
00475
00479
void headerOfMsgChanged(
const KMMsgBase*,
int idx);
00480
00483
virtual KMMessage*
readMsg(
int idx) = 0;
00484
00486
virtual bool readIndex() = 0;
00487
00491
virtual int removeContents() = 0;
00492
00496
virtual int expungeContents() = 0;
00497
00498
virtual KMMsgBase* takeIndexEntry(
int idx ) = 0;
00499
virtual KMMsgInfo* setIndexEntry(
int idx, KMMessage *msg ) = 0;
00500
virtual void clearIndex(
bool autoDelete=
true,
bool syncDict =
false) = 0;
00501
virtual void fillDictFromIndex(KMMsgDict *dict) = 0;
00502
virtual void truncateIndex() = 0;
00503
00504
int mOpenCount;
00505
int mQuiet;
00506
bool mChanged;
00508 bool mAutoCreateIndex;
00510 bool mDirty;
00512 bool mFilesLocked;
00513 KMAcctList* mAcctList;
00514
00516 int mUnreadMsgs,
mGuessedUnreadMsgs;
00517
int mTotalMsgs;
00518
bool mWriteConfigEnabled;
00520 bool needsCompact;
00522 bool mCompactable;
00523
bool mNoContent;
00524
bool mNoChildren;
00525
bool mConvertToUtf8;
00526
bool mContentsTypeChanged;
00527
00529 KMMsgDictREntry *
mRDict;
00531 mutable QPtrList<FolderJob> mJobList;
00532
00533
QTimer *mDirtyTimer;
00534
enum { mDirtyTimerInterval = 600000 };
00535
00536 ChildrenState mHasChildren;
00537
00539 KMail::FolderContentsType
mContentsType;
00540
00541
KMFolder* mFolder;
00542 };
00543
00544
#endif // FOLDERSTORAGE_H