kmail

kmfolderindex.h
1/*
2 This file is part of KMail, the KDE mail client.
3 Copyright (c) 2000 Don Sanders <sanders@kde.org>
4
5 KMail is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License, version 2, as
7 published by the Free Software Foundation.
8
9 KMail is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17*/
18// Virtual base class for mail folder with .*.index style index
19
20#ifndef kmfolderindex_h
21#define kmfolderindex_h
22
23#include "folderstorage.h"
24#include "kmmsglist.h"
25
38{
39 TQ_OBJECT
40
41 //TODO:Have to get rid of this friend declaration and add necessary pure
42 //virtuals to kmfolder.h so that KMMsgBase::parent() can be a plain KMFolder
43 //rather than a KMFolderIndex. Need this for database indices.
44 friend class ::KMMsgBase;
45public:
46
50 enum IndexStatus { IndexOk,
51 IndexMissing,
52 IndexCorrupt,
53 IndexTooOld
54 };
55
59 KMFolderIndex(KMFolder* folder, const char* name=0);
60 virtual ~KMFolderIndex();
61 virtual int count(bool cache = false) const;
62
63 virtual KMMsgBase* takeIndexEntry( int idx ) { return mMsgList.take( idx ); }
64 virtual KMMsgInfo* setIndexEntry( int idx, KMMessage *msg );
65 virtual void clearIndex(bool autoDelete=true, bool syncDict = false);
66 virtual void truncateIndex();
67
68 virtual const KMMsgBase* getMsgBase(int idx) const { return mMsgList[idx]; }
69 virtual KMMsgBase* getMsgBase(int idx) { return mMsgList[idx]; }
70
71 virtual int find(const KMMsgBase* msg) const { return mMsgList.find((KMMsgBase*)msg); }
72 int find( const KMMessage * msg ) const { return FolderStorage::find( msg ); }
73
75 int serialIndexId() const { return mIndexId; }
76
77 uchar *indexStreamBasePtr() { return mIndexStreamPtr; }
78
79 bool indexSwapByteOrder() { return mIndexSwapByteOrder; }
80 int indexSizeOfLong() { return mIndexSizeOfLong; }
81
82 virtual TQString indexLocation() const;
83 virtual int writeIndex( bool createEmptyIndex = false );
84
85 void recreateIndex( bool readIndexAfterwards = true );
86 void silentlyRecreateIndex();
87
94 virtual IndexStatus indexStatus() = 0;
95
96public slots:
98 virtual int updateIndex();
99
100protected:
101 bool readIndex();
102
104 bool readIndexHeader(int *gv=0);
105
109 virtual int createIndexFromContents() = 0;
110
111 bool updateIndexStreamPtr(bool just_close=FALSE);
112
117 virtual void fillMessageDict();
118
123
126
127 uchar *mIndexStreamPtr;
128 int mIndexStreamPtrLength, mIndexId;
129 bool mIndexSwapByteOrder; // Index file was written with swapped byte order
130 int mIndexSizeOfLong; // Index file was written with longs of this size
131
132private:
133 void updateInvitationAndAddressFieldsFromContents();
134
135};
136
137#endif /*kmfolderindex_h*/
The FolderStorage class is the bass class for the storage related aspects of a collection of mail (a ...
Definition: folderstorage.h:80
virtual int find(const KMMsgBase *msg) const =0
Returns the index of the given message or -1 if not found.
A FolderStorage with an index for faster access to often used message properties.
Definition: kmfolderindex.h:38
bool readIndexHeader(int *gv=0)
Read index header.
KMFolderIndex(KMFolder *folder, const char *name=0)
Usually a parent is given.
FILE * mIndexStream
table of contents file
virtual int find(const KMMsgBase *msg) const
Returns the index of the given message or -1 if not found.
Definition: kmfolderindex.h:71
virtual int writeIndex(bool createEmptyIndex=false)
Write index to index-file.
virtual TQString indexLocation() const
Returns full path to index file.
off_t mHeaderOffset
offset of header of index file
int serialIndexId() const
Registered unique serial number for the index file.
Definition: kmfolderindex.h:75
virtual int count(bool cache=false) const
Number of messages in this folder.
IndexStatus
This enum indicates the status of the index file.
Definition: kmfolderindex.h:50
virtual IndexStatus indexStatus()=0
Tests whether the contents of this folder is newer than the index.
virtual const KMMsgBase * getMsgBase(int idx) const
Provides access to the basic message fields that are also stored in the index.
Definition: kmfolderindex.h:68
virtual int updateIndex()
Incrementally update the index if possible else call writeIndex.
bool readIndex()
Read index file and fill the message-info list mMsgList.
virtual int createIndexFromContents()=0
Create index file from messages file and fill the message-info list mMsgList.
virtual void fillMessageDict()
Inserts messages into the message dictionary by iterating over the message list.
KMMsgList mMsgList
list of index entries or messages
Mail folder.
Definition: kmfolder.h:69
This is a Mime Message.
Definition: kmmessage.h:68
An abstraction of an array of pointers to messages.
Definition: kmmsglist.h:38
KMMsgBase * take(unsigned int idx)
Returns message at given index and removes it from the list.
Definition: kmmsglist.cpp:161