kmail

kmfoldermbox.h
1 /*
2  * kmail: KDE mail client
3  * Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  */
20 #ifndef kmfoldermbox_h
21 #define kmfoldermbox_h
22 
23 #include "kmfolderindex.h"
24 #include "mboxjob.h"
25 
26 #include <sys/types.h> // for size_t
27 
28 namespace KMail {
29  class FolderJob;
30  class MboxJob;
31  class AttachmentStrategy;
32 }
33 using KMail::FolderJob;
34 using KMail::MboxJob;
35 using KMail::AttachmentStrategy;
36 
37 /* Mail folder.
38  * (description will be here).
39  *
40  * Accounts:
41  * The accounts (of KMail) that are fed into the folder are
42  * represented as the children of the folder. They are only stored here
43  * during runtime to have a reference for which accounts point to a
44  * specific folder.
45  */
46 
47 class KMFolderMbox : public KMFolderIndex
48 {
49  Q_OBJECT
50 
51  friend class ::KMail::MboxJob;
52 public:
53 
54 
58  KMFolderMbox(KMFolder* folder, const char* name=0);
59  virtual ~KMFolderMbox();
60 
62  virtual KMFolderType folderType() const { return KMFolderTypeMbox; }
63 
65  DwString getDwString(int idx);
66 
73  virtual int addMsg( KMMessage* msg, int* index_return = 0 );
74 
80  virtual int open(const char *owner);
81 
83  virtual void reallyDoClose(const char *owner);
84 
85  virtual int canAccess();
86 
88  virtual void sync();
89 
91  virtual int create();
92 
95  virtual int compact( bool silent );
96 
99  int compact( unsigned int startIndex, int nbMessages, FILE* tmpFile, off_t& offs, bool& done );
100 
102  virtual bool isReadOnly() const { return mReadOnly; }
103 
105  bool isLocked() const { return mFilesLocked; }
106 
107  void setLockType( LockType ltype=FCNTL );
108 
109  void setProcmailLockFileName( const TQString& );
110 
111  static TQByteArray escapeFrom( const DwString & str );
112 
113  virtual IndexStatus indexStatus();
114 
116  virtual TQ_INT64 doFolderSize() const;
117 
118 protected:
119  virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
120  TQString partSpecifier, const AttachmentStrategy *as ) const;
121  virtual FolderJob* doCreateJob( TQPtrList<KMMessage>& msgList, const TQString& sets,
122  FolderJob::JobType jt, KMFolder *folder ) const;
125  virtual KMMessage* readMsg(int idx);
126 
130  virtual int createIndexFromContents();
131 
134  virtual int lock();
135 
138  virtual int unlock();
139 
143  virtual int removeContents();
144 
148  virtual int expungeContents();
149 
150 private:
151  FILE *mStream;
152  bool mFilesLocked; // TRUE if the files of the folder are locked (writable)
153  bool mReadOnly; // true if locking failed
154  LockType mLockType;
155  TQString mProcmailLockFileName;
156 };
157 
158 #endif // kmfoldermbox_h