kmail

folderstorage.h
1 /*
2  Virtual base class for mail storage.
3 
4  This file is part of KMail.
5 
6  Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with this library; see the file COPYING.LIB. If not, write to
20  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA.
22 
23  In addition, as a special exception, the copyright holders give
24  permission to link the code of this program with any edition of
25  the TQt library by Trolltech AS, Norway (or with modified versions
26  of TQt that use the same license as TQt), and distribute linked
27  combinations including the two. You must obey the GNU General
28  Public License in all respects for all of the code used other than
29  TQt. If you modify this file, you may extend this exception to
30  your version of the file, but you are not obligated to do so. If
31  you do not wish to do so, delete this exception statement from
32  your version.
33 */
34 
35 #ifndef FOLDERSTORAGE_H
36 #define FOLDERSTORAGE_H
37 
38 // for large file support
39 #include <config.h>
40 
41 #include "kmfoldernode.h"
42 #include "kmfoldertype.h"
43 #include "kmmsginfo.h"
44 #include "kmglobal.h"
45 #include "folderjob.h"
46 using KMail::FolderJob;
47 
48 #include "mimelib/string.h"
49 
50 #include <sys/types.h>
51 #include <stdio.h>
52 
53 class KMMessage;
54 class KMAccount;
55 class KMFolderDir;
56 class KMMsgDict; // for the rDict manipulations
57 class KMMsgDictREntry;
58 class TQTimer;
59 class KMSearchPattern;
60 
61 namespace KMail {
62  class AttachmentStrategy;
63 }
64 using KMail::AttachmentStrategy;
65 
66 typedef TQValueList<TQ_UINT32> SerNumList;
67 
79 class FolderStorage : public TQObject
80 {
81  TQ_OBJECT
82 
83 
84 public:
85 
86 
90  FolderStorage( KMFolder* folder, const char* name=0 );
91  virtual ~FolderStorage();
92 
93  KMFolder* folder() const { return mFolder; }
94 
96  virtual KMFolderType folderType() const { return KMFolderTypeUnknown; }
97 
99  virtual TQString fileName() const;
101  TQString location() const;
102 
104  virtual TQString indexLocation() const = 0;
105 
107  virtual bool noContent() const { return mNoContent; }
108 
110  virtual void setNoContent(bool aNoContent);
111 
113  virtual bool noChildren() const { return mNoChildren; }
114 
116  virtual void setNoChildren( bool aNoChildren );
117 
118  enum ChildrenState {
119  HasChildren,
120  HasNoChildren,
121  ChildrenUnknown
122  };
125  virtual ChildrenState hasChildren() const { return mHasChildren; }
126 
128  virtual void setHasChildren( ChildrenState state )
129  { mHasChildren = state; }
130 
132  virtual void updateChildrenState();
133 
135  virtual KMMessage* getMsg(int idx);
136 
138  virtual KMMsgInfo* unGetMsg(int idx);
139 
141  virtual bool isMessage(int idx);
142 
147  virtual KMMessage* readTemporaryMsg(int idx);
148 
150  virtual DwString getDwString(int idx) = 0;
151 
155  virtual void ignoreJobsForMessage( KMMessage* );
156 
161  virtual FolderJob* createJob( KMMessage *msg, FolderJob::JobType jt = FolderJob::tGetMessage,
162  KMFolder *folder = 0, TQString partSpecifier = TQString(),
163  const AttachmentStrategy *as = 0 ) const;
164  virtual FolderJob* createJob( TQPtrList<KMMessage>& msgList, const TQString& sets,
165  FolderJob::JobType jt = FolderJob::tGetMessage,
166  KMFolder *folder = 0 ) const;
167 
172  virtual const KMMsgBase* getMsgBase(int idx) const = 0;
173  virtual KMMsgBase* getMsgBase(int idx) = 0;
174 
176  virtual const KMMsgBase* operator[](int idx) const { return getMsgBase(idx); }
177 
179  virtual KMMsgBase* operator[](int idx) { return getMsgBase(idx); }
180 
183  virtual KMMessage* take(int idx);
184  virtual void take(TQPtrList<KMMessage> msgList);
185 
192  virtual int addMsg(KMMessage* msg, int* index_return = 0) = 0;
193 
197  virtual int addMsgKeepUID(KMMessage* msg, int* index_return = 0) {
198  return addMsg(msg, index_return);
199  }
200 
205  virtual int addMsg( TQPtrList<KMMessage>&, TQValueList<int>& index_return );
206 
209  void emitMsgAddedSignals(int idx);
210 
213  virtual bool canAddMsgNow(KMMessage* aMsg, int* aIndex_ret);
214 
216  virtual void removeMsg(int i, bool imapQuiet = false);
217  virtual void removeMsg(const TQPtrList<KMMsgBase>& msgList, bool imapQuiet = false);
218  virtual void removeMsg(const TQPtrList<KMMessage>& msgList, bool imapQuiet = false);
219 
222  virtual int expungeOldMsg(int days);
223 
228  virtual int moveMsg(KMMessage* msg, int* index_return = 0);
229  virtual int moveMsg(TQPtrList<KMMessage>, int* index_return = 0);
230 
232  virtual int find(const KMMsgBase* msg) const = 0;
233  int find( const KMMessage * msg ) const;
234 
236  virtual int count(bool cache = false) const;
237 
239  virtual int countUnread();
240 
242  TQ_INT64 folderSize() const;
243 
246  virtual bool isCloseToQuota() const;
247 
250  virtual void msgStatusChanged( const KMMsgStatus oldStatus,
251  const KMMsgStatus newStatus,
252  int idx);
253 
259  virtual int open(const char* owner) = 0;
260 
263  virtual int canAccess() = 0;
264 
268  void close(const char* owner, bool force=false);
269  virtual void reallyDoClose(const char* owner) = 0;
270 
273  virtual void tryReleasingFolder(KMFolder*) {}
274 
276  virtual void sync() = 0;
277 
279  bool isOpened() const { return (mOpenCount>0); }
280 
282  virtual void markNewAsUnread();
283 
285  virtual void markUnreadAsRead();
286 
290  virtual int create() = 0;
291 
296  virtual void remove();
297 
301  virtual int expunge();
302 
307  virtual int compact( bool silent ) = 0;
308 
311  virtual int rename(const TQString& newName, KMFolderDir *aParent = 0);
312 
314  bool autoCreateIndex() const { return mAutoCreateIndex; }
315 
318  virtual void setAutoCreateIndex(bool);
319 
323  bool dirty() const { return mDirty; }
324 
326  void setDirty(bool f);
327 
329  bool needsCompacting() const { return needsCompact; }
330  virtual void setNeedsCompacting(bool f) { needsCompact = f; }
331 
340  virtual void quiet(bool beQuiet);
341 
343  virtual bool isReadOnly() const = 0;
344 
346  virtual bool canDeleteMessages() const;
347 
349  TQString label() const;
350 
352  virtual void correctUnreadMsgsCount();
353 
356  virtual int writeIndex( bool createEmptyIndex = false ) = 0;
357 
361 
365 
367  virtual void setStatus(int idx, KMMsgStatus status, bool toggle=false);
368 
370  virtual void setStatus(TQValueList<int>& ids, KMMsgStatus status, bool toggle=false);
371 
372  void removeJobs();
373 
375  static TQString dotEscape(const TQString&);
376 
378  virtual void readConfig();
379 
381  virtual void writeConfig();
382 
387  virtual KMFolder* trashFolder() const { return 0; }
388 
393  void addJob( FolderJob* ) const;
394 
396  bool compactable() const { return mCompactable; }
397 
399  // If quiet is true, the KMailIcalIface is not informed of the changed. That's usefull
400  // for folder that are being copied around, should retain their type, but not cause
401  // conflicts on copy because events are identical in two folders.
402  virtual void setContentsType( KMail::FolderContentsType type, bool quiet = false );
404  KMail::FolderContentsType contentsType() const { return mContentsType; }
405 
410  virtual void search( const KMSearchPattern* );
411 
416  virtual void search( const KMSearchPattern*, TQ_UINT32 serNum );
417 
419  virtual bool isMoveable() const;
420 
421  virtual KMAccount* account() const;
422 
423  virtual bool mailCheckInProgress() const;
424 
425 signals:
428  void changed();
429 
432  void cleared();
433 
436  void expunged( KMFolder* );
437 
439  void closed( KMFolder* );
440 
443 
445  void nameChanged();
446 
450  void locationChanged( const TQString &, const TQString & );
451 
454  void contentsTypeChanged( KMail::FolderContentsType type );
455 
458 
461 
463  void msgRemoved(KMFolder*, TQ_UINT32 sernum);
464 
466  void msgRemoved( int idx, TQString msgIdMD5 );
467  void msgRemoved( KMFolder* );
468 
470  void msgAdded(int idx);
471  void msgAdded(KMFolder*, TQ_UINT32 sernum);
472 
474  void msgChanged(KMFolder*, TQ_UINT32 sernum, int delta);
475 
478 
480  void statusMsg(const TQString&);
481 
484 
486  void removed(KMFolder*, bool);
487 
493  void searchResult( KMFolder*, TQValueList<TQ_UINT32>,
494  const KMSearchPattern*, bool complete );
495 
500  void searchDone( KMFolder*, TQ_UINT32, const KMSearchPattern*, bool );
501 
504 
510 
511 public slots:
513  virtual int updateIndex() = 0;
514 
517  virtual void reallyAddMsg(KMMessage* aMsg);
518 
521  virtual void reallyAddCopyOfMsg(KMMessage* aMsg);
522 
524  void slotEmitChangedTimer();
525 
526 protected slots:
527  virtual void removeJob( TQObject* );
528 
531 
532 protected:
533 
539  virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
540  TQString partSpecifier, const AttachmentStrategy *as ) const = 0;
541  virtual FolderJob* doCreateJob( TQPtrList<KMMessage>& msgList, const TQString& sets,
542  FolderJob::JobType jt, KMFolder *folder ) const = 0;
543 
547  void headerOfMsgChanged(const KMMsgBase*, int idx);
548 
551  virtual KMMessage* readMsg(int idx) = 0;
552 
553  //--------- Message Dict manipulation
554 friend class KMMsgDict;
558  virtual void fillMessageDict() {}
559 
563  void readFolderIdsFile();
564 
566  int writeFolderIdsFile() const;
567 
569  int touchFolderIdsFile();
570 
572  int appendToFolderIdsFile( int idx = -1 );
573 
577  void setRDict(KMMsgDictREntry *rentry) const;
578 
580  KMMsgDictREntry *rDict() const { return mRDict; }
581 
582 
585  void replaceMsgSerNum( unsigned long sernum, KMMsgBase* msg, int idx );
586 
590  void invalidateFolder();
591 
595  virtual int removeContents() = 0;
596 
600  virtual int expungeContents() = 0;
601 
603  virtual bool readIndex() = 0;
604  virtual KMMsgBase* takeIndexEntry( int idx ) = 0;
605  virtual KMMsgInfo* setIndexEntry( int idx, KMMessage *msg ) = 0;
606  virtual void clearIndex(bool autoDelete=true, bool syncDict = false) = 0;
607  virtual void truncateIndex() = 0;
608 
609  virtual TQ_INT64 doFolderSize() const { return 0; };
610 
611  int mOpenCount;
612  int mQuiet;
613  bool mChanged :1;
620  bool mDirty :1;
622  bool mFilesLocked :1;
623 
625  int mUnreadMsgs, mGuessedUnreadMsgs;
626  int mTotalMsgs;
627  TQ_INT64 mSize;
628  bool mWriteConfigEnabled :1;
630  bool needsCompact :1;
632  bool mCompactable :1;
633  bool mNoContent :1;
634  bool mNoChildren :1;
635  bool mConvertToUtf8 :1;
636 
638  mutable KMMsgDictREntry *mRDict;
640  mutable TQPtrList<FolderJob> mJobList;
641 
642  TQTimer *mDirtyTimer;
643  enum { mDirtyTimerInterval = 600000 }; // 10 minutes
644 
645  ChildrenState mHasChildren;
646 
648  KMail::FolderContentsType mContentsType;
649 
650  KMFolder* mFolder;
651 
652  TQTimer * mEmitChangedTimer;
653 
654  int mCurrentSearchedMsg;
655  const KMSearchPattern* mSearchPattern;
656 };
657 
658 #endif // FOLDERSTORAGE_H
The FolderStorage class is the bass class for the storage related aspects of a collection of mail (a ...
Definition: folderstorage.h:80
virtual FolderJob * doCreateJob(KMMessage *msg, FolderJob::JobType jt, KMFolder *folder, TQString partSpecifier, const AttachmentStrategy *as) const =0
These two methods actually create the jobs.
virtual bool isMessage(int idx)
Checks if the message is already "gotten" with getMsg.
virtual int countUnread()
Number of new or unread messages in this folder.
void folderSizeChanged()
Emitted when the folder's size changes.
virtual int create()=0
Create a new folder with the name of this object and open it.
virtual void ignoreJobsForMessage(KMMessage *)
Removes and deletes all jobs associated with the particular message.
void nameChanged()
Emitted when the name of the folder changes.
virtual DwString getDwString(int idx)=0
Read a message and returns a DwString.
virtual void markNewAsUnread()
Mark all new messages as unread.
int writeFolderIdsFile() const
Writes the message serial number file.
virtual int open(const char *owner)=0
Open folder for access.
virtual TQString indexLocation() const =0
Returns full path to index file.
virtual KMMessage * take(int idx)
Detach message from this folder.
virtual int count(bool cache=false) const
Number of messages in this folder.
void invalidated(KMFolder *)
Emitted when the serial numbers of this folder were invalidated.
virtual bool noChildren() const
Returns, if the folder can't have children.
void cleared()
Emitted when the contents of a folder have been cleared (new search in a search folder,...
void emitMsgAddedSignals(int idx)
Called by derived classes implementation of addMsg.
void msgHeaderChanged(KMFolder *, int)
Emitted when a field of the header of a specific message changed.
virtual bool isMoveable() const
Returns true if this folder can be moved.
void slotEmitChangedTimer()
Emit changed signal if mQuite <=0.
virtual int updateIndex()=0
Incrementally update the index if possible else call writeIndex.
virtual int expungeOldMsg(int days)
Delete messages in the folder that are older than days.
virtual KMMessage * readTemporaryMsg(int idx)
Load message from file and do NOT store it, only return it.
virtual int rename(const TQString &newName, KMFolderDir *aParent=0)
Physically rename the folder.
virtual bool readIndex()=0
Read index file and fill the message-info list mMsgList.
virtual void setContentsType(KMail::FolderContentsType type, bool quiet=false)
Set the type of contents held in this folder (mail, calendar, etc.)
bool isOpened() const
Test if folder is opened, i.e.
virtual void msgStatusChanged(const KMMsgStatus oldStatus, const KMMsgStatus newStatus, int idx)
Called by KMMsgBase::setStatus when status of a message has changed required to keep the number unrea...
int appendToFolderIdsFile(int idx=-1)
Append message to end of message serial number file.
void registerWithMessageDict()
Triggers registration with the message dict, which will cause the dict to ask the FolderStorage to fi...
virtual TQString fileName() const
Returns the filename of the folder (reimplemented in KMFolderImap)
void msgRemoved(KMFolder *, TQ_UINT32 sernum)
Emitted before a message is removed from the folder.
virtual int find(const KMMsgBase *msg) const =0
Returns the index of the given message or -1 if not found.
void msgRemoved(int idx, TQString msgIdMD5)
Emitted after a message is removed from the folder.
virtual void reallyAddMsg(KMMessage *aMsg)
Add the message to the folder after it has been retrieved from an IMAP server.
bool needsCompact
sven: true if on destruct folder needs to be compacted.
bool needsCompacting() const
Returns TRUE if the folder contains deleted messages.
void msgChanged(KMFolder *, TQ_UINT32 sernum, int delta)
Emitted, when the status of a message is changed.
void expunged(KMFolder *)
Emitted after an expunge.
virtual FolderJob * createJob(KMMessage *msg, FolderJob::JobType jt=FolderJob::tGetMessage, KMFolder *folder=0, TQString partSpecifier=TQString(), const AttachmentStrategy *as=0) const
These methods create respective FolderJob (You should derive FolderJob for each derived KMFolder).
virtual KMMessage * readMsg(int idx)=0
Load message from file and store it at given index.
virtual void setHasChildren(ChildrenState state)
Specify if the folder has children.
int touchFolderIdsFile()
Touches the message serial number file.
void syncStateChanged()
Emiitted when the sync state, i.e.
virtual const KMMsgBase * operator[](int idx) const
Same as getMsgBase(int).
bool autoCreateIndex() const
Returns TRUE if a table of contents file is automatically created.
void addJob(FolderJob *) const
Add job for this folder.
void statusMsg(const TQString &)
Emmited to display a message somewhere in a status line.
virtual void readConfig()
Read the config file.
virtual int addMsgKeepUID(KMMessage *msg, int *index_return=0)
(Note(bo): This needs to be fixed better at a later point.) This is overridden by dIMAP because addMs...
static TQString dotEscape(const TQString &)
Escape a leading dot.
bool mFilesLocked
TRUE if the files of the folder are locked (writable)
FolderStorage(KMFolder *folder, const char *name=0)
Usually a parent is given.
virtual void markUnreadAsRead()
Mark all new and unread messages as read.
void numUnreadMsgsChanged(KMFolder *)
Emitted when number of unread messages has changed.
void replaceMsgSerNum(unsigned long sernum, KMMsgBase *msg, int idx)
Replaces the serial number for the message msg at index idx with sernum.
void changed()
Emitted when the status, name, or associated accounts of this folder changed.
virtual void setStatus(int idx, KMMsgStatus status, bool toggle=false)
Set the status of the message at index idx to status.
void invalidateFolder()
Called when serial numbers for a folder are invalidated, invalidates/recreates data structures depend...
TQPtrList< FolderJob > mJobList
List of jobs created by this folder.
bool compactable() const
false if index file is out of sync with mbox file
virtual int expunge()
Delete entire folder.
virtual KMFolder * trashFolder() const
If this folder has a special trash folder set, return it.
bool mExportsSernums
Has this storage exported its serial numbers to the global message dict for lookup?
virtual void correctUnreadMsgsCount()
A cludge to help make sure the count of unread messges is kept in sync.
virtual void reallyAddCopyOfMsg(KMMessage *aMsg)
Add a copy of the message to the folder after it has been retrieved from an IMAP server.
virtual KMFolderType folderType() const
Returns the type of this folder.
Definition: folderstorage.h:96
virtual int expungeContents()=0
Called by KMFolder::expunge() to delete the actual contents.
virtual void updateChildrenState()
Updates the hasChildren() state.
void searchDone(KMFolder *, TQ_UINT32, const KMSearchPattern *, bool)
Emitted when a search for a single message is completed The serial number and a bool matching yes/no ...
virtual void removeMsg(int i, bool imapQuiet=false)
Remove (first occurrence of) given message from the folder.
void readFolderIdsFile()
Read the on-disk cache of serial numbers of messages in this store and fill those into the global mes...
virtual void tryReleasingFolder(KMFolder *)
Try releasing folder if possible, something is attempting an exclusive access to it.
virtual bool canAddMsgNow(KMMessage *aMsg, int *aIndex_ret)
Returns FALSE, if the message has to be retrieved from an IMAP account first.
void setDirty(bool f)
Change the dirty flag.
void headerOfMsgChanged(const KMMsgBase *, int idx)
Tell the folder that a header field that is usually used for the index (subject, from,...
KMail::FolderContentsType mContentsType
Type of contents in this folder.
virtual void search(const KMSearchPattern *)
Search for messages The end is signaled with searchDone()
virtual void remove()
Removes the folder physically from disk and empties the contents of the folder in memory.
virtual bool canDeleteMessages() const
Can messages in this folder be deleted?
KMail::FolderContentsType contentsType() const
virtual KMMsgBase * operator[](int idx)
Same as getMsgBase(int).
void close(const char *owner, bool force=false)
Close folder.
virtual KMMsgInfo * unGetMsg(int idx)
Replace KMMessage with KMMsgInfo and delete KMMessage
virtual int removeContents()=0
Called by KMFolder::remove() to delete the actual contents.
void noContentChanged()
Emitted when the no content state of the folder changes.
bool mDirty
if the index is dirty it will be recreated upon close()
virtual void writeConfig()
Write the config file.
void locationChanged(const TQString &, const TQString &)
Emitted when the location on disk of the folder changes.
virtual int moveMsg(KMMessage *msg, int *index_return=0)
Detaches the given message from it's current folder and adds it to this folder.
virtual void sync()=0
fsync buffers to disk
virtual int addMsg(KMMessage *msg, int *index_return=0)=0
Add the given message to the folder.
void removed(KMFolder *, bool)
Emitted when a folder was removed.
bool dirty() const
Returns TRUE if the table of contents is dirty.
void slotProcessNextSearchBatch()
Process the next search batch.
void msgAdded(int idx)
Emitted when a message is added from the folder.
virtual int canAccess()=0
Check folder for permissions Returns zero if readable and writable.
virtual void setAutoCreateIndex(bool)
Allow/disallow automatic creation of a table of contents file.
void searchResult(KMFolder *, TQValueList< TQ_UINT32 >, const KMSearchPattern *, bool complete)
Emitted when a search delivers results The matching serial numbers are included If complete is true t...
virtual bool noContent() const
Returns, if the folder can't contain mails, but only subfolder.
TQString label() const
Returns the label of the folder for visualization.
bool mCompactable
false if index file is out of sync with mbox file
virtual void setNoChildren(bool aNoChildren)
Specify, that the folder can't have children.
void setRDict(KMMsgDictREntry *rentry) const
Sets the reverse-dictionary for this folder.
KMMsgDictREntry * rDict() const
Returns the reverse-dictionary for this folder.
KMMsgDictREntry * mRDict
Points at the reverse dictionary for this folder.
void readOnlyChanged(KMFolder *)
Emitted when the readonly status of the folder changes.
TQString location() const
Returns full path to folder file.
void contentsTypeChanged(KMail::FolderContentsType type)
Emitted when the contents type (calendar, mail, tasks, ..) of the folderstorage changes.
virtual void fillMessageDict()
Inserts messages into the message dictionary.
virtual bool isReadOnly() const =0
Is the folder read-only?
virtual KMMessage * getMsg(int idx)
Read message at given index.
int mUnreadMsgs
number of unread messages, -1 if not yet set
virtual const KMMsgBase * getMsgBase(int idx) const =0
Provides access to the basic message fields that are also stored in the index.
virtual int writeIndex(bool createEmptyIndex=false)=0
Write index to index-file.
bool mAutoCreateIndex
is the automatic creation of a index file allowed ?
void closed(KMFolder *)
Emitted when the folder was closed and ticket owners have to reopen.
virtual bool isCloseToQuota() const
Return whether the folder is close to its quota limit, which can be reflected in the UI.
TQ_INT64 folderSize() const
Total size of the contents of this folder.
virtual int compact(bool silent)=0
Remove deleted messages from the folder.
virtual void quiet(bool beQuiet)
If set to quiet the folder will not emit msgAdded(idx) signal.
void deregisterFromMessageDict()
Triggers deregistration from the message dict, which will cause the dict to ask the FolderStorage to ...
virtual void setNoContent(bool aNoContent)
Specify, that the folder can't contain mails.
virtual ChildrenState hasChildren() const
Returns if the folder has children, has no children or we don't know.
KMail list that manages the contents of one directory that may contain folders and/or other directori...
Definition: kmfolderdir.h:16
Mail folder.
Definition: kmfolder.h:69
This is a Mime Message.
Definition: kmmessage.h:68
KMail message dictionary.
Definition: kmmsgdict.h:53
This class is an abstraction of a search over messages.
folderdiaquotatab.h
Definition: aboutdata.cpp:40