bincimap

Log | Files | Refs | LICENSE

depot.h (4326B)


      1 /* -*- Mode: c++; -*- */
      2 /*  --------------------------------------------------------------------
      3  *  Filename:
      4  *    src/depot.h
      5  *  
      6  *  Description:
      7  *    <--->
      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 #ifndef depot_h_included
     35 #define depot_h_included
     36 #include <map>
     37 #include <string>
     38 #include <vector>
     39 
     40 #include <dirent.h>
     41 
     42 namespace Binc {
     43 
     44   class Mailbox;
     45   class Depot;
     46   class Status;
     47 
     48   //------------------------------------------------------------------
     49   class DepotFactory {
     50   private:
     51     std::vector<Depot *> depots;
     52     DepotFactory(void);
     53 
     54   public:
     55     void assign(Depot *);
     56     Depot *get(const std::string &name) const;
     57 
     58     static DepotFactory &getInstance(void);
     59     ~DepotFactory(void);
     60   };
     61 
     62   //------------------------------------------------------------------
     63   class Depot {
     64   public:
     65     //--
     66     class iterator {
     67     public:      
     68       std::string operator * (void) const;
     69       void operator ++ (void);
     70       bool operator != (iterator) const;
     71       bool operator == (iterator) const;
     72 
     73       iterator(void);
     74       iterator(const iterator &copy);
     75       iterator(DIR *, struct dirent *);
     76       ~iterator(void);
     77 
     78       void deref(void);
     79 
     80       iterator &operator =(const iterator &copy);
     81 
     82       friend class Depot;
     83 
     84     private:
     85       DIR *dirp;
     86       struct dirent *direntp;
     87       int *ref;
     88     };
     89 
     90   private:
     91     iterator enditerator;
     92     std::vector<Mailbox *> backends;
     93     Mailbox *defaultmailbox;
     94     Mailbox *selectedmailbox;
     95 
     96   protected:
     97     mutable std::string lastError;
     98     std::string name;
     99     char delimiter;
    100     mutable std::map<std::string, Status> mailboxstatuses;
    101 
    102   public:
    103     iterator begin(const std::string &) const;
    104     const iterator &end(void) const;
    105 
    106     void setDelimiter(char);
    107     const char getDelimiter(void) const;
    108 
    109     void assign(Mailbox *);
    110 
    111     bool setDefaultType(const std::string &n) ;
    112     Mailbox *getDefault(void) const;
    113     Mailbox *get(const std::string &path) const;
    114 
    115     bool setSelected(Mailbox *);
    116     Mailbox *getSelected(void) const;
    117     void resetSelected(void);
    118 
    119     bool getStatus(const std::string &s_in, Status &dest) const;
    120 
    121     const std::string &getName(void) const;
    122 
    123     virtual std::string mailboxToFilename(const std::string &m) const = 0;
    124     virtual std::string filenameToMailbox(const std::string &m) const = 0;
    125 
    126     virtual bool createMailbox(const std::string &m) const;
    127     virtual bool deleteMailbox(const std::string &m) const;
    128     virtual bool renameMailbox(const std::string &m, const std::string &n) const;
    129 
    130     const std::string &getLastError(void) const;
    131     void setLastError(const std::string &error) const;
    132 
    133     //--
    134     Depot(void);
    135     Depot(const std::string &name);
    136     virtual ~Depot(void);
    137   };
    138 
    139   //------------------------------------------------------------------
    140   class MaildirPPDepot : public Depot {
    141   public:
    142     std::string mailboxToFilename(const std::string &m) const;
    143     std::string filenameToMailbox(const std::string &m) const;
    144 
    145     //--
    146     MaildirPPDepot();
    147     ~MaildirPPDepot();
    148   };
    149 
    150   //------------------------------------------------------------------
    151   class IMAPdirDepot : public Depot {
    152   public:
    153     std::string mailboxToFilename(const std::string &m) const;
    154     std::string filenameToMailbox(const std::string &m) const;
    155 
    156     //--
    157     IMAPdirDepot();
    158     ~IMAPdirDepot();
    159   };
    160 
    161 }
    162 
    163 #endif