bincimap

Log | Files | Refs | LICENSE

operator-create.cc (3201B)


      1 /* -*- Mode: c++; -*- */
      2 /*  --------------------------------------------------------------------
      3  *  Filename:
      4  *    bincimapd-create.cc
      5  *  
      6  *  Description:
      7  *    Implementation of the CREATE command.
      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 #include <string>
     39 
     40 #include "depot.h"
     41 #include "io.h"
     42 #include "mailbox.h"
     43 #include "operators.h"
     44 #include "imapparser.h"
     45 #include "recursivedescent.h"
     46 #include "session.h"
     47 #include "convert.h"
     48 
     49 using namespace ::std;
     50 using namespace Binc;
     51 
     52 //----------------------------------------------------------------------
     53 CreateOperator::CreateOperator(void)
     54 {
     55 }
     56 
     57 //----------------------------------------------------------------------
     58 CreateOperator::~CreateOperator(void)
     59 {
     60 }
     61 
     62 //----------------------------------------------------------------------
     63 const string CreateOperator::getName(void) const
     64 {
     65   return "CREATE";
     66 }
     67 
     68 //----------------------------------------------------------------------
     69 int CreateOperator::getState(void) const
     70 {
     71   return Session::AUTHENTICATED | Session::SELECTED;
     72 }
     73 
     74 //------------------------------------------------------------------------
     75 Operator::ProcessResult CreateOperator::process(Depot &depot,
     76 						Request &command)
     77 {
     78   if (depot.createMailbox(command.getMailbox()))
     79     return OK;
     80   else {
     81     Session &session = Session::getInstance();
     82     session.setLastError(depot.getLastError());
     83     return NO;
     84   }
     85 }
     86 
     87 //----------------------------------------------------------------------
     88 Operator::ParseResult CreateOperator::parse(Request &c_in) const
     89 {
     90   Session &session = Session::getInstance();
     91 
     92   if (c_in.getUidMode())
     93     return REJECT;
     94 
     95   Operator::ParseResult res;
     96   if ((res = expectSPACE()) != ACCEPT) {
     97     session.setLastError("Expected SPACE after CREATE");
     98     return res;
     99   }
    100 
    101   string mailbox;
    102   if ((res = expectMailbox(mailbox)) != ACCEPT) {
    103     session.setLastError("Expected mailbox after CREATE SPACE");
    104     return res;
    105   }
    106 
    107   if ((res = expectCRLF()) != ACCEPT) {
    108     session.setLastError("Expected CRLF after CREATE SPACE CRLF");
    109     return res;
    110   }
    111 
    112   session.mailboxchanges = true;
    113 
    114   c_in.setName("CREATE");
    115   c_in.setMailbox(mailbox);
    116   return ACCEPT;
    117 }