bincimap

Log | Files | Refs | LICENSE

operator-expunge.cc (3247B)


      1 /* -*- Mode: c++; -*- */
      2 /*  --------------------------------------------------------------------
      3  *  Filename:
      4  *    operator-expunge.cc
      5  *  
      6  *  Description:
      7  *    Implementation of the EXPUNGE 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 "imapparser.h"
     41 #include "recursivedescent.h"
     42 #include "pendingupdates.h"
     43 #include "session.h"
     44 
     45 using namespace ::std;
     46 using namespace Binc;
     47 
     48 //----------------------------------------------------------------------
     49 ExpungeOperator::ExpungeOperator(void)
     50 {
     51 }
     52 
     53 //----------------------------------------------------------------------
     54 ExpungeOperator::~ExpungeOperator(void)
     55 {
     56 }
     57 
     58 //----------------------------------------------------------------------
     59 const string ExpungeOperator::getName(void) const
     60 {
     61   return "EXPUNGE";
     62 }
     63 
     64 //----------------------------------------------------------------------
     65 int ExpungeOperator::getState(void) const
     66 {
     67   return Session::SELECTED;
     68 }
     69 
     70 //----------------------------------------------------------------------
     71 Operator::ProcessResult ExpungeOperator::process(Depot &depot,
     72 						 Request &command)
     73 {
     74   Mailbox *mailbox = depot.getSelected();
     75   mailbox->expungeMailbox();
     76 
     77   if (!pendingUpdates(mailbox, PendingUpdates::EXPUNGE
     78 		      | PendingUpdates::EXISTS 
     79 		      | PendingUpdates::RECENT
     80 		      | PendingUpdates::FLAGS, true, false, true)) {
     81       Session &session = Session::getInstance();
     82       IO &com = IOFactory::getInstance().get(1);
     83       IO &logger = IOFactory::getInstance().get(2);
     84       logger << "when scanning mailbox: "
     85 	     << session.getLastError() << endl;
     86       com << "* BYE " << session.getLastError() << endl;
     87       com.flushContent();
     88       session.setState(Session::LOGOUT);
     89       return NOTHING;
     90   }
     91 
     92   return OK;
     93 }
     94 
     95 //----------------------------------------------------------------------
     96 Operator::ParseResult ExpungeOperator::parse(Request &c_in) const
     97 {
     98   Session &session = Session::getInstance();
     99 
    100   if (c_in.getUidMode())
    101     return REJECT;
    102 
    103   Operator::ParseResult res; 
    104  if ((res = expectCRLF()) != ACCEPT) {
    105     session.setLastError("Expected CRLF");
    106     return res;
    107   }
    108 
    109   c_in.setName("EXPUNGE");
    110   return ACCEPT;
    111 }