/** * @file bincimapd-capability.cc * @brief Implementation of the CAPABILITY command * @author Andreas Aardal Hanssen, Erwin Hoffmann * @date 2002-2005, 2023 */ #include "depot.h" #include "globals.h" #include "iodevice.h" #include "iofactory.h" #include "operators.h" #include "recursivedescent.h" #include "session.h" #include using namespace Binc; using std::string; CapabilityOperator::CapabilityOperator() {} CapabilityOperator::~CapabilityOperator() {} const string CapabilityOperator::getName() const { return "CAPABILITY"; } Session::State CapabilityOperator::getState() const { return Session::State(Session::NONAUTHENTICATED | Session::AUTHENTICATED | Session::SELECTED); } void CapabilityOperator::addCapability(const string &cap) { capabilities.push_back(cap); } Operator::ProcessResult CapabilityOperator::process(Depot &depot, Request &command) { Session &session = Session::getInstance(); bincClient << "* CAPABILITY " << IMAP_VERSION; if (session.getState() == Session::NONAUTHENTICATED) { if (getenv("UCSPITLS")) { if (!session.command.ssl) bincClient << " STARTTLS"; } const string authmethods = session.getEnv("BINCIMAP_LOGIN"); auto cram = authmethods.find("+CRAM-MD5"); if (session.command.ssl || session.hasEnv("ALLOW_NONSSL_PLAINTEXT_LOGINS")) if (cram != string::npos) bincClient << " AUTH=LOGIN AUTH=PLAIN AUTH=CRAM-MD5"; else bincClient << " AUTH=LOGIN AUTH=PLAIN"; else bincClient << " LOGINDISABLED"; } bincClient << " IDLE LITERAL+ NAMESPACE CHILDREN"; std::vector::const_iterator i = capabilities.begin(); while (i != capabilities.end()) { bincClient << " " << *i; ++i; } bincClient << std::endl; return Operator::ProcessResult::OK; } Parser::ParseResult CapabilityOperator::parse(Request &c_in, Parser &p) { Session &session = Session::getInstance(); if (c_in.getUidMode()) return Parser::ParseResult::REJECT; Parser::ParseResult res; if ((res = p.expectCRLF()) != Parser::ParseResult::ACCEPT) { session.setLastError("Expected CRLF after CAPABILITY"); return res; } c_in.setName("CAPABILITY"); return Parser::ParseResult::ACCEPT; }