operator-unsubscribe.cc (3355B)
1 /* -*- Mode: c++; -*- */ 2 /* -------------------------------------------------------------------- 3 * Filename: 4 * operator-unsubscribe.cc 5 * 6 * Description: 7 * Implementation of the UNSUBSCRIBE 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 <vector> 40 #include <iostream> 41 42 #include "io.h" 43 #include "convert.h" 44 #include "storage.h" 45 46 #include <sys/stat.h> 47 48 #include "recursivedescent.h" 49 50 #include "session.h" 51 #include "depot.h" 52 #include "operators.h" 53 54 using namespace ::std; 55 using namespace Binc; 56 57 //---------------------------------------------------------------------- 58 UnsubscribeOperator::UnsubscribeOperator(void) 59 { 60 } 61 62 //---------------------------------------------------------------------- 63 UnsubscribeOperator::~UnsubscribeOperator(void) 64 { 65 } 66 67 //---------------------------------------------------------------------- 68 const string UnsubscribeOperator::getName(void) const 69 { 70 return "UNSUBSCRIBE"; 71 } 72 73 //---------------------------------------------------------------------- 74 int UnsubscribeOperator::getState(void) const 75 { 76 return Session::AUTHENTICATED | Session::SELECTED; 77 } 78 79 //------------------------------------------------------------------------ 80 Operator::ProcessResult UnsubscribeOperator::process(Depot &depot, 81 Request &command) 82 { 83 Session &session = Session::getInstance(); 84 85 const string &mailbox = command.getMailbox(); 86 const string &canonmailbox = toCanonMailbox(mailbox); 87 88 session.loadSubscribes(); 89 if (!session.unsubscribeTo(canonmailbox)) { 90 session.setLastError("Not subscribed to " + toImapString(mailbox)); 91 return NO; 92 } 93 94 session.saveSubscribes(); 95 96 return OK; 97 } 98 99 //---------------------------------------------------------------------- 100 Operator::ParseResult UnsubscribeOperator::parse(Request &c_in) const 101 { 102 Session &session = Session::getInstance(); 103 104 if (c_in.getUidMode()) 105 return REJECT; 106 107 Operator::ParseResult res; 108 if ((res = expectSPACE()) != ACCEPT) { 109 session.setLastError("Expected SPACE"); 110 return res; 111 } 112 113 string mailbox; 114 if ((res = expectMailbox(mailbox)) != ACCEPT) { 115 session.setLastError("Expected mailbox"); 116 return res; 117 } 118 119 if ((res = expectCRLF()) != ACCEPT) { 120 session.setLastError("Expected CRLF"); 121 return res; 122 } 123 124 c_in.setMailbox(mailbox); 125 return ACCEPT; 126 }