/** * @file maildir.h * @brief Declaration of the Maildir class. * @author Andreas Aardal Hanssen * @date 2002-2005 */ #ifndef maildir_h_included #define maildir_h_included #include "mailbox.h" #include "maildirmessage.h" #include #include #include namespace Binc { static const std::string CACHEFILEVERSION = "1.0.5"; static const std::string UIDVALFILEVERSION = "1.0.5"; class Lock { public: Lock(const std::string &path); ~Lock(); private: std::string lock; }; class MaildirIndexItem { public: unsigned int uid; std::string fileName; }; class MaildirIndex { private: std::map idx; public: void insert(const std::string &unique, unsigned int uid, const std::string &fileName = ""); void remove(const std::string &unique); void clear(); void clearFileNames(); void clearUids(); unsigned int getSize() const; MaildirIndexItem *find(const std::string &unique); }; class Maildir : public Mailbox { public: typedef std::map MessageMap; class iterator : public BaseIterator { public: iterator(); iterator(Maildir *home, MessageMap::iterator i, const SequenceSet &bset, unsigned int mod = INCLUDE_EXPUNGED | SQNR_MODE); iterator(const iterator ©); ~iterator(); Message &operator*(); void operator++(); bool operator==(const BaseIterator &) const; bool operator!=(const BaseIterator &) const; iterator &operator=(const iterator ©); void erase(); friend class Maildir; protected: void reposition(); MaildirMessage &curMessage(); private: Maildir *mailbox; SequenceSet bset; int mod; MessageMap::iterator i; unsigned int uidmax; unsigned int sqnrmax; iterator(iterator &external); }; const std::string getTypeName() const; Mailbox::iterator begin(const SequenceSet &bset, unsigned int mod = INCLUDE_EXPUNGED | SQNR_MODE) const; Mailbox::iterator end() const; unsigned int getMaxUid() const; unsigned int getMaxSqnr() const; unsigned int getUidValidity() const; unsigned int getUidNext() const; bool getUpdates(bool doscan, unsigned int type, PendingUpdates &updates, bool forceScan); const std::string &getPath() const; void setPath(const std::string &path_in); void bumpUidValidity(const std::string &) const; unsigned int getStatusID(const std::string &) const; bool getStatus(const std::string &, Status &) const; void updateFlags(); bool isMailbox(const std::string &) const; bool isMarked(const std::string &) const; bool selectMailbox(const std::string &name, const std::string &s_in); void closeMailbox(); void expungeMailbox(); bool createMailbox(const std::string &s, mode_t mode, uid_t owner = 0, gid_t group = 0, bool root = false); bool deleteMailbox(const std::string &s); Message *createMessage(const std::string &mbox, time_t idate = 0); bool commitNewMessages(const std::string &mbox); bool rollBackNewMessages(); bool fastCopy(Message &source, Mailbox &desttype, const std::string &destname); Maildir(); ~Maildir(); friend class Maildir::iterator; friend class MaildirMessage; protected: enum ReadCacheResult { Ok, NoCache, Error }; ReadCacheResult readCache(); bool writeCache(); bool scanFileNames() const; enum ScanResult { Success = 0, TemporaryError = 1, PermanentError = 2 }; ScanResult scan(bool forceScan = false); MaildirMessage *get(const std::string &id); void add(MaildirMessage &m); private: std::vector newMessages; unsigned int uidvalidity; unsigned int uidnext; bool selected; std::string path; mutable iterator beginIterator; mutable iterator endIterator; mutable bool firstscan; mutable bool cacheRead; mutable MaildirIndex index; mutable MessageMap messages; mutable unsigned int oldrecent; mutable unsigned int oldexists; mutable time_t old_bincimap_cache_st_mtime; mutable time_t old_bincimap_cache_st_ctime; mutable time_t old_cur_st_mtime; mutable time_t old_cur_st_ctime; mutable time_t old_new_st_mtime; mutable time_t old_new_st_ctime; mutable bool mailboxchanged; }; } #endif