summaryrefslogtreecommitdiff
path: root/src/include/mailbox.h
blob: 870a6959e90eb92c435fbb131d5dd22d409bebfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**  --------------------------------------------------------------------
 *  @file mailbox.h
 *  @brief Declaration of the Mailbox class (Mailbox is logical container)
 *  @author Andreas Aardal Hanssen
 *  @date 2002-2005
 *  -----------------------------------------------------------------  **/
#ifndef mailbox_h_included
#define mailbox_h_included

#include "imapparser.h"

#include <map>
#include <queue>
#include <string>
#include <vector>

#include <stdio.h>
#include <string.h>
#include <time.h>

#include <sys/types.h>

namespace Binc {

  class Message;
  class Status;
  class PendingUpdates;
  class File;

  //------------------------------------------------------------------------
  class Mailbox {
  public:
    //----------------------------------------------------------------------
    class BaseIterator {
    public:
      BaseIterator(int sqn = 0);
      virtual ~BaseIterator(void);

      virtual Message &operator*(void) = 0;
      virtual void operator++(void) = 0;
      virtual bool operator!=(const BaseIterator &d) const = 0;
      virtual bool operator==(const BaseIterator &d) const = 0;

      virtual void erase(void) = 0;

      unsigned int sqnr;
    };

    //----------------------------------------------------------------------
    class iterator {
    public:
      iterator(BaseIterator &i);

      Message &operator*(void);
      void operator++(void);
      bool operator==(const iterator &) const;
      bool operator!=(const iterator &) const;

      unsigned int getSqnr() const;

      void erase(void);

    protected:
      BaseIterator &realIterator;
    };

    enum Iterator { INCLUDE_EXPUNGED = 1, SKIP_EXPUNGED = 2 };

    enum Mode { UID_MODE = 4, SQNR_MODE = 8 };

    virtual iterator begin(const SequenceSet &bset,
                           unsigned int mod = INCLUDE_EXPUNGED | SQNR_MODE) const = 0;
    virtual iterator end(void) const = 0;

    //-- Generic for one mailbox type
    virtual bool getStatus(const std::string &, Status &) const = 0;
    virtual bool isMailbox(const std::string &) const = 0;
    virtual bool isMarked(const std::string &) const = 0;
    virtual unsigned int getStatusID(const std::string &) const = 0;
    virtual void bumpUidValidity(const std::string &) const = 0;

    //-- Specific for one mailbox
    void setReadOnly(bool readOnly);
    bool isReadOnly(void) const;

    virtual const std::string getTypeName(void) const = 0;
    const std::string getName(void) const;
    void setName(const std::string &name);

    virtual unsigned int getMaxUid(void) const = 0;
    virtual unsigned int getMaxSqnr(void) const = 0;
    virtual unsigned int getUidNext(void) const = 0;
    virtual unsigned int getUidValidity(void) const = 0;

    virtual bool getUpdates(bool scan, unsigned int type, PendingUpdates &updates, bool forceScan) = 0;

    virtual void updateFlags(void) = 0;
    virtual void expungeMailbox(void) = 0;
    virtual bool selectMailbox(const std::string &name, const std::string &s_in) = 0;
    virtual bool createMailbox(const std::string &s,
                               mode_t mode,
                               uid_t owner = 0,
                               gid_t group = 0,
                               bool root = false) = 0;
    virtual bool deleteMailbox(const std::string &s) = 0;
    virtual void closeMailbox(void) = 0;

    virtual Message *createMessage(const std::string &mbox, time_t idate = 0) = 0;
    virtual bool commitNewMessages(const std::string &mbox) = 0;
    virtual bool rollBackNewMessages(void) = 0;
    virtual bool fastCopy(Message &source, Mailbox &desttype, const std::string &destname) = 0;

    const std::string &getLastError(void) const;
    void setLastError(const std::string &error) const;

    //--
    Mailbox(void);
    virtual ~Mailbox(void);

    friend class Mailbox::iterator;

  protected:
    bool readOnly;

  private:
    Mailbox(const Mailbox &copy);

    mutable std::string lastError;

    std::string name;
  };
}

#endif