summaryrefslogtreecommitdiff
path: root/src/include/imapparser.h
blob: 5dfffb4fe0f36090e8c49d5174aa641508973836 (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**  --------------------------------------------------------------------
 *  @file imapparser.h
 *  @brief  Declaration of the common items for parsing IMAP input
 *  @author Andreas Aardal Hanssen
 *  @date 2002-2005
 *  -----------------------------------------------------------------  **/
#ifndef imapparser_h_included
#define imapparser_h_included

/* stl includes */
#include <map>
#include <string>
#include <vector>

namespace Binc {
  //------------------------------------------------------------------------
  class SequenceSet {
  public:
    void addRange(unsigned int a_in, unsigned int b_in);
    bool isInSet(unsigned int n) const;
    void addNumber(unsigned int a_in);

    inline bool isLimited(void) const
    {
      return limited;
    }

    static SequenceSet &all(void);

    static SequenceSet &null(void);

    SequenceSet &operator=(const SequenceSet &copy);

    SequenceSet(void);
    SequenceSet(const SequenceSet &copy);
    ~SequenceSet(void);

  protected:
    bool isNull(void) const;

  private:
    bool limited;
    bool nullSet;

    class Range {
    public:
      unsigned int from;
      unsigned int to;
      Range(unsigned int from, unsigned int to);
    };

    std::vector<Range> internal;
  };

  //------------------------------------------------------------------------
  class BincImapParserFetchAtt {
  public:
    std::string type;
    std::string section;
    std::string sectiontext;
    std::vector<std::string> headerlist;
    unsigned int offsetstart;
    unsigned int offsetlength;
    bool hassection;

    BincImapParserFetchAtt(const std::string &typeName = "");

    std::string toString(void);
  };

  //------------------------------------------------------------------------
  class BincImapParserSearchKey {
  public:
    std::string name;
    std::string date;
    std::string astring;
    std::string bstring;
    int type;
    unsigned int number;
    SequenceSet bset;

    enum { KEY_AND, KEY_OR, KEY_NOT, KEY_OTHER, KEY_SET };

    std::vector<BincImapParserSearchKey> children;

    const SequenceSet &getSet(void) const;

    BincImapParserSearchKey(void);
  };

  //------------------------------------------------------------------------
  class BincImapParserData {
  public:
    virtual ~BincImapParserData(void) {}
  };

  //------------------------------------------------------------------------
  class Request {
  private:
    std::string tag;
    std::string name;
    std::string mode;
    std::string date;
    std::string userid;
    std::string password;
    std::string mailbox;
    std::string newmailbox;
    std::string authtype;
    std::string listmailbox;
    std::string charset;
    std::string literal;
    std::string contextInfo;
    bool uidmode;

  public:
    BincImapParserData *extra;
    std::vector<std::string> flags;
    std::vector<std::string> statuses;

    SequenceSet bset;
    BincImapParserSearchKey searchkey;
    std::vector<BincImapParserFetchAtt> fatt;

    void setUidMode(void);
    bool getUidMode(void) const;

    void setTag(std::string &t_in);
    const std::string &getTag(void) const;

    void setMode(const std::string &m_in);
    const std::string &getMode(void) const;

    void setName(const std::string &s_in);
    const std::string &getName(void) const;

    void setLiteral(const std::string &s_in);
    const std::string &getLiteral(void) const;

    void setDate(const std::string &s_in);
    const std::string &getDate(void) const;

    void setCharSet(const std::string &s_in);
    const std::string &getCharSet(void) const;

    void setUserID(const std::string &s_in);
    const std::string &getUserID(void) const;

    void setPassword(const std::string &s_in);
    const std::string &getPassword(void) const;

    void setMailbox(const std::string &s_in);
    const std::string &getMailbox(void) const;

    void setAuthType(const std::string &s_in);
    const std::string &getAuthType(void) const;

    void setNewMailbox(const std::string &s_in);
    const std::string &getNewMailbox(void) const;

    void setListMailbox(const std::string &s_in);
    const std::string &getListMailbox(void) const;

    void setContextInfo(const std::string &s_in);
    const std::string &getContextInfo(void) const;

    SequenceSet &getSet(void);

    std::vector<std::string> &getFlags(void);
    std::vector<std::string> &getStatuses(void);

    Request(void);
    ~Request(void);
  };
}

#endif