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