bincimap

Log | Files | Refs | LICENSE

operator-close.cc (2896B)


      1 /* -*- Mode: c++; -*- */
      2 /*  --------------------------------------------------------------------
      3  *  Filename:
      4  *    operator-close.cc
      5  *  
      6  *  Description:
      7  *    Implementation of the CLOSE 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 #include <string>
     35 
     36 #include "depot.h"
     37 #include "io.h"
     38 #include "mailbox.h"
     39 #include "operators.h"
     40 #include "recursivedescent.h"
     41 #include "session.h"
     42 
     43 using namespace ::std;
     44 using namespace Binc;
     45 
     46 //----------------------------------------------------------------------
     47 CloseOperator::CloseOperator(void)
     48 {
     49 }
     50 
     51 //----------------------------------------------------------------------
     52 CloseOperator::~CloseOperator(void)
     53 {
     54 }
     55 
     56 //------------------------------------------------------------------------
     57 const string CloseOperator::getName(void) const
     58 {
     59   return "CLOSE";
     60 }
     61 
     62 //------------------------------------------------------------------------
     63 int CloseOperator::getState(void) const
     64 {
     65   return Session::SELECTED;
     66 }
     67 
     68 //------------------------------------------------------------------------
     69 Operator::ProcessResult CloseOperator::process(Depot &depot,
     70 					       Request &command)
     71 {
     72   IO &logger = IOFactory::getInstance().get(2);
     73 
     74   Mailbox *mailbox = depot.getSelected();
     75   mailbox->expungeMailbox();
     76   mailbox->closeMailbox();
     77   depot.resetSelected();
     78 
     79   Session &session = Session::getInstance();
     80   session.setState(Session::AUTHENTICATED);
     81 
     82   logger.setLogPrefix(session.getUserID() + "@" + session.getIP() + ":");
     83 
     84   return OK;
     85 }
     86 
     87 //----------------------------------------------------------------------
     88 Operator::ParseResult CloseOperator::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 = expectCRLF()) != ACCEPT) {
     97     session.setLastError("Expected CRLF after CLOSE");
     98     return res;
     99   }
    100 
    101   c_in.setName("CLOSE");
    102   return ACCEPT;
    103 }