mailbox.h (4897B)
1 /* -*- Mode: c++; -*- */ 2 /* -------------------------------------------------------------------- 3 * Filename: 4 * src/mailbox/mailbox.h 5 * 6 * Description: 7 * Declaration of the Mailbox class. 8 * 9 * Authors: 10 * Andreas Aardal Hanssen <andreas-binc curly bincimap spot org> 11 * 12 * Bugs: 13 * 14 * ChangeLog: 15 * 16 * -------------------------------------------------------------------- 17 * Copyright 2002-2005 Andreas Aardal Hanssen 18 * 19 * This program is free software; you can redistribute it and/or modify 20 * it under the terms of the GNU General Public License as published by 21 * the Free Software Foundation; either version 2 of the License, or 22 * (at your option) any later version. 23 * 24 * This program is distributed in the hope that it will be useful, 25 * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 * GNU General Public License for more details. 28 * 29 * You should have received a copy of the GNU General Public License 30 * along with this program; if not, write to the Free Software 31 * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. 32 * -------------------------------------------------------------------- 33 */ 34 #ifdef HAVE_CONFIG_H 35 #include <config.h> 36 #endif 37 38 #ifndef mailbox_h_included 39 #define mailbox_h_included 40 41 #include <map> 42 #include <string> 43 #include <queue> 44 #include <vector> 45 46 #include <time.h> 47 #include <stdio.h> 48 #include <string.h> 49 #include <sys/types.h> 50 51 #include "imapparser.h" 52 53 namespace Binc { 54 55 class Message; 56 class Status; 57 class PendingUpdates; 58 class File; 59 60 //------------------------------------------------------------------------ 61 class Mailbox { 62 public: 63 64 //---------------------------------------------------------------------- 65 class BaseIterator { 66 public: 67 BaseIterator(int sqn = 0); 68 virtual ~BaseIterator(void); 69 70 virtual Message &operator *(void) = 0; 71 virtual void operator ++(void) = 0; 72 virtual bool operator !=(const BaseIterator &d) const = 0; 73 virtual bool operator ==(const BaseIterator &d) const = 0; 74 75 virtual void erase(void) = 0; 76 77 unsigned int sqnr; 78 }; 79 80 //---------------------------------------------------------------------- 81 class iterator { 82 public: 83 iterator(BaseIterator &i); 84 85 Message &operator *(void); 86 void operator ++(void); 87 bool operator ==(const iterator &) const; 88 bool operator !=(const iterator &) const; 89 90 unsigned int getSqnr() const; 91 92 void erase(void); 93 94 protected: 95 BaseIterator &realIterator; 96 }; 97 98 enum Iterator { 99 INCLUDE_EXPUNGED = 1, 100 SKIP_EXPUNGED = 2 101 }; 102 103 enum Mode { 104 UID_MODE = 4, 105 SQNR_MODE = 8 106 }; 107 108 virtual iterator begin(const SequenceSet &bset, unsigned int mod = INCLUDE_EXPUNGED | SQNR_MODE) const = 0; 109 virtual iterator end(void) const = 0; 110 111 //-- Generic for one mailbox type 112 virtual bool getStatus(const std::string &, Status &) const = 0; 113 virtual bool isMailbox(const std::string &) const = 0; 114 virtual bool isMarked(const std::string &) const = 0; 115 virtual unsigned int getStatusID(const std::string &) const = 0; 116 virtual void bumpUidValidity(const std::string &) const = 0; 117 118 //-- Specific for one mailbox 119 void setReadOnly(bool readOnly); 120 bool isReadOnly(void) const; 121 122 virtual const std::string getTypeName(void) const = 0; 123 const std::string getName(void) const; 124 void setName(const std::string &name); 125 126 virtual unsigned int getMaxUid(void) const = 0; 127 virtual unsigned int getMaxSqnr(void) const = 0; 128 virtual unsigned int getUidNext(void) const = 0; 129 virtual unsigned int getUidValidity(void) const = 0; 130 131 virtual bool getUpdates(bool scan, unsigned int type, 132 PendingUpdates &updates, bool forceScan) = 0; 133 134 virtual void updateFlags(void) = 0; 135 virtual void expungeMailbox(void) = 0; 136 virtual bool selectMailbox(const std::string &name, const std::string &s_in) = 0; 137 virtual bool createMailbox(const std::string &s, mode_t mode, uid_t owner = 0, gid_t group = 0, bool root = false) = 0; 138 virtual bool deleteMailbox(const std::string &s) = 0; 139 virtual void closeMailbox(void) = 0; 140 141 virtual Message *createMessage(const std::string &mbox, time_t idate = 0) = 0; 142 virtual bool commitNewMessages(const std::string &mbox) = 0; 143 virtual bool rollBackNewMessages(void) = 0; 144 virtual bool fastCopy(Message &source, Mailbox &desttype, const std::string &destname) = 0; 145 146 const std::string &getLastError(void) const; 147 void setLastError(const std::string &error) const; 148 149 //-- 150 Mailbox(void); 151 virtual ~Mailbox(void); 152 153 friend class Mailbox::iterator; 154 155 protected: 156 bool readOnly; 157 158 private: 159 Mailbox(const Mailbox ©); 160 161 mutable std::string lastError; 162 163 std::string name; 164 }; 165 } 166 167 #endif