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