bincimap

Log | Files | Refs | LICENSE

imapparser.h (5323B)


      1 /* -*- Mode: c++; -*- */
      2 /*  --------------------------------------------------------------------
      3  *  Filename:
      4  *    src/parsers/imap/imapparser.h
      5  *  
      6  *  Description:
      7  *    Declaration of the common items for parsing IMAP input
      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 imapparser_h_included
     39 #define imapparser_h_included
     40 
     41 /* stl includes */
     42 #include <string>
     43 #include <map>
     44 #include <vector>
     45 
     46 namespace Binc {
     47   //------------------------------------------------------------------------
     48   class SequenceSet {
     49   public:
     50     void addRange(unsigned int a_in, unsigned int b_in);
     51     bool isInSet(unsigned int n) const;
     52     void addNumber(unsigned int a_in);
     53     inline bool isLimited(void) const { return limited; }
     54 
     55     static SequenceSet &all(void);
     56 
     57     static SequenceSet &null(void);
     58 
     59     SequenceSet &operator = (const SequenceSet &copy);
     60 
     61     SequenceSet(void);
     62     SequenceSet(const SequenceSet &copy);
     63     ~SequenceSet(void);
     64 
     65   protected:
     66     bool isNull(void) const;
     67 
     68   private:
     69     bool limited;
     70     bool nullSet;
     71 
     72     class Range {
     73     public:
     74       unsigned int from;
     75       unsigned int to;
     76       Range(unsigned int from, unsigned int to);
     77     };
     78 
     79     std::vector<Range> internal;
     80   };
     81 
     82   //------------------------------------------------------------------------
     83   class BincImapParserFetchAtt {
     84   public:
     85     std::string type;
     86     std::string section;
     87     std::string sectiontext;
     88     std::vector<std::string> headerlist;
     89     unsigned int offsetstart;
     90     unsigned int offsetlength;
     91     bool hassection;
     92 
     93     BincImapParserFetchAtt(const std::string &typeName = "");
     94 
     95     std::string toString(void);
     96   };
     97 
     98   //------------------------------------------------------------------------
     99   class BincImapParserSearchKey {
    100   public:
    101     std::string name;
    102     std::string date;
    103     std::string astring;
    104     std::string bstring;
    105     int type;
    106     unsigned int number;
    107     SequenceSet bset;
    108     enum {KEY_AND, KEY_OR, KEY_NOT, KEY_OTHER, KEY_SET};
    109       
    110     std::vector<BincImapParserSearchKey> children;
    111 
    112     const SequenceSet& getSet(void) const;
    113 
    114     BincImapParserSearchKey(void);
    115   };
    116 
    117   //------------------------------------------------------------------------
    118   class BincImapParserData {
    119   public:
    120     virtual ~BincImapParserData(void) {}
    121   };
    122 
    123   //------------------------------------------------------------------------
    124   class Request {
    125   private:
    126     std::string tag;
    127     std::string name;
    128     std::string mode;
    129     std::string date;
    130     std::string userid;
    131     std::string password;
    132     std::string mailbox;
    133     std::string newmailbox;
    134     std::string authtype;
    135     std::string listmailbox;
    136     std::string charset;
    137     std::string literal;
    138     bool uidmode;
    139       
    140   public:
    141     BincImapParserData * extra;
    142     std::vector<std::string> flags;
    143     std::vector<std::string> statuses;
    144 
    145     SequenceSet bset;
    146     BincImapParserSearchKey searchkey;
    147     std::vector<BincImapParserFetchAtt> fatt;
    148 
    149     void setUidMode(void);
    150     bool getUidMode(void) const;
    151 
    152     void setTag(std::string &t_in);
    153     const std::string &getTag(void) const;
    154 
    155     void setMode(const std::string &m_in);
    156     const std::string &getMode(void) const;
    157 
    158     void setName(const std::string &s_in);
    159     const std::string &getName(void) const;
    160 
    161     void setLiteral(const std::string &s_in);
    162     const std::string &getLiteral(void) const;
    163 
    164     void setDate(const std::string &s_in);
    165     const std::string &getDate(void) const;
    166 
    167     void setCharSet(const std::string &s_in);
    168     const std::string &getCharSet(void) const;
    169 
    170     void setUserID(const std::string &s_in);
    171     const std::string &getUserID(void) const;
    172 
    173     void setPassword(const std::string &s_in);
    174     const std::string &getPassword(void) const;
    175 
    176     void setMailbox(const std::string &s_in);
    177     const std::string &getMailbox(void) const;
    178 
    179     void setAuthType(const std::string &s_in);
    180     const std::string &getAuthType(void) const;
    181 
    182     void setNewMailbox(const std::string &s_in);
    183     const std::string &getNewMailbox(void) const;
    184 
    185     void setListMailbox(const std::string &s_in);
    186     const std::string &getListMailbox(void) const;
    187 
    188     SequenceSet &getSet(void);
    189 
    190     std::vector<std::string> &getFlags(void);
    191     std::vector<std::string> &getStatuses(void);
    192 
    193     Request(void);
    194     ~Request(void);
    195   };
    196 }
    197 
    198 
    199 #endif