bincimap

Log | Files | Refs | LICENSE

operator-logout.cc (3121B)


      1 /* -*- Mode: c++; -*- */
      2 /*  --------------------------------------------------------------------
      3  *  Filename:
      4  *    operator-logout.cc
      5  *  
      6  *  Description:
      7  *    Implementation of the LOGOUT 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 #include <iostream>
     40 
     41 #include "io.h"
     42 
     43 #include "mailbox.h"
     44 #include "recursivedescent.h"
     45 #include "session.h"
     46 #include "convert.h"
     47 
     48 #include "depot.h"
     49 #include "operators.h"
     50 
     51 using namespace ::std;
     52 using namespace Binc;
     53 
     54 //----------------------------------------------------------------------
     55 LogoutOperator::LogoutOperator(void)
     56 {
     57 }
     58 
     59 //----------------------------------------------------------------------
     60 LogoutOperator::~LogoutOperator(void)
     61 {
     62 }
     63 
     64 //----------------------------------------------------------------------
     65 const string LogoutOperator::getName(void) const
     66 {
     67   return "LOGOUT";
     68 }
     69 
     70 //----------------------------------------------------------------------
     71 int LogoutOperator::getState(void) const
     72 {
     73   return Session::NONAUTHENTICATED
     74     | Session::AUTHENTICATED
     75     | Session::SELECTED;
     76 }
     77 
     78 //------------------------------------------------------------------------
     79 Operator::ProcessResult LogoutOperator::process(Depot &depot,
     80 						Request &command)
     81 {
     82   IO &com = IOFactory::getInstance().get(1);
     83 
     84   com << "* BYE Binc IMAP shutting down" << endl;
     85   com << command.getTag() << " OK LOGOUT completed" << endl;
     86   com.flushContent();
     87   
     88 #ifdef BINCIMAPD
     89   Mailbox *mailbox = 0;
     90   if ((mailbox = depot.getSelected()) != 0) {
     91     mailbox->closeMailbox();
     92     delete mailbox;
     93   }
     94 #endif
     95   
     96   Session &session = Session::getInstance();
     97   session.setState(Session::LOGOUT);
     98 
     99   return NOTHING;
    100 }
    101 
    102 //----------------------------------------------------------------------
    103 Operator::ParseResult LogoutOperator::parse(Request & c_in) const
    104 {
    105   Session &session = Session::getInstance();
    106 
    107   if (c_in.getUidMode())
    108     return REJECT;
    109 
    110   Operator::ParseResult res;
    111   if ((res = expectCRLF()) != ACCEPT) {
    112     session.setLastError("Expected CRLF");
    113     return res;
    114   }
    115 
    116   c_in.setName("LOGOUT");
    117   return ACCEPT;
    118 }