summaryrefslogtreecommitdiff
path: root/src/include/imapparser.h
blob: 7d2ac274e9ceac93bb7c988c8d76ead0adbcf9fb (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
/**
 *  @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

#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() const
    {
      return limited;
    }

    static SequenceSet &all();

    static SequenceSet &null();

    SequenceSet();
    SequenceSet(const SequenceSet &copy);
    SequenceSet &operator=(const SequenceSet &copy);
    ~SequenceSet();

  protected:
    bool isNull() 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();
  };

  struct BincImapParserSearchKey {
    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() const;

    BincImapParserSearchKey();
  };

  struct BincImapParserData {
    virtual ~BincImapParserData() = default;
  };

  class Request {
    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();
    bool getUidMode() const;

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

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

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

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

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

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

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

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

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

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

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

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

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

    SequenceSet &getSet();

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

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

#endif