bincimap

Log | Files | Refs | LICENSE

operator-capability.cc (3638B)


      1 /* -*- Mode: c++; -*- */
      2 /*  --------------------------------------------------------------------
      3  *  Filename:
      4  *    bincimapd-capability.cc
      5  *  
      6  *  Description:
      7  *    Implementation of the CAPABILITY 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 
     40 #include "depot.h"
     41 #include "io.h"
     42 #include "operators.h"
     43 #include "recursivedescent.h"
     44 #include "session.h"
     45 
     46 using namespace ::std;
     47 using namespace Binc;
     48 
     49 //----------------------------------------------------------------------
     50 CapabilityOperator::CapabilityOperator(void)
     51 {
     52 }
     53 
     54 //----------------------------------------------------------------------
     55 CapabilityOperator::~CapabilityOperator(void)
     56 {
     57 }
     58 
     59 //----------------------------------------------------------------------
     60 const string CapabilityOperator::getName(void) const
     61 {
     62   return "CAPABILITY";
     63 }
     64 
     65 //----------------------------------------------------------------------
     66 int CapabilityOperator::getState(void) const
     67 {
     68   return Session::NONAUTHENTICATED 
     69     | Session::AUTHENTICATED
     70     | Session::SELECTED;
     71 }
     72 
     73 //----------------------------------------------------------------------
     74 void CapabilityOperator::addCapability(const string &cap)
     75 {
     76   capabilities.push_back(cap);
     77 }
     78 
     79 //----------------------------------------------------------------------
     80 Operator::ProcessResult CapabilityOperator::process(Depot &depot,
     81 						    Request &command)
     82 {
     83   IO &com = IOFactory::getInstance().get(1);
     84   Session &session = Session::getInstance();
     85 
     86   com << "* CAPABILITY IMAP4rev1";
     87 
     88   if (session.getState() == Session::NONAUTHENTICATED) {
     89     if (!session.command.ssl
     90 	&& (session.globalconfig["Authentication"]["disable starttls"] != "yes"))
     91       com << " STARTTLS";
     92 
     93     const bool allowplain 
     94       = (session.globalconfig["Authentication"]["allow plain auth in non ssl"] == "yes");
     95     
     96     if (session.command.ssl || session["sslmode"] == "yes" || allowplain || getenv("ALLOWPLAIN"))
     97       com << " AUTH=LOGIN AUTH=PLAIN";
     98     else
     99       com << " LOGINDISABLED";
    100   }
    101 
    102   vector<string>::const_iterator i = capabilities.begin();
    103   while (i != capabilities.end()) {
    104     com << " " << *i;
    105     ++i;
    106   }
    107   com << endl;
    108 
    109   return OK;
    110 }
    111 
    112 //----------------------------------------------------------------------
    113 Operator::ParseResult CapabilityOperator::parse(Request &c_in) const
    114 {
    115   Session &session = Session::getInstance();
    116 
    117   if (c_in.getUidMode())
    118     return REJECT;
    119 
    120   Operator::ParseResult res;
    121   if ((res = expectCRLF()) != ACCEPT) {
    122     session.setLastError("Expected CRLF after CAPABILITY");
    123     return res;
    124   }
    125 
    126   c_in.setName("CAPABILITY");
    127   return ACCEPT;
    128 }