1
#ifndef kmfoldermaildir_h
2
#define kmfoldermaildir_h
4
#include "kmfolderindex.h"
10
class KMFolderMaildir;
14
class AttachmentStrategy;
17
using KMail::FolderJob;
18
using KMail::MaildirJob;
19
using KMail::AttachmentStrategy;
21
class KMFolderMaildir : public KMFolderIndex
24
friend class ::KMail::MaildirJob;
26
/** Usually a parent is given. But in some cases there is no
27
fitting parent object available. Then the name of the folder
28
is used as the absolute path to the folder file. */
29
explicit KMFolderMaildir(KMFolder* folder, const char* name=0);
30
virtual ~KMFolderMaildir();
32
/** Returns the type of this folder */
33
virtual KMFolderType folderType() const { return KMFolderTypeMaildir; }
35
/** Read a message and return it as a string */
36
virtual DwString getDwString(int idx);
38
/** Detach message from this folder. Usable to call addMsg() afterwards.
39
Loads the message if it is not loaded up to now. */
40
virtual KMMessage* take(int idx);
42
/** Add the given message to the folder. Usually the message
43
is added at the end of the folder. Returns zero on success and
44
an errno error code on failure. The index of the new message
45
is stored in index_return if given.
46
Please note that the message is added as is to the folder and the folder
47
takes ownership of the message (deleting it in the destructor).*/
48
virtual int addMsg(KMMessage* msg, int* index_return = 0);
50
/** Remove (first occurrence of) given message from the folder. */
51
virtual void removeMsg(int i, bool imapQuiet = false);
53
// Called by KMMsgBase::setStatus when status of a message has changed
54
// required to keep the number unread messages variable current.
55
virtual void msgStatusChanged( const MessageStatus& oldStatus,
56
const MessageStatus& newStatus,
59
/** Open folder for access.
60
Does nothing if the folder is already opened. To reopen a folder
62
Returns zero on success and an error code equal to the c-library
63
fopen call otherwise (errno). */
64
virtual int open( const char *owner );
66
virtual bool canAccess() const;
68
/** fsync buffers to disk */
71
/** Close folder. If force is true the files are closed even if
72
others still use it (e.g. other mail reader windows). */
73
virtual void reallyDoClose();
75
/** Create the necessary folders for a maildir folder. Usually you will
76
want to use create() instead.
78
@param folderPath the full path of the folder as returned by location()
79
@return 0 on success and an error code (cf. man 3 errno) otherwise
81
static int createMaildirFolders( const QString & folderPath );
83
static QString constructValidFileName( const QString & filename = QString(),
84
const MessageStatus & status = MessageStatus::statusNew() );
86
static bool removeFile( const QString & folderPath,
87
const QString & filename );
92
/** Remove some deleted messages from the folder. Returns zero on success
93
and an errno on failure. This is only for use from MaildirCompactionJob. */
94
int compact( int startIndex, int nbMessages, const QStringList& entryList, bool& done );
96
/** Remove deleted messages from the folder. Returns zero on success
97
and an errno on failure. */
98
virtual int compact( bool silent );
100
/** Is the folder read-only? */
101
virtual bool isReadOnly() const { return false; }
104
virtual qint64 doFolderSize() const;
106
/** Create index file from messages file and fill the message-info list
107
mMsgList. Returns 0 on success and an errno value (see fopen) on
109
virtual int createIndexFromContents();
112
virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
113
const QString &partSpecifier, const AttachmentStrategy *as ) const;
114
virtual FolderJob* doCreateJob( QList<KMMessage*>& msgList, const QString& sets,
115
FolderJob::JobType jt, KMFolder *folder ) const;
116
/** Load message from file and store it at given index. Returns 0
118
virtual KMMessage* readMsg(int idx);
120
/** Called by KMFolder::remove() to delete the actual contents.
121
At the time of the call the folder has already been closed, and
122
the various index files deleted. Returns 0 on success. */
123
virtual int removeContents();
125
/** Called by KMFolder::expunge() to delete the actual contents.
126
At the time of the call the folder has already been closed, and
127
the various index files deleted. Returns 0 on success. */
128
virtual int expungeContents();
131
* Internal helper called by addMsg. If stripUid is true it will remove any
132
* uid headers and uid index setting before writing. KMFolderCachedImap needs this
133
* but can't do it itself, since the final take() which removes the original mail
134
* from the source folder, in moves, needs to happen after the adding, for safety
135
* reasons, but needs the uid, in case the source folder was an imap folder, to
136
* delete the original.
137
* TODO: Avoid this by moving the take() out of the addMsg() methods and moving it
138
* into the KMMoveCommand, where it can safely happen at a much higher level. */
139
int addMsgInternal( KMMessage* msg, int* index_return = 0, bool stripUid=false );
142
void slotDirSizeJobResult( KJob* job );
145
void readFileHeaderIntern( const QString& dir, const QString& file,
146
MessageStatus& status);
147
QString moveInternal( const QString& oldLoc, const QString& newLoc,
149
QString moveInternal( const QString& oldLoc, const QString& newLoc,
150
QString& aFileName, const MessageStatus& status );
151
bool removeFile( const QString& filename );
153
/** Tests whether the contents of this folder is newer than the index.
154
Returns IndexTooOld if the index is older than the contents.
155
Returns IndexMissing if there is no index.
156
Returns IndexOk if the index is not older than the contents.
158
virtual IndexStatus indexStatus();
161
mutable bool mCurrentlyCheckingFolderSize;
163
#endif /*kmfoldermaildir_h*/