diff options
103 files changed, 1291 insertions, 2046 deletions
diff --git a/src/address.cc b/src/address.cc index eff4ccd..33d216e 100644 --- a/src/address.cc +++ b/src/address.cc @@ -1,35 +1,38 @@ -/** ------------------------------------------------------------------- +/** * @file address.cc * @brief Implementation of the Address class * @author Andreas Aardal Hanssen * @date 2005 - * ---------------------------------------------------------------- **/ + */ + #include "address.h" #include "convert.h" #include <string> -using namespace ::std; using namespace Binc; +using std::string; -//------------------------------------------------------------------------ Address::Address(const string &name, const string &addr) { - string::size_type pos = addr.find('@'); + auto pos = addr.find('@'); + this->name = name; + if (pos != string::npos) { this->local = addr.substr(0, pos); this->host = addr.substr(pos + 1); - } else + } else { this->local = addr; + } } -//------------------------------------------------------------------------ Address::Address(const string &wholeaddress) { - string::size_type start = wholeaddress.find('<'); + auto start = wholeaddress.find('<'); string addr; + if (start != string::npos) addr = wholeaddress.substr(start + 1); else @@ -41,6 +44,7 @@ Address::Address(const string &wholeaddress) name = wholeaddress.substr(0, start); else name = ""; + trim(name); trim(name, "\""); @@ -53,7 +57,6 @@ Address::Address(const string &wholeaddress) trim(name); } -//------------------------------------------------------------------------ string Address::toParenList(void) const { string tmp = "("; diff --git a/src/argparser.cc b/src/argparser.cc index 1382610..d8e45ae 100644 --- a/src/argparser.cc +++ b/src/argparser.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file argparser.cc * @brief Implementation of the command line argument parser * @author Andreas Aardal Hanssen * @date 2005 - * ------------------------------------------------------------------ **/ + */ + #include "argparser.h" #include "convert.h" @@ -11,17 +12,15 @@ #include <map> #include <string> -using namespace ::std; using namespace Binc; +using std::string; -//---------------------------------------------------------------------- CommandLineArgs::CommandLineArgs() { errString = "Unknown error for args"; ac = 0; } -//---------------------------------------------------------------------- bool CommandLineArgs::parse(int argc, char *argv[]) { ac = -1; @@ -79,7 +78,7 @@ bool CommandLineArgs::parse(int argc, char *argv[]) // parse --argument string arg = s.substr(2); string val; - string::size_type epos = arg.find('='); + auto epos = arg.find('='); if (epos != string::npos) { val = arg.substr(epos + 1); arg = arg.substr(0, epos); @@ -128,12 +127,11 @@ bool CommandLineArgs::parse(int argc, char *argv[]) // parse -argument string arg = s.substr(1); if (arg.length() == 1) { - map<string, ArgOpts>::const_iterator it = reg.begin(); bool match = false; - for (; it != reg.end(); ++it) { - if (it->second.c.find(arg[0]) != string::npos) { - lastKey = it->first; - if (it->second.b) lastIsBoolean = true; + for (const auto &[first, second] : reg) { + if (second.c.find(arg[0]) != string::npos) { + lastKey = first; + if (second.b) lastIsBoolean = true; match = true; break; } @@ -145,23 +143,21 @@ bool CommandLineArgs::parse(int argc, char *argv[]) return false; } } else { - string::const_iterator its = arg.begin(); - for (; its != arg.end(); ++its) { - map<string, ArgOpts>::const_iterator it = reg.begin(); + for (auto its : arg) { bool match = false; - for (; it != reg.end(); ++it) { - if (it->second.c.find(*its) != string::npos) { - if (!it->second.b) { + for (const auto &[first, second] : reg) { + if (second.c.find(its) != string::npos) { + if (!second.b) { errString = "argument is not a boolean: "; - errString += "--" + it->first; + errString += "--" + first; errString += " / -"; - errString += it->second.c; + errString += second.c; return false; } match = true; - args[it->first] = "yes"; - passedArgs[it->first] = true; + args[first] = "yes"; + passedArgs[first] = true; lastKey = ""; lastIsBoolean = false; @@ -192,15 +188,14 @@ bool CommandLineArgs::parse(int argc, char *argv[]) } // assign default "no" values for arguments that were not passed. - map<string, ArgOpts>::const_iterator it = reg.begin(); - for (; it != reg.end(); ++it) { - if (args.find(it->first) == args.end()) { - if (!it->second.o) { + for (const auto &[first, second] : reg) { + if (args.find(first) == args.end()) { + if (!second.o) { errString = "missing argument: "; - errString += it->first; + errString += first; return false; } - if (it->second.b) args[it->first] = "no"; + if (second.b) args[first] = "no"; } } if (ac == -1) ac = argc; @@ -208,32 +203,27 @@ bool CommandLineArgs::parse(int argc, char *argv[]) return true; } -//---------------------------------------------------------------------- string CommandLineArgs::errorString(void) const { return errString; } -//---------------------------------------------------------------------- const string CommandLineArgs::operator[](const string &arg) const { if (args.find(arg) == args.end()) return ""; return args.find(arg)->second; } -//---------------------------------------------------------------------- void CommandLineArgs::addOptional(const string &arg, const string &desc, bool boolean) { registerArg(arg, desc, boolean, true); } -//---------------------------------------------------------------------- void CommandLineArgs::addRequired(const string &arg, const string &desc, bool boolean) { registerArg(arg, desc, boolean, false); } -//---------------------------------------------------------------------- void CommandLineArgs::registerArg(const string &arg, const string &desc, bool boolean, bool optional) { string name = arg; @@ -247,26 +237,22 @@ void CommandLineArgs::registerArg(const string &arg, const string &desc, bool bo reg.insert(make_pair(name, ArgOpts(shorts, boolean, optional, desc))); } -//---------------------------------------------------------------------- -bool CommandLineArgs::hasArg(const std::string &arg) const +bool CommandLineArgs::hasArg(const string &arg) const { string tmp = arg; lowercase(tmp); return passedArgs.find(tmp) != passedArgs.end(); } -//---------------------------------------------------------------------- string CommandLineArgs::usageString(void) const { string tmp = head; tmp += '\n'; - map<string, ArgOpts>::const_iterator it = reg.begin(); - for (; it != reg.end(); ++it) { - if (it->second.c != "") { - string::const_iterator sit = it->second.c.begin(); - for (; sit != it->second.c.end(); ++sit) { - if (sit != it->second.c.begin()) tmp += '\n'; + for (const auto &[first, second] : reg) { + if (!second.c.empty()) { + for (auto sit = second.c.cbegin(); sit != second.c.cend(); ++sit) { + if (sit != second.c.begin()) tmp += '\n'; tmp += " -"; tmp += *sit; } @@ -275,13 +261,12 @@ string CommandLineArgs::usageString(void) const tmp += " "; } - tmp += "--"; - tmp += it->first; - if (!it->second.b) tmp += "=<str>"; + tmp += "--" + first; + if (!second.b) tmp += "=<str>"; - if (!it->second.o) tmp += " (required)"; + if (!second.o) tmp += " (required)"; - string::size_type lineStart = tmp.rfind('\n'); + auto lineStart = tmp.rfind('\n'); if (lineStart == string::npos) lineStart = 0; int pad = 21 - (tmp.length() - lineStart); @@ -290,32 +275,25 @@ string CommandLineArgs::usageString(void) const pad = 20; } - tmp += string(pad, ' '); - tmp += it->second.desc; - tmp += '\n'; + tmp += string(pad, ' ') + second.desc + '\n'; } - tmp += '\n'; - tmp += tail; - tmp += '\n'; + tmp += '\n' + tail + '\n'; return tmp; } -//---------------------------------------------------------------------- int CommandLineArgs::argc(void) const { return ac; } -//---------------------------------------------------------------------- void CommandLineArgs::setTail(const string &str) { tail = str; } -//---------------------------------------------------------------------- -const vector<string> &CommandLineArgs::getUnqualifiedArgs() const +const std::vector<string> &CommandLineArgs::getUnqualifiedArgs() const { return unqualified; } diff --git a/src/authenticate.cc b/src/authenticate.cc index 88bfa63..63a8b3a 100644 --- a/src/authenticate.cc +++ b/src/authenticate.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file authenticate.cc * @brief Implementation of the common (C/R) authentication mechanism. * @author Andreas Aardal Hanssen, Erwin Hoffmann * @date 2002-2005, 2023 - * ----------------------------------------------------------------- **/ + */ + #include <string> #include <vector> @@ -28,15 +29,16 @@ #include "iofactory.h" #include "session.h" -using namespace ::std; using namespace Binc; +using std::endl; +using std::string; // 0 = ok // 1 = internal error // 2 = failed // 3 = timeout // -1 = abort -//------------------------------------------------------------------------ + int Binc::authenticate(Depot &depot, const string &username, const string &password, @@ -46,7 +48,7 @@ int Binc::authenticate(Depot &depot, session.setUserID(username); // check if checkpassword is present - if (::access(session.unparsedArgs[0], X_OK) != 0) { // x is enough + if (access(session.unparsedArgs[0], X_OK) != 0) { // x is enough bincError << "unable to start authenticator " << session.unparsedArgs[0] << ": " << strerror(errno) << endl; return 1; @@ -84,15 +86,16 @@ int Binc::authenticate(Depot &depot, } string timestamp; - time_t t = time(0); + time_t t = time(nullptr); char *c; - if ((c = ctime(&t)) != 0) { + if ((c = ctime(&t)) != nullptr) { timestamp = c; trim(timestamp); - } else + } else { timestamp = "unknown timestamp"; + } - string pid = to_string(session.getPid()); + string pid = std::to_string(session.getPid()); // execute authentication module int result; @@ -128,7 +131,7 @@ int Binc::authenticate(Depot &depot, exit(111); } - if (session.unparsedArgs[0] != 0) { + if (session.unparsedArgs[0] != nullptr) { execvp(session.unparsedArgs[0], &session.unparsedArgs[0]); bincDebug << "bincimap-up: pid " << pid << " authenticate(), [auth module] invocation of " << session.unparsedArgs[0] << " failed: " << strerror(errno) << endl; @@ -212,7 +215,7 @@ int Binc::authenticate(Depot &depot, // EINTR. int n; do { - n = select(maxfd + 1, &rtmp, 0, 0, &timeout); + n = select(maxfd + 1, &rtmp, nullptr, nullptr, &timeout); } while (n < 0 && errno == EINTR); if (n < 0) { @@ -295,8 +298,7 @@ int Binc::authenticate(Depot &depot, return -1; } - // if the server died because we closed the sockets after a timeout, - // exit 3. + // if the server died because we closed the sockets after a timeout, exit 3. if (timedout) return 3; if (disconnected) return 0; diff --git a/src/base64.cc b/src/base64.cc index 5b182b2..1cbac91 100644 --- a/src/base64.cc +++ b/src/base64.cc @@ -1,22 +1,23 @@ -/** -------------------------------------------------------------------- +/** * @file base64.cc * @brief Implementation of base64 Utilities * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "base64.h" #include <iostream> #include <string> -using namespace ::std; +using std::string; -typedef unsigned char bbyte; /* Byte type */ +typedef unsigned char bbyte; // Byte type #define TRUE 1 #define FALSE 0 -#define LINELEN 72 /* Encoded line length (max 76) */ +#define LINELEN 72 // Encoded line length (max 76) static bbyte dtable[256]; @@ -25,15 +26,14 @@ string Binc::base64encode(const string &s_in) int i; string result; - /* Fill dtable with character encodings. */ + // Fill dtable with character encodings. for (i = 0; i < 26; i++) { dtable[i] = 'A' + i; dtable[26 + i] = 'a' + i; } - for (i = 0; i < 10; i++) { + for (i = 0; i < 10; i++) dtable[52 + i] = '0' + i; - } dtable[62] = '+'; dtable[63] = '/'; @@ -45,23 +45,22 @@ string Binc::base64encode(const string &s_in) igroup[0] = igroup[1] = igroup[2] = 0; for (n = 0; n < 3 && s_i != s_in.end(); n++) { c = *s_i++; - igroup[n] = (bbyte)c; + igroup[n] = static_cast<bbyte>(c); } + if (n > 0) { ogroup[0] = dtable[igroup[0] >> 2]; ogroup[1] = dtable[((igroup[0] & 3) << 4) | (igroup[1] >> 4)]; ogroup[2] = dtable[((igroup[1] & 0xF) << 2) | (igroup[2] >> 6)]; ogroup[3] = dtable[igroup[2] & 0x3F]; - /* Replace characters in output stream with "=" pad - characters if fewer than three characters were - read from the end of the input stream. */ + // Replace characters in output stream with "=" pad + // characters if fewer than three characters were + // read from the end of the input stream. if (n < 3) { ogroup[3] = '='; - if (n < 2) { - ogroup[2] = '='; - } + if (n < 2) ogroup[2] = '='; } for (i = 0; i < 4; i++) @@ -77,18 +76,14 @@ string Binc::base64decode(const string &s_in) string result; int i; - for (i = 0; i < 255; i++) { + for (i = 0; i < 255; i++) dtable[i] = 0x80; - } - for (i = 'A'; i <= 'Z'; i++) { + for (i = 'A'; i <= 'Z'; i++) dtable[i] = 0 + (i - 'A'); - } - for (i = 'a'; i <= 'z'; i++) { + for (i = 'a'; i <= 'z'; i++) dtable[i] = 26 + (i - 'a'); - } - for (i = '0'; i <= '9'; i++) { + for (i = '0'; i <= '9'; i++) dtable[i] = 52 + (i - '0'); - } dtable[(int)'+'] = 62; dtable[(int)'/'] = 63; dtable[(int)'='] = 0; diff --git a/src/bincimap-up.cc b/src/bincimap-up.cc index c74b98f..48615ad 100644 --- a/src/bincimap-up.cc +++ b/src/bincimap-up.cc @@ -1,15 +1,15 @@ -/** -------------------------------------------------------------------- +/** * @file bincimap-up.cc * @brief Implementation of the preauthenticated bincimap stub * @author Andreas Aardal Hanssen * @date 2002-2005 - * ------------------------------------------------------------------ **/ + */ + #include "imapserver.h" -//------------------------------------------------------------------------ int main(int argc, char *argv[]) { - Binc::IMAPServer imapServer(argc, argv); + auto imapServer = Binc::IMAPServer(argc, argv); int initResult = imapServer.initialize(); if (initResult != 0) return initResult; return imapServer.runStub(); diff --git a/src/bincimap-updatecache.cc b/src/bincimap-updatecache.cc index b89abdf..b1cf7b3 100644 --- a/src/bincimap-updatecache.cc +++ b/src/bincimap-updatecache.cc @@ -1,16 +1,16 @@ -/** -------------------------------------------------------------------- +/** * @file bincimap-updatecache.cc * @brief Implementation of the bincimap-updatecache tool. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "depot.h" #include "mailbox.h" #include "maildir.h" #include "session.h" -using namespace ::Binc; -using namespace ::std; +using namespace Binc; int main(int argc, char *argv[]) { @@ -27,11 +27,11 @@ int main(int argc, char *argv[]) depotfactory.assign(new IMAPdirDepot()); depotfactory.assign(new MaildirPPDepot()); - string depottype = session.getEnv("DEPOT"); + std::string depottype = session.getEnv("DEPOT"); if (depottype == "") depottype = "Maildir++"; Depot *depot; - if ((depot = depotfactory.get(depottype)) == 0) { + if ((depot = depotfactory.get(depottype)) == nullptr) { fprintf(stderr, "Found no Depot for \"%s\". Please check " " your configurations file under the Mailbox section.\n", diff --git a/src/bincimapd.cc b/src/bincimapd.cc index b8ba1cb..1ec89df 100644 --- a/src/bincimapd.cc +++ b/src/bincimapd.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file bincimapd.cc * @brief Implementation of the main bincimapd service * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "imapserver.h" namespace Binc { @@ -12,7 +13,7 @@ namespace Binc { int main(int argc, char *argv[]) { - Binc::IMAPServer imapServer(argc, argv); + auto imapServer = Binc::IMAPServer(argc, argv); int initResult = imapServer.initialize(); if (initResult != 0) return initResult; return imapServer.run(); diff --git a/src/broker.cc b/src/broker.cc index 4cb7787..507c8c4 100644 --- a/src/broker.cc +++ b/src/broker.cc @@ -1,9 +1,10 @@ -/** --------------------------------------------------------------------- +/** * @file broker.cc * @brief Implementation of the Broker class * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "broker.h" #include "convert.h" @@ -14,10 +15,9 @@ #include <map> #include <string> -using namespace ::std; using namespace Binc; +using std::string; -//---------------------------------------------------------------------- BrokerFactory::BrokerFactory(void) { brokers[Session::NONAUTHENTICATED] = new Broker(); @@ -25,86 +25,74 @@ BrokerFactory::BrokerFactory(void) brokers[Session::SELECTED] = new Broker(); } -//---------------------------------------------------------------------- BrokerFactory::~BrokerFactory(void) { - for (map<int, Broker *>::iterator i = brokers.begin(); i != brokers.end(); ++i) - delete i->second; + for (auto &[_, second] : brokers) + delete second; } -//---------------------------------------------------------------------- BrokerFactory &BrokerFactory::getInstance(void) { static BrokerFactory brokerfactory; return brokerfactory; } -//---------------------------------------------------------------------- void BrokerFactory::addCapability(const std::string &c) { - for (map<int, Broker *>::iterator i = brokers.begin(); i != brokers.end(); ++i) { - CapabilityOperator *o; - o = dynamic_cast<CapabilityOperator *>(i->second->get("CAPABILITY")); - if (o != 0) { + for (const auto &[_, second] : brokers) { + auto o = dynamic_cast<CapabilityOperator *>(second->get("CAPABILITY")); + if (o != nullptr) { o->addCapability(c); break; } } } -//---------------------------------------------------------------------- void BrokerFactory::assign(const string &fname, Operator *o) { int deletable = true; - for (map<int, Broker *>::iterator i = brokers.begin(); i != brokers.end(); ++i) - if (i->first & o->getState()) { - i->second->assign(fname, o, deletable); + for (const auto &[first, second] : brokers) { + if (first & o->getState()) { + second->assign(fname, o, deletable); deletable = false; } + } } -//---------------------------------------------------------------------- Operator *BrokerFactory::getOperator(int state, const string &name) const { if (brokers.find(state) == brokers.end()) - return 0; + return nullptr; else return brokers.find(state)->second->get(name); } -//---------------------------------------------------------------------- Broker *BrokerFactory::getBroker(int state) { if (brokers.find(state) == brokers.end()) { setLastError("No appropriate broker for state."); - return 0; + return nullptr; } return brokers[state]; } -//---------------------------------------------------------------------- Broker::Broker(void) {} -//---------------------------------------------------------------------- Broker::~Broker(void) {} -//---------------------------------------------------------------------- void Broker::assign(const string &fname, Operator *o, bool deletable) { deletables[fname] = deletable; operators[fname] = o; } -//---------------------------------------------------------------------- Operator *Broker::get(const string &name) const { - if (operators.find(name) == operators.end()) return 0; - + if (operators.find(name) == operators.end()) return nullptr; return operators.find(name)->second; } -//---------------------------------------------------------------------- Operator::ParseResult Broker::parseStub(Request &command) { Session &session = Session::getInstance(); @@ -117,6 +105,7 @@ Operator::ParseResult Broker::parseStub(Request &command) break; case Operator::REJECT: session.setLastError("Syntax error; first token must be a tag"); + [[fallthrough]]; case Operator::ERROR: return Operator::ERROR; case Operator::TIMEOUT: @@ -128,6 +117,7 @@ Operator::ParseResult Broker::parseStub(Request &command) break; case Operator::REJECT: session.setLastError("Syntax error; second token must be a SPACE"); + [[fallthrough]]; case Operator::ERROR: return Operator::ERROR; case Operator::TIMEOUT: @@ -139,6 +129,7 @@ Operator::ParseResult Broker::parseStub(Request &command) break; case Operator::REJECT: session.setLastError("Syntax error; third token must be a command"); + [[fallthrough]]; case Operator::ERROR: return Operator::ERROR; case Operator::TIMEOUT: @@ -154,8 +145,8 @@ Operator::ParseResult Broker::parseStub(Request &command) case Operator::ACCEPT: break; case Operator::REJECT: - session.setLastError("Syntax error; after UID there" - " must come a SPACE"); + session.setLastError("Syntax error; after UID there must come a SPACE"); + [[fallthrough]]; case Operator::ERROR: return Operator::ERROR; case Operator::TIMEOUT: @@ -166,8 +157,8 @@ Operator::ParseResult Broker::parseStub(Request &command) case Operator::ACCEPT: break; case Operator::REJECT: - session.setLastError("Syntax error; after UID " - "SPACE there must come a command"); + session.setLastError("Syntax error; after UID SPACE there must come a command"); + [[fallthrough]]; case Operator::ERROR: return Operator::ERROR; case Operator::TIMEOUT: diff --git a/src/convert.cc b/src/convert.cc index ac1c01b..5e77f97 100644 --- a/src/convert.cc +++ b/src/convert.cc @@ -1,26 +1,24 @@ -/** -------------------------------------------------------------------- +/** * @file convert.cc * @brief Implementation of miscellaneous convertion functions * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "convert.h" #include <string> -using namespace ::std; using namespace Binc; +using std::string; -//------------------------------------------------------------------------ BincStream::BincStream(void) {} -//------------------------------------------------------------------------ BincStream::~BincStream(void) { clear(); } -//------------------------------------------------------------------------ string BincStream::popString(unsigned int size) { if (size > nstr.length()) size = nstr.length(); @@ -29,7 +27,6 @@ string BincStream::popString(unsigned int size) return tmp; } -//------------------------------------------------------------------------ char BincStream::popChar(void) { if (nstr.length() == 0) return '\0'; @@ -39,58 +36,49 @@ char BincStream::popChar(void) return c; } -//------------------------------------------------------------------------ void BincStream::unpopChar(char c) { nstr = c + nstr; } -//------------------------------------------------------------------------ void BincStream::unpopStr(const string &s) { nstr = s + nstr; } -//------------------------------------------------------------------------ const string &BincStream::str(void) const { return nstr; } -//------------------------------------------------------------------------ void BincStream::clear(void) { nstr = ""; } -//------------------------------------------------------------------------ unsigned int BincStream::getSize(void) const { return (unsigned int)nstr.length(); } -//------------------------------------------------------------------------ BincStream &BincStream::operator<<(std::ostream &(*)(std::ostream &)) { nstr += "\r\n"; return *this; } -//------------------------------------------------------------------------ BincStream &BincStream::operator<<(const string &t) { nstr += t; return *this; } -//------------------------------------------------------------------------ BincStream &BincStream::operator<<(int t) { nstr += toString(t); return *this; } -//------------------------------------------------------------------------ BincStream &BincStream::operator<<(unsigned long t) { nstr += toString(t); @@ -103,7 +91,6 @@ BincStream &BincStream::operator<<(unsigned int t) return *this; } -//------------------------------------------------------------------------ BincStream &BincStream::operator<<(char t) { nstr += t; diff --git a/src/depot.cc b/src/depot.cc index c31c04b..86ac5f4 100644 --- a/src/depot.cc +++ b/src/depot.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file depot.cc * @brief Implementation of the Depot class. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ------------------------------------------------------------------ **/ + */ + #include "depot.h" #include "convert.h" @@ -12,6 +13,7 @@ #include "mailbox.h" #include "status.h" +#include <cstddef> #include <map> #include <string> @@ -19,224 +21,191 @@ #include <unistd.h> -using namespace ::std; using namespace Binc; +using std::endl; +using std::string; -//-------------------------------------------------------------------- DepotFactory::DepotFactory(void) {} -//-------------------------------------------------------------------- DepotFactory::~DepotFactory(void) { - for (vector<Depot *>::iterator i = depots.begin(); i != depots.end(); ++i) - delete *i; + for (auto i : depots) + delete i; } -//-------------------------------------------------------------------- Depot *DepotFactory::get(const string &name) const { - for (vector<Depot *>::const_iterator i = depots.begin(); i != depots.end(); ++i) - if ((*i)->getName() == name) return *i; + for (const auto i : depots) + if (i->getName() == name) return i; - return 0; + return nullptr; } -//-------------------------------------------------------------------- void DepotFactory::assign(Depot *depot) { depots.push_back(depot); } -//-------------------------------------------------------------------- DepotFactory &DepotFactory::getInstance(void) { static DepotFactory depotfactory; return depotfactory; } -//-------------------------------------------------------------------- -Depot::Depot(void) : enditerator(0, 0) -{ - defaultmailbox = 0; - selectedmailbox = 0; - - delimiter = '/'; -} - -//-------------------------------------------------------------------- -Depot::Depot(const string &name) : enditerator(0, 0) -{ - defaultmailbox = 0; - selectedmailbox = 0; - - delimiter = '/'; - - this->name = name; -} +Depot::Depot() : Depot("") {} -//-------------------------------------------------------------------- -Depot::~Depot(void) {} +Depot::Depot(const std::string &name) + : enditerator(nullptr, nullptr) + , defaultmailbox(nullptr) + , selectedmailbox(nullptr) + , name(name) + , delimiter('/') +{} -//-------------------------------------------------------------------- const string &Depot::getLastError(void) const { return lastError; } -//-------------------------------------------------------------------- void Depot::setLastError(const string &error) const { lastError = error; } -//-------------------------------------------------------------------- void Depot::assign(Mailbox *m) { - for (vector<Mailbox *>::const_iterator i = backends.begin(); i != backends.end(); ++i) - if (*i == m) break; + for (const auto i : backends) + if (i == m) break; backends.push_back(m); } -//-------------------------------------------------------------------- Mailbox *Depot::get(const string &s_in) const { - for (vector<Mailbox *>::const_iterator i = backends.begin(); i != backends.end(); ++i) - if ((*i)->isMailbox(mailboxToFilename(s_in))) return *i; + for (const auto i : backends) + if (i->isMailbox(mailboxToFilename(s_in))) return i; setLastError("No such mailbox " + toImapString(s_in)); - return 0; + return nullptr; } -//-------------------------------------------------------------------- bool Depot::setSelected(Mailbox *m) { - for (vector<Mailbox *>::const_iterator i = backends.begin(); i != backends.end(); ++i) - if (*i == m) { + for (const auto i : backends) { + if (i == m) { selectedmailbox = m; return true; } + } setLastError("Attempted to select unregistered Mailbox type in Depot"); return false; } -//-------------------------------------------------------------------- const string &Depot::getName(void) const { return name; } -//-------------------------------------------------------------------- const string &Depot::getPersonalNamespace(void) const { return personalNamespace; } -//-------------------------------------------------------------------- const string &Depot::getOthersNamespace(void) const { return othersNamespace; } -//-------------------------------------------------------------------- const string &Depot::getSharedNamespace(void) const { return sharedNamespace; } -//-------------------------------------------------------------------- void Depot::setDelimiter(char c) { delimiter = c; } -//-------------------------------------------------------------------- -const char Depot::getDelimiter(void) const +char Depot::getDelimiter(void) const { return delimiter; } -//-------------------------------------------------------------------- bool Depot::setDefaultType(const string &name) { - for (vector<Mailbox *>::const_iterator i = backends.begin(); i != backends.end(); ++i) - if ((*i)->getTypeName() == name) { - defaultmailbox = *i; + for (const auto i : backends) { + if (i->getTypeName() == name) { + defaultmailbox = i; return true; } + } setLastError("attempt to default to unregistered Mailbox type " + name); return false; } -//-------------------------------------------------------------------- Mailbox *Depot::getSelected(void) const { return selectedmailbox; } -//-------------------------------------------------------------------- void Depot::resetSelected(void) { - selectedmailbox = 0; + selectedmailbox = nullptr; } -//-------------------------------------------------------------------- Mailbox *Depot::getDefault(void) const { return defaultmailbox; } -//-------------------------------------------------------------------- bool Depot::createMailbox(const string &s_in) const { const string &mailboxname = mailboxToFilename(toCanonMailbox(s_in)); - if (mailboxname == "") { + if (mailboxname.empty()) { setLastError("invalid mailbox name"); return false; } Mailbox *mailbox = getDefault(); - if (mailbox == 0) { + if (mailbox == nullptr) { setLastError("no default mailbox defined"); return false; } bool result = mailbox->createMailbox(mailboxname, 0777); - if (result) + if (result) { return true; - else { + } else { setLastError(mailbox->getLastError()); return false; } } -//-------------------------------------------------------------------- bool Depot::deleteMailbox(const string &s_in) const { const string &mailboxname = mailboxToFilename(toCanonMailbox(s_in)); Mailbox *mailbox = get(s_in); - if (mailbox == 0) { + if (mailbox == nullptr) { setLastError(s_in + ": no such mailbox"); return false; } bool result = mailbox->deleteMailbox(mailboxname); - if (result) + if (result) { return true; - else { + } else { setLastError(mailbox->getLastError()); return false; } } -//-------------------------------------------------------------------- bool Depot::renameMailbox(const string &s_in, const string &t_in) const { - const string &source = mailboxToFilename(s_in).c_str(); - const string &dest = mailboxToFilename(t_in).c_str(); + const string &source = mailboxToFilename(s_in); + const string &dest = mailboxToFilename(t_in); int nrenamed = 0; const iterator e = end(); @@ -249,23 +218,24 @@ bool Depot::renameMailbox(const string &s_in, const string &t_in) const if (entry.length() == source.length()) { sourcename = source; destname = dest; - } else if (entry.length() > source.length() && entry[source.length()] == '.') { sourcename = entry; destname = dest + entry.substr(source.length()); - } else + } else { continue; + } if (rename(sourcename.c_str(), destname.c_str()) != 0) { bincWarning << "error renaming " << sourcename << " to " << destname << ": " << strerror(errno) << endl; - } else + } else { nrenamed++; + } Mailbox *mailbox; - if ((mailbox = get(filenameToMailbox(sourcename))) != 0) + if ((mailbox = get(filenameToMailbox(sourcename))) != nullptr) mailbox->bumpUidValidity(filenameToMailbox(sourcename)); - if ((mailbox = get(filenameToMailbox(destname))) != 0) + if ((mailbox = get(filenameToMailbox(destname))) != nullptr) mailbox->bumpUidValidity(filenameToMailbox(destname)); } } @@ -276,16 +246,16 @@ bool Depot::renameMailbox(const string &s_in, const string &t_in) const " then copy over all messages." " Finally, delete the original mailbox"); return false; - } else + } else { return true; + } } -//-------------------------------------------------------------------- bool Depot::getStatus(const std::string &s_in, Status &dest) const { const string mailbox = toCanonMailbox(s_in); Mailbox *m = get(mailbox); - if (m == 0) { + if (m == nullptr) { setLastError("Unrecognized mailbox: " + toImapString(s_in)); return false; } @@ -306,26 +276,22 @@ bool Depot::getStatus(const std::string &s_in, Status &dest) const return true; } -//---------------------------------------------------------------------- -vector<string> Depot::getSubscriptions(void) const +std::vector<string> Depot::getSubscriptions(void) const { return subscribed; } -//---------------------------------------------------------------------- -void Depot::subscribeTo(const std::string mailbox) +void Depot::subscribeTo(const string mailbox) { - for (vector<string>::iterator i = subscribed.begin(); i != subscribed.end(); ++i) { - if (*i == mailbox) return; - } + for (const auto &i : subscribed) + if (i == mailbox) return; subscribed.push_back(mailbox); } -//---------------------------------------------------------------------- -bool Depot::unsubscribeTo(const std::string mailbox) +bool Depot::unsubscribeTo(const string mailbox) { - for (vector<string>::iterator i = subscribed.begin(); i != subscribed.end(); ++i) { + for (auto i = subscribed.begin(); i != subscribed.end(); ++i) { if (*i == mailbox) { subscribed.erase(i); return true; @@ -335,7 +301,6 @@ bool Depot::unsubscribeTo(const std::string mailbox) return false; } -//---------------------------------------------------------------------- void Depot::loadSubscribes(void) { // drop all existing subscribed folders. @@ -344,7 +309,7 @@ void Depot::loadSubscribes(void) // try loading the .subscribed file bool ok = false; FILE *fp = fopen(".subscribed", "r"); - map<string, bool> addedEntries; + std::map<string, bool> addedEntries; if (fp) { int c; string current; @@ -361,8 +326,9 @@ void Depot::loadSubscribes(void) } current = ""; } - } else + } else { current += c; + } } fclose(fp); @@ -375,28 +341,24 @@ void Depot::loadSubscribes(void) } } -//---------------------------------------------------------------------- bool Depot::saveSubscribes(void) const { // create a safe file name - string tpl = ".subscribed-tmp-XXXXXX"; - char *ftemplate = new char[tpl.length() + 1]; + string ftemplate = ".subscribed-tmp-XXXXXX"; - strcpy(ftemplate, tpl.c_str()); - int fd = mkstemp(ftemplate); + int fd = mkstemp(ftemplate.data()); if (fd == -1) { - bincWarning << "unable to create temporary file \"" << tpl << "\"" << endl; - delete[] ftemplate; + bincWarning << "unable to create temporary file \"" << ftemplate << "\"" << endl; return false; } - map<string, bool> addedEntries; - for (vector<string>::const_iterator i = subscribed.begin(); i != subscribed.end(); ++i) { - if (addedEntries.find(*i) == addedEntries.end()) { - addedEntries[*i] = true; - string w = mailboxToFilename(*i) + "\n"; + std::map<string, bool> addedEntries; + for (const auto &i : subscribed) { + if (addedEntries.find(i) == addedEntries.end()) { + addedEntries[i] = true; + string w = mailboxToFilename(i) + "\n"; if (write(fd, w.c_str(), w.length()) != (ssize_t)w.length()) { - bincWarning << "failed to write to " << tpl << ": " << strerror(errno) << endl; + bincWarning << "failed to write to " << ftemplate << ": " << strerror(errno) << endl; break; } } @@ -404,29 +366,24 @@ bool Depot::saveSubscribes(void) const if ((fsync(fd) && (errno != EROFS || errno != EINVAL)) || close(fd)) { bincWarning << "failed to close " << ftemplate << ": " << strerror(errno) << endl; - delete[] ftemplate; return false; } - if (rename(ftemplate, ".subscribed") != 0) { + if (rename(ftemplate.c_str(), ".subscribed") != 0) { bincWarning << "failed to rename " << ftemplate << " to .subscribed: " << strerror(errno) << endl; - delete[] ftemplate; return false; } - delete[] ftemplate; return true; } -//-------------------------------------------------------------------- Depot::iterator::iterator(void) { - dirp = 0; + dirp = nullptr; ref = new int; *ref = 1; } -//-------------------------------------------------------------------- Depot::iterator::iterator(DIR *dp, struct dirent *sp) { dirp = dp; @@ -436,7 +393,6 @@ Depot::iterator::iterator(DIR *dp, struct dirent *sp) *ref = 1; } -//-------------------------------------------------------------------- Depot::iterator::iterator(const iterator ©) { if (*copy.ref != 0) ++(*copy.ref); @@ -446,13 +402,11 @@ Depot::iterator::iterator(const iterator ©) direntp = copy.direntp; } -//-------------------------------------------------------------------- Depot::iterator::~iterator(void) { deref(); } -//-------------------------------------------------------------------- Depot::iterator &Depot::iterator::operator=(const iterator ©) { if (*copy.ref != 0) ++(*copy.ref); @@ -466,53 +420,47 @@ Depot::iterator &Depot::iterator::operator=(const iterator ©) return *this; } -//-------------------------------------------------------------------- void Depot::iterator::deref(void) { // decrease existing copy ref if there is one if (*ref != 0 && --(*ref) == 0) { if (dirp) { closedir(dirp); - dirp = 0; + dirp = nullptr; } delete ref; - ref = 0; + ref = nullptr; } } -//-------------------------------------------------------------------- string Depot::iterator::operator*(void) const { - if (direntp == 0) return ""; + if (direntp == nullptr) return ""; return direntp->d_name; } -//-------------------------------------------------------------------- void Depot::iterator::operator++(void) { direntp = readdir(dirp); } -//-------------------------------------------------------------------- bool Depot::iterator::operator==(Depot::iterator i) const { return direntp == i.direntp; } -//-------------------------------------------------------------------- bool Depot::iterator::operator!=(Depot::iterator i) const { return direntp != i.direntp; } -//-------------------------------------------------------------------- Depot::iterator Depot::begin(const string &path) const { Depot::iterator i; - if ((i.dirp = opendir(path.c_str())) == 0) { + if ((i.dirp = opendir(path.c_str())) == nullptr) { bincWarning << "opendir on " << path << " failed" << endl; setLastError("opendir on " + path + " failed"); return end(); @@ -522,29 +470,24 @@ Depot::iterator Depot::begin(const string &path) const return i; } -//-------------------------------------------------------------------- const Depot::iterator &Depot::end(void) const { return enditerator; } -//-------------------------------------------------------------------- MaildirPPDepot::MaildirPPDepot(void) : Depot("Maildir++") { privateNamespace = "INBOX"; privateNamespace += getDelimiter(); } -//-------------------------------------------------------------------- MaildirPPDepot::~MaildirPPDepot(void) {} -//-------------------------------------------------------------------- const string &MaildirPPDepot::getPersonalNamespace(void) const { return privateNamespace; } -//-------------------------------------------------------------------- string MaildirPPDepot::mailboxToFilename(const string &m) const { string prefix = "INBOX"; @@ -566,9 +509,9 @@ string MaildirPPDepot::mailboxToFilename(const string &m) const twodelim += delimiter; twodelim += delimiter; - if (mm == "INBOX") + if (mm == "INBOX") { return "."; - else if (mm.length() <= 6) { + } else if (mm.length() <= 6) { setLastError("With a Maildir++ depot, you must create all" " mailboxes under INBOX."); return ""; @@ -584,37 +527,34 @@ string MaildirPPDepot::mailboxToFilename(const string &m) const return ""; } else { string tmp = mm.substr(6); - for (string::iterator i = tmp.begin(); i != tmp.end(); ++i) - if (*i == delimiter) *i = '.'; + for (auto &i : tmp) + if (i == delimiter) i = '.'; return "." + tmp; } } -//-------------------------------------------------------------------- string MaildirPPDepot::filenameToMailbox(const string &m) const { - if (m == ".") + if (m == ".") { return "INBOX"; - else if (delimiter != '.' && m.find(delimiter) != string::npos) + } else if (delimiter != '.' && m.find(delimiter) != string::npos) { return ""; - else if (m != "" && m[0] == '.') { + } else if (m != "" && m[0] == '.') { string tmp = m; - for (string::iterator i = tmp.begin(); i != tmp.end(); ++i) - if (*i == '.') *i = delimiter; + for (auto &i : tmp) + if (i == '.') i = delimiter; return "INBOX" + tmp; - } else + } else { return ""; + } } -//-------------------------------------------------------------------- IMAPdirDepot::IMAPdirDepot(void) : Depot("IMAPdir") {} -//-------------------------------------------------------------------- IMAPdirDepot::~IMAPdirDepot(void) {} -//-------------------------------------------------------------------- string IMAPdirDepot::mailboxToFilename(const string &m) const { string tmp; @@ -630,28 +570,23 @@ string IMAPdirDepot::mailboxToFilename(const string &m) const return ""; } - string::const_iterator i = mm.begin(); - while (i != mm.end()) { - if (*i == delimiter) { + for (auto i = mm.cbegin(); i != mm.cend(); ++i) { + if (*i == delimiter) tmp += '.'; - } else if (*i == '\\') { + else if (*i == '\\') tmp += "\\\\"; - } else if (*i == '.') { - if (i == mm.begin()) + else if (*i == '.') + if (i == mm.cbegin()) tmp += "."; else tmp += "\\."; - } else { + else tmp += *i; - } - - ++i; } return tmp; } -//-------------------------------------------------------------------- string IMAPdirDepot::filenameToMailbox(const string &m) const { string tmp; @@ -660,33 +595,28 @@ string IMAPdirDepot::filenameToMailbox(const string &m) const // hide the magic "." mailbox. if (m == "." || m == "..") return ""; - string::const_iterator i = m.begin(); - while (i != m.end()) { + for (auto i = m.cbegin(); i != m.cend(); ++i) { if (*i == '.') { - if (i != m.begin() && !escape) + if (i != m.cbegin() && !escape) tmp += delimiter; - else if (i == m.begin() || escape) + else if (i == m.cbegin() || escape) tmp += '.'; escape = false; } else if (*i == '\\') { - if (!escape) + if (!escape) { escape = true; - else { + } else { tmp += '\\'; escape = false; } } else if (*i == delimiter) { return ""; + } else if (escape) { + return ""; } else { - if (escape) - return ""; - else { - tmp += *i; - escape = false; - } + tmp += *i; + escape = false; } - - ++i; } return tmp; diff --git a/src/greeting.cc b/src/greeting.cc index 95e93c0..d96ab96 100644 --- a/src/greeting.cc +++ b/src/greeting.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file greeting.cc * @brief Implementation of the inital greeting. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "globals.h" #include "iodevice.h" #include "iofactory.h" @@ -11,7 +12,6 @@ #include <time.h> -using namespace ::std; using namespace Binc; static const unsigned int ISO8601SIZE = 32; @@ -20,12 +20,10 @@ namespace Binc { void showGreeting(void); }; -//------------------------------------------------------------------------ void Binc::showGreeting(void) { Session &session = Session::getInstance(); - - time_t t = time(0); + time_t t = time(nullptr); struct tm *mytm = localtime(&t); char mytime[ISO8601SIZE]; @@ -34,8 +32,8 @@ void Binc::showGreeting(void) if (session.hasEnv("VERBOSE_GREETING")) { bincClient << "* OK Welcome to Binc IMAP " << BINC_VERSION << " " << IMAP_VERSION - << " by Andreas Aardal Hanssen & Erwin Hoffmann at " << mytime << endl; + << " by Andreas Aardal Hanssen & Erwin Hoffmann at " << mytime << std::endl; } else { - bincClient << "* OK Welcome to Binc IMAP at " << mytime << endl; + bincClient << "* OK Welcome to Binc IMAP at " << mytime << std::endl; } } diff --git a/src/imapparser.cc b/src/imapparser.cc index fc2e071..d5e5f55 100644 --- a/src/imapparser.cc +++ b/src/imapparser.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file imapparser.cc * @brief Implementation of the common items for parsing IMAP input * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "imapparser.h" #include "convert.h" @@ -16,218 +17,181 @@ #include <stdio.h> -using namespace ::std; using namespace Binc; +using std::string; -//------------------------------------------------------------------------ -Request::Request(void) : extra(0), flags(), statuses(), bset(), searchkey(), fatt() -{ - uidmode = false; -} +Request::Request(void) : uidmode(false), extra(nullptr), flags(), statuses(), bset(), searchkey(), fatt() +{} Request::~Request(void) { - if (extra != 0) delete extra; + if (extra != nullptr) delete extra; } -//------------------------------------------------------------------------ void Request::setUidMode(void) { uidmode = true; } -//------------------------------------------------------------------------ bool Request::getUidMode(void) const { return uidmode; } -//------------------------------------------------------------------------ void Request::setTag(string &t_in) { tag = t_in; } -//------------------------------------------------------------------------ const string &Request::getTag(void) const { return tag; } -//------------------------------------------------------------------------ void Request::setMode(const string &m_in) { mode = m_in; } -//------------------------------------------------------------------------ const string &Request::getMode(void) const { return mode; } -//------------------------------------------------------------------------ void Request::setName(const string &s_in) { name = s_in; } -//------------------------------------------------------------------------ const string &Request::getName(void) const { return name; } -//------------------------------------------------------------------------ void Request::setAuthType(const string &s_in) { authtype = s_in; } -//------------------------------------------------------------------------ const string &Request::getAuthType(void) const { return authtype; } -//------------------------------------------------------------------------ void Request::setLiteral(const string &s_in) { literal = s_in; } -//------------------------------------------------------------------------ const string &Request::getLiteral(void) const { return literal; } -//------------------------------------------------------------------------ void Request::setDate(const string &s_in) { date = s_in; } -//------------------------------------------------------------------------ const string &Request::getDate(void) const { return date; } -//------------------------------------------------------------------------ void Request::setCharSet(const string &s_in) { charset = s_in; uppercase(charset); } -//------------------------------------------------------------------------ const string &Request::getCharSet(void) const { return charset; } -//------------------------------------------------------------------------ void Request::setUserID(const string &s_in) { userid = s_in; } -//------------------------------------------------------------------------ const string &Request::getUserID(void) const { return userid; } -//------------------------------------------------------------------------ void Request::setPassword(const string &s_in) { password = s_in; } -//------------------------------------------------------------------------ const string &Request::getPassword(void) const { return password; } -//------------------------------------------------------------------------ void Request::setMailbox(const string &s_in) { mailbox = s_in; } -//------------------------------------------------------------------------ const string &Request::getMailbox(void) const { return mailbox; } -//------------------------------------------------------------------------ void Request::setListMailbox(const string &s_in) { listmailbox = s_in; } -//------------------------------------------------------------------------ const string &Request::getListMailbox(void) const { return listmailbox; } -//------------------------------------------------------------------------ void Request::setContextInfo(const string &s_in) { contextInfo = s_in; } -//------------------------------------------------------------------------ const string &Request::getContextInfo(void) const { return contextInfo; } -//------------------------------------------------------------------------ void Request::setNewMailbox(const string &s_in) { newmailbox = s_in; } -//------------------------------------------------------------------------ const string &Request::getNewMailbox(void) const { return newmailbox; } -//------------------------------------------------------------------------ SequenceSet &Request::getSet(void) { return bset; } -//------------------------------------------------------------------------ -vector<string> &Request::getStatuses(void) +std::vector<string> &Request::getStatuses(void) { return statuses; } -//------------------------------------------------------------------------ -vector<string> &Request::getFlags(void) +std::vector<string> &Request::getFlags(void) { return flags; } -//------------------------------------------------------------------------ SequenceSet::SequenceSet(void) : limited(true), nullSet(false) {} -//------------------------------------------------------------------------ SequenceSet::SequenceSet(const SequenceSet ©) : limited(copy.limited) , nullSet(copy.nullSet) , internal(copy.internal) {} -//------------------------------------------------------------------------ SequenceSet &SequenceSet::operator=(const SequenceSet ©) { limited = copy.limited; @@ -237,10 +201,8 @@ SequenceSet &SequenceSet::operator=(const SequenceSet ©) return *this; } -//------------------------------------------------------------------------ SequenceSet::~SequenceSet(void) {} -//------------------------------------------------------------------------ SequenceSet &SequenceSet::null(void) { static SequenceSet nil; @@ -248,13 +210,11 @@ SequenceSet &SequenceSet::null(void) return nil; } -//------------------------------------------------------------------------ bool SequenceSet::isNull(void) const { return nullSet; } -//------------------------------------------------------------------------ SequenceSet &SequenceSet::all(void) { static bool initialized = false; @@ -268,7 +228,6 @@ SequenceSet &SequenceSet::all(void) return all; } -//------------------------------------------------------------------------ SequenceSet::Range::Range(unsigned int a, unsigned int b) { if (a > b) { @@ -280,40 +239,33 @@ SequenceSet::Range::Range(unsigned int a, unsigned int b) } } -//------------------------------------------------------------------------ void SequenceSet::addRange(unsigned int a, unsigned int b) { if (a == (unsigned int)-1 || b == (unsigned int)-1) limited = false; internal.push_back(Range(a, b)); } -//------------------------------------------------------------------------ void SequenceSet::addNumber(unsigned int a) { if (a == (unsigned int)-1) limited = false; internal.push_back(Range(a, a)); } -//------------------------------------------------------------------------ bool SequenceSet::isInSet(unsigned int n) const { unsigned int maxvalue = 0; - for (vector<Range>::const_iterator i = internal.begin(); i != internal.end(); ++i) { - const Range &r = *i; + for (const auto &r : internal) { if (r.from > maxvalue) maxvalue = r.from; else if (r.to > maxvalue) maxvalue = r.to; - if (n >= (*i).from && n <= (*i).to) { - return true; - } + if (n >= r.from && n <= r.to) return true; } return (n > maxvalue && !limited); } -//------------------------------------------------------------------------ BincImapParserFetchAtt::BincImapParserFetchAtt(const std::string &typeName) : type(typeName) { offsetstart = 0; @@ -321,7 +273,6 @@ BincImapParserFetchAtt::BincImapParserFetchAtt(const std::string &typeName) : ty hassection = false; } -//------------------------------------------------------------------------ string BincImapParserFetchAtt::toString(void) { string tmp; @@ -340,8 +291,8 @@ string BincImapParserFetchAtt::toString(void) if (headerlist.size() > 0) { tmp += " ("; - for (vector<string>::iterator i = headerlist.begin(); i != headerlist.end(); ++i) { - if (i != headerlist.begin()) tmp += " "; + for (auto i = headerlist.cbegin(); i != headerlist.cend(); ++i) { + if (i != headerlist.cbegin()) tmp += " "; tmp += Binc::toImapString(*i); } tmp += ")"; @@ -359,14 +310,12 @@ string BincImapParserFetchAtt::toString(void) return tmp; } -//------------------------------------------------------------------------ BincImapParserSearchKey::BincImapParserSearchKey(void) { type = 0; number = 0; } -//------------------------------------------------------------------------ const SequenceSet &BincImapParserSearchKey::getSet(void) const { return bset; diff --git a/src/imapserver.cc b/src/imapserver.cc index 4ec646d..b19bc90 100644 --- a/src/imapserver.cc +++ b/src/imapserver.cc @@ -1,10 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file imapserver.cc * @brief Implementation of the IMAPServer class. * @author Andreas Aardal Hanssen * @date 2005 - * -------------------------------------------------------------------- */ + #include "imapserver.h" #include "broker.h" @@ -14,8 +14,10 @@ #include "iofactory.h" #include "session.h" -using namespace ::Binc; -using namespace ::std; +#include <cstdint> + +using namespace Binc; +using std::endl; namespace Binc { void showGreeting(void); @@ -62,7 +64,7 @@ int IMAPServer::run(void) { Session &session = Session::getInstance(); bincLog.setOutputLevelLimit(IODevice::InfoLevel); - string pid = to_string(session.getPid()); + std::string pid = std::to_string(session.getPid()); bincDebug << "IMAPServer::run(), started server" << endl; @@ -106,7 +108,7 @@ int IMAPServer::run(void) Operator *o = broker->get(clientRequest.getName()); if (!o) { serverStatus = RequestRejected; - string err = "The command \""; + std::string err = "The command \""; if (clientRequest.getUidMode()) err += "UID "; err += clientRequest.getName(); err += "\" is unsupported in this state. "; @@ -166,9 +168,9 @@ int IMAPServer::run(void) if (skipToNextRequest) { if (!bincClient.skipTo('\n')) { - if (bincClient.getLastError() == IODevice::Timeout) { + if (bincClient.getLastError() == IODevice::Timeout) serverStatus = Timeout; - } else + else serverStatus = ClientDisconnected; break; } @@ -177,7 +179,7 @@ int IMAPServer::run(void) // Session finished - write some log information - string userID = this->stubMode ? session.getIP() : session.getEnv("USER"); + std::string userID = this->stubMode ? session.getIP() : session.getEnv("USER"); if (this->stubMode) { bincLog << "bincimap-up: pid " << pid << " (Read: " << session.getReadBytes() diff --git a/src/include/address.h b/src/include/address.h index a8aded9..6d0a6cd 100644 --- a/src/include/address.h +++ b/src/include/address.h @@ -1,26 +1,24 @@ -/** -------------------------------------------------------------------- +/** * @file address.h * @brief Declaration of the Address class. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #ifndef address_h_included #define address_h_included + #include <string> namespace Binc { - //------------------------------------------------------------------------ - class Address { - public: + struct Address { std::string name; std::string local; std::string host; - //-- std::string toParenList(void) const; - //-- Address(const std::string &name, const std::string &addr); Address(const std::string &wholeaddr); }; diff --git a/src/include/argparser.h b/src/include/argparser.h index ba7838d..0e9b060 100644 --- a/src/include/argparser.h +++ b/src/include/argparser.h @@ -1,30 +1,31 @@ -/** -------------------------------------------------------------------- +/** * @file argparser.h * @brief Declaration of the argument parser class. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #ifndef ARGPARSER_H_INCLUDED #define ARGPARSER_H_INCLUDED + #include <map> #include <string> #include <vector> namespace Binc { - class ArgOpts { - public: + + struct ArgOpts { std::string c; bool b; bool o; std::string desc; - inline ArgOpts(const std::string &chr, bool boolean, bool optional, const std::string &descr) - { - c = chr; - b = boolean; - o = optional; - desc = descr; - } + ArgOpts(const std::string &chr, bool boolean, bool optional, const std::string &descr) + : c(chr) + , b(boolean) + , o(optional) + , desc(descr) + {} }; class CommandLineArgs { @@ -46,7 +47,7 @@ namespace Binc { void setTail(const std::string &str); - const std::vector<std::string> &getUnqualifiedArgs() const; + const std::vector<std::string> &getUnqualifiedArgs(void) const; private: void registerArg(const std::string &arg, const std::string &desc, bool boolean, bool optional); diff --git a/src/include/authenticate.h b/src/include/authenticate.h index a3d63ce..b3f68e9 100644 --- a/src/include/authenticate.h +++ b/src/include/authenticate.h @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file authenticate.h * @brief Declaration of the common authentication mechanism. * @author Andreas Aardal Hanssen, Erwin Hoffmann * @date 2002-2005, 2023 - * ----------------------------------------------------------------- **/ + */ + #ifndef authenticate_h_included #define authenticate_h_included #include "depot.h" diff --git a/src/include/base64.h b/src/include/base64.h index 25b0ff4..da219d2 100644 --- a/src/include/base64.h +++ b/src/include/base64.h @@ -1,18 +1,18 @@ -/** -------------------------------------------------------------------- +/** * @file base64.h * @brief Declaration of base64 Utilities * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #ifndef base64_h_included #define base64_h_included + #include <string> namespace Binc { - std::string base64decode(const std::string &s_in); std::string base64encode(const std::string &s_in); - } #endif diff --git a/src/include/broker.h b/src/include/broker.h index ac78041..eb28bd4 100644 --- a/src/include/broker.h +++ b/src/include/broker.h @@ -1,11 +1,13 @@ -/** -------------------------------------------------------------------- +/** * @file broker.h * @brief Declaration of the Broker class. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #ifndef broker_h_included #define broker_h_included + #include "depot.h" #include "operators.h" @@ -17,12 +19,10 @@ namespace Binc { class Request; class Broker; - //------------------------------------------------------------------ class BrokerFactory { private: std::map<int, Broker *> brokers; - //-- BrokerFactory(void); mutable std::string lastError; @@ -36,24 +36,20 @@ namespace Binc { inline const std::string &getLastError(void) const; inline void setLastError(const std::string &error) const; - //-- static BrokerFactory &getInstance(void); ~BrokerFactory(void); }; - //------------------------------------------------------------------ inline const std::string &BrokerFactory::getLastError(void) const { return lastError; } - //------------------------------------------------------------------ inline void BrokerFactory::setLastError(const std::string &error) const { lastError = error; } - //------------------------------------------------------------------ class Broker { private: std::map<std::string, Operator *> operators; @@ -64,11 +60,10 @@ namespace Binc { void assign(const std::string &fname, Operator *o, bool deletable = false); Operator::ParseResult parseStub(Request &cmd); - //-- inline Broker(Broker &); inline Broker(const Broker &); Broker(void); - ~Broker(void); + ~Broker(); }; inline Broker::Broker(Broker &) {} diff --git a/src/include/convert.h b/src/include/convert.h index 9e51027..2342a70 100644 --- a/src/include/convert.h +++ b/src/include/convert.h @@ -1,12 +1,13 @@ -/** -------------------------------------------------------------------- +/** * @file convert.h * @brief Declaration of miscellaneous convertion functions. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ #ifndef convert_h_included #define convert_h_included + #include "address.h" #include "depot.h" @@ -22,7 +23,6 @@ namespace Binc { - //---------------------------------------------------------------------- inline std::string toString(int i_in) { char intbuf[16]; @@ -30,7 +30,6 @@ namespace Binc { return std::string(intbuf); } - //---------------------------------------------------------------------- inline std::string toString(unsigned int i_in) { char intbuf[16]; @@ -38,7 +37,6 @@ namespace Binc { return std::string(intbuf); } - //---------------------------------------------------------------------- inline std::string toString(unsigned long i_in) { char longbuf[40]; @@ -46,25 +44,22 @@ namespace Binc { return std::string(longbuf); } - //---------------------------------------------------------------------- inline std::string toString(const char *i_in) { return std::string(i_in); } - //---------------------------------------------------------------------- inline int atoi(const std::string &s_in) { return ::atoi(s_in.c_str()); } - //---------------------------------------------------------------------- inline std::string toHex(const std::string &s) { const char hexchars[] = "0123456789abcdef"; std::string tmp; - for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) { - unsigned char c = (unsigned char)*i; + for (auto i : s) { + unsigned char c = static_cast<unsigned char>(i); tmp += hexchars[((c & 0xf0) >> 4)]; tmp += hexchars[c & 0x0f]; } @@ -72,22 +67,21 @@ namespace Binc { return tmp; } - //---------------------------------------------------------------------- inline std::string fromHex(const std::string &s) { // const char hexchars[] = "0123456789abcdef"; std::string tmp; - for (std::string::const_iterator i = s.begin(); i != s.end() && i + 1 != s.end(); i += 2) { + for (auto i = s.cbegin(); i != s.cend() && i + 1 != s.cend(); i += 2) { int n; unsigned char c = *i; unsigned char d = *(i + 1); char *t; - if ((t = strchr(hexchars, c)) == 0) return "out of range"; + if ((t = strchr(hexchars, c)) == nullptr) return "out of range"; n = (t - hexchars) << 4; - if ((t = strchr(hexchars, d)) == 0) return "out of range"; + if ((t = strchr(hexchars, d)) == nullptr) return "out of range"; n += (t - hexchars); if (n >= 0 && n <= 255) @@ -99,11 +93,10 @@ namespace Binc { return tmp; } - //---------------------------------------------------------------------- inline std::string toImapString(const std::string &s_in) { - for (std::string::const_iterator i = s_in.begin(); i != s_in.end(); ++i) { - unsigned char c = (unsigned char)*i; + for (const auto i : s_in) { + auto c = static_cast<unsigned char>(i); if (c <= 31 || c >= 127 || c == '\"' || c == '\\') return "{" + toString(s_in.length()) + "}\r\n" + s_in; } @@ -111,21 +104,18 @@ namespace Binc { return "\"" + s_in + "\""; } - //---------------------------------------------------------------------- inline void uppercase(std::string &input) { - for (std::string::iterator i = input.begin(); i != input.end(); ++i) - *i = toupper(*i); + for (auto &i : input) + i = toupper(i); } - //---------------------------------------------------------------------- inline void lowercase(std::string &input) { - for (std::string::iterator i = input.begin(); i != input.end(); ++i) - *i = tolower(*i); + for (char &i : input) + i = tolower(i); } - //---------------------------------------------------------------------- inline void chomp(std::string &s_in, const std::string &chars = " \t\r\n") { int n = s_in.length(); @@ -133,7 +123,6 @@ namespace Binc { s_in.resize(n-- - 1); } - //---------------------------------------------------------------------- inline void trim(std::string &s_in, const std::string &chars = " \t\r\n") { while (s_in != "" && chars.find(s_in[0]) != std::string::npos) @@ -141,14 +130,15 @@ namespace Binc { chomp(s_in, chars); } - //---------------------------------------------------------------------- inline const std::string unfold(const std::string &a, bool removecomment = true) { std::string tmp; + bool incomment = false; bool inquotes = false; - for (std::string::const_iterator i = a.begin(); i != a.end(); ++i) { - unsigned char c = (unsigned char)*i; + + for (const char i : a) { + unsigned char c = (unsigned char)i; if (!inquotes && removecomment) { if (c == '(') { incomment = true; @@ -156,14 +146,14 @@ namespace Binc { } else if (c == ')') { incomment = false; } else if (c != 0x0a && c != 0x0d) { - tmp += *i; + tmp += i; } } else if (c != 0x0a && c != 0x0d) { - tmp += *i; + tmp += i; } if (!incomment) { - if (*i == '\"') inquotes = !inquotes; + if (i == '\"') inquotes = !inquotes; } } @@ -171,46 +161,45 @@ namespace Binc { return tmp; } - //---------------------------------------------------------------------- inline void split(const std::string &s_in, const std::string &delim, std::vector<std::string> &dest, bool skipempty = true) { std::string token; - for (std::string::const_iterator i = s_in.begin(); i != s_in.end(); ++i) { - if (delim.find(*i) != std::string::npos) { + for (const char i : s_in) { + if (delim.find(i) != std::string::npos) { if (!skipempty || token != "") dest.push_back(token); token = ""; - } else - token += *i; + } else { + token += i; + } } if (token != "") dest.push_back(token); } - //---------------------------------------------------------------------- inline void splitAddr(const std::string &s_in, std::vector<std::string> &dest, bool skipempty = true) { static const std::string delim = ","; std::string token; bool inquote = false; - for (std::string::const_iterator i = s_in.begin(); i != s_in.end(); ++i) { - if (inquote && *i == '\"') + for (const char i : s_in) { + if (inquote && i == '\"') inquote = false; - else if (!inquote && *i == '\"') + else if (!inquote && i == '\"') inquote = true; - if (!inquote && delim.find(*i) != std::string::npos) { + if (!inquote && delim.find(i) != std::string::npos) { if (!skipempty || token != "") dest.push_back(token); token = ""; - } else - token += *i; + } else { + token += i; + } } if (token != "") dest.push_back(token); } - //---------------------------------------------------------------------- inline std::string toCanonMailbox(const std::string &s_in) { if (s_in.find("..") != std::string::npos) return ""; @@ -224,27 +213,27 @@ namespace Binc { return s_in; } - //------------------------------------------------------------------------ inline std::string toRegex(const std::string &s_in, char delimiter) { std::string regex = "^"; - for (std::string::const_iterator i = s_in.begin(); i != s_in.end(); ++i) { - if (*i == '.' || *i == '[' || *i == ']' || *i == '{' || *i == '}' || *i == '(' || *i == ')' - || *i == '^' || *i == '$' || *i == '?' || *i == '+' || *i == '\\') + for (const char i : s_in) { + if (i == '.' || i == '[' || i == ']' || i == '{' || i == '}' || i == '(' || i == ')' || i == '^' + || i == '$' || i == '?' || i == '+' || i == '\\') { regex += "\\"; - regex += *i; - } else if (*i == '*') + regex += i; + } else if (i == '*') { regex += ".*?"; - else if (*i == '%') { + } else if (i == '%') { regex += "(\\"; regex += delimiter; regex += "){0,1}"; regex += "[^\\"; regex += delimiter; regex += "]*?"; - } else - regex += *i; + } else { + regex += i; + } } if (regex[regex.length() - 1] == '?') @@ -255,13 +244,11 @@ namespace Binc { return regex; } - //------------------------------------------------------------------------ class BincStream { private: std::string nstr; public: - //-- BincStream &operator<<(std::ostream &(*)(std::ostream &)); BincStream &operator<<(const std::string &t); BincStream &operator<<(unsigned long t); @@ -269,24 +256,18 @@ namespace Binc { BincStream &operator<<(int t); BincStream &operator<<(char t); - //-- std::string popString(unsigned int size); - //-- char popChar(void); void unpopChar(char c); void unpopStr(const std::string &s); - //-- const std::string &str(void) const; - //-- unsigned int getSize(void) const; - //-- void clear(void); - //-- BincStream(void); ~BincStream(void); }; diff --git a/src/include/depot.h b/src/include/depot.h index bd4f743..3e65c8e 100644 --- a/src/include/depot.h +++ b/src/include/depot.h @@ -1,11 +1,13 @@ -/** -------------------------------------------------------------------- +/** * @filec depot.h * @file Declaration of the Depot class (the mail storage) * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #ifndef depot_h_included #define depot_h_included + #include <map> #include <string> #include <vector> @@ -18,7 +20,6 @@ namespace Binc { class Depot; class Status; - //------------------------------------------------------------------ class DepotFactory { private: std::vector<Depot *> depots; @@ -32,26 +33,24 @@ namespace Binc { ~DepotFactory(void); }; - //------------------------------------------------------------------ class Depot { public: - //-- class iterator { public: - std::string operator*(void) const; - void operator++(void); - bool operator!=(iterator) const; - bool operator==(iterator) const; - iterator(void); iterator(const iterator ©); iterator(DIR *, struct dirent *); ~iterator(void); - void deref(void); - iterator &operator=(const iterator ©); + std::string operator*(void) const; + void operator++(void); + bool operator!=(iterator) const; + bool operator==(iterator) const; + + void deref(void); + friend class Depot; private: @@ -77,11 +76,15 @@ namespace Binc { mutable std::map<std::string, Status> mailboxstatuses; public: + Depot(); + Depot(const std::string &name); + virtual ~Depot(void) = default; + virtual iterator begin(const std::string &) const; virtual const iterator &end(void) const; void setDelimiter(char); - const char getDelimiter(void) const; + char getDelimiter(void) const; virtual void assign(Mailbox *); @@ -116,14 +119,8 @@ namespace Binc { virtual bool unsubscribeTo(const std::string mailbox); virtual void loadSubscribes(void); virtual bool saveSubscribes(void) const; - - //-- - Depot(void); - Depot(const std::string &name); - virtual ~Depot(void); }; - //------------------------------------------------------------------ class MaildirPPDepot : public Depot { public: std::string mailboxToFilename(const std::string &m) const; @@ -131,7 +128,6 @@ namespace Binc { const std::string &getPersonalNamespace(void) const; - //-- MaildirPPDepot(); ~MaildirPPDepot(); @@ -139,13 +135,11 @@ namespace Binc { std::string privateNamespace; }; - //------------------------------------------------------------------ class IMAPdirDepot : public Depot { public: std::string mailboxToFilename(const std::string &m) const; std::string filenameToMailbox(const std::string &m) const; - //-- IMAPdirDepot(); ~IMAPdirDepot(); }; diff --git a/src/include/globals.h b/src/include/globals.h index d86ae4d..8d939b6 100644 --- a/src/include/globals.h +++ b/src/include/globals.h @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file globals.h * @brief Global constants. * @author Andreas Aardal Hanssen, Erwin Hoffmann * @date 2002-2005, 2023 - * ----------------------------------------------------------------- **/ + */ + #ifndef GLOBAL_H_INCLUDED #define GLOBAL_H_INCLUDED @@ -20,6 +21,6 @@ namespace Binc { static const int TRANSFER_TIMEOUT = 20 * 60; static const int TRANSFER_BUFFER_SIZE = 1024; static const int INPUT_BUFFER_LIMIT = 8192; - }; + #endif diff --git a/src/include/imapparser.h b/src/include/imapparser.h index 5dfffb4..737d7c7 100644 --- a/src/include/imapparser.h +++ b/src/include/imapparser.h @@ -1,19 +1,18 @@ -/** -------------------------------------------------------------------- +/** * @file imapparser.h * @brief Declaration of the common items for parsing IMAP input * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #ifndef imapparser_h_included #define imapparser_h_included -/* stl includes */ #include <map> #include <string> #include <vector> namespace Binc { - //------------------------------------------------------------------------ class SequenceSet { public: void addRange(unsigned int a_in, unsigned int b_in); @@ -52,7 +51,6 @@ namespace Binc { std::vector<Range> internal; }; - //------------------------------------------------------------------------ class BincImapParserFetchAtt { public: std::string type; @@ -68,7 +66,6 @@ namespace Binc { std::string toString(void); }; - //------------------------------------------------------------------------ class BincImapParserSearchKey { public: std::string name; @@ -88,13 +85,11 @@ namespace Binc { BincImapParserSearchKey(void); }; - //------------------------------------------------------------------------ class BincImapParserData { public: virtual ~BincImapParserData(void) {} }; - //------------------------------------------------------------------------ class Request { private: std::string tag; diff --git a/src/include/imapserver.h b/src/include/imapserver.h index d3268ba..2afaadd 100644 --- a/src/include/imapserver.h +++ b/src/include/imapserver.h @@ -1,9 +1,9 @@ -/** -------------------------------------------------------------------- +/** * @file imapserver.h * @brief Declaration of the IMAPServer class. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ namespace Binc { diff --git a/src/include/iodevice.h b/src/include/iodevice.h index 73dd2ab..1612d3a 100644 --- a/src/include/iodevice.h +++ b/src/include/iodevice.h @@ -1,14 +1,15 @@ -/** -------------------------------------------------------------------- +/** * @file iodevice.h * @brief Declaration of the IODevice class. * @author Andreas Aardal Hanssen * @date 2002, 2003 - * ----------------------------------------------------------------- **/ + */ + #ifndef iodevice_h_included #define iodevice_h_included #include "convert.h" // BincStream -// #include <iostream> + #include <string> #include <unistd.h> // ::write @@ -143,7 +144,7 @@ namespace Binc { For instance, if the output level is set to 0, then "Hello" is written, and the output level is set to 1, followed by writing - "Daisy", the output level limit value will decive wether only + "Daisy", the output level limit value will decide whether only "Hello" is written, or if also "Daisy" is written. A low value of the level gives higher priority, and a high level @@ -233,7 +234,7 @@ namespace Binc { \param dest The incoming byte is stored in this char. */ - bool readChar(char *dest = 0); + bool readChar(char *dest = nullptr); /*! FIXME: add docs @@ -347,7 +348,6 @@ namespace Binc { int dumpfd; }; - //---------------------------------------------------------------------- template<class T> IODevice &IODevice::operator<<(const T &source) { if ((flags & IsEnabled) && outputLevel <= outputLevelLimit) { @@ -359,8 +359,9 @@ namespace Binc { ::write(dumpfd, ss.str().c_str(), ss.getSize()); } - if (flags & HasInputLimit) + if (flags & HasInputLimit) { if (outputBuffer.getSize() > maxOutputBufferSize) flush(); + } } return *this; diff --git a/src/include/iofactory.h b/src/include/iofactory.h index 1a50e4e..70bd8f4 100644 --- a/src/include/iofactory.h +++ b/src/include/iofactory.h @@ -1,11 +1,13 @@ -/** -------------------------------------------------------------------- +/** * @file iofactory.h * @brief Declaration of the IOFactory class. * @author Andreas Aardal Hanssen * @date 2002, 2003 - * ----------------------------------------------------------------- **/ + */ + #ifndef IOFACTORY_H_INCLUDED #define IOFACTORY_H_INCLUDED + #include "iodevice.h" #include <map> diff --git a/src/include/mailbox.h b/src/include/mailbox.h index 870a695..d8c9592 100644 --- a/src/include/mailbox.h +++ b/src/include/mailbox.h @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file mailbox.h * @brief Declaration of the Mailbox class (Mailbox is logical container) * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #ifndef mailbox_h_included #define mailbox_h_included @@ -27,10 +28,8 @@ namespace Binc { class PendingUpdates; class File; - //------------------------------------------------------------------------ class Mailbox { public: - //---------------------------------------------------------------------- class BaseIterator { public: BaseIterator(int sqn = 0); @@ -46,7 +45,6 @@ namespace Binc { unsigned int sqnr; }; - //---------------------------------------------------------------------- class iterator { public: iterator(BaseIterator &i); @@ -117,6 +115,8 @@ namespace Binc { Mailbox(void); virtual ~Mailbox(void); + Mailbox &operator=(const Mailbox &m) = delete; + friend class Mailbox::iterator; protected: diff --git a/src/include/maildir.h b/src/include/maildir.h index dda88df..4a4c106 100644 --- a/src/include/maildir.h +++ b/src/include/maildir.h @@ -1,11 +1,13 @@ -/** -------------------------------------------------------------------- +/** * @file maildir.h * @brief Declaration of the Maildir class. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #ifndef maildir_h_included #define maildir_h_included + #include "mailbox.h" #include "maildirmessage.h" @@ -17,7 +19,6 @@ namespace Binc { static const std::string CACHEFILEVERSION = "1.0.5"; static const std::string UIDVALFILEVERSION = "1.0.5"; - //---------------------------------------------------------------------- class Lock { public: Lock(const std::string &path); @@ -27,14 +28,12 @@ namespace Binc { std::string lock; }; - //------------------------------------------------------------------------ class MaildirIndexItem { public: unsigned int uid; std::string fileName; }; - //------------------------------------------------------------------------ class MaildirIndex { private: std::map<std::string, MaildirIndexItem> idx; @@ -49,7 +48,6 @@ namespace Binc { MaildirIndexItem *find(const std::string &unique); }; - //------------------------------------------------------------------------ class Maildir : public Mailbox { public: typedef std::map<unsigned int, MaildirMessage> MessageMap; @@ -131,7 +129,6 @@ namespace Binc { bool fastCopy(Message &source, Mailbox &desttype, const std::string &destname); - //-- Maildir(void); ~Maildir(void); diff --git a/src/include/maildirmessage.h b/src/include/maildirmessage.h index 6bc2a20..96dcf73 100644 --- a/src/include/maildirmessage.h +++ b/src/include/maildirmessage.h @@ -1,15 +1,18 @@ -/** -------------------------------------------------------------------- +/** * @file maildirmessage.h * @brief Declaration of the MaildirMessage class. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #ifndef maildirmessage_h_included #define maildirmessage_h_included + #include "address.h" #include "message.h" #include "mime.h" +#include <deque> #include <exception> #include <iostream> #include <map> @@ -278,7 +281,6 @@ namespace Binc { std::vector<std::string> *customFlags; }; - //------------------------------------------------------------------------ class MaildirMessageCache { public: ~MaildirMessageCache(); diff --git a/src/include/message.h b/src/include/message.h index e1bbf2b..130902e 100644 --- a/src/include/message.h +++ b/src/include/message.h @@ -1,11 +1,13 @@ -/** -------------------------------------------------------------------- +/** * @file message.h * @brief Declaration of the Message class. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #ifndef message_h_included #define message_h_included + #include <string> #include <vector> @@ -18,33 +20,30 @@ namespace Binc { /*! - \class Message - \brief The Message class provides an interface for - IMAP messages. - - Mailbox independent operations and properties are available - through this interface. - - This class is an abstract, and has no implementation. - - \sa MaildirMessage - */ + * \class Message + * \brief The Message class provides an interface for + * IMAP messages. + * + * Mailbox independent operations and properties are available + * through this interface. + * + * This class is an abstract, and has no implementation. + * + * \sa MaildirMessage + */ class Message { public: - /*! - Standard IMAP message flags. - - */ + //! Standard IMAP message flags. enum Flags { - F_NONE = 0x00, /*!< No flag is set */ - F_SEEN = 0x01, /*!< The message has been seen */ - F_ANSWERED = 0x02, /*!< The message has been answered */ - F_DELETED = 0x04, /*!< The message is marked as deleted */ - F_DRAFT = 0x08, /*!< The message is a draft */ - F_RECENT = 0x10, /*!< The message arrived recently */ - F_FLAGGED = 0x20, /*!< The message is flagged / important */ - F_EXPUNGED = 0x40, /*!< The message has been expunged */ - F_PASSED = 0x80 /*!< The message has been bounced */ + F_NONE = 0x00, //!< No flag is set + F_SEEN = 0x01, //!< The message has been seen + F_ANSWERED = 0x02, //!< The message has been answered + F_DELETED = 0x04, //!< The message is marked as deleted + F_DRAFT = 0x08, //!< The message is a draft + F_RECENT = 0x10, //!< The message arrived recently + F_FLAGGED = 0x20, //!< The message is flagged / important + F_EXPUNGED = 0x40, //!< The message has been expunged + F_PASSED = 0x80 //!< The message has been bounced }; virtual void setUID(unsigned int) = 0; @@ -68,7 +67,7 @@ namespace Binc { virtual void setInternalDate(time_t) = 0; virtual time_t getInternalDate(void) const = 0; - // virtual void rewind(void) = 0; + // virtual void rewind(void) = 0; virtual int readChunk(std::string &) = 0; virtual bool appendChunk(const std::string &) = 0; virtual void close(void) = 0; diff --git a/src/include/mime-inputsource.h b/src/include/mime-inputsource.h index 8ff97f4..011c4c3 100644 --- a/src/include/mime-inputsource.h +++ b/src/include/mime-inputsource.h @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file mime-inputsource.h * @brief The base class of the MIME input source * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #ifndef mime_inputsource_h_included #define mime_inputsource_h_included diff --git a/src/include/mime-utils.h b/src/include/mime-utils.h index 8a59041..a8f62c7 100644 --- a/src/include/mime-utils.h +++ b/src/include/mime-utils.h @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file mime.cc * @brief Implementation of main mime parser components * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #ifndef mime_utils_h_included #define mime_utils_h_included @@ -12,8 +13,6 @@ #include <stdio.h> #include <string.h> -using namespace ::std; - inline bool compareStringToQueue(const char *s_in, char *bqueue, int pos, int size) { for (int i = 0; i < size; ++i) diff --git a/src/include/mime.h b/src/include/mime.h index f35ebb2..a8050af 100644 --- a/src/include/mime.h +++ b/src/include/mime.h @@ -1,11 +1,13 @@ -/** -------------------------------------------------------------------- +/** * @file mime.h * @brief Declaration of main mime parser components * @author Andreas Aardal Hanssen * @date Andreas Aardal Hanssen - * ----------------------------------------------------------------- **/ + */ + #ifndef mime_h_included #define mime_h_included + #include <map> #include <string> #include <vector> @@ -13,7 +15,6 @@ #include <stdio.h> namespace Binc { - //---------------------------------------------------------------------- class HeaderItem { private: mutable std::string key; @@ -30,12 +31,10 @@ namespace Binc { return value; } - //-- HeaderItem(void); HeaderItem(const std::string &key, const std::string &value); }; - //---------------------------------------------------------------------- class Header { private: mutable std::vector<HeaderItem> content; @@ -46,12 +45,10 @@ namespace Binc { void add(const std::string &name, const std::string &content); void clear(void) const; - //-- Header(void); ~Header(void); }; - //---------------------------------------------------------------------- class IODevice; class MimeDocument; @@ -140,7 +137,6 @@ namespace Binc { virtual ~MimePart(void); }; - //---------------------------------------------------------------------- class MimeDocument : public MimePart { private: mutable bool headerIsParsed; @@ -161,7 +157,6 @@ namespace Binc { return allIsParsed; } - //-- MimeDocument(void); ~MimeDocument(void); }; diff --git a/src/include/multilogdevice.h b/src/include/multilogdevice.h index a6f29f2..3ae4655 100644 --- a/src/include/multilogdevice.h +++ b/src/include/multilogdevice.h @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file multilogdevice.h * @brief Declaration of the MultilogDevice class. * @author Andreas Aardal Hanssen * @date Andreas Aardal Hanssen - * ----------------------------------------------------------------- **/ + */ + #ifndef multilogdevice_h_included #define multilogdevice_h_included diff --git a/src/include/operators.h b/src/include/operators.h index a4e0f74..66c7e2b 100644 --- a/src/include/operators.h +++ b/src/include/operators.h @@ -1,11 +1,13 @@ -/** -------------------------------------------------------------------- +/** * @file operators.h * @brief Declaration of all operators. * @author Andreas Aardal Hanssen, Erwin Hoffmann * @date 2002-2005, 2023 - * ----------------------------------------------------------------- **/ + */ + #ifndef operators_h_included #define operators_h_included + #include "depot.h" #include "imapparser.h" #include "message.h" @@ -15,7 +17,6 @@ namespace Binc { - //-------------------------------------------------------------------- class Operator { public: enum ProcessResult { OK, BAD, NO, NOTHING, ABORT }; @@ -27,11 +28,9 @@ namespace Binc { virtual int getState(void) const = 0; virtual const std::string getName(void) const = 0; - //-- virtual ~Operator(void){}; }; - //-------------------------------------------------------------------- class AppendOperator : public Operator { public: ProcessResult process(Depot &, Request &); @@ -43,7 +42,6 @@ namespace Binc { ~AppendOperator(void); }; - //-------------------------------------------------------------------- class AuthenticateOperator : public Operator { public: ProcessResult process(Depot &, Request &); @@ -60,7 +58,6 @@ namespace Binc { ~AuthenticateOperator(void); }; - //-------------------------------------------------------------------- class CapabilityOperator : public Operator { std::vector<std::string> capabilities; @@ -77,7 +74,6 @@ namespace Binc { ~CapabilityOperator(void); }; - //-------------------------------------------------------------------- class CheckOperator : public Operator { public: ProcessResult process(Depot &, Request &); @@ -90,7 +86,6 @@ namespace Binc { ~CheckOperator(void); }; - //-------------------------------------------------------------------- class CreateOperator : public Operator { public: ProcessResult process(Depot &, Request &); @@ -103,7 +98,6 @@ namespace Binc { ~CreateOperator(void); }; - //-------------------------------------------------------------------- class CloseOperator : public Operator { public: ProcessResult process(Depot &, Request &); @@ -116,7 +110,6 @@ namespace Binc { ~CloseOperator(void); }; - //-------------------------------------------------------------------- class CopyOperator : public Operator { public: ProcessResult process(Depot &, Request &); @@ -129,7 +122,6 @@ namespace Binc { ~CopyOperator(void); }; - //-------------------------------------------------------------------- class DeleteOperator : public Operator { public: ProcessResult process(Depot &, Request &); @@ -142,7 +134,6 @@ namespace Binc { ~DeleteOperator(void); }; - //-------------------------------------------------------------------- class ExpungeOperator : public Operator { public: ProcessResult process(Depot &, Request &); @@ -155,7 +146,6 @@ namespace Binc { ~ExpungeOperator(void); }; - //-------------------------------------------------------------------- class FetchOperator : public Operator { protected: ParseResult expectSectionText(BincImapParserFetchAtt &f_in) const; @@ -175,7 +165,6 @@ namespace Binc { ~FetchOperator(void); }; - //-------------------------------------------------------------------- class IdOperator : public Operator { public: ProcessResult process(Depot &, Request &); @@ -188,7 +177,6 @@ namespace Binc { ~IdOperator(void); }; - //-------------------------------------------------------------------- class IdleOperator : public Operator { protected: ParseResult expectSectionText(BincImapParserFetchAtt &f_in) const; @@ -208,7 +196,6 @@ namespace Binc { ~IdleOperator(void); }; - //-------------------------------------------------------------------- class ListOperator : public Operator { protected: enum MailboxFlags { DIR_SELECT = 0x01, DIR_MARKED = 0x02, DIR_NOINFERIORS = 0x04, DIR_LEAF = 0x08 }; @@ -227,7 +214,6 @@ namespace Binc { ~ListOperator(void); }; - //-------------------------------------------------------------------- class LoginOperator : public Operator { public: ProcessResult process(Depot &, Request &); @@ -240,7 +226,6 @@ namespace Binc { ~LoginOperator(void); }; - //-------------------------------------------------------------------- class LogoutOperator : public Operator { public: ProcessResult process(Depot &, Request &); @@ -253,7 +238,6 @@ namespace Binc { ~LogoutOperator(void); }; - //-------------------------------------------------------------------- class LsubOperator : public Operator { public: ProcessResult process(Depot &, Request &); @@ -266,7 +250,6 @@ namespace Binc { ~LsubOperator(void); }; - //-------------------------------------------------------------------- class NamespaceOperator : public Operator { public: virtual ProcessResult process(Depot &, Request &); @@ -279,7 +262,6 @@ namespace Binc { ~NamespaceOperator(void); }; - //-------------------------------------------------------------------- class NoopOperator : public Operator { public: virtual ProcessResult process(Depot &, Request &); @@ -292,7 +274,6 @@ namespace Binc { ~NoopOperator(void); }; - //-------------------------------------------------------------------- class NoopPendingOperator : public NoopOperator { public: ProcessResult process(Depot &, Request &); @@ -301,7 +282,6 @@ namespace Binc { ~NoopPendingOperator(void); }; - //-------------------------------------------------------------------- class RenameOperator : public Operator { public: ProcessResult process(Depot &, Request &); @@ -314,12 +294,10 @@ namespace Binc { ~RenameOperator(void); }; - //-------------------------------------------------------------------- class SearchOperator : public Operator { protected: ParseResult expectSearchKey(BincImapParserSearchKey &s_in) const; - //------------------------------------------------------------------ class SearchNode { std::string date; std::string astring; @@ -390,7 +368,6 @@ namespace Binc { void init(const BincImapParserSearchKey &a); - //- static bool compareNodes(const SearchNode &a, const SearchNode &b) { return a.getWeight() < b.getWeight(); @@ -411,7 +388,6 @@ namespace Binc { ~SearchOperator(void); }; - //-------------------------------------------------------------------- class SelectOperator : public Operator { public: ProcessResult process(Depot &, Request &); @@ -424,7 +400,6 @@ namespace Binc { ~SelectOperator(void); }; - //-------------------------------------------------------------------- class ExamineOperator : public SelectOperator { public: const std::string getName(void) const; @@ -432,7 +407,6 @@ namespace Binc { ~ExamineOperator(void); }; - //-------------------------------------------------------------------- class StarttlsOperator : public Operator { public: ProcessResult process(Depot &, Request &); @@ -446,7 +420,6 @@ namespace Binc { ~StarttlsOperator(void); }; - //-------------------------------------------------------------------- class StatusOperator : public Operator { std::map<int, Status> statuses; @@ -461,7 +434,6 @@ namespace Binc { ~StatusOperator(void); }; - //-------------------------------------------------------------------- class StoreOperator : public Operator { public: ProcessResult process(Depot &, Request &); @@ -474,7 +446,6 @@ namespace Binc { ~StoreOperator(void); }; - //-------------------------------------------------------------------- class SubscribeOperator : public Operator { public: ProcessResult process(Depot &, Request &); @@ -487,7 +458,6 @@ namespace Binc { ~SubscribeOperator(void); }; - //-------------------------------------------------------------------- class UnsubscribeOperator : public Operator { public: ProcessResult process(Depot &, Request &); diff --git a/src/include/pendingupdates.h b/src/include/pendingupdates.h index c1adda0..eddf8f9 100644 --- a/src/include/pendingupdates.h +++ b/src/include/pendingupdates.h @@ -1,24 +1,24 @@ -/** -------------------------------------------------------------------- +/** * @file pendingupdates.h * @brief <---> * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ -#include <map> -#include <vector> + */ #ifndef pendingupdates_h_included #define pendingupdates_h_included +#include <map> +#include <string> +#include <vector> + namespace Binc { class Mailbox; - //------------------------------------------------------------------------ class PendingUpdates { public: enum { EXPUNGE = 0x01, FLAGS = 0x02, EXISTS = 0x04, RECENT = 0x08 }; - //---------------------------------------------------------------------- class expunged_const_iterator { private: std::vector<unsigned int>::iterator internal; @@ -29,16 +29,13 @@ namespace Binc { bool operator!=(expunged_const_iterator) const; bool operator==(expunged_const_iterator) const; - //-- expunged_const_iterator(void); expunged_const_iterator(std::vector<unsigned int>::iterator i); }; - //-- expunged_const_iterator beginExpunged(void); expunged_const_iterator endExpunged(void); - //---------------------------------------------------------------------- class flagupdates_const_iterator { private: std::map<unsigned int, unsigned int>::iterator internal; @@ -54,18 +51,15 @@ namespace Binc { void operator++(void); bool operator!=(flagupdates_const_iterator) const; - //-- flagupdates_const_iterator(void); flagupdates_const_iterator(std::map<unsigned int, unsigned int>::iterator i, std::map<unsigned int, std::vector<std::string>> *, std::map<unsigned int, unsigned int> *); }; - //-- flagupdates_const_iterator beginFlagUpdates(void); flagupdates_const_iterator endFlagUpdates(void); - //-- void addExpunged(unsigned int uid); void addFlagUpdates(unsigned int sqnr, unsigned int uid, @@ -78,7 +72,6 @@ namespace Binc { bool newExists(void) const; bool newRecent(void) const; - //-- PendingUpdates(void); ~PendingUpdates(void); diff --git a/src/include/recursivedescent.h b/src/include/recursivedescent.h index 96c3a7e..26ad794 100644 --- a/src/include/recursivedescent.h +++ b/src/include/recursivedescent.h @@ -1,11 +1,13 @@ -/** -------------------------------------------------------------------- +/** * @file recursivedescent.h * @brief Declaration of a recursive descent IMAP command parser. * @author Andreas Aardal Hanssen * @date Andreas Aardal Hanssen - * ----------------------------------------------------------------- **/ + */ + #ifndef expectcommand_h_inluded #define expectcommand_h_inluded + #include "imapparser.h" #include "operators.h" diff --git a/src/include/regmatch.h b/src/include/regmatch.h index 1471e90..5cc2274 100644 --- a/src/include/regmatch.h +++ b/src/include/regmatch.h @@ -1,16 +1,16 @@ -/** -------------------------------------------------------------------- +/** * @file regex.h * @brief Declaration of miscellaneous regexp functions. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #ifndef regex_h_included #define regex_h_included #include <string> namespace Binc { - int regexMatch(const std::string &data_in, const std::string &p_in); } diff --git a/src/include/session.h b/src/include/session.h index ee96613..a329183 100644 --- a/src/include/session.h +++ b/src/include/session.h @@ -1,11 +1,13 @@ -/** -------------------------------------------------------------------- +/** * @file session.h * @brief <---> * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #ifndef session_h_included #define session_h_included + #include "argparser.h" #include <map> @@ -18,7 +20,6 @@ namespace Binc { class Depot; - //-------------------------------------------------------------------- class Session { public: std::map<std::string, std::string> attrs; @@ -37,13 +38,13 @@ namespace Binc { CommandLineArgs args; - int timeout() const; + int timeout(void) const; bool hasEnv(const std::string &key) const; std::string getEnv(const std::string &key); void setEnv(const std::string &key, const std::string &value); - const int getState(void) const; + int getState(void) const; void setState(int n); bool parseCommandLine(int argc, char *argv[]); void assignCommandLineArgs(void); @@ -61,7 +62,7 @@ namespace Binc { const std::string &getLastError(void) const; const std::string &getResponseCode(void) const; const std::string &getIP(void) const; - const std::string &getUserID() const; + const std::string &getUserID(void) const; pid_t getPid(void); const std::string &getHostname(void); void setLastError(const std::string &error) const; @@ -72,13 +73,11 @@ namespace Binc { inline Depot *getDepot(void) const; - //-- static Session &getInstance(void); bool initialize(int argc, char *argv[]); private: - //-- int state; std::string userid; std::string ip; diff --git a/src/include/status.h b/src/include/status.h index 9248505..ae944c0 100644 --- a/src/include/status.h +++ b/src/include/status.h @@ -1,28 +1,25 @@ -/** -------------------------------------------------------------------- +/** * @file status.h * @brief Declaration of the Status class. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #ifndef status_h_included #define status_h_included namespace Binc { - //------------------------------------------------------------------------ class Status { - //-- int recent; int messages; int unseen; int uidvalidity; int uidnext; - //-- int statusid; public: - //-- inline void setMessages(int i) { messages = i; @@ -53,7 +50,6 @@ namespace Binc { uidnext = i; } - //-- inline int getMessages(void) const { return messages; @@ -84,7 +80,6 @@ namespace Binc { return uidnext; } - //-- Status(void); ~Status(void); }; diff --git a/src/include/stdiodevice.h b/src/include/stdiodevice.h index 7b4f465..9dac4fd 100644 --- a/src/include/stdiodevice.h +++ b/src/include/stdiodevice.h @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file stdiodevice.h * @brief Declaration of the StdIODevice class. * @author Andreas Aardal Hanssen * @date 2002, 2003 - * ----------------------------------------------------------------- **/ + */ + #ifndef stdiodevice_h_included #define stdiodevice_h_included diff --git a/src/include/syslogdevice.h b/src/include/syslogdevice.h index 68d4112..78389d7 100644 --- a/src/include/syslogdevice.h +++ b/src/include/syslogdevice.h @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file Syslogdevice.h * @brief Declaration of the SyslogDevice class. * @author Andreas Aardal Hanssen * @date 2002, 2003 - * ----------------------------------------------------------------- **/ + */ + #ifndef syslogdevice_h_included #define syslogdevice_h_included diff --git a/src/include/tools.h b/src/include/tools.h index 67ed91e..70f5cf4 100644 --- a/src/include/tools.h +++ b/src/include/tools.h @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file tools.h * @brief Declaration of miscellaneous tools. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include <string> namespace Binc { @@ -16,7 +17,6 @@ namespace Binc { void setenv(const std::string &key, const std::string &value) const; std::string getenv(const std::string &key) const; - //-- static Tools &getInstance(void); }; diff --git a/src/iodevice.cc b/src/iodevice.cc index c2bc9ee..851bfb1 100644 --- a/src/iodevice.cc +++ b/src/iodevice.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file iodevice.cc * @brief Implementation of the IODevice class. * @author Andreas Aardal Hanssen * @date 2002, 2003 - * ----------------------------------------------------------------- **/ + */ + #include "iodevice.h" #include "convert.h" // BincStream @@ -13,10 +14,9 @@ #include <unistd.h> -using namespace ::std; -using namespace ::Binc; +using namespace Binc; +using std::ostream; -//------------------------------------------------------------------------ IODevice::IODevice(int f) : flags(f | IsEnabled) , maxInputBufferSize(0) @@ -31,15 +31,13 @@ IODevice::IODevice(int f) , dumpfd(0) {} -//------------------------------------------------------------------------ IODevice::~IODevice(void) {} -//------------------------------------------------------------------------ IODevice &IODevice::operator<<(ostream &(*source)(ostream &)) { if (!(flags & IsEnabled) || outputLevel > outputLevelLimit) return *this; - static std::ostream &(*endl_funcptr)(ostream &) = endl; + static ostream &(*endl_funcptr)(ostream &) = std::endl; if (source != endl_funcptr) return *this; @@ -47,21 +45,20 @@ IODevice &IODevice::operator<<(ostream &(*source)(ostream &)) if (dumpfd) ::write(dumpfd, "\r\n", 2); - if (flags & FlushesOnEndl) + if (flags & FlushesOnEndl) { flush(); - else if (flags & HasOutputLimit) + } else if (flags & HasOutputLimit) { if (outputBuffer.getSize() > maxOutputBufferSize) flush(); + } return *this; } -//------------------------------------------------------------------------ bool IODevice::canRead(void) const { return false; } -//------------------------------------------------------------------------ void IODevice::clear() { if (!(flags & IsEnabled)) return; @@ -70,7 +67,6 @@ void IODevice::clear() outputBuffer.clear(); } -//------------------------------------------------------------------------ bool IODevice::flush() { if (!(flags & IsEnabled)) return true; @@ -90,31 +86,26 @@ bool IODevice::flush() return true; } -//------------------------------------------------------------------------ void IODevice::setFlags(unsigned int f) { flags |= f; } -//------------------------------------------------------------------------ void IODevice::clearFlags(unsigned int f) { flags &= ~f; } -//------------------------------------------------------------------------ void IODevice::setMaxInputBufferSize(unsigned int max) { maxInputBufferSize = max; } -//------------------------------------------------------------------------ void IODevice::setMaxOutputBufferSize(unsigned int max) { maxOutputBufferSize = max; } -//------------------------------------------------------------------------ void IODevice::setTimeout(unsigned int t) { timeout = t; @@ -125,52 +116,43 @@ void IODevice::setTimeout(unsigned int t) flags &= ~HasTimeout; } -//------------------------------------------------------------------------ unsigned int IODevice::getTimeout(void) const { return timeout; } -//------------------------------------------------------------------------ void IODevice::setOutputLevel(LogLevel level) { outputLevel = level; } -//------------------------------------------------------------------------ IODevice::LogLevel IODevice::getOutputLevel(void) const { return outputLevel; } -//------------------------------------------------------------------------ void IODevice::setOutputLevelLimit(LogLevel level) { outputLevelLimit = level; } -//------------------------------------------------------------------------ IODevice::LogLevel IODevice::getOutputLevelLimit(void) const { return outputLevelLimit; } -//------------------------------------------------------------------------ -bool IODevice::readStr(string *dest, unsigned int max) +bool IODevice::readStr(std::string *dest, unsigned int max) { // If max is 0, fill the input buffer once only if it's empty. if (!max && inputBuffer.getSize() == 0 && !fillInputBuffer()) return false; // If max is != 0, wait until we have max. - while (max && inputBuffer.getSize() < max) { + while (max && inputBuffer.getSize() < max) if (!fillInputBuffer()) return false; - } unsigned int bytesToRead = max ? max : inputBuffer.getSize(); *dest += inputBuffer.str().substr(0, bytesToRead); - if (dumpfd) { - ::write(dumpfd, inputBuffer.str().substr(0, bytesToRead).c_str(), bytesToRead); - } + if (dumpfd) ::write(dumpfd, inputBuffer.str().substr(0, bytesToRead).c_str(), bytesToRead); inputBuffer.popString(bytesToRead); readCount += bytesToRead; @@ -178,7 +160,6 @@ bool IODevice::readStr(string *dest, unsigned int max) return true; } -//------------------------------------------------------------------------ bool IODevice::readChar(char *dest) { if (inputBuffer.getSize() == 0 && !fillInputBuffer()) return false; @@ -192,19 +173,16 @@ bool IODevice::readChar(char *dest) return true; } -//------------------------------------------------------------------------ void IODevice::unreadChar(char c) { inputBuffer.unpopChar(c); } -//------------------------------------------------------------------------ -void IODevice::unreadStr(const string &s) +void IODevice::unreadStr(const std::string &s) { inputBuffer.unpopStr(s); } -//------------------------------------------------------------------------ bool IODevice::skipTo(char c) { char dest = '\0'; @@ -216,67 +194,57 @@ bool IODevice::skipTo(char c) return true; } -//------------------------------------------------------------------------ -string IODevice::service(void) const +std::string IODevice::service(void) const { return "nul"; } -//------------------------------------------------------------------------ bool IODevice::waitForWrite(void) const { return false; } -//------------------------------------------------------------------------ bool IODevice::waitForRead(void) const { return false; } -//------------------------------------------------------------------------ IODevice::WriteResult IODevice::write(void) { return WriteError; } -//------------------------------------------------------------------------ bool IODevice::fillInputBuffer(void) { return false; } -//------------------------------------------------------------------------ IODevice::Error IODevice::getLastError(void) const { return error; } -//------------------------------------------------------------------------ -string IODevice::getLastErrorString(void) const +std::string IODevice::getLastErrorString(void) const { return errorString; } -//------------------------------------------------------------------------ unsigned int IODevice::getReadCount(void) const { return readCount; } -//------------------------------------------------------------------------ unsigned int IODevice::getWriteCount(void) const { return writeCount; } -//------------------------------------------------------------------------ void IODevice::enableProtocolDumping(void) { BincStream ss; - ss << "/tmp/bincimap-dump-" << (int)time(0) << "-" << Session::getInstance().getIP() << "-XXXXXX"; - char *safename = strdup(ss.str().c_str()); - dumpfd = mkstemp(safename); + ss << "/tmp/bincimap-dump-" << static_cast<int>(time(nullptr)) << "-" << Session::getInstance().getIP() + << "-XXXXXX"; + std::string safename = ss.str(); + dumpfd = mkstemp(safename.data()); if (dumpfd == -1) dumpfd = 0; - delete[] safename; } diff --git a/src/iofactory.cc b/src/iofactory.cc index abe71b4..e58efdb 100644 --- a/src/iofactory.cc +++ b/src/iofactory.cc @@ -1,30 +1,26 @@ -/* -------------------------------------------------------------------- - * @file iofactory.cc - * @brief Implementation of the IOFactory class. - * @author Andreas Aardal Hanssen - * @date 2002, 2003 - * ----------------------------------------------------------------- **/ +/** + * @file iofactory.cc + * @brief Implementation of the IOFactory class. + * @author Andreas Aardal Hanssen + * @date 2002, 2003 + */ + #include "iofactory.h" #include "iodevice.h" -using namespace ::Binc; -using namespace ::std; +using namespace Binc; -//------------------------------------------------------------------------ IOFactory::IOFactory(void) {} -//------------------------------------------------------------------------ IOFactory::~IOFactory(void) {} -//------------------------------------------------------------------------ IOFactory &IOFactory::getInstance(void) { static IOFactory ioFactory; return ioFactory; } -//------------------------------------------------------------------------ void IOFactory::addDevice(IODevice *dev) { IODevice *ioDevice = IOFactory::getInstance().devices[dev->service()]; @@ -36,7 +32,6 @@ void IOFactory::addDevice(IODevice *dev) IOFactory::getInstance().devices[dev->service()] = dev; } -//------------------------------------------------------------------------ IODevice &IOFactory::getClient(void) { static IODevice nulDevice; @@ -48,7 +43,6 @@ IODevice &IOFactory::getClient(void) return nulDevice; } -//------------------------------------------------------------------------ IODevice &IOFactory::getLogger(void) { static IODevice nulDevice; diff --git a/src/mailbox.cc b/src/mailbox.cc index fd83276..23ed2a5 100644 --- a/src/mailbox.cc +++ b/src/mailbox.cc @@ -1,104 +1,87 @@ -/** -------------------------------------------------------------------- +/** * @file mailbox.cc * @brief Implementation of the Mailbox class. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "mailbox.h" #include "message.h" #include <string> -using namespace ::std; using namespace Binc; -//------------------------------------------------------------------------ Mailbox::BaseIterator::BaseIterator(int sqn) { sqnr = sqn; } -//------------------------------------------------------------------------ Mailbox::BaseIterator::~BaseIterator(void) {} -//------------------------------------------------------------------------ Mailbox::Mailbox(void) : readOnly(false) {} -//------------------------------------------------------------------------ Mailbox::~Mailbox(void) {} -//------------------------------------------------------------------------ bool Mailbox::isReadOnly(void) const { return readOnly; } -//------------------------------------------------------------------------ void Mailbox::setReadOnly(bool readOnly) { this->readOnly = readOnly; } -//------------------------------------------------------------------------ Mailbox::iterator::iterator(BaseIterator &i) : realIterator(i) {} -//------------------------------------------------------------------------ Message &Mailbox::iterator::operator*(void) { return *realIterator; } -//------------------------------------------------------------------------ void Mailbox::iterator::operator++(void) { ++realIterator; } -//------------------------------------------------------------------------ bool Mailbox::iterator::operator==(const iterator &i) const { return realIterator == i.realIterator; } -//------------------------------------------------------------------------ bool Mailbox::iterator::operator!=(const iterator &i) const { return realIterator != i.realIterator; } -//------------------------------------------------------------------------ void Mailbox::iterator::erase(void) { realIterator.erase(); } -//------------------------------------------------------------------------ unsigned int Mailbox::iterator::getSqnr(void) const { return realIterator.sqnr; } -//------------------------------------------------------------------------ -void Mailbox::setName(const string &name) +void Mailbox::setName(const std::string &name) { this->name = name; } -//------------------------------------------------------------------------ -const string Mailbox::getName(void) const +const std::string Mailbox::getName(void) const { return name; } -//------------------------------------------------------------------------ -const string &Mailbox::getLastError(void) const +const std::string &Mailbox::getLastError(void) const { return lastError; } -//------------------------------------------------------------------------ -void Mailbox::setLastError(const string &error) const +void Mailbox::setLastError(const std::string &error) const { lastError = error; } diff --git a/src/maildir-close.cc b/src/maildir-close.cc index c0e0dbd..81e526f 100644 --- a/src/maildir-close.cc +++ b/src/maildir-close.cc @@ -1,18 +1,17 @@ -/** -------------------------------------------------------------------- - * @file maildir-close.cc - * @brief Implementation of the Maildir class. - * @author Andreas Aardal Hanssen - * @date 2002-2005 - * ----------------------------------------------------------------- **/ +/** + * @file maildir-close.cc + * @brief Implementation of the Maildir class. + * @author Andreas Aardal Hanssen + * @date 2002-2005 + */ + #include "maildir.h" #include <fcntl.h> #include <unistd.h> -using namespace ::std; using namespace Binc; -//------------------------------------------------------------------------ void Binc::Maildir::closeMailbox(void) { if (!selected) return; diff --git a/src/maildir-create.cc b/src/maildir-create.cc index 6e08b61..89d9f40 100644 --- a/src/maildir-create.cc +++ b/src/maildir-create.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- - * @file maildir-create.cc - * @brief Implementation of the Maildir class. - * @author Andreas Aardal Hanssen - * @date 2002-2005 - * ----------------------------------------------------------------- **/ +/** + * @file maildir-create.cc + * @brief Implementation of the Maildir class. + * @author Andreas Aardal Hanssen + * @date 2002-2005 + */ + #include "maildir.h" #include <errno.h> @@ -13,10 +14,9 @@ #include <sys/types.h> #include <unistd.h> -using namespace ::std; using namespace Binc; +using std::string; -//------------------------------------------------------------------------ bool Binc::Maildir::createMailbox(const string &s_in, mode_t mode, uid_t owner, gid_t group, bool root) { if (s_in != "." && mkdir(s_in.c_str(), mode) == -1) { diff --git a/src/maildir-delete.cc b/src/maildir-delete.cc index b0abb2a..356128b 100644 --- a/src/maildir-delete.cc +++ b/src/maildir-delete.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file maildir-delete.cc * @brief Implementation of the Maildir class. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "maildir.h" #include <errno.h> @@ -14,18 +15,18 @@ #include <sys/types.h> #include <unistd.h> -using namespace ::std; using namespace Binc; +using std::string; namespace { bool recursiveDelete(const string &path) { DIR *mydir = opendir(path.c_str()); - if (mydir == 0) return false; + if (mydir == nullptr) return false; struct dirent *mydirent; - while ((mydirent = readdir(mydir)) != 0) { + while ((mydirent = readdir(mydir)) != nullptr) { string d = mydirent->d_name; if (d == "." || d == "..") continue; @@ -46,11 +47,9 @@ namespace { closedir(mydir); return false; } - } else { - if (unlink(f.c_str()) != 0 && errno != ENOENT) { - closedir(mydir); - return false; - } + } else if (unlink(f.c_str()) != 0 && errno != ENOENT) { + closedir(mydir); + return false; } } @@ -59,7 +58,6 @@ namespace { } } -//------------------------------------------------------------------------ bool Binc::Maildir::deleteMailbox(const string &s_in) { if (s_in == ".") { diff --git a/src/maildir-expunge.cc b/src/maildir-expunge.cc index 75c8f3d..a63f354 100644 --- a/src/maildir-expunge.cc +++ b/src/maildir-expunge.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file maildir-expunge.cc * @brief Implementation of the Maildir class. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "iodevice.h" #include "iofactory.h" #include "maildir.h" @@ -13,35 +14,32 @@ #include <unistd.h> -using namespace ::std; using namespace Binc; -//------------------------------------------------------------------------ void Maildir::expungeMailbox(void) { if (readOnly) return; Mailbox::iterator i = begin(SequenceSet::all(), SQNR_MODE | INCLUDE_EXPUNGED); - bool success = true; - for (; success && i != end(); ++i) { + for (bool success = true; success && i != end(); ++i) { MaildirMessage &message = reinterpret_cast<MaildirMessage &>(*i); if ((message.getStdFlags() & Message::F_DELETED) == 0) continue; message.setExpunged(); - const string &id = message.getUnique(); + const std::string &id = message.getUnique(); // The message might be gone already MaildirIndexItem *item = index.find(id); if (!item) continue; - string fpath = path + "/cur/" + item->fileName; + std::string fpath = path + "/cur/" + item->fileName; while (unlink(fpath.c_str()) != 0) { if (errno != ENOENT) { - bincWarning << "unable to remove " << fpath << ": " << strerror(errno) << endl; + bincWarning << "unable to remove " << fpath << ": " << strerror(errno) << std::endl; break; } diff --git a/src/maildir-readcache.cc b/src/maildir-readcache.cc index dbbf4ef..5864ff6 100644 --- a/src/maildir-readcache.cc +++ b/src/maildir-readcache.cc @@ -1,19 +1,20 @@ -/** -------------------------------------------------------------------- +/** * @file maildir-readcache.cc * @brief Implementation of the Maildir class. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "convert.h" #include "globals.h" #include "maildir.h" #include <algorithm> -using namespace ::std; using namespace Binc; +using std::string; +using std::vector; -//------------------------------------------------------------------------ Maildir::ReadCacheResult Maildir::readCache(void) { index.clearUids(); @@ -21,7 +22,7 @@ Maildir::ReadCacheResult Maildir::readCache(void) const string cachefilename = path + "/bincimap-cache"; FILE *fp = fopen(cachefilename.c_str(), "r"); if (!fp) { - uidvalidity = time(0); + uidvalidity = time(nullptr); uidnext = 1; messages.clear(); index.clear(); @@ -32,7 +33,7 @@ Maildir::ReadCacheResult Maildir::readCache(void) char inputBuffer[512]; if (!fgets(inputBuffer, sizeof(inputBuffer), fp)) { fclose(fp); - uidvalidity = time(0); + uidvalidity = time(nullptr); uidnext = 1; messages.clear(); index.clear(); @@ -52,7 +53,7 @@ Maildir::ReadCacheResult Maildir::readCache(void) { // bump cache fclose(fp); - uidvalidity = time(0); + uidvalidity = time(nullptr); uidnext = 1; messages.clear(); index.clear(); @@ -73,7 +74,7 @@ Maildir::ReadCacheResult Maildir::readCache(void) if (sscanf(inputBuffer, "%u %u %u %s", &readUID, &readInternalDate, &readSize, readUnique) != 4) { // error in input fclose(fp); - uidvalidity = time(0); + uidvalidity = time(nullptr); uidnext = 1; messages.clear(); index.clear(); @@ -84,7 +85,7 @@ Maildir::ReadCacheResult Maildir::readCache(void) vector<string> customFlags; char *flagStart = inputBuffer; - for (int i = 0; flagStart != 0 && *flagStart != '\0' && i < 4; ++i) { + for (int i = 0; flagStart != nullptr && *flagStart != '\0' && i < 4; ++i) { flagStart = strchr(flagStart, ' '); // skip consecutive white space @@ -112,9 +113,8 @@ Maildir::ReadCacheResult Maildir::readCache(void) m.setUnique(readUnique); m.setInternalDate(readInternalDate); - if (index.find(readUnique) == 0) { - for (vector<string>::const_iterator it = customFlags.begin(); it != customFlags.end(); ++it) { - string tmpFlag = *it; + if (index.find(readUnique) == nullptr) { + for (auto tmpFlag : customFlags) { trim(tmpFlag, " \n"); m.setCustomFlag(tmpFlag); } @@ -134,8 +134,7 @@ Maildir::ReadCacheResult Maildir::readCache(void) sort(customFlags.begin(), customFlags.end()); if (oldCustomFlags != customFlags) { existingMessage.resetCustomFlags(); - for (vector<string>::const_iterator it = customFlags.begin(); it != customFlags.end(); ++it) { - string tmpFlag = *it; + for (auto tmpFlag : customFlags) { trim(tmpFlag, " \n"); existingMessage.setCustomFlag(tmpFlag); } diff --git a/src/maildir-scan.cc b/src/maildir-scan.cc index 2f3a9b4..65548f7 100644 --- a/src/maildir-scan.cc +++ b/src/maildir-scan.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file maildir-scan.cc * @brief Implementation of the Maildir class. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "iodevice.h" #include "iofactory.h" #include "maildir.h" @@ -16,7 +17,8 @@ #include <unistd.h> using namespace Binc; -using namespace ::std; +using std::endl; +using std::string; Lock::Lock(const string &path) { @@ -32,19 +34,18 @@ Lock::Lock(const string &path) struct stat mystat; bincWarning << "waiting for mailbox lock " << lock << "." << endl; if (lstat(lock.c_str(), &mystat) == 0) { - if ((time(0) - mystat.st_ctime) > 300) { - if (unlink(lock.c_str()) == 0) + if ((time(nullptr) - mystat.st_ctime) > 300) { + if (unlink(lock.c_str()) == 0) { continue; - else + } else { bincWarning << "failed to force mailbox lock: " << lock << ", " << string(strerror(errno)) << endl; + } } - } else { - if (errno != ENOENT) { - string err = "invalid lock " + lock + ": " + strerror(errno); - bincWarning << err << endl; - return; - } + } else if (errno != ENOENT) { + string err = "invalid lock " + lock + ": " + strerror(errno); + bincWarning << err << endl; + return; } // sleep one second. @@ -57,15 +58,14 @@ Lock::Lock(const string &path) Lock::~Lock() { // remove the lock - if (unlink(lock.c_str()) != 0) + if (unlink(lock.c_str()) != 0) { bincWarning << "failed to unlock mailbox: " << lock << ", " << strerror(errno) << endl; + } } -//------------------------------------------------------------------------ // scan the maildir. update flags, find messages in new/ and move them // to cur, setting the recent flag in memory only. check for expunged // messages. give newly arrived messages uids. -//------------------------------------------------------------------------ Maildir::ScanResult Maildir::scan(bool forceScan) { const string newpath = path + "/new/"; @@ -95,8 +95,8 @@ Maildir::ScanResult Maildir::scan(bool forceScan) old_bincimap_cache_st_mtime = oldstat.st_mtime; old_bincimap_cache_st_ctime = oldstat.st_ctime; } else { - old_bincimap_cache_st_mtime = 0; - old_bincimap_cache_st_ctime = 0; + old_bincimap_cache_st_mtime = {}; + old_bincimap_cache_st_ctime = {}; } } else { struct stat oldcurstat; @@ -147,10 +147,10 @@ Maildir::ScanResult Maildir::scan(bool forceScan) // An error with reading the cache files when it's not the first // time we scan the depot is treated as an error. if (!firstscan && !readOnly) { - old_cur_st_mtime = (time_t)0; - old_cur_st_ctime = (time_t)0; - old_new_st_mtime = (time_t)0; - old_new_st_ctime = (time_t)0; + old_cur_st_mtime = {}; + old_cur_st_ctime = {}; + old_new_st_mtime = {}; + old_new_st_ctime = {}; return TemporaryError; } mailboxchanged = true; @@ -161,7 +161,7 @@ Maildir::ScanResult Maildir::scan(bool forceScan) // open new/ directory DIR *pdir = opendir(newpath.c_str()); - if (pdir == 0) { + if (pdir == nullptr) { string reason = "failed to open \"" + newpath + "\" ("; reason += strerror(errno); reason += ")"; @@ -172,7 +172,7 @@ Maildir::ScanResult Maildir::scan(bool forceScan) // scan all entries struct dirent *pdirent; - while ((pdirent = readdir(pdir)) != 0) { + while ((pdirent = readdir(pdir)) != nullptr) { // "Unless you're writing messages to a maildir, the format of a // unique name is none of your business. A unique name can be // anything that doesn't contain a colon (or slash) and doesn't @@ -201,15 +201,16 @@ Maildir::ScanResult Maildir::scan(bool forceScan) // a rare race between readdir and stat force us to restart the scan. closedir(pdir); - if ((pdir = opendir(newpath.c_str())) == 0) { + if ((pdir = opendir(newpath.c_str())) == nullptr) { string reason = "Warning: opendir(\"" + newpath + "\") == 0 ("; reason += strerror(errno); reason += ")"; setLastError(reason); return PermanentError; } - } else + } else { bincWarning << "junk in Maildir: \"" << fullfilename << "\": " << strerror(errno); + } continue; } @@ -220,22 +221,19 @@ Maildir::ScanResult Maildir::scan(bool forceScan) // and st_mtime. the next time the mailbox is scanned, it must not // simply be skipped. :-) - vector<MaildirMessage>::const_iterator newIt = newMessages.begin(); bool ours = false; - for (; newIt != newMessages.end(); ++newIt) { - if ((filename == (*newIt).getUnique()) - && ((*newIt).getInternalFlags() & MaildirMessage::Committed)) - { + for (const auto &newIt : newMessages) { + if ((filename == newIt.getUnique()) && (newIt.getInternalFlags() & MaildirMessage::Committed)) { ours = true; break; } } - if (!ours && ::time(0) <= mystat.st_mtime) { - old_cur_st_mtime = (time_t)0; - old_cur_st_ctime = (time_t)0; - old_new_st_mtime = (time_t)0; - old_new_st_ctime = (time_t)0; + if (!ours && ::time(nullptr) <= mystat.st_mtime) { + old_cur_st_mtime = {}; + old_cur_st_ctime = {}; + old_new_st_mtime = {}; + old_new_st_ctime = {}; continue; } @@ -261,7 +259,7 @@ Maildir::ScanResult Maildir::scan(bool forceScan) // Then, scan cur // open directory - if ((pdir = opendir(curpath.c_str())) == 0) { + if ((pdir = opendir(curpath.c_str())) == nullptr) { string reason = "Maildir::scan::opendir(\"" + curpath + "\") == 0 ("; reason += strerror(errno); reason += ")"; @@ -275,10 +273,10 @@ Maildir::ScanResult Maildir::scan(bool forceScan) index.clearFileNames(); // this is to sort recent messages by internaldate - multimap<unsigned int, MaildirMessage> tempMessageMap; + std::multimap<unsigned int, MaildirMessage> tempMessageMap; // scan all entries - while ((pdirent = readdir(pdir)) != 0) { + while ((pdirent = readdir(pdir)) != nullptr) { string filename = pdirent->d_name; if (filename[0] == '.') continue; @@ -289,12 +287,13 @@ Maildir::ScanResult Maildir::scan(bool forceScan) uniquename = filename.substr(0, pos); string tmp = filename.substr(pos); if ((pos = tmp.find("2,")) != string::npos) standard = tmp.substr(pos + 2); - } else + } else { uniquename = filename; + } unsigned char mflags = Message::F_NONE; - for (string::const_iterator i = standard.begin(); i != standard.end(); ++i) { - switch (*i) { + for (char i : standard) { + switch (i) { case 'R': mflags |= Message::F_ANSWERED; break; @@ -335,7 +334,7 @@ Maildir::ScanResult Maildir::scan(bool forceScan) closedir(pdir); - if ((pdir = opendir(newpath.c_str())) == 0) { + if ((pdir = opendir(newpath.c_str())) == nullptr) { string reason = "Warning: opendir(\"" + newpath + "\") == 0 ("; reason += strerror(errno); reason += ")"; @@ -354,7 +353,7 @@ Maildir::ScanResult Maildir::scan(bool forceScan) // If we have this message in memory already.. if (message) { - if (message->getInternalDate() == 0) { + if (message->getInternalDate() == time_t{}) { mailboxchanged = true; message->setInternalDate(mystat.st_mtime); } @@ -382,7 +381,7 @@ Maildir::ScanResult Maildir::scan(bool forceScan) m.setInternalDate(mystat.st_mtime); m.setStdFlag((mflags | Message::F_RECENT) & ~Message::F_EXPUNGED); m.setUnique(uniquename); - tempMessageMap.insert(make_pair((unsigned int)mystat.st_mtime, m)); + tempMessageMap.insert(std::make_pair((unsigned int)mystat.st_mtime, m)); mailboxchanged = true; } @@ -392,14 +391,11 @@ Maildir::ScanResult Maildir::scan(bool forceScan) // Recent messages are added, ordered by internaldate. { int readonlyuidnext = uidnext; - multimap<unsigned int, MaildirMessage>::iterator i = tempMessageMap.begin(); - while (i != tempMessageMap.end()) { + + for (auto i = tempMessageMap.begin(); i != tempMessageMap.end(); ++i) { i->second.setUID(readOnly ? readonlyuidnext++ : uidnext++); - multimap<unsigned int, MaildirMessage>::iterator itmp = i; - ++itmp; add(i->second); tempMessageMap.erase(i); - i = itmp; mailboxchanged = true; } } @@ -410,7 +406,7 @@ Maildir::ScanResult Maildir::scan(bool forceScan) // exist in the Maildir, are removed from the messages list. Mailbox::iterator jj = begin(SequenceSet::all(), INCLUDE_EXPUNGED | SQNR_MODE); while (jj != end()) { - MaildirMessage &message = (MaildirMessage &)*jj; + auto &message = dynamic_cast<MaildirMessage &>(*jj); if (message.isExpunged()) { mailboxchanged = true; @@ -434,12 +430,12 @@ Maildir::ScanResult Maildir::scan(bool forceScan) Mailbox::iterator ii = begin(SequenceSet::all(), INCLUDE_EXPUNGED | SQNR_MODE); for (; ii != end(); ++ii) { - MaildirMessage &message = (MaildirMessage &)*ii; + MaildirMessage &message = dynamic_cast<MaildirMessage &>(*ii); message.clearInternalFlag(MaildirMessage::JustArrived); - if (lastuid < message.getUID()) + if (lastuid < message.getUID()) { lastuid = message.getUID(); - else { + } else { bincWarning << "UID values are not strictly ascending in this" " mailbox: " << path << ". This is usually caused by " @@ -450,10 +446,10 @@ Maildir::ScanResult Maildir::scan(bool forceScan) if (!readOnly) { bumpUidValidity(path); - old_cur_st_mtime = (time_t)0; - old_cur_st_ctime = (time_t)0; - old_new_st_mtime = (time_t)0; - old_new_st_ctime = (time_t)0; + old_cur_st_mtime = {}; + old_cur_st_ctime = {}; + old_new_st_mtime = {}; + old_new_st_ctime = {}; return TemporaryError; } else { return PermanentError; diff --git a/src/maildir-scanfilesnames.cc b/src/maildir-scanfilesnames.cc index 0bde999..ff5c2d4 100644 --- a/src/maildir-scanfilesnames.cc +++ b/src/maildir-scanfilesnames.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file maildir-scanfilesnames.cc * @brief Implementation of the Maildir class. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "iodevice.h" #include "iofactory.h" #include "maildir.h" @@ -16,23 +17,22 @@ #include <dirent.h> #include <unistd.h> -using namespace ::std; +using std::string; -//------------------------------------------------------------------------ bool Binc::Maildir::scanFileNames(void) const { string curpath = path + "/cur/"; DIR *pdir = opendir(curpath.c_str()); - if (pdir == 0) { + if (pdir == nullptr) { setLastError("when scanning mailbox \"" + path + "\": " + string(strerror(errno))); - bincWarning << getLastError() << endl; + bincWarning << getLastError() << std::endl; return false; } index.clearFileNames(); struct dirent *pdirent; - while ((pdirent = readdir(pdir)) != 0) { + while ((pdirent = readdir(pdir)) != nullptr) { if (!isdigit(pdirent->d_name[0])) continue; string filename = pdirent->d_name; diff --git a/src/maildir-select.cc b/src/maildir-select.cc index a779a4a..470dbbc 100644 --- a/src/maildir-select.cc +++ b/src/maildir-select.cc @@ -1,18 +1,17 @@ -/** -------------------------------------------------------------------- +/** * @file maildir-select.cc * @brief Implementation of the Maildir class. * @author Andreas Aardal Hanssen * @date Andreas Aardal Hanssen - * ----------------------------------------------------------------- **/ + */ + #include "maildir.h" #include <fcntl.h> #include <unistd.h> -using namespace ::std; using namespace Binc; -//------------------------------------------------------------------------ bool Binc::Maildir::selectMailbox(const std::string &name, const std::string &s_in) { setName(name); @@ -34,6 +33,7 @@ bool Binc::Maildir::selectMailbox(const std::string &name, const std::string &s_ break; case TemporaryError: if (scan() == Success) break; + [[fallthrough]]; case PermanentError: return false; } diff --git a/src/maildir-updateflags.cc b/src/maildir-updateflags.cc index a3d2ab7..ba18f82 100644 --- a/src/maildir-updateflags.cc +++ b/src/maildir-updateflags.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file maildir-updateflags.cc * @brief Implementation of the Maildir class. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "iodevice.h" #include "iofactory.h" #include "maildir.h" @@ -13,9 +14,8 @@ #include <dirent.h> #include <unistd.h> -using namespace ::std; +using std::string; -//------------------------------------------------------------------------ void Binc::Maildir::updateFlags(void) { // don't update a read-only mailbox. @@ -24,15 +24,15 @@ void Binc::Maildir::updateFlags(void) // open the cur/ directory string curpath = path + "/cur/"; DIR *pdir = opendir(curpath.c_str()); - if (pdir == 0) { - bincError << "failed to open " << curpath << ": " << strerror(errno) << endl; + if (pdir == nullptr) { + bincError << "failed to open " << curpath << ": " << strerror(errno) << std::endl; return; } // read all entries in the directory - vector<string> entries; + std::vector<string> entries; struct dirent *pdirent; - while ((pdirent = readdir(pdir)) != 0) { + while ((pdirent = readdir(pdir)) != nullptr) { string filename = pdirent->d_name; if (filename[0] == '.') continue; entries.push_back(filename); @@ -41,11 +41,8 @@ void Binc::Maildir::updateFlags(void) bool customFlagsChanged = false; - // loop through all messages in cur/, and update the flags that have - // changed. - for (vector<string>::const_iterator it = entries.begin(); it != entries.end(); ++it) { - string filename = *it; - + // loop through all messages in cur/, and update the flags that have changed. + for (const auto &filename : entries) { // separate the unique name from the flags. accept messages that do not // contain the flags section. string uniquename; @@ -83,8 +80,8 @@ void Binc::Maildir::updateFlags(void) if (rename(srcname.c_str(), destname.c_str()) != 0) { if (errno == ENOENT) { closedir(pdir); - if ((pdir = opendir(curpath.c_str())) == 0) { - bincError << "failed to open " << curpath << ": " << strerror(errno) << endl; + if ((pdir = opendir(curpath.c_str())) == nullptr) { + bincError << "failed to open " << curpath << ": " << strerror(errno) << std::endl; return; } @@ -94,7 +91,7 @@ void Binc::Maildir::updateFlags(void) } bincError << "failed to rename " << srcname << " to " << destname << ": " << strerror(errno) - << endl; + << std::endl; } else { index.insert(uniquename, 0, uniquename + ":2," + flags); } diff --git a/src/maildir-writecache.cc b/src/maildir-writecache.cc index 2a51b49..ceb2f81 100644 --- a/src/maildir-writecache.cc +++ b/src/maildir-writecache.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file maildir-writecache.cc * @brief Implementation of the Maildir class. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ------------------------------------------------------------------ **/ + */ + #include "globals.h" #include "maildir.h" @@ -11,9 +12,6 @@ #include <fcntl.h> #include <unistd.h> -using namespace ::std; - -//------------------------------------------------------------------------ bool Binc::Maildir::writeCache(void) { if (readOnly) return true; @@ -25,7 +23,7 @@ bool Binc::Maildir::writeCache(void) return false; } - string safeName = safename; + std::string safeName = safename; free(safename); FILE *fp = fdopen(fd, "w"); @@ -35,7 +33,7 @@ bool Binc::Maildir::writeCache(void) } if (uidvalidity == 0 || uidnext == 0) { - uidvalidity = time(0); + uidvalidity = time(nullptr); uidnext = messages.size() + 1; } @@ -49,10 +47,9 @@ bool Binc::Maildir::writeCache(void) (unsigned int)message.getInternalDate(), message.getSize(), message.getUnique().c_str()); - vector<string> cflags = message.getCustomFlags(); - for (vector<string>::const_iterator it = cflags.begin(); it != cflags.end(); ++it) { + std::vector<std::string> cflags = message.getCustomFlags(); + for (std::vector<std::string>::const_iterator it = cflags.begin(); it != cflags.end(); ++it) fprintf(fp, " %s", (*it).c_str()); - } fprintf(fp, "\n"); } @@ -67,9 +64,7 @@ bool Binc::Maildir::writeCache(void) } int dfd = open(path.c_str(), O_RDONLY); - if (dfd == -1 || (fsync(fd) && (errno != EROFS || errno != EINVAL)) || close(dfd)) { - return false; - } + if (dfd == -1 || (fsync(fd) && (errno != EROFS || errno != EINVAL)) || close(dfd)) return false; return true; } diff --git a/src/maildir.cc b/src/maildir.cc index 5071a1a..dc7e45a 100644 --- a/src/maildir.cc +++ b/src/maildir.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file maildir.cc * @brief Implementation of the Maildir class. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "maildir.h" #include "convert.h" @@ -30,16 +31,16 @@ #include <sys/types.h> #include <unistd.h> -using namespace ::std; using namespace Binc; +using std::endl; +using std::map; +using std::string; // Used to generate the unique names for Maildir delivery static int numDeliveries = 0; -//------------------------------------------------------------------------ Maildir::iterator::iterator(void) {} -//------------------------------------------------------------------------ Maildir::iterator::iterator(Maildir *home, MessageMap::iterator it, const SequenceSet &_bset, @@ -54,7 +55,6 @@ Maildir::iterator::iterator(Maildir *home, sqnrmax = home->getMaxSqnr(); } -//------------------------------------------------------------------------ Maildir::iterator::iterator(const iterator ©) : BaseIterator(copy.sqnr) , mailbox(copy.mailbox) @@ -65,7 +65,6 @@ Maildir::iterator::iterator(const iterator ©) , sqnrmax(copy.sqnrmax) {} -//------------------------------------------------------------------------ Maildir::iterator &Maildir::iterator::operator=(const iterator ©) { sqnr = copy.sqnr; @@ -78,22 +77,18 @@ Maildir::iterator &Maildir::iterator::operator=(const iterator ©) return *this; } -//------------------------------------------------------------------------ Maildir::iterator::~iterator(void) {} -//------------------------------------------------------------------------ MaildirMessage &Maildir::iterator::curMessage(void) { return i->second; } -//------------------------------------------------------------------------ Message &Maildir::iterator::operator*(void) { return curMessage(); } -//------------------------------------------------------------------------ void Maildir::iterator::operator++(void) { ++i; @@ -101,20 +96,17 @@ void Maildir::iterator::operator++(void) reposition(); } -//------------------------------------------------------------------------ bool Maildir::iterator::operator==(const BaseIterator &a) const { const iterator *b = dynamic_cast<const iterator *>(&a); return b ? (i == b->i) : false; } -//------------------------------------------------------------------------ bool Maildir::iterator::operator!=(const BaseIterator &a) const { return !((*this) == a); } -//------------------------------------------------------------------------ void Maildir::iterator::reposition(void) { for (;;) { @@ -144,23 +136,20 @@ void Maildir::iterator::reposition(void) } } -//------------------------------------------------------------------------ Mailbox::iterator Maildir::begin(const SequenceSet &bset, unsigned int mod) const { - beginIterator = iterator((Maildir *)this, messages.begin(), bset, mod); + beginIterator = iterator(const_cast<Maildir *>(this), messages.begin(), bset, mod); beginIterator.reposition(); return Mailbox::iterator(beginIterator); } -//------------------------------------------------------------------------ Mailbox::iterator Maildir::end(void) const { - endIterator = iterator((Maildir *)this, messages.end(), endIterator.bset, endIterator.mod); + endIterator = iterator(const_cast<Maildir *>(this), messages.end(), endIterator.bset, endIterator.mod); return Mailbox::iterator(endIterator); } -//------------------------------------------------------------------------ void Maildir::iterator::erase(void) { MessageMap::iterator iter = i; @@ -174,7 +163,6 @@ void Maildir::iterator::erase(void) reposition(); } -//------------------------------------------------------------------------ Maildir::Maildir(void) : Mailbox() { firstscan = true; @@ -186,16 +174,13 @@ Maildir::Maildir(void) : Mailbox() oldexists = 0; } -//------------------------------------------------------------------------ Maildir::~Maildir(void) {} -//------------------------------------------------------------------------ void Maildir::setPath(const string &path_in) { path = path_in; } -//------------------------------------------------------------------------ bool Maildir::getUpdates(bool doscan, unsigned int type, PendingUpdates &updates, bool forceScan) { if (doscan && scan(forceScan) != Success) return false; @@ -216,8 +201,9 @@ bool Maildir::getUpdates(bool doscan, unsigned int type, PendingUpdates &updates i.erase(); mailboxchanged = true; displayExists = true; - } else + } else { ++i; + } } } @@ -250,7 +236,6 @@ bool Maildir::getUpdates(bool doscan, unsigned int type, PendingUpdates &updates return true; } -//------------------------------------------------------------------------ bool Maildir::isMailbox(const std::string &s_in) const { struct stat mystat; @@ -260,27 +245,24 @@ bool Maildir::isMailbox(const std::string &s_in) const && (stat((s_in + "/tmp").c_str(), &mystat) == 0 && S_ISDIR(mystat.st_mode))); } -//------------------------------------------------------------------------ const std::string Maildir::getTypeName(void) const { return "Maildir"; } -//------------------------------------------------------------------------ void Maildir::bumpUidValidity(const string &s_in) const { unlink((s_in + "/bincimap-uidvalidity").c_str()); unlink((s_in + "/bincimap-cache").c_str()); } -//------------------------------------------------------------------------ bool Maildir::isMarked(const std::string &s_in) const { DIR *dirp = opendir((s_in + "/new").c_str()); - if (dirp == 0) return false; + if (dirp == nullptr) return false; struct dirent *direntp; - while ((direntp = readdir(dirp)) != 0) { + while ((direntp = readdir(dirp)) != nullptr) { string s = direntp->d_name; if (s[0] != '.' && s.find('/') == string::npos && s.find(':') == string::npos) { closedir(dirp); @@ -292,7 +274,6 @@ bool Maildir::isMarked(const std::string &s_in) const return false; } -//------------------------------------------------------------------------ unsigned int Maildir::getStatusID(const string &path) const { unsigned int statusid = 0; @@ -306,7 +287,6 @@ unsigned int Maildir::getStatusID(const string &path) const return statusid; } -//------------------------------------------------------------------------ bool Maildir::getStatus(const string &path, Status &s) const { unsigned int messages = 0; @@ -319,8 +299,8 @@ bool Maildir::getStatus(const string &path, Status &s) const const string cachefilename = path + "/bincimap-cache"; FILE *fp = fopen(cachefilename.c_str(), "r"); - if (fp) do - { + if (fp) { + do { char inputBuffer[512]; if (!fgets(inputBuffer, sizeof(inputBuffer), fp)) { fclose(fp); @@ -362,18 +342,18 @@ bool Maildir::getStatus(const string &path, Status &s) const fclose(fp); - s.setUidValidity(readUidValidity < 1 ? time(0) : readUidValidity); + s.setUidValidity(readUidValidity < 1 ? time(nullptr) : readUidValidity); } while (0); - else { - s.setUidValidity(time(0)); + } else { + s.setUidValidity(time(nullptr)); } // Scan new DIR *dirp = opendir((path + "/new").c_str()); - if (dirp == 0) return false; + if (dirp == nullptr) return false; struct dirent *direntp; - while ((direntp = readdir(dirp)) != 0) { + while ((direntp = readdir(dirp)) != nullptr) { const string filename = direntp->d_name; if (filename[0] == '.' || filename.find(':') != string::npos || filename.find('/') != string::npos) continue; @@ -387,9 +367,9 @@ bool Maildir::getStatus(const string &path, Status &s) const closedir(dirp); // Scan cur - if ((dirp = opendir((path + "/cur").c_str())) == 0) return false; + if ((dirp = opendir((path + "/cur").c_str())) == nullptr) return false; - while ((direntp = readdir(dirp)) != 0) { + while ((direntp = readdir(dirp)) != nullptr) { const string dname = direntp->d_name; if (dname[0] == '.') continue; @@ -425,7 +405,6 @@ bool Maildir::getStatus(const string &path, Status &s) const return true; } -//------------------------------------------------------------------------ unsigned int Maildir::getMaxUid(void) const { MessageMap::const_iterator i = messages.end(); @@ -445,7 +424,6 @@ unsigned int Maildir::getMaxUid(void) const return 0; } -//------------------------------------------------------------------------ unsigned int Maildir::getMaxSqnr(void) const { int sqnr = messages.size(); @@ -467,51 +445,41 @@ unsigned int Maildir::getMaxSqnr(void) const return 0; } -//------------------------------------------------------------------------ unsigned int Maildir::getUidValidity(void) const { return uidvalidity; } -//------------------------------------------------------------------------ unsigned int Maildir::getUidNext(void) const { return uidnext; } -//------------------------------------------------------------------------ Message *Maildir::createMessage(const string &mbox, time_t idate) { string sname = mbox + "/tmp/bincimap-XXXXXX"; - char *safename = strdup(sname.c_str()); - int fd = mkstemp(safename); + int fd = mkstemp(sname.data()); if (fd == -1) { setLastError("Unable to create safe name."); - return 0; + return nullptr; } - string safenameStr = safename; - delete[] safename; - MaildirMessage message(*this); message.setFile(fd); - message.setSafeName(safenameStr); + message.setSafeName(sname); message.setInternalDate(idate); newMessages.push_back(message); - vector<MaildirMessage>::iterator i = newMessages.end(); - --i; - return &(*i); + return &newMessages.back(); } -//------------------------------------------------------------------------ bool Maildir::commitNewMessages(const string &mbox) { Session &session = Session::getInstance(); - vector<MaildirMessage>::iterator i = newMessages.begin(); + std::vector<MaildirMessage>::iterator i = newMessages.begin(); map<MaildirMessage *, string> committedMessages; struct timeval youngestFile = {0, 0}; @@ -531,13 +499,13 @@ bool Maildir::commitNewMessages(const string &mbox) for (int attempt = 0; !abort && attempt < 1000; ++attempt) { struct timeval tv; - gettimeofday(&tv, 0); + gettimeofday(&tv, nullptr); youngestFile = tv; // Generate Maildir conformant file name BincStream ssid; ssid << (int)tv.tv_sec << "." - << "R" << (int)rand() << "M" << (int)tv.tv_usec << "P" << (int)session.getPid() << "Q" + << "R" << rand() << "M" << (int)tv.tv_usec << "P" << session.getPid() << "Q" << numDeliveries++ << "." << session.getEnv("TCPLOCALHOST"); BincStream ss; @@ -568,33 +536,29 @@ bool Maildir::commitNewMessages(const string &mbox) ++i; } - // abort means to make an attempt to restore the mailbox to - // its original state. + // abort means to make an attempt to restore the mailbox to its original state. if (abort) { // Fixme: Messages that are in committedMessages should be skipped // here. - for (i = newMessages.begin(); i != newMessages.end(); ++i) - unlink((*i).getSafeName().c_str()); + for (const auto &i : newMessages) + unlink(i.getSafeName().c_str()); - map<MaildirMessage *, string>::const_iterator j = committedMessages.begin(); - while (j != committedMessages.end()) { - if (unlink(j->second.c_str()) != 0) { + for (const auto &[_, second] : committedMessages) { + if (unlink(second.c_str()) != 0) { if (errno == ENOENT) { // FIXME: The message was probably moves away from new/ by // another IMAP session. bincWarning << "error rollbacking after failed commit to " << toImapString(mbox) - << ", failed to unlink " << toImapString(j->second) << ": " << strerror(errno) + << ", failed to unlink " << toImapString(second) << ": " << strerror(errno) << endl; } else { bincWarning << "error rollbacking after failed commit to " << toImapString(mbox) - << ", failed to unlink " << toImapString(j->second) << ": " << strerror(errno) + << ", failed to unlink " << toImapString(second) << ": " << strerror(errno) << endl; newMessages.clear(); return false; } } - - ++j; } newMessages.clear(); @@ -606,16 +570,14 @@ bool Maildir::commitNewMessages(const string &mbox) // random number by spinning until the timestamp has changed before // moving the message into cur. struct timeval tv; - gettimeofday(&tv, 0); - while (tv.tv_sec == youngestFile.tv_sec && tv.tv_usec == youngestFile.tv_usec) { - gettimeofday(&tv, 0); - } + gettimeofday(&tv, nullptr); + while (tv.tv_sec == youngestFile.tv_sec && tv.tv_usec == youngestFile.tv_usec) + gettimeofday(&tv, nullptr); - map<MaildirMessage *, string>::const_iterator j = committedMessages.begin(); - for (; j != committedMessages.end(); ++j) { - string basename = j->second.substr(j->second.rfind('/') + 1); + for (auto &j : committedMessages) { + string basename = j.second.substr(j.second.rfind('/') + 1); - int flags = j->first->getStdFlags(); + int flags = j.first->getStdFlags(); string flagStr; if (flags & Message::F_DRAFT) flagStr += "D"; if (flags & Message::F_FLAGGED) flagStr += "F"; @@ -624,30 +586,27 @@ bool Maildir::commitNewMessages(const string &mbox) if (flags & Message::F_DELETED) flagStr += "T"; string dest = mbox + "/cur/" + basename + ":2," + flagStr; - if (rename(j->second.c_str(), dest.c_str()) == 0) continue; + if (rename(j.second.c_str(), dest.c_str()) == 0) continue; - if (errno != ENOENT) - bincWarning << "when setting flags on: " << j->second << ": " << strerror(errno) << endl; + if (errno != ENOENT) { + bincWarning << "when setting flags on: " << j.second << ": " << strerror(errno) << endl; + } } committedMessages.clear(); return true; } -//------------------------------------------------------------------------ bool Maildir::rollBackNewMessages(void) { - vector<MaildirMessage>::const_iterator i = newMessages.begin(); - // Fixme: Messages that are in committedMessages should be skipped - // here. - for (; i != newMessages.end(); ++i) - unlink((*i).getSafeName().c_str()); + // Fixme: Messages that are in committedMessages should be skipped here. + for (const auto &i : newMessages) + unlink(i.getSafeName().c_str()); newMessages.clear(); return true; } -//------------------------------------------------------------------------ bool Maildir::fastCopy(Message &m, Mailbox &desttype, const std::string &destname) { // At this point, fastCopy is broken because the creation time is @@ -669,7 +628,7 @@ bool Maildir::fastCopy(Message &m, Mailbox &desttype, const std::string &destnam for (int attempt = 0; attempt < 1000; ++attempt) { struct timeval tv; - gettimeofday(&tv, 0); + gettimeofday(&tv, nullptr); // Generate Maildir conformant file name BincStream ssid; @@ -686,7 +645,7 @@ bool Maildir::fastCopy(Message &m, Mailbox &desttype, const std::string &destnam MaildirMessage newmess = *message; newmess.setSafeName(fileName); newmess.setUnique(ssid.str()); - newmess.setInternalDate((time_t)tv.tv_sec); + newmess.setInternalDate(tv.tv_sec); newmess.setUID(0); newMessages.push_back(newmess); break; @@ -705,34 +664,30 @@ bool Maildir::fastCopy(Message &m, Mailbox &desttype, const std::string &destnam return true; } -//------------------------------------------------------------------------ MaildirMessage *Maildir::get(const std::string &id) { MaildirIndexItem *item = index.find(id); - if (!item) return 0; + if (!item) return nullptr; unsigned int uid = item->uid; - if (messages.find(uid) == messages.end()) return 0; + if (messages.find(uid) == messages.end()) return nullptr; return &messages.find(uid)->second; } -//------------------------------------------------------------------------ void Maildir::add(MaildirMessage &m) { MessageMap::iterator it = messages.find(m.getUID()); if (it != messages.end()) messages.erase(it); - messages.insert(make_pair(m.getUID(), m)); + messages.insert(std::make_pair(m.getUID(), m)); index.insert(m.getUnique(), m.getUID()); } -//------------------------------------------------------------------------ unsigned int MaildirIndex::getSize(void) const { return idx.size(); } -//------------------------------------------------------------------------ void MaildirIndex::insert(const string &unique, unsigned int uid, const string &fileName) { if (idx.find(unique) == idx.end()) { @@ -747,40 +702,33 @@ void MaildirIndex::insert(const string &unique, unsigned int uid, const string & } } -//------------------------------------------------------------------------ void MaildirIndex::remove(const string &unique) { map<string, MaildirIndexItem>::iterator it = idx.find(unique); if (it != idx.end()) idx.erase(it); } -//------------------------------------------------------------------------ MaildirIndexItem *MaildirIndex::find(const string &unique) { map<string, MaildirIndexItem>::iterator it = idx.find(unique); if (it != idx.end()) return &it->second; - return 0; + return nullptr; } -//------------------------------------------------------------------------ void MaildirIndex::clear(void) { idx.clear(); } -//------------------------------------------------------------------------ void MaildirIndex::clearUids(void) { - map<string, MaildirIndexItem>::iterator it = idx.begin(); - for (; it != idx.end(); ++it) - it->second.uid = 0; + for (auto &it : idx) + it.second.uid = 0; } -//------------------------------------------------------------------------ void MaildirIndex::clearFileNames(void) { - map<string, MaildirIndexItem>::iterator it = idx.begin(); - for (; it != idx.end(); ++it) - it->second.fileName = ""; + for (auto &it : idx) + it.second.fileName = ""; } diff --git a/src/maildirmessage.cc b/src/maildirmessage.cc index ee1d889..56a75c4 100644 --- a/src/maildirmessage.cc +++ b/src/maildirmessage.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file maildirmessage.cc * @brief Implementation of the MaildirMessage class. * @author Andreas Aardal Hanssen * @date Copyright 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "maildirmessage.h" #include "convert.h" @@ -25,14 +26,14 @@ #include <unistd.h> #include <utime.h> -using namespace ::std; using namespace Binc; +using std::string; +using std::vector; string Message::lastError; string MaildirMessage::storage; namespace { - //---------------------------------------------------------------------- void printOneHeader(IODevice &io, const MimePart *message, const string &s_in, @@ -44,11 +45,11 @@ namespace { if (message->h.getFirstHeader(s_in, hitem)) { tmp = hitem.getValue(); io << toImapString(unfold(tmp, removecomments)); - } else + } else { io << "NIL"; + } } - //---------------------------------------------------------------------- void printOneAddressList(IODevice &io, const MimePart *message, const string &s_in, @@ -63,17 +64,17 @@ namespace { splitAddr(unfold(tmp, removecomments), addr); if (addr.size() != 0) { io << "("; - for (vector<string>::const_iterator i = addr.begin(); i != addr.end(); ++i) - - io << Address(*i).toParenList(); + for (const auto &i : addr) + io << Address(i).toParenList(); io << ")"; - } else + } else { io << "NIL"; - } else + } + } else { io << "NIL"; + } } - //---------------------------------------------------------------------- void envelope(IODevice &io, const MimePart *message) { HeaderItem hitem; @@ -106,16 +107,14 @@ namespace { io << ")"; } - //---------------------------------------------------------------------- void bodyStructure(IODevice &io, const MimePart *message, bool extended) { HeaderItem hitem; if (message->isMultipart() && message->members.size() > 0) { io << "("; - for (vector<MimePart>::const_iterator i = message->members.begin(); i != message->members.end(); - ++i) - bodyStructure(io, &(*i), extended); + for (const auto &i : message->members) + bodyStructure(io, &i, extended); io << " "; io << toImapString(message->getSubType()); @@ -137,8 +136,7 @@ namespace { vector<string> v; split(tmp, ";", v); - for (vector<string>::const_iterator i = v.begin(); i != v.end(); ++i) { - string element = *i; + for (string element : v) { trim(element); if (element.find('=') != string::npos) { string::size_type pos = element.find('='); @@ -153,15 +151,17 @@ namespace { if (parameters.size() != 0) { io << "("; - for (vector<string>::const_iterator i = parameters.begin(); i != parameters.end(); ++i) { - if (i != parameters.begin()) io << " "; + for (auto i = parameters.cbegin(); i != parameters.cend(); ++i) { + if (i != parameters.cbegin()) io << " "; io << toImapString(*i); } io << ")"; - } else + } else { io << "NIL"; - } else + } + } else { io << "NIL"; + } // CONTENT-DISPOSITION io << " "; @@ -207,13 +207,16 @@ namespace { ++i; } io << ")"; - } else + } else { io << "NIL"; + } io << ")"; - } else + } else { io << "NIL"; - } else + } + } else { io << "NIL"; + } // CONTENT-LANGUAGE io << " "; @@ -251,8 +254,8 @@ namespace { subtype = "plain"; } - for (vector<string>::const_iterator i = v.begin(); i != v.end(); ++i) { - if (i == v.begin()) continue; + for (auto i = v.cbegin(); i != v.cend(); ++i) { + if (i == v.cbegin()) continue; string element = *i; trim(element); if (element.find('=') != string::npos) { @@ -278,13 +281,14 @@ namespace { io << " "; if (parameters.size() != 0) { io << "("; - for (vector<string>::const_iterator i = parameters.begin(); i != parameters.end(); ++i) { - if (i != parameters.begin()) io << " "; + for (auto i = parameters.cbegin(); i != parameters.cend(); ++i) { + if (i != parameters.cbegin()) io << " "; io << toImapString(*i); } io << ")"; - } else + } else { io << "NIL"; + } // CONTENT-ID io << " "; @@ -301,8 +305,9 @@ namespace { tmp = hitem.getValue(); trim(tmp); io << toImapString(tmp); - } else + } else { io << "\"7bit\""; + } io << " "; // Size of body in octets @@ -366,13 +371,16 @@ namespace { ++i; } io << ")"; - } else + } else { io << "NIL"; + } io << ")"; - } else + } else { io << "NIL"; - } else + } + } else { io << "NIL"; + } // CONTENT-LANGUAGE io << " "; @@ -388,10 +396,9 @@ namespace { } } -//------------------------------------------------------------------------ MaildirMessage::MaildirMessage(Maildir &hom) : fd(-1) - , doc(0) + , doc(nullptr) , internalFlags(None) , stdflags(F_NONE) , uid(0) @@ -400,10 +407,9 @@ MaildirMessage::MaildirMessage(Maildir &hom) , safeName("") , internaldate(0) , home(hom) - , customFlags(0) + , customFlags(nullptr) {} -//------------------------------------------------------------------------ MaildirMessage::MaildirMessage(const MaildirMessage ©) : fd(copy.fd) , doc(copy.doc) @@ -424,43 +430,16 @@ MaildirMessage::MaildirMessage(const MaildirMessage ©) } } -//------------------------------------------------------------------------ MaildirMessage::~MaildirMessage(void) { delete customFlags; } -//------------------------------------------------------------------------ -MaildirMessage &MaildirMessage::operator=(const MaildirMessage ©) -{ - fd = copy.fd; - doc = copy.doc; - internalFlags = copy.internalFlags; - stdflags = copy.stdflags; - uid = copy.uid; - size = copy.size; - unique = copy.unique; - safeName = copy.safeName; - internaldate = copy.internaldate; - home = copy.home; - - if (copy.customFlags) { - customFlags = new vector<string>; - *customFlags = *copy.customFlags; - } else { - customFlags = 0; - } - - return *this; -} - -//------------------------------------------------------------------------ bool MaildirMessage::operator<(const MaildirMessage &a) const { return uid < a.uid; } -//------------------------------------------------------------------------ void MaildirMessage::close(void) { if (fd != -1) { @@ -482,7 +461,7 @@ void MaildirMessage::close(void) struct utimbuf tim = {internaldate, internaldate}; utime(safeName.c_str(), &tim); } else { - time_t t = time(0); + time_t t = time(nullptr); struct utimbuf tim = {t, t}; utime(safeName.c_str(), &tim); } @@ -490,57 +469,48 @@ void MaildirMessage::close(void) internalFlags &= ~WasWrittenTo; } - if (doc) { doc->clear(); delete doc; - doc = 0; + doc = nullptr; } } -//------------------------------------------------------------------------ void MaildirMessage::setExpunged(void) { internalFlags |= Expunged; } -//------------------------------------------------------------------------ void MaildirMessage::setUnExpunged(void) { internalFlags &= ~Expunged; } -//------------------------------------------------------------------------ void MaildirMessage::setFlagsUnchanged(void) { internalFlags &= ~FlagsChanged; } -//------------------------------------------------------------------------ bool MaildirMessage::hasFlagsChanged(void) const { return (internalFlags & FlagsChanged) != 0; } -//------------------------------------------------------------------------ unsigned char MaildirMessage::getStdFlags(void) const { return stdflags; } -//------------------------------------------------------------------------ bool MaildirMessage::isExpunged(void) const { return (internalFlags & Expunged) != 0; } -//------------------------------------------------------------------------ unsigned int MaildirMessage::getUID(void) const { return uid; } -//------------------------------------------------------------------------ unsigned int MaildirMessage::getSize(bool render) const { if (size == 0 && render) { @@ -551,57 +521,48 @@ unsigned int MaildirMessage::getSize(bool render) const return size; } -//------------------------------------------------------------------------ const string &MaildirMessage::getUnique(void) const { return unique; } -//------------------------------------------------------------------------ time_t MaildirMessage::getInternalDate(void) const { return internaldate; } -//------------------------------------------------------------------------ void MaildirMessage::setInternalDate(time_t t) { internaldate = t; } -//------------------------------------------------------------------------ void MaildirMessage::setStdFlag(unsigned char f_in) { internalFlags |= FlagsChanged; stdflags |= f_in; } -//------------------------------------------------------------------------ void MaildirMessage::resetStdFlags(void) { internalFlags |= FlagsChanged; stdflags = F_NONE; } -//------------------------------------------------------------------------ void MaildirMessage::setUID(unsigned int i_in) { uid = i_in; } -//------------------------------------------------------------------------ void MaildirMessage::setSize(unsigned int i_in) { size = i_in; } -//------------------------------------------------------------------------ void MaildirMessage::setUnique(const string &s_in) { unique = s_in; } -//------------------------------------------------------------------------ int MaildirMessage::getFile(void) const { if (fd != -1) return fd; @@ -619,16 +580,16 @@ int MaildirMessage::getFile(void) const if (errno == ENOENT) { struct stat st; if (lstat(fpath.c_str(), &st) != -1) { - bincWarning << "dangling symlink: " << fpath << endl; + bincWarning << "dangling symlink: " << fpath << std::endl; return -1; } } else { - bincWarning << "unable to open " << fpath << ": " << strerror(errno) << endl; + bincWarning << "unable to open " << fpath << ": " << strerror(errno) << std::endl; return -1; } home.scanFileNames(); - if ((item = home.index.find(id)) == 0) + if ((item = home.index.find(id)) == nullptr) break; else fpath = home.path + "/cur/" + item->fileName; @@ -643,38 +604,33 @@ int MaildirMessage::getFile(void) const return -1; } -//------------------------------------------------------------------------ void MaildirMessage::setFile(int fd) { this->fd = fd; } -//------------------------------------------------------------------------ void MaildirMessage::setSafeName(const string &name) { safeName = name; } -//------------------------------------------------------------------------ const string &MaildirMessage::getSafeName(void) const { return safeName; } -//------------------------------------------------------------------------ string MaildirMessage::getFileName(void) const { MaildirIndexItem *item = home.index.find(getUnique()); if (!item) { home.scanFileNames(); - if ((item = home.index.find(getUnique())) == 0) return ""; + if ((item = home.index.find(getUnique())) == nullptr) return ""; } return item->fileName; } -//------------------------------------------------------------------------ int MaildirMessage::readChunk(string &chunk) { if (fd == -1) { @@ -692,7 +648,6 @@ int MaildirMessage::readChunk(string &chunk) return readBytes; } -//------------------------------------------------------------------------ bool MaildirMessage::appendChunk(const string &chunk) { if (fd == -1) { @@ -725,7 +680,6 @@ bool MaildirMessage::appendChunk(const string &chunk) return false; } -//------------------------------------------------------------------------ bool MaildirMessage::parseFull(void) const { MaildirMessageCache &cache = MaildirMessageCache::getInstance(); @@ -744,7 +698,6 @@ bool MaildirMessage::parseFull(void) const return true; } -//------------------------------------------------------------------------ bool MaildirMessage::parseHeaders(void) const { MaildirMessageCache &cache = MaildirMessageCache::getInstance(); @@ -764,7 +717,6 @@ bool MaildirMessage::parseHeaders(void) const return true; } -//------------------------------------------------------------------------ bool MaildirMessage::printBodyStructure(bool extended) const { if (!parseFull()) return false; @@ -773,7 +725,6 @@ bool MaildirMessage::printBodyStructure(bool extended) const return true; } -//------------------------------------------------------------------------ bool MaildirMessage::printEnvelope(void) const { if (!parseFull()) return false; @@ -782,7 +733,6 @@ bool MaildirMessage::printEnvelope(void) const return true; } -//------------------------------------------------------------------------ bool MaildirMessage::printHeader(const std::string §ion, std::vector<std::string> headers, bool includeHeaders, @@ -795,7 +745,6 @@ bool MaildirMessage::printHeader(const std::string §ion, return true; } -//------------------------------------------------------------------------ unsigned int MaildirMessage::getHeaderSize(const std::string §ion, std::vector<std::string> headers, bool includeHeaders, @@ -805,8 +754,9 @@ unsigned int MaildirMessage::getHeaderSize(const std::string §ion, { if (section == "") { if (!parseHeaders()) return 0; - } else if (!parseFull()) + } else if (!parseFull()) { return 0; + } const MimePart *part = doc->getPart(section, "", mime ? MimePart::FetchMime : MimePart::FetchHeader); if (!part) { @@ -823,7 +773,6 @@ unsigned int MaildirMessage::getHeaderSize(const std::string §ion, return storage.size(); } -//------------------------------------------------------------------------ bool MaildirMessage::printBody(const std::string §ion, unsigned int startOffset, unsigned int length) const @@ -833,7 +782,7 @@ bool MaildirMessage::printBody(const std::string §ion, const MimePart *part = doc->getPart(section, ""); if (!part) { storage = ""; - return 0; + return false; } int fd = getFile(); @@ -844,7 +793,6 @@ bool MaildirMessage::printBody(const std::string §ion, return true; } -//------------------------------------------------------------------------ unsigned int MaildirMessage::getBodySize(const std::string §ion, unsigned int startOffset, unsigned int length) const @@ -863,7 +811,6 @@ unsigned int MaildirMessage::getBodySize(const std::string §ion, return s < length ? s : length; } -//------------------------------------------------------------------------ bool MaildirMessage::printDoc(unsigned int startOffset, unsigned int length, bool onlyText) const { if (!parseFull()) return false; @@ -878,7 +825,6 @@ bool MaildirMessage::printDoc(unsigned int startOffset, unsigned int length, boo return true; } -//------------------------------------------------------------------------ unsigned int MaildirMessage::getDocSize(unsigned int startOffset, unsigned int length, bool onlyText) const @@ -894,7 +840,6 @@ unsigned int MaildirMessage::getDocSize(unsigned int startOffset, return s < length ? s : length; } -//------------------------------------------------------------------------ bool MaildirMessage::headerContains(const std::string &header, const std::string &text) { if (!parseHeaders()) return false; @@ -909,7 +854,6 @@ bool MaildirMessage::headerContains(const std::string &header, const std::string return (tmp.find(tmp2) != string::npos); } -//------------------------------------------------------------------------ bool MaildirMessage::bodyContains(const std::string &text) { if (!parseFull()) return false; @@ -944,7 +888,6 @@ bool MaildirMessage::bodyContains(const std::string &text) return false; } -//------------------------------------------------------------------------ bool MaildirMessage::textContains(const std::string &text) { // search the body part of the message.. @@ -973,7 +916,6 @@ bool MaildirMessage::textContains(const std::string &text) return false; } -//------------------------------------------------------------------------ const std::string &MaildirMessage::getHeader(const std::string &header) { static string NIL = ""; @@ -986,23 +928,19 @@ const std::string &MaildirMessage::getHeader(const std::string &header) return hitem.getValue(); } -//------------------------------------------------------------------------ MaildirMessageCache::MaildirMessageCache(void) {} -//------------------------------------------------------------------------ MaildirMessageCache::~MaildirMessageCache(void) { clear(); } -//------------------------------------------------------------------------ MaildirMessageCache &MaildirMessageCache::getInstance(void) { static MaildirMessageCache cache; return cache; } -//------------------------------------------------------------------------ void MaildirMessageCache::addStatus(const MaildirMessage *m, ParseStatus s) { if (statuses.find(m) == statuses.end()) { @@ -1019,7 +957,6 @@ void MaildirMessageCache::addStatus(const MaildirMessage *m, ParseStatus s) statuses[m] = s; } -//------------------------------------------------------------------------ MaildirMessageCache::ParseStatus MaildirMessageCache::getStatus(const MaildirMessage *m) const { if (statuses.find(m) == statuses.end()) return NotParsed; @@ -1027,24 +964,19 @@ MaildirMessageCache::ParseStatus MaildirMessageCache::getStatus(const MaildirMes return statuses[m]; } -//------------------------------------------------------------------------ void MaildirMessageCache::clear(void) { - for (deque<const MaildirMessage *>::iterator i = parsed.begin(); i != parsed.end(); ++i) - const_cast<MaildirMessage *>(*i)->close(); - + for (std::deque<const MaildirMessage *>::iterator i = parsed.begin(); i != parsed.end(); ++i) parsed.clear(); - statuses.clear(); } -//------------------------------------------------------------------------ void MaildirMessageCache::removeStatus(const MaildirMessage *m) { if (statuses.find(m) == statuses.end()) return; statuses.erase(statuses.find(m)); - for (deque<const MaildirMessage *>::iterator i = parsed.begin(); i != parsed.end(); ++i) { + for (std::deque<const MaildirMessage *>::iterator i = parsed.begin(); i != parsed.end(); ++i) { if (*i == m) { const_cast<MaildirMessage *>(*i)->close(); parsed.erase(i); @@ -1053,25 +985,21 @@ void MaildirMessageCache::removeStatus(const MaildirMessage *m) } } -//------------------------------------------------------------------------ void MaildirMessage::setInternalFlag(unsigned char f) { internalFlags |= f; } -//------------------------------------------------------------------------ unsigned char MaildirMessage::getInternalFlags(void) const { return internalFlags; } -//------------------------------------------------------------------------ void MaildirMessage::clearInternalFlag(unsigned char f) { internalFlags &= ~f; } -//------------------------------------------------------------------------ void MaildirMessage::setCustomFlag(const string &flag) { if (!customFlags) { @@ -1079,15 +1007,13 @@ void MaildirMessage::setCustomFlag(const string &flag) customFlags = new vector<string>; } - for (vector<string>::const_iterator it = customFlags->begin(); it != customFlags->end(); ++it) { - if (*it == flag) return; - } + for (const auto &it : *customFlags) + if (it == flag) return; internalFlags |= FlagsChanged | CustomFlagsChanged; customFlags->push_back(flag); } -//------------------------------------------------------------------------ void MaildirMessage::removeCustomFlag(const string &flag) { internalFlags |= FlagsChanged | CustomFlagsChanged; @@ -1102,16 +1028,14 @@ void MaildirMessage::removeCustomFlag(const string &flag) } } -//------------------------------------------------------------------------ void MaildirMessage::resetCustomFlags(void) { internalFlags |= FlagsChanged | CustomFlagsChanged; delete customFlags; - customFlags = 0; + customFlags = nullptr; } -//------------------------------------------------------------------------ vector<string> MaildirMessage::getCustomFlags(void) const { if (!customFlags) return vector<string>(); diff --git a/src/mime-getpart.cc b/src/mime-getpart.cc index 02a1ec5..42f6c60 100644 --- a/src/mime-getpart.cc +++ b/src/mime-getpart.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file mime-getpart.cc * @brief Implementation of main mime parser components * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "convert.h" #include "mime.h" @@ -18,32 +19,27 @@ #include <stdio.h> #include <string.h> -using namespace ::std; - -//------------------------------------------------------------------------ -const Binc::MimePart *Binc::MimePart::getPart(const string &findpart, - string genpart, +const Binc::MimePart *Binc::MimePart::getPart(const std::string &findpart, + std::string genpart, FetchType fetchType) const { if (findpart == genpart) return this; if (isMultipart()) { if (members.size() != 0) { - vector<MimePart>::const_iterator i = members.begin(); int part = 1; - while (i != members.end()) { + for (const auto &i : members) { BincStream ss; ss << genpart; if (genpart != "") ss << "."; ss << part; const MimePart *m; - if ((m = (*i).getPart(findpart, ss.str())) != 0) { + if ((m = i.getPart(findpart, ss.str())) != nullptr) { if (fetchType == FetchHeader && m->isMessageRFC822()) m = &m->members[0]; return m; } - ++i; ++part; } } @@ -52,7 +48,7 @@ const Binc::MimePart *Binc::MimePart::getPart(const string &findpart, const MimePart *m = members[0].getPart(findpart, genpart); return m; } else { - return 0; + return nullptr; } } else { // Singlepart @@ -62,5 +58,5 @@ const Binc::MimePart *Binc::MimePart::getPart(const string &findpart, if (findpart == genpart) return this; } - return 0; + return nullptr; } diff --git a/src/mime-parsefull.cc b/src/mime-parsefull.cc index 50d3157..5d5d836 100644 --- a/src/mime-parsefull.cc +++ b/src/mime-parsefull.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file mime-parsefull.cc * @brief Implementation of main mime parser components * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "convert.h" #include "mime-inputsource.h" #include "mime-utils.h" @@ -20,11 +21,11 @@ #include <stdio.h> #include <string.h> -Binc::MimeInputSource *mimeSource = 0; +Binc::MimeInputSource *mimeSource = nullptr; -using namespace ::std; +using std::string; +using std::vector; -//------------------------------------------------------------------------ void Binc::MimeDocument::parseFull(int fd) const { if (allIsParsed) return; @@ -58,7 +59,6 @@ void Binc::MimeDocument::parseFull(int fd) const size = mimeSource->getOffset(); } -//------------------------------------------------------------------------ static bool parseOneHeaderLine(Binc::Header *header, unsigned int *nlines) { using namespace ::Binc; @@ -139,14 +139,12 @@ static bool parseOneHeaderLine(Binc::Header *header, unsigned int *nlines) return !(eof || endOfHeaders); } -//------------------------------------------------------------------------ static void parseHeader(Binc::Header *header, unsigned int *nlines) { while (parseOneHeaderLine(header, nlines)) { } } -//------------------------------------------------------------------------ static void analyzeHeader(Binc::Header *header, bool *multipart, bool *messagerfc822, @@ -211,7 +209,7 @@ static void parseMessageRFC822(vector<Binc::MimePart> *members, unsigned int *nbodylines, const string &toboundary) { - using namespace ::Binc; + using namespace Binc; // message rfc822 means a completely enclosed mime document. we // call the parser recursively, and pass on the boundary string @@ -230,11 +228,10 @@ static void parseMessageRFC822(vector<Binc::MimePart> *members, *bodylength = mimeSource->getOffset(); if (*bodylength >= bodystartoffsetcrlf) { *bodylength -= bodystartoffsetcrlf; - if (*bodylength >= (unsigned int)bsize) { + if (*bodylength >= (unsigned int)bsize) *bodylength -= (unsigned int)bsize; - } else { + else *bodylength = 0; - } } else { *bodylength = 0; } @@ -247,7 +244,7 @@ static void parseMessageRFC822(vector<Binc::MimePart> *members, static bool skipUntilBoundary(const string &delimiter, unsigned int *nlines, bool *eof) { int endpos = delimiter.length(); - char *delimiterqueue = 0; + char *delimiterqueue = nullptr; int delimiterpos = 0; const char *delimiterStr = delimiter.c_str(); if (delimiter != "") { @@ -282,7 +279,7 @@ static bool skipUntilBoundary(const string &delimiter, unsigned int *nlines, boo } delete[] delimiterqueue; - delimiterqueue = 0; + delimiterqueue = nullptr; return foundBoundary; } @@ -338,9 +335,9 @@ static void parseMultipart(const string &boundary, // This exception is to handle a special case where the // delimiter of one part is not followed by CRLF, but // immediately followed by a CRLF prefixed delimiter. - if (!mimeSource->getChar(&a) || !mimeSource->getChar(&b)) + if (!mimeSource->getChar(&a) || !mimeSource->getChar(&b)) { *eof = true; - else if (a == '-' && b == '-') { + } else if (a == '-' && b == '-') { mimeSource->ungetChar(); mimeSource->ungetChar(); mimeSource->ungetChar(); @@ -415,9 +412,9 @@ static void parseMultipart(const string &boundary, // This exception is to handle a special case where the // delimiter of one part is not followed by CRLF, but // immediately followed by a CRLF prefixed delimiter. - if (!mimeSource->getChar(&a) || !mimeSource->getChar(&b)) + if (!mimeSource->getChar(&a) || !mimeSource->getChar(&b)) { *eof = true; - else if (a == '-' && b == '-') { + } else if (a == '-' && b == '-') { mimeSource->ungetChar(); mimeSource->ungetChar(); mimeSource->ungetChar(); @@ -439,11 +436,10 @@ static void parseMultipart(const string &boundary, *bodylength = mimeSource->getOffset(); if (*bodylength >= bodystartoffsetcrlf) { *bodylength -= bodystartoffsetcrlf; - if (*bodylength >= (unsigned int)*boundarysize) { + if (*bodylength >= (unsigned int)*boundarysize) *bodylength -= (unsigned int)*boundarysize; - } else { + else *bodylength = 0; - } } else { *bodylength = 0; } @@ -471,7 +467,7 @@ static void parseSinglePart(const string &toboundary, // if (skipUntilBoundary(_toboundary, nlines, eof)) // *boundarysize = _toboundary.length(); - char *boundaryqueue = 0; + char *boundaryqueue = nullptr; int endpos = _toboundary.length(); if (toboundary != "") { boundaryqueue = new char[endpos]; @@ -525,9 +521,9 @@ static void parseSinglePart(const string &toboundary, // This exception is to handle a special case where the // delimiter of one part is not followed by CRLF, but // immediately followed by a CRLF prefixed delimiter. - if (!mimeSource->getChar(&a) || !mimeSource->getChar(&b)) + if (!mimeSource->getChar(&a) || !mimeSource->getChar(&b)) { *eof = true; - else if (a == '-' && b == '-') { + } else if (a == '-' && b == '-') { mimeSource->ungetChar(); mimeSource->ungetChar(); mimeSource->ungetChar(); @@ -548,17 +544,15 @@ static void parseSinglePart(const string &toboundary, *bodylength = mimeSource->getOffset(); if (*bodylength >= bodystartoffsetcrlf) { *bodylength -= bodystartoffsetcrlf; - if (*bodylength >= (unsigned int)*boundarysize) { + if (*bodylength >= (unsigned int)*boundarysize) *bodylength -= (unsigned int)*boundarysize; - } else { + else *bodylength = 0; - } } else { *bodylength = 0; } } -//------------------------------------------------------------------------ int Binc::MimePart::parseFull(const string &toboundary, int &boundarysize) const { headerstartoffsetcrlf = mimeSource->getOffset(); diff --git a/src/mime-parseonlyheader.cc b/src/mime-parseonlyheader.cc index 5245aa5..36679b2 100644 --- a/src/mime-parseonlyheader.cc +++ b/src/mime-parseonlyheader.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file mime-parseonlyheader.cc * @brief Implementation of main mime parser components * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "convert.h" #include "mime-inputsource.h" #include "mime-utils.h" @@ -20,9 +21,6 @@ #include <stdio.h> #include <string.h> -using namespace ::std; - -//------------------------------------------------------------------------ void Binc::MimeDocument::parseOnlyHeader(int fd) const { if (allIsParsed || headerIsParsed) return; @@ -36,7 +34,6 @@ void Binc::MimeDocument::parseOnlyHeader(int fd) const mimeSource->reset(); } - headerstartoffsetcrlf = 0; headerlength = 0; bodystartoffsetcrlf = 0; @@ -50,11 +47,10 @@ void Binc::MimeDocument::parseOnlyHeader(int fd) const MimePart::parseOnlyHeader(""); } -//------------------------------------------------------------------------ -int Binc::MimePart::parseOnlyHeader(const string &toboundary) const +int Binc::MimePart::parseOnlyHeader(const std::string &toboundary) const { - string name; - string content; + std::string name; + std::string content; char cqueue[4]; memset(cqueue, 0, sizeof(cqueue)); diff --git a/src/mime-printbody.cc b/src/mime-printbody.cc index 0c9e0b8..0159e61 100644 --- a/src/mime-printbody.cc +++ b/src/mime-printbody.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file mime-printbody.cc * @brief Implementation of main mime parser components * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "convert.h" #include "iodevice.h" #include "iofactory.h" @@ -22,9 +23,6 @@ #include <stdio.h> #include <string.h> -using namespace ::std; - -//------------------------------------------------------------------------ void Binc::MimePart::printBody(int fd, IODevice &output, unsigned int startoffset, diff --git a/src/mime-printdoc.cc b/src/mime-printdoc.cc index 37ec356..f9f86dc 100644 --- a/src/mime-printdoc.cc +++ b/src/mime-printdoc.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file mime-printdoc.cc * @brief Implementation of main mime parser components * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "convert.h" #include "iodevice.h" #include "iofactory.h" @@ -22,9 +23,6 @@ #include <stdio.h> #include <string.h> -using namespace ::std; - -//------------------------------------------------------------------------ void Binc::MimePart::printDoc(int fd, IODevice &output, unsigned int startoffset, diff --git a/src/mime-printheader.cc b/src/mime-printheader.cc index 9fb168e..34f1b99 100644 --- a/src/mime-printheader.cc +++ b/src/mime-printheader.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file mime-printheader.cc * @brief Implementation of main mime parser components * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "convert.h" #include "iodevice.h" #include "iofactory.h" @@ -22,9 +23,9 @@ #include <stdio.h> #include <string.h> -using namespace ::std; +using std::string; +using std::vector; -//------------------------------------------------------------------------ void Binc::MimePart::printHeader(int fd, IODevice &output, vector<string> headers, @@ -116,8 +117,7 @@ void Binc::MimePart::printHeader(int fd, trim(lowername, ": \t"); bool foundMatch = false; - for (vector<string>::const_iterator i = headers.begin(); i != headers.end(); ++i) { - string nametmp = *i; + for (auto nametmp : headers) { lowercase(nametmp); if (nametmp == lowername) { foundMatch = true; @@ -127,14 +127,16 @@ void Binc::MimePart::printHeader(int fd, if (foundMatch == includeheaders || headers.size() == 0) { string out = name + content; - for (string::const_iterator i = out.begin(); i != out.end(); ++i) + for (char i : out) { if (processedbytes >= startoffset && wrotebytes < length) { if (processedbytes >= startoffset) { - store += *i; + store += i; ++wrotebytes; } - } else + } else { ++processedbytes; + } + } } // move on to the next header @@ -151,8 +153,7 @@ void Binc::MimePart::printHeader(int fd, lowercase(lowername); trim(lowername, ": \t"); bool foundMatch = false; - for (vector<string>::const_iterator i = headers.begin(); i != headers.end(); ++i) { - string nametmp = *i; + for (auto nametmp : headers) { lowercase(nametmp); if (nametmp == lowername) { foundMatch = true; @@ -162,12 +163,14 @@ void Binc::MimePart::printHeader(int fd, if (hasHeaderSeparator || foundMatch == includeheaders || headers.size() == 0) { string out = name + content; - for (string::const_iterator i = out.begin(); i != out.end(); ++i) + for (char i : out) { if (processedbytes >= startoffset && wrotebytes < length) { - store += *i; + store += i; ++wrotebytes; - } else + } else { ++processedbytes; + } + } } } } diff --git a/src/mime.cc b/src/mime.cc index fa2e2ea..6a4817e 100644 --- a/src/mime.cc +++ b/src/mime.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file mime.cc * @brief Implementation of main mime parser components * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "mime.h" #include "convert.h" @@ -19,19 +20,16 @@ #include <stdio.h> #include <string.h> -using namespace ::std; +using std::string; -//------------------------------------------------------------------------ Binc::MimeDocument::MimeDocument(void) : MimePart() { allIsParsed = false; headerIsParsed = false; } -//------------------------------------------------------------------------ Binc::MimeDocument::~MimeDocument(void) {} -//------------------------------------------------------------------------ void Binc::MimeDocument::clear(void) const { members.clear(); @@ -40,14 +38,12 @@ void Binc::MimeDocument::clear(void) const allIsParsed = false; } -//------------------------------------------------------------------------ void Binc::MimePart::clear(void) const { members.clear(); h.clear(); } -//------------------------------------------------------------------------ Binc::MimePart::MimePart(void) { size = 0; @@ -58,50 +54,43 @@ Binc::MimePart::MimePart(void) nbodylines = 0; } -//------------------------------------------------------------------------ Binc::MimePart::~MimePart(void) {} -//------------------------------------------------------------------------ Binc::HeaderItem::HeaderItem(void) {} -//------------------------------------------------------------------------ Binc::HeaderItem::HeaderItem(const string &key, const string &value) { this->key = key; this->value = value; } -//------------------------------------------------------------------------ Binc::Header::Header(void) {} -//------------------------------------------------------------------------ Binc::Header::~Header(void) {} -//------------------------------------------------------------------------ bool Binc::Header::getFirstHeader(const string &key, HeaderItem &dest) const { string k = key; lowercase(k); - for (vector<HeaderItem>::const_iterator i = content.begin(); i != content.end(); ++i) { - string tmp = (*i).getKey(); + for (const auto &i : content) { + string tmp = i.getKey(); lowercase(tmp); if (tmp == k) { - dest = *i; + dest = i; return true; } } return false; } -//------------------------------------------------------------------------ -bool Binc::Header::getAllHeaders(const string &key, vector<HeaderItem> &dest) const +bool Binc::Header::getAllHeaders(const string &key, std::vector<HeaderItem> &dest) const { string k = key; lowercase(k); - for (vector<HeaderItem>::const_iterator i = content.begin(); i != content.end(); ++i) { + for (std::vector<HeaderItem>::const_iterator i = content.begin(); i != content.end(); ++i) { string tmp = (*i).getKey(); lowercase(tmp); if (tmp == k) dest.push_back(*i); @@ -110,13 +99,11 @@ bool Binc::Header::getAllHeaders(const string &key, vector<HeaderItem> &dest) co return (dest.size() != 0); } -//------------------------------------------------------------------------ void Binc::Header::clear(void) const { content.clear(); } -//------------------------------------------------------------------------ void Binc::Header::add(const string &key, const string &value) { content.push_back(HeaderItem(key, value)); diff --git a/src/multilogdevice.cc b/src/multilogdevice.cc index 7452432..cf7c412 100644 --- a/src/multilogdevice.cc +++ b/src/multilogdevice.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file multilogdevice.cc * @brief Implementation of the MultilogDevice class * @author Andreas Aardal Hanssen * @date 2003/2023 - * --------------------------------------------------------------- **/ + */ + #include "multilogdevice.h" #include <string> @@ -15,22 +16,17 @@ #include <sys/types.h> #include <unistd.h> -using namespace ::std; -using namespace ::Binc; +using namespace Binc; -//------------------------------------------------------------------------ MultilogDevice::MultilogDevice(int f) : IODevice(f) {} -//------------------------------------------------------------------------ MultilogDevice::~MultilogDevice(void) {} -//------------------------------------------------------------------------ -string MultilogDevice::service(void) const +std::string MultilogDevice::service(void) const { return "log"; } -//------------------------------------------------------------------------ bool MultilogDevice::waitForWrite(void) const { fd_set writeMask; @@ -41,18 +37,16 @@ bool MultilogDevice::waitForWrite(void) const tv.tv_sec = getTimeout(); tv.tv_usec = 0; - int result = select(fileno(stderr) + 1, 0, &writeMask, 0, tv.tv_sec ? &tv : 0); + int result = select(fileno(stderr) + 1, nullptr, &writeMask, nullptr, tv.tv_sec ? &tv : nullptr); return result > 0; } -//------------------------------------------------------------------------ bool MultilogDevice::waitForRead(void) const { return false; } -//------------------------------------------------------------------------ IODevice::WriteResult MultilogDevice::write(void) { for (;;) { @@ -75,7 +69,6 @@ IODevice::WriteResult MultilogDevice::write(void) } } -//------------------------------------------------------------------------ bool MultilogDevice::fillInputBuffer(void) { return false; diff --git a/src/operator-append.cc b/src/operator-append.cc index f4eaaa9..cf40fdf 100644 --- a/src/operator-append.cc +++ b/src/operator-append.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file operator-append.cc * @brief Implementation of the APPEND command. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "depot.h" #include "iodevice.h" #include "iofactory.h" @@ -18,37 +19,32 @@ #include <fcntl.h> -using namespace ::std; using namespace Binc; +using std::string; -//---------------------------------------------------------------------- AppendOperator::AppendOperator(void) {} -//---------------------------------------------------------------------- AppendOperator::~AppendOperator(void) {} -//---------------------------------------------------------------------- const string AppendOperator::getName(void) const { return "APPEND"; } -//---------------------------------------------------------------------- int AppendOperator::getState(void) const { return Session::AUTHENTICATED | Session::SELECTED; } -//------------------------------------------------------------------------ Operator::ProcessResult AppendOperator::process(Depot &depot, Request &command) { Session &session = Session::getInstance(); const string &srcmailbox = command.getMailbox(); const string &canonmailbox = toCanonMailbox(srcmailbox); - Mailbox *mailbox = 0; + Mailbox *mailbox = nullptr; - if ((mailbox = depot.get(canonmailbox)) == 0) { + if ((mailbox = depot.get(canonmailbox)) == nullptr) { session.setResponseCode("TRYCREATE"); session.setLastError("invalid destination mailbox " + toImapString(srcmailbox)); return NO; @@ -56,7 +52,7 @@ Operator::ProcessResult AppendOperator::process(Depot &depot, Request &command) // mask all passed flags together unsigned int newflags = (unsigned int)Message::F_NONE; - vector<string>::const_iterator f_i = command.flags.begin(); + std::vector<string>::const_iterator f_i = command.flags.begin(); while (f_i != command.flags.end()) { if (*f_i == "\\Deleted") newflags |= Message::F_DELETED; if (*f_i == "\\Answered") newflags |= Message::F_ANSWERED; @@ -150,7 +146,7 @@ Operator::ProcessResult AppendOperator::process(Depot &depot, Request &command) return BAD; } - nr += (char)c; + nr += c; } int nchars = atoi(nr.c_str()); @@ -173,8 +169,8 @@ Operator::ProcessResult AppendOperator::process(Depot &depot, Request &command) return BAD; } - time_t newtime = (command.getDate() != "") ? mktime(&mytm) : time(0); - if (newtime == -1) newtime = time(0); + time_t newtime = (command.getDate() != "") ? mktime(&mytm) : time(nullptr); + if (newtime == -1) newtime = time(nullptr); Message *dest = mailbox->createMessage(depot.mailboxToFilename(canonmailbox), newtime); if (!dest) { session.setLastError(mailbox->getLastError()); @@ -182,7 +178,7 @@ Operator::ProcessResult AppendOperator::process(Depot &depot, Request &command) } if (!literalPlus) { - bincClient << "+ go ahead with " << nchars << " characters" << endl; + bincClient << "+ go ahead with " << nchars << " characters" << std::endl; bincClient.flush(); } @@ -248,7 +244,6 @@ Operator::ProcessResult AppendOperator::process(Depot &depot, Request &command) return OK; } -//---------------------------------------------------------------------- Operator::ParseResult AppendOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); @@ -275,7 +270,7 @@ Operator::ParseResult AppendOperator::parse(Request &c_in) const } if ((res = expectThisString("(")) == ACCEPT) { - if ((res = expectFlag(c_in.getFlags())) == ACCEPT) + if ((res = expectFlag(c_in.getFlags())) == ACCEPT) { while (1) { if ((res = expectSPACE()) != ACCEPT) break; if ((res = expectFlag(c_in.getFlags())) != ACCEPT) { @@ -283,6 +278,7 @@ Operator::ParseResult AppendOperator::parse(Request &c_in) const return res; } } + } if ((res = expectThisString(")")) != ACCEPT) { session.setLastError("expected a ')'"); @@ -296,11 +292,12 @@ Operator::ParseResult AppendOperator::parse(Request &c_in) const } string date; - if ((res = expectDateTime(date)) == ACCEPT) + if ((res = expectDateTime(date)) == ACCEPT) { if ((res = expectSPACE()) != ACCEPT) { session.setLastError("expected a SPACE after date_time"); return res; } + } c_in.setDate(date); c_in.setName("APPEND"); diff --git a/src/operator-authenticate.cc b/src/operator-authenticate.cc index 7802c47..2cb9ced 100644 --- a/src/operator-authenticate.cc +++ b/src/operator-authenticate.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file operator-authenticate.cc * @brief Implementation of the AUTHENTICATE command, incl. CRAM-MD5. * @author Andreas Aardal Hanssen, Erwin Hoffmann * @date 2002-2005, 2023 - * ----------------------------------------------------------------- **/ + */ + #include "authenticate.h" #include "base64.h" #include "convert.h" @@ -18,28 +19,24 @@ #include <cstring> #include <string> -using namespace ::std; using namespace Binc; +using std::endl; +using std::string; -//---------------------------------------------------------------------- AuthenticateOperator::AuthenticateOperator(void) {} -//---------------------------------------------------------------------- AuthenticateOperator::~AuthenticateOperator(void) {} -//---------------------------------------------------------------------- const string AuthenticateOperator::getName(void) const { return "AUTHENTICATE"; } -//---------------------------------------------------------------------- int AuthenticateOperator::getState(void) const { return Session::NONAUTHENTICATED; } -//------------------------------------------------------------------------ Operator::ProcessResult AuthenticateOperator::Login(string &username, string &password) { Session &session = Session::getInstance(); @@ -90,7 +87,6 @@ Operator::ProcessResult AuthenticateOperator::Login(string &username, string &pa return OK; } -//------------------------------------------------------------------------ Operator::ProcessResult AuthenticateOperator::Plain(string &username, string &password) { Session &session = Session::getInstance(); @@ -139,14 +135,13 @@ Operator::ProcessResult AuthenticateOperator::Plain(string &username, string &pa return OK; } -//------------------------------------------------------------------------ Operator::ProcessResult AuthenticateOperator::Cram(string &username, string &password, string &challenge) { Session &session = Session::getInstance(); // generate challenge first: <pid.time@fqdn> and deploy it to authenticator time_t timer; - struct tm y2k = {0}; + struct tm y2k = {}; int timestamp; y2k.tm_hour = 0; y2k.tm_min = 0; @@ -159,9 +154,9 @@ Operator::ProcessResult AuthenticateOperator::Cram(string &username, string &pas timestamp = difftime(timer, mktime(&y2k)); challenge += "<"; - challenge += to_string(session.getPid()); + challenge += std::to_string(session.getPid()); challenge += "."; - challenge += to_string(timestamp); + challenge += std::to_string(timestamp); challenge += "@"; challenge += session.getEnv("TCPLOCALHOST"); challenge += ">"; @@ -195,7 +190,6 @@ Operator::ProcessResult AuthenticateOperator::Cram(string &username, string &pas return OK; } -//------------------------------------------------------------------------ Operator::ProcessResult AuthenticateOperator::process(Depot &depot, Request &command) { Session &session = Session::getInstance(); @@ -231,7 +225,6 @@ Operator::ProcessResult AuthenticateOperator::process(Depot &depot, Request &com // this type can be used even over unencrypted connections if ((r = Cram(username, password, challenge)) != OK) return r; - } else { // Any other disallowed session.setLastError("The authentication method " + toImapString(authtype) + " is not supported. " @@ -281,7 +274,6 @@ Operator::ProcessResult AuthenticateOperator::process(Depot &depot, Request &com return NOTHING; } -//---------------------------------------------------------------------- Operator::ParseResult AuthenticateOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); diff --git a/src/operator-capability.cc b/src/operator-capability.cc index 73f5a26..6be3e79 100644 --- a/src/operator-capability.cc +++ b/src/operator-capability.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @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" @@ -14,34 +15,28 @@ #include <string> -using namespace ::std; using namespace Binc; +using std::string; -//---------------------------------------------------------------------- CapabilityOperator::CapabilityOperator(void) {} -//---------------------------------------------------------------------- CapabilityOperator::~CapabilityOperator(void) {} -//---------------------------------------------------------------------- const string CapabilityOperator::getName(void) const { return "CAPABILITY"; } -//---------------------------------------------------------------------- int CapabilityOperator::getState(void) const { return 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(); @@ -49,34 +44,34 @@ Operator::ProcessResult CapabilityOperator::process(Depot &depot, Request &comma bincClient << "* CAPABILITY " << IMAP_VERSION; if (session.getState() == Session::NONAUTHENTICATED) { - if (getenv("UCSPITLS")) + 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 (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 + else bincClient << " LOGINDISABLED"; } bincClient << " IDLE LITERAL+ NAMESPACE CHILDREN"; - vector<string>::const_iterator i = capabilities.begin(); + std::vector<string>::const_iterator i = capabilities.begin(); while (i != capabilities.end()) { bincClient << " " << *i; ++i; } - bincClient << endl; + bincClient << std::endl; return OK; } -//---------------------------------------------------------------------- Operator::ParseResult CapabilityOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); diff --git a/src/operator-check.cc b/src/operator-check.cc index 045f8b0..110ce9c 100644 --- a/src/operator-check.cc +++ b/src/operator-check.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file operator-check.cc * @author Implementation of the CHECK command. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "depot.h" #include "mailbox.h" #include "operators.h" @@ -13,40 +14,34 @@ #include <string> -using namespace ::std; using namespace Binc; -//---------------------------------------------------------------------- CheckOperator::CheckOperator(void) {} -//---------------------------------------------------------------------- CheckOperator::~CheckOperator(void) {} -//---------------------------------------------------------------------- -const string CheckOperator::getName(void) const +const std::string CheckOperator::getName(void) const { return "CHECK"; } -//---------------------------------------------------------------------- int CheckOperator::getState(void) const { return Session::SELECTED; } -//------------------------------------------------------------------------ Operator::ProcessResult CheckOperator::process(Depot &depot, Request &command) { Mailbox *mailbox = depot.getSelected(); - if (mailbox != 0) + if (mailbox != nullptr) { pendingUpdates(mailbox, PendingUpdates::FLAGS | PendingUpdates::EXISTS | PendingUpdates::RECENT, true); + } return OK; } -//---------------------------------------------------------------------- Operator::ParseResult CheckOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); diff --git a/src/operator-close.cc b/src/operator-close.cc index 686f668..2727e25 100644 --- a/src/operator-close.cc +++ b/src/operator-close.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file operator-close.cc * @brief Implementation of the CLOSE command. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "depot.h" #include "mailbox.h" #include "operators.h" @@ -12,28 +13,22 @@ #include <string> -using namespace ::std; using namespace Binc; -//---------------------------------------------------------------------- CloseOperator::CloseOperator(void) {} -//---------------------------------------------------------------------- CloseOperator::~CloseOperator(void) {} -//------------------------------------------------------------------------ -const string CloseOperator::getName(void) const +const std::string CloseOperator::getName(void) const { return "CLOSE"; } -//------------------------------------------------------------------------ int CloseOperator::getState(void) const { return Session::SELECTED; } -//------------------------------------------------------------------------ Operator::ProcessResult CloseOperator::process(Depot &depot, Request &command) { Mailbox *mailbox = depot.getSelected(); @@ -47,7 +42,6 @@ Operator::ProcessResult CloseOperator::process(Depot &depot, Request &command) return OK; } -//---------------------------------------------------------------------- Operator::ParseResult CloseOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); diff --git a/src/operator-copy.cc b/src/operator-copy.cc index 50afe77..77e1b9d 100644 --- a/src/operator-copy.cc +++ b/src/operator-copy.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file operator-copy.cc * @brief Implementation of the COPY command. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "convert.h" #include "depot.h" #include "iodevice.h" @@ -15,28 +16,23 @@ #include <string> -using namespace ::std; using namespace Binc; +using std::string; -//---------------------------------------------------------------------- CopyOperator::CopyOperator(void) {} -//---------------------------------------------------------------------- CopyOperator::~CopyOperator(void) {} -//---------------------------------------------------------------------- const string CopyOperator::getName(void) const { return "COPY"; } -//---------------------------------------------------------------------- int CopyOperator::getState(void) const { return Session::SELECTED; } -//------------------------------------------------------------------------ Operator::ProcessResult CopyOperator::process(Depot &depot, Request &command) { Session &session = Session::getInstance(); @@ -47,7 +43,7 @@ Operator::ProcessResult CopyOperator::process(Depot &depot, Request &command) // Get the destination mailbox string dmailbox = command.getMailbox(); Mailbox *destMailbox = depot.get(toCanonMailbox(dmailbox)); - if (destMailbox == 0) { + if (destMailbox == nullptr) { session.setResponseCode("TRYCREATE"); session.setLastError("invalid mailbox " + toImapString(dmailbox)); return NO; @@ -84,14 +80,14 @@ Operator::ProcessResult CopyOperator::process(Depot &depot, Request &command) do { int readSize = source.readChunk(chunk); - if (readSize == 0) + if (readSize == 0) { break; - else if (readSize == -1) { + } else if (readSize == -1) { bincWarning << "when reading from message " << i.getSqnr() << "/" << source.getUID() << " in \"" - << srcMailbox->getName() << "\": " << source.getLastError() << endl; + << srcMailbox->getName() << "\": " << source.getLastError() << std::endl; success = false; } else if (!dest->appendChunk(chunk)) { - bincWarning << "when writing to \"" << dmailbox << "\": " << dest->getLastError() << endl; + bincWarning << "when writing to \"" << dmailbox << "\": " << dest->getLastError() << std::endl; success = false; } } while (success); @@ -104,21 +100,22 @@ Operator::ProcessResult CopyOperator::process(Depot &depot, Request &command) return NO; } - if (success) + if (success) { if (!destMailbox->commitNewMessages(depot.mailboxToFilename(toCanonMailbox(dmailbox)))) { session.setLastError("Failed to commit after successful copy: " + destMailbox->getLastError()); return NO; } + } - if (!success) + if (!success) { session.setLastError("The transaction was unrolled. Please " "contant your system administrator for " "more information."); + } return success ? OK : NO; } -//------------------------------------------------------------------------ Operator::ParseResult CopyOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); diff --git a/src/operator-create.cc b/src/operator-create.cc index 83c5e1d..22fd37e 100644 --- a/src/operator-create.cc +++ b/src/operator-create.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file bincimapd-create.cc * @brief Implementation of the CREATE command. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "convert.h" #include "depot.h" #include "imapparser.h" @@ -14,40 +15,33 @@ #include <string> -using namespace ::std; using namespace Binc; -//---------------------------------------------------------------------- CreateOperator::CreateOperator(void) {} -//---------------------------------------------------------------------- CreateOperator::~CreateOperator(void) {} -//---------------------------------------------------------------------- -const string CreateOperator::getName(void) const +const std::string CreateOperator::getName(void) const { return "CREATE"; } -//---------------------------------------------------------------------- int CreateOperator::getState(void) const { return Session::AUTHENTICATED | Session::SELECTED; } -//------------------------------------------------------------------------ Operator::ProcessResult CreateOperator::process(Depot &depot, Request &command) { - if (depot.createMailbox(command.getMailbox())) + if (depot.createMailbox(command.getMailbox())) { return OK; - else { + } else { Session &session = Session::getInstance(); session.setLastError(depot.getLastError()); return NO; } } -//---------------------------------------------------------------------- Operator::ParseResult CreateOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); @@ -60,7 +54,7 @@ Operator::ParseResult CreateOperator::parse(Request &c_in) const return res; } - string mailbox; + std::string mailbox; if ((res = expectMailbox(mailbox)) != ACCEPT) { session.setLastError("Expected mailbox after CREATE SPACE"); return res; diff --git a/src/operator-delete.cc b/src/operator-delete.cc index 350e572..00d7ecb 100644 --- a/src/operator-delete.cc +++ b/src/operator-delete.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file operator-delete.cc * @briefe Implementation of the DELETE command. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "convert.h" #include "depot.h" #include "imapparser.h" @@ -14,40 +15,33 @@ #include <string> -using namespace ::std; using namespace Binc; -//---------------------------------------------------------------------- DeleteOperator::DeleteOperator(void) {} -//---------------------------------------------------------------------- DeleteOperator::~DeleteOperator(void) {} -//---------------------------------------------------------------------- -const string DeleteOperator::getName(void) const +const std::string DeleteOperator::getName(void) const { return "DELETE"; } -//---------------------------------------------------------------------- int DeleteOperator::getState(void) const { return Session::AUTHENTICATED | Session::SELECTED; } -//------------------------------------------------------------------------ Operator::ProcessResult DeleteOperator::process(Depot &depot, Request &command) { - if (depot.deleteMailbox(command.getMailbox())) + if (depot.deleteMailbox(command.getMailbox())) { return OK; - else { + } else { Session &session = Session::getInstance(); session.setLastError(depot.getLastError()); return NO; } } -//---------------------------------------------------------------------- Operator::ParseResult DeleteOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); @@ -60,7 +54,7 @@ Operator::ParseResult DeleteOperator::parse(Request &c_in) const return res; } - string mailbox; + std::string mailbox; if ((res = expectMailbox(mailbox)) != ACCEPT) { session.setLastError("Expected mailbox after DELETE SPACE"); return res; diff --git a/src/operator-examine.cc b/src/operator-examine.cc index 9f64ce6..ceb1ec6 100644 --- a/src/operator-examine.cc +++ b/src/operator-examine.cc @@ -1,22 +1,19 @@ -/** -------------------------------------------------------------------- +/** * @file operator-examine.cc * @brief Implementation of the EXAMINE command * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "operators.h" -using namespace ::std; using namespace Binc; -//---------------------------------------------------------------------- const std::string ExamineOperator::getName(void) const { return "EXAMINE"; } -//---------------------------------------------------------------------- ExamineOperator::ExamineOperator(void) {} -//---------------------------------------------------------------------- ExamineOperator::~ExamineOperator(void) {} diff --git a/src/operator-expunge.cc b/src/operator-expunge.cc index 03fd655..2416417 100644 --- a/src/operator-expunge.cc +++ b/src/operator-expunge.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file operator-expunge.cc * @brief Implementation of the EXPUNGE command * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "depot.h" #include "imapparser.h" #include "mailbox.h" @@ -14,28 +15,22 @@ #include <string> -using namespace ::std; using namespace Binc; -//---------------------------------------------------------------------- ExpungeOperator::ExpungeOperator(void) {} -//---------------------------------------------------------------------- ExpungeOperator::~ExpungeOperator(void) {} -//---------------------------------------------------------------------- -const string ExpungeOperator::getName(void) const +const std::string ExpungeOperator::getName(void) const { return "EXPUNGE"; } -//---------------------------------------------------------------------- int ExpungeOperator::getState(void) const { return Session::SELECTED; } -//---------------------------------------------------------------------- Operator::ProcessResult ExpungeOperator::process(Depot &depot, Request &command) { Mailbox *mailbox = depot.getSelected(); @@ -49,7 +44,6 @@ Operator::ProcessResult ExpungeOperator::process(Depot &depot, Request &command) return OK; } -//---------------------------------------------------------------------- Operator::ParseResult ExpungeOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); diff --git a/src/operator-fetch.cc b/src/operator-fetch.cc index 8b33d79..4fcdf1a 100644 --- a/src/operator-fetch.cc +++ b/src/operator-fetch.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file operator-fetch.cc * @brief Implementation of the FETCH command * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "convert.h" #include "depot.h" #include "imapparser.h" @@ -17,8 +18,9 @@ #include <string> -using namespace ::std; using namespace Binc; +using std::string; +using std::vector; namespace { void outputFlags(const Message &message) @@ -35,13 +37,13 @@ namespace { if (flags & Message::F_RECENT) flagv.push_back("\\Recent"); if (flags & Message::F_FLAGGED) flagv.push_back("\\Flagged"); - for (vector<string>::const_iterator k = flagv.begin(); k != flagv.end(); ++k) { + for (auto k = flagv.begin(); k != flagv.end(); ++k) { if (k != flagv.begin()) bincClient << " "; bincClient << *k; } vector<string> customFlags = message.getCustomFlags(); - for (vector<string>::const_iterator it = customFlags.begin(); it != customFlags.end(); ++it) { + for (auto it = customFlags.begin(); it != customFlags.end(); ++it) { if (flagv.size() > 0 || it != customFlags.begin()) bincClient << " "; bincClient << *it; } @@ -51,25 +53,20 @@ namespace { } -//---------------------------------------------------------------------- FetchOperator::FetchOperator(void) {} -//---------------------------------------------------------------------- FetchOperator::~FetchOperator(void) {} -//---------------------------------------------------------------------- const string FetchOperator::getName(void) const { return "FETCH"; } -//---------------------------------------------------------------------- int FetchOperator::getState(void) const { return Session::SELECTED; } -//------------------------------------------------------------------------ Operator::ProcessResult FetchOperator::process(Depot &depot, Request &request) { Session &session = Session::getInstance(); @@ -130,9 +127,10 @@ Operator::ProcessResult FetchOperator::process(Depot &depot, Request &request) else mode = Mailbox::SQNR_MODE; - Mailbox::iterator i = mailbox->begin(req.bset, Mailbox::SKIP_EXPUNGED | mode); - - for (; i != mailbox->end(); ++i) { + for (Mailbox::iterator i = mailbox->begin(req.bset, Mailbox::SKIP_EXPUNGED | mode); + i != mailbox->end(); + ++i) + { Message &message = *i; bincClient << "* " << i.getSqnr() << " FETCH ("; @@ -186,8 +184,9 @@ Operator::ProcessResult FetchOperator::process(Depot &depot, Request &request) if (strftime(internal, sizeof(internal), "%d-%b-%Y %H:%M:%S %z", _tm) != 0) { if (internal[0] == '0') internal[0] = ' '; iDateStr = internal; - } else + } else { iDateStr = "NIL"; + } bincClient << toImapString(iDateStr); } else if (fatt.type == "BODY" || fatt.type == "BODY.PEEK") { @@ -220,8 +219,9 @@ Operator::ProcessResult FetchOperator::process(Depot &depot, Request &request) v.push_back("content-transfer-encoding"); v.push_back("content-disposition"); v.push_back("content-description"); - } else + } else { v = fatt.headerlist; + } string dummy; unsigned int size = fullheader ? message.getHeaderSize(fatt.section, @@ -270,8 +270,9 @@ Operator::ProcessResult FetchOperator::process(Depot &depot, Request &request) } // set the \Seen flag if .PEEK is not used. - if (!peek) + if (!peek) { if ((message.getStdFlags() & Message::F_SEEN) == 0) message.setStdFlag(Message::F_SEEN); + } } else if (fatt.type == "RFC822") { bincClient << prefix; hasprinted = true; @@ -330,13 +331,13 @@ Operator::ProcessResult FetchOperator::process(Depot &depot, Request &request) // FIXME: how are parse error passed back? - bincClient << ")" << endl; + bincClient << ")" << std::endl; if (message.hasFlagsChanged()) { updateFlags = true; bincClient << "* " << i.getSqnr() << " FETCH ("; outputFlags(message); - bincClient << ")" << endl; + bincClient << ")" << std::endl; message.setFlagsUnchanged(); } } @@ -351,7 +352,6 @@ Operator::ProcessResult FetchOperator::process(Depot &depot, Request &request) return OK; } -//---------------------------------------------------------------------- Operator::ParseResult FetchOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); @@ -419,7 +419,6 @@ Operator::ParseResult FetchOperator::parse(Request &c_in) const return ACCEPT; } -//---------------------------------------------------------------------- Operator::ParseResult FetchOperator::expectSectionText(BincImapParserFetchAtt &f_in) const { Session &session = Session::getInstance(); @@ -443,15 +442,15 @@ Operator::ParseResult FetchOperator::expectSectionText(BincImapParserFetchAtt &f return res; } } - } else if ((res = expectThisString("TEXT")) == ACCEPT) + } else if ((res = expectThisString("TEXT")) == ACCEPT) { f_in.sectiontext = "TEXT"; - else + } else { return REJECT; + } return ACCEPT; } -//---------------------------------------------------------------------- Operator::ParseResult FetchOperator::expectSection(BincImapParserFetchAtt &f_in) const { Session &session = Session::getInstance(); @@ -500,7 +499,6 @@ Operator::ParseResult FetchOperator::expectSection(BincImapParserFetchAtt &f_in) return ACCEPT; } -//---------------------------------------------------------------------- Operator::ParseResult FetchOperator::expectHeaderList(BincImapParserFetchAtt &f_in) const { Session &session = Session::getInstance(); @@ -531,7 +529,6 @@ Operator::ParseResult FetchOperator::expectHeaderList(BincImapParserFetchAtt &f_ return ACCEPT; } -//---------------------------------------------------------------------- Operator::ParseResult FetchOperator::expectOffset(BincImapParserFetchAtt &f_in) const { Session &session = Session::getInstance(); @@ -566,30 +563,29 @@ Operator::ParseResult FetchOperator::expectOffset(BincImapParserFetchAtt &f_in) return ACCEPT; } -//---------------------------------------------------------------------- Operator::ParseResult FetchOperator::expectFetchAtt(BincImapParserFetchAtt &f_in) const { Operator::ParseResult res; Session &session = Session::getInstance(); - if ((res = expectThisString("ENVELOPE")) == ACCEPT) + if ((res = expectThisString("ENVELOPE")) == ACCEPT) { f_in.type = "ENVELOPE"; - else if ((res = expectThisString("FLAGS")) == ACCEPT) + } else if ((res = expectThisString("FLAGS")) == ACCEPT) { f_in.type = "FLAGS"; - else if ((res = expectThisString("INTERNALDATE")) == ACCEPT) + } else if ((res = expectThisString("INTERNALDATE")) == ACCEPT) { f_in.type = "INTERNALDATE"; - else if ((res = expectThisString("UID")) == ACCEPT) + } else if ((res = expectThisString("UID")) == ACCEPT) { f_in.type = "UID"; - else if ((res = expectThisString("RFC822")) == ACCEPT) { + } else if ((res = expectThisString("RFC822")) == ACCEPT) { f_in.type = "RFC822"; - if ((res = expectThisString(".HEADER")) == ACCEPT) + if ((res = expectThisString(".HEADER")) == ACCEPT) { f_in.type += ".HEADER"; - else if ((res = expectThisString(".SIZE")) == ACCEPT) + } else if ((res = expectThisString(".SIZE")) == ACCEPT) { f_in.type += ".SIZE"; - else if ((res = expectThisString(".TEXT")) == ACCEPT) + } else if ((res = expectThisString(".TEXT")) == ACCEPT) { f_in.type += ".TEXT"; - else if ((res = expectThisString(".")) == ACCEPT) { + } else if ((res = expectThisString(".")) == ACCEPT) { session.setLastError("Expected RFC822, RFC822.HEADER," " RFC822.SIZE or RFC822.TEXT"); return ERROR; @@ -603,14 +599,15 @@ Operator::ParseResult FetchOperator::expectFetchAtt(BincImapParserFetchAtt &f_in else if ((res = expectThisString(".PEEK")) == ACCEPT) f_in.type += ".PEEK"; - if ((res = expectSection(f_in)) != ACCEPT) + if ((res = expectSection(f_in)) != ACCEPT) { f_in.hassection = false; - else { + } else { f_in.hassection = true; if ((res = expectOffset(f_in)) == ERROR) return ERROR; } - } else + } else { return REJECT; + } return ACCEPT; } diff --git a/src/operator-id.cc b/src/operator-id.cc index de74909..3a6fd49 100644 --- a/src/operator-id.cc +++ b/src/operator-id.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file operator-id.cc * @brief Operator for the ID extension. Described in RFC2971 Oct 2000. * @author Erwin Hoffmann * @date 22.09.2023 - * ------------------------------------------------------------------ **/ + */ + #include "depot.h" #include "globals.h" #include "iodevice.h" @@ -15,37 +16,30 @@ #include <iostream> #include <string> -using namespace ::std; using namespace Binc; -//---------------------------------------------------------------------- IdOperator::IdOperator(void) {} -//---------------------------------------------------------------------- IdOperator::~IdOperator(void) {} -//---------------------------------------------------------------------- -const string IdOperator::getName(void) const +const std::string IdOperator::getName(void) const { return "ID"; } -//---------------------------------------------------------------------- int IdOperator::getState(void) const { return Session::NONAUTHENTICATED | Session::AUTHENTICATED | Session::SELECTED; } -//---------------------------------------------------------------------- Operator::ProcessResult IdOperator::process(Depot &depot, Request &command) { bincClient << "* ID (\"name\" \"Binc IMAP\"" - << " \"version\" \"" << BINC_VERSION "\")" << endl; + << " \"version\" \"" << BINC_VERSION "\")" << std::endl; return OK; } -//---------------------------------------------------------------------- Operator::ParseResult IdOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); diff --git a/src/operator-idle.cc b/src/operator-idle.cc index 369bcd9..ff95dbf 100644 --- a/src/operator-idle.cc +++ b/src/operator-idle.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file operator-idle.cc * @brief Operator for the IDLE command. Described in RFC2177 / June 1997. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ------------------------------------------------------------------ **/ + */ + #include "convert.h" #include "depot.h" #include "globals.h" @@ -36,8 +37,8 @@ void fnotifyEventHandler(int sig) } #endif -using namespace ::std; using namespace Binc; +using std::endl; // Seconds between each poll. With FNOTIFY support, we can idle for 30 // minutes before timing out. @@ -47,29 +48,24 @@ static const int POLLTIMEOUT = 30 * 60; static const int POLLTIMEOUT = 30; #endif -//---------------------------------------------------------------------- IdleOperator::IdleOperator(void) {} -//---------------------------------------------------------------------- IdleOperator::~IdleOperator(void) {} -//---------------------------------------------------------------------- -const string IdleOperator::getName(void) const +const std::string IdleOperator::getName(void) const { return "IDLE"; } -//---------------------------------------------------------------------- int IdleOperator::getState(void) const { return Session::SELECTED; } -//---------------------------------------------------------------------- Operator::ProcessResult IdleOperator::process(Depot &depot, Request &command) { Mailbox *mailbox = depot.getSelected(); - string mailboxDir = depot.mailboxToFilename(mailbox->getName()); + std::string mailboxDir = depot.mailboxToFilename(mailbox->getName()); #ifdef HAVE_FNOTIFY // Check for FNOTIFY support. @@ -93,7 +89,7 @@ Operator::ProcessResult IdleOperator::process(Depot &depot, Request &command) #endif // when not using FNOTIFY, we need to check the session timeout. - time_t startTime = time(0); + time_t startTime = time(nullptr); #ifdef HAVE_FNOTIFY (void)startTime; // removes a compile warning #endif @@ -110,9 +106,9 @@ Operator::ProcessResult IdleOperator::process(Depot &depot, Request &command) // check for data from stdin. with FNOTIFY enabled, this select // will be interrupted by the notification signal. - string input; + std::string input; struct timeval tv = {POLLTIMEOUT, 0}; - int ret = select(maxfd + 1, &readfds, 0, 0, &tv); + int ret = select(maxfd + 1, &readfds, nullptr, nullptr, &tv); // check if the select timed out. if (ret == 0) { @@ -126,7 +122,7 @@ Operator::ProcessResult IdleOperator::process(Depot &depot, Request &command) return NOTHING; } else #endif - if (time(0) > startTime + IDLE_TIMEOUT) + if (time(nullptr) > startTime + IDLE_TIMEOUT) { bincClient << "* BYE Timeout after " << IDLE_TIMEOUT << " seconds of inactivity." << endl; session.setState(Session::LOGOUT); @@ -136,7 +132,7 @@ Operator::ProcessResult IdleOperator::process(Depot &depot, Request &command) // unless the select failed, attempt to read client input. if (ret > 0 && FD_ISSET(0, &readfds)) { - if (bincClient.readStr(&input) == 0) { + if (bincClient.readStr(&input) == false) { break; } else { uppercase(input); @@ -170,11 +166,10 @@ Operator::ProcessResult IdleOperator::process(Depot &depot, Request &command) } // scan for changes in the mailbox and report to the client. - if (pendingUpdates(mailbox, - PendingUpdates::EXPUNGE | PendingUpdates::EXISTS | PendingUpdates::RECENT - | PendingUpdates::FLAGS, - true) - == false) + if (!pendingUpdates(mailbox, + PendingUpdates::EXPUNGE | PendingUpdates::EXISTS | PendingUpdates::RECENT + | PendingUpdates::FLAGS, + true)) { Session &session = Session::getInstance(); bincClient << "* NO " << session.getLastError() << endl; @@ -217,7 +212,6 @@ Operator::ProcessResult IdleOperator::process(Depot &depot, Request &command) return OK; } -//---------------------------------------------------------------------- Operator::ParseResult IdleOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); diff --git a/src/operator-list.cc b/src/operator-list.cc index 7ee66f3..b304e08 100644 --- a/src/operator-list.cc +++ b/src/operator-list.cc @@ -1,7 +1,8 @@ -/** -------------------------------------------------------------------- +/** * @file operator-list.cc * @brief Implementation of the LIST command. - * ----------------------------------------------------------------- **/ + */ + #include "convert.h" #include "depot.h" #include "iodevice.h" @@ -19,35 +20,30 @@ #include <sys/stat.h> #include <sys/types.h> -using namespace ::std; using namespace Binc; +using std::string; namespace { const time_t LIST_CACHE_TIMEOUT = 10; } -//---------------------------------------------------------------------- ListOperator::ListOperator(void) { cacheTimeout = 0; } -//---------------------------------------------------------------------- ListOperator::~ListOperator(void) {} -//---------------------------------------------------------------------- const string ListOperator::getName(void) const { return "LIST"; } -//---------------------------------------------------------------------- int ListOperator::getState(void) const { return Session::AUTHENTICATED | Session::SELECTED; } -//------------------------------------------------------------------------ Operator::ProcessResult ListOperator::process(Depot &depot, Request &command) { Session &session = Session::getInstance(); @@ -57,7 +53,7 @@ Operator::ProcessResult ListOperator::process(Depot &depot, Request &command) // hard coded reply. string wildcard; if ((wildcard = command.getListMailbox()) == "") { - bincClient << "* LIST (\\Noselect) \"" << delim << "\" \"\"" << endl; + bincClient << "* LIST (\\Noselect) \"" << delim << "\" \"\"" << std::endl; return OK; } @@ -78,30 +74,32 @@ Operator::ProcessResult ListOperator::process(Depot &depot, Request &command) if (wildcardLower.substr(0, 6) == "^inbox") ref = "^[iI][nN][bB][oO][xX]" + ref.substr(6); if (wildcardLower.substr(0, 5) == "inbox" && (wildcardLower.length() == 5 || wildcardLower[5] == delim)) + { ref = "INBOX" + ref.substr(5); + } // a map from mailbox name to flags - map<string, unsigned int> mailboxes; + std::map<string, unsigned int> mailboxes; - if (cacheTimeout == 0 || cacheTimeout < time(0) - LIST_CACHE_TIMEOUT || session.mailboxchanges) { + if (cacheTimeout == 0 || cacheTimeout < time(nullptr) - LIST_CACHE_TIMEOUT || session.mailboxchanges) { session.mailboxchanges = false; // read through all entries in depository. for (Depot::iterator i = depot.begin("."); i != depot.end(); ++i) { const string path = *i; const string mpath = depot.filenameToMailbox(path); - Mailbox *m = 0; + Mailbox *m = nullptr; // skip entries that are not identified as mailboxes - if ((m = depot.get(mpath)) == 0) continue; + if ((m = depot.get(mpath)) == nullptr) continue; // convert file name to mailbox name. skip it if there is no // corresponding mailbox name. string tmp = toCanonMailbox(depot.filenameToMailbox(path)); trim(tmp, string(&delim, 1)); - if (tmp == "") + if (tmp == "") { continue; - else { + } else { // inherit flags that were already set for this mailbox. int flags = DIR_SELECT; if (m->isMarked(path)) flags |= DIR_MARKED; @@ -123,14 +121,13 @@ Operator::ProcessResult ListOperator::process(Depot &depot, Request &command) } // find leaf nodes O(N^2) - map<string, unsigned int>::iterator i; - for (i = mailboxes.begin(); i != mailboxes.end(); ++i) { + for (auto i = mailboxes.begin(); i != mailboxes.end(); ++i) { string mailbox = i->first; mailbox += delim; bool leaf = true; - map<string, unsigned int>::const_iterator j = mailboxes.begin(); - for (; j != mailboxes.end(); ++j) { + + for (auto j = mailboxes.begin(); j != mailboxes.end(); ++j) { string::size_type pos = j->first.rfind(delim); if (pos == string::npos) continue; @@ -150,17 +147,15 @@ Operator::ProcessResult ListOperator::process(Depot &depot, Request &command) } cache = mailboxes; - cacheTimeout = time(0); + cacheTimeout = time(nullptr); } else { mailboxes = cache; - cacheTimeout = time(0); + cacheTimeout = time(nullptr); } // finally, print all mailbox entries with flags. - map<string, unsigned int>::iterator i = mailboxes.begin(); - - for (; i != mailboxes.end(); ++i) { - if (ref == "" || (ref.length() <= i->first.length() && ref == i->first.substr(0, ref.length()))) + for (auto i = mailboxes.begin(); i != mailboxes.end(); ++i) { + if (ref == "" || (ref.length() <= i->first.length() && ref == i->first.substr(0, ref.length()))) { if (regexMatch(i->first.substr(ref.length()), regex) == 0) { bincClient << "* LIST ("; string sep = ""; @@ -190,14 +185,14 @@ Operator::ProcessResult ListOperator::process(Depot &depot, Request &command) if (flags & DIR_NOINFERIORS) bincClient << sep << "\\Noinferiors"; - bincClient << ") \"" << depot.getDelimiter() << "\" " << toImapString(i->first) << endl; + bincClient << ") \"" << depot.getDelimiter() << "\" " << toImapString(i->first) << std::endl; } + } } return OK; } -//---------------------------------------------------------------------- Operator::ParseResult ListOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); diff --git a/src/operator-login.cc b/src/operator-login.cc index 7b7ffc2..cacafbb 100644 --- a/src/operator-login.cc +++ b/src/operator-login.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file operator-login.cc * @brief Implementation of the rapid LOGIN command * @author Andreas Aardal Hanssen, Erwin Hoffmann * @date 2002-2005, 2023 - * ----------------------------------------------------------------- **/ + */ + #include "authenticate.h" #include "depot.h" #include "globals.h" @@ -22,28 +23,22 @@ #include <sys/types.h> #include <unistd.h> -using namespace ::std; using namespace Binc; -//---------------------------------------------------------------------- LoginOperator::LoginOperator(void) {} -//---------------------------------------------------------------------- LoginOperator::~LoginOperator(void) {} -//---------------------------------------------------------------------- -const string LoginOperator::getName(void) const +const std::string LoginOperator::getName(void) const { return "LOGIN"; } -//---------------------------------------------------------------------- int LoginOperator::getState(void) const { return Session::NONAUTHENTICATED; } -//------------------------------------------------------------------------ Operator::ProcessResult LoginOperator::process(Depot &depot, Request &command) { Session &session = Session::getInstance(); @@ -55,7 +50,7 @@ Operator::ProcessResult LoginOperator::process(Depot &depot, Request &command) } session.setEnv("BINCIMAP_LOGIN", "LOGIN+" + command.getTag()); - string challenge; + std::string challenge; switch (authenticate(depot, command.getUserID(), command.getPassword(), challenge)) { case 1: @@ -70,12 +65,12 @@ Operator::ProcessResult LoginOperator::process(Depot &depot, Request &command) "your system administrator."); return NO; case 3: - bincClient << "* BYE Timeout after " << IDLE_TIMEOUT << " seconds of inactivity." << endl; + bincClient << "* BYE Timeout after " << IDLE_TIMEOUT << " seconds of inactivity." << std::endl; break; case -1: bincClient << "* BYE The server died unexpectedly. Please contact " "your system administrator for more information." - << endl; + << std::endl; break; } @@ -85,7 +80,6 @@ Operator::ProcessResult LoginOperator::process(Depot &depot, Request &command) return NOTHING; } -//---------------------------------------------------------------------- Operator::ParseResult LoginOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); @@ -98,7 +92,7 @@ Operator::ParseResult LoginOperator::parse(Request &c_in) const return res; } - string userid; + std::string userid; if ((res = expectAstring(userid)) != ACCEPT) { session.setLastError("Expected userid after LOGIN SPACE"); return res; @@ -110,7 +104,7 @@ Operator::ParseResult LoginOperator::parse(Request &c_in) const return res; } - string password; + std::string password; if ((res = expectAstring(password)) != ACCEPT) { session.setLastError("Expected password after LOGIN " "SPACE userid SPACE"); diff --git a/src/operator-logout.cc b/src/operator-logout.cc index aabffdf..67458f3 100644 --- a/src/operator-logout.cc +++ b/src/operator-logout.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file operator-logout.cc * @brief Implementation of the LOGOUT command * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "convert.h" #include "depot.h" #include "iodevice.h" @@ -16,32 +17,26 @@ #include <iostream> #include <string> -using namespace ::std; using namespace Binc; -//---------------------------------------------------------------------- LogoutOperator::LogoutOperator(void) {} -//---------------------------------------------------------------------- LogoutOperator::~LogoutOperator(void) {} -//---------------------------------------------------------------------- -const string LogoutOperator::getName(void) const +const std::string LogoutOperator::getName(void) const { return "LOGOUT"; } -//---------------------------------------------------------------------- int LogoutOperator::getState(void) const { return Session::NONAUTHENTICATED | Session::AUTHENTICATED | Session::SELECTED; } -//------------------------------------------------------------------------ Operator::ProcessResult LogoutOperator::process(Depot &depot, Request &command) { - bincClient << "* BYE Binc IMAP shutting down" << endl; - bincClient << command.getTag() << " OK LOGOUT completed" << endl; + bincClient << "* BYE Binc IMAP shutting down" << std::endl; + bincClient << command.getTag() << " OK LOGOUT completed" << std::endl; bincClient.flush(); #ifdef BINCIMAPD @@ -58,7 +53,6 @@ Operator::ProcessResult LogoutOperator::process(Depot &depot, Request &command) return NOTHING; } -//---------------------------------------------------------------------- Operator::ParseResult LogoutOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); diff --git a/src/operator-lsub.cc b/src/operator-lsub.cc index e2bd07d..35c4d7d 100644 --- a/src/operator-lsub.cc +++ b/src/operator-lsub.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file operator-lsub.cc * @brief Implementation of the LSUB command. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "convert.h" #include "depot.h" #include "iodevice.h" @@ -26,28 +27,24 @@ namespace { const int DIR_LEAF = 0x08; } -using namespace ::std; using namespace Binc; +using std::multimap; +using std::string; -//---------------------------------------------------------------------- LsubOperator::LsubOperator(void) {} -//---------------------------------------------------------------------- LsubOperator::~LsubOperator(void) {} -//---------------------------------------------------------------------- const string LsubOperator::getName(void) const { return "LSUB"; } -//---------------------------------------------------------------------- int LsubOperator::getState(void) const { return Session::AUTHENTICATED | Session::SELECTED; } -//------------------------------------------------------------------------ Operator::ProcessResult LsubOperator::process(Depot &depot, Request &command) { const char delim = depot.getDelimiter(); @@ -69,27 +66,29 @@ Operator::ProcessResult LsubOperator::process(Depot &depot, Request &command) lowercase(wildcardLower); if (wildcardLower.substr(0, 5) == "inbox" && (wildcardLower.length() == 5 || wildcardLower[5] == delim)) + { ref = "INBOX" + ref.substr(5); + } // a multimap from mailbox name to flags multimap<string, int> mailboxes; // read through all entries in depository. - for (Depot::iterator i = depot.begin("."); i != depot.end(); ++i) { + for (auto i = depot.begin("."); i != depot.end(); ++i) { const string path = *i; const string mpath = depot.filenameToMailbox(path); - Mailbox *m = 0; + Mailbox *m = nullptr; // skip entries that are not identified as mailboxes - if ((m = depot.get(mpath)) == 0) continue; + if ((m = depot.get(mpath)) == nullptr) continue; // convert file name to mailbox name. skip it if there is no // corresponding mailbox name. string tmp = toCanonMailbox(depot.filenameToMailbox(path)); trim(tmp, string(&delim, 1)); - if (tmp == "") + if (tmp == "") { continue; - else { + } else { int flags = DIR_SELECT; multimap<string, int>::iterator mi = mailboxes.find(tmp); if (mi != mailboxes.end()) { @@ -139,16 +138,16 @@ Operator::ProcessResult LsubOperator::process(Depot &depot, Request &command) depot.loadSubscribes(); - vector<string> subscribed = depot.getSubscriptions(); + std::vector<string> subscribed = depot.getSubscriptions(); sort(subscribed.begin(), subscribed.end()); // finally, print all mailbox entries with flags. - for (vector<string>::const_iterator j = subscribed.begin(); j != subscribed.end(); ++j) { - if (ref == "" || (ref.length() <= (*j).length() && ref == (*j).substr(0, ref.length()))) - if (regexMatch((*j).substr(ref.length()), regex) == 0) { + for (const auto &j : subscribed) { + if (ref == "" || (ref.length() <= j.length() && ref == j.substr(0, ref.length()))) { + if (regexMatch(j.substr(ref.length()), regex) == 0) { int flags = 0; for (i = mailboxes.begin(); i != mailboxes.end(); ++i) { - if (i->first == *j) { + if (i->first == j) { flags = i->second; break; } @@ -174,14 +173,14 @@ Operator::ProcessResult LsubOperator::process(Depot &depot, Request &command) bincClient << sep << "\\HasChildren"; sep = " "; if (flags & DIR_NOINFERIORS) bincClient << sep << "\\Noinferiors"; - bincClient << ") \"" << depot.getDelimiter() << "\" " << toImapString(*j) << endl; + bincClient << ") \"" << depot.getDelimiter() << "\" " << toImapString(j) << std::endl; } + } } return OK; } -//---------------------------------------------------------------------- Operator::ParseResult LsubOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); diff --git a/src/operator-namespace.cc b/src/operator-namespace.cc index f03f0c7..96a3ee8 100644 --- a/src/operator-namespace.cc +++ b/src/operator-namespace.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file operator-namespace.cc * @brief Operator for the NAMESPACE command. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "depot.h" #include "iodevice.h" #include "iofactory.h" @@ -14,28 +15,22 @@ #include <iostream> #include <string> -using namespace ::std; using namespace Binc; -//---------------------------------------------------------------------- NamespaceOperator::NamespaceOperator(void) {} -//---------------------------------------------------------------------- NamespaceOperator::~NamespaceOperator(void) {} -//---------------------------------------------------------------------- -const string NamespaceOperator::getName(void) const +const std::string NamespaceOperator::getName(void) const { return "NAMESPACE"; } -//---------------------------------------------------------------------- int NamespaceOperator::getState(void) const { return Session::AUTHENTICATED | Session::SELECTED; } -//---------------------------------------------------------------------- Operator::ProcessResult NamespaceOperator::process(Depot &depot, Request &command) { bincClient << "* NAMESPACE "; @@ -44,17 +39,16 @@ Operator::ProcessResult NamespaceOperator::process(Depot &depot, Request &comman bincClient << toImapString(depot.getPersonalNamespace()); bincClient << " "; char c = depot.getDelimiter(); - bincClient << toImapString(string(&c, 1)); + bincClient << toImapString(std::string(&c, 1)); bincClient << "))"; bincClient << " NIL"; // others' namespaces bincClient << " NIL"; // shared namespaces - bincClient << endl; + bincClient << std::endl; return OK; } -//---------------------------------------------------------------------- Operator::ParseResult NamespaceOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); diff --git a/src/operator-noop-pending.cc b/src/operator-noop-pending.cc index 96b255a..b13fdc1 100644 --- a/src/operator-noop-pending.cc +++ b/src/operator-noop-pending.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file operator-noop-pending.cc * @brief Operator for the NOOP command, with pending extension * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "depot.h" #include "mailbox.h" #include "operators.h" @@ -14,16 +15,12 @@ #include <iostream> #include <string> -using namespace ::std; using namespace Binc; -//---------------------------------------------------------------------- NoopPendingOperator::NoopPendingOperator(void) : NoopOperator() {} -//---------------------------------------------------------------------- NoopPendingOperator::~NoopPendingOperator(void) {} -//---------------------------------------------------------------------- Operator::ProcessResult NoopPendingOperator::process(Depot &depot, Request &command) { Mailbox *mailbox = depot.getSelected(); diff --git a/src/operator-noop.cc b/src/operator-noop.cc index a32214f..bc73a10 100644 --- a/src/operator-noop.cc +++ b/src/operator-noop.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file operator-noop.cc * @brief Operator for the NOOP command. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ------------------------------------------------------------------ **/ + */ + #include "depot.h" #include "operators.h" #include "recursivedescent.h" @@ -12,34 +13,27 @@ #include <iostream> #include <string> -using namespace ::std; using namespace Binc; -//---------------------------------------------------------------------- NoopOperator::NoopOperator(void) {} -//---------------------------------------------------------------------- NoopOperator::~NoopOperator(void) {} -//---------------------------------------------------------------------- -const string NoopOperator::getName(void) const +const std::string NoopOperator::getName(void) const { return "NOOP"; } -//---------------------------------------------------------------------- int NoopOperator::getState(void) const { return Session::NONAUTHENTICATED | Session::AUTHENTICATED | Session::SELECTED; } -//---------------------------------------------------------------------- Operator::ProcessResult NoopOperator::process(Depot &depot, Request &command) { return OK; } -//---------------------------------------------------------------------- Operator::ParseResult NoopOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); diff --git a/src/operator-rename.cc b/src/operator-rename.cc index bfbe226..1d3a69a 100644 --- a/src/operator-rename.cc +++ b/src/operator-rename.cc @@ -1,7 +1,8 @@ -/** -------------------------------------------------------------------- +/** * @file operator-rename.cc * @brief Implementation of the RENAME command. - * ----------------------------------------------------------------- **/ + */ + #include "convert.h" #include "depot.h" #include "mailbox.h" @@ -16,28 +17,23 @@ #include <sys/stat.h> #include <sys/types.h> -using namespace ::std; using namespace Binc; +using std::string; -//---------------------------------------------------------------------- RenameOperator::RenameOperator(void) {} -//---------------------------------------------------------------------- RenameOperator::~RenameOperator(void) {} -//---------------------------------------------------------------------- const string RenameOperator::getName(void) const { return "RENAME"; } -//---------------------------------------------------------------------- int RenameOperator::getState(void) const { return Session::AUTHENTICATED | Session::SELECTED; } -//------------------------------------------------------------------------ Operator::ProcessResult RenameOperator::process(Depot &depot, Request &command) { Session &session = Session::getInstance(); @@ -66,7 +62,6 @@ Operator::ProcessResult RenameOperator::process(Depot &depot, Request &command) return NO; } -//---------------------------------------------------------------------- Operator::ParseResult RenameOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); diff --git a/src/operator-search.cc b/src/operator-search.cc index 08f51c1..aca9f1f 100644 --- a/src/operator-search.cc +++ b/src/operator-search.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file operator-search.cc * @brief Implementation of the SEARCH command. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "convert.h" #include "depot.h" #include "imapparser.h" @@ -21,10 +22,11 @@ #include <ctype.h> -using namespace ::std; using namespace Binc; +using std::endl; +using std::string; +using std::vector; -//---------------------------------------------------------------------- bool SearchOperator::SearchNode::convertDate(const string &date, time_t &t, const string &delim) { vector<string> parts; @@ -32,7 +34,7 @@ bool SearchOperator::SearchNode::convertDate(const string &date, time_t &t, cons if (parts.size() < 3) return false; struct tm mold; - memset((char *)&mold, 0, sizeof(struct tm)); + memset(&mold, 0, sizeof(struct tm)); mold.tm_mday = atoi(parts[0].c_str()); mold.tm_year = atoi(parts[2].c_str()) - 1900; @@ -70,7 +72,6 @@ bool SearchOperator::SearchNode::convertDate(const string &date, time_t &t, cons return true; } -//---------------------------------------------------------------------- bool SearchOperator::SearchNode::convertDateHeader(const string &d_in, time_t &t) { string date = d_in; @@ -82,22 +83,18 @@ bool SearchOperator::SearchNode::convertDateHeader(const string &d_in, time_t &t return result; } -//---------------------------------------------------------------------- SearchOperator::SearchNode::SearchNode(void) {} -//---------------------------------------------------------------------- SearchOperator::SearchNode::SearchNode(const BincImapParserSearchKey &a) { init(a); } -//---------------------------------------------------------------------- int SearchOperator::SearchNode::getType(void) const { return type; } -//---------------------------------------------------------------------- bool SearchOperator::SearchNode::match(Mailbox *mailbox, Message *m, unsigned int seqnr, @@ -108,16 +105,12 @@ bool SearchOperator::SearchNode::match(Mailbox *mailbox, string tmp; switch (type) { - //-------------------------------------------------------------------- case S_ALL: return true; - //-------------------------------------------------------------------- case S_ANSWERED: return (m->getStdFlags() & Message::F_ANSWERED); - //-------------------------------------------------------------------- case S_BCC: return m->headerContains("bcc", astring); - //-------------------------------------------------------------------- case S_BEFORE: { time_t mtime = m->getInternalDate(); struct tm *mtime_ = localtime(&mtime); @@ -136,32 +129,24 @@ bool SearchOperator::SearchNode::match(Mailbox *mailbox, } return mtime < atime; - } //-------------------------------------------------------------------- + } case S_BODY: return m->bodyContains(astring); - //-------------------------------------------------------------------- case S_CC: return m->headerContains("cc", astring); - //-------------------------------------------------------------------- case S_DELETED: return (m->getStdFlags() & Message::F_DELETED); - //-------------------------------------------------------------------- case S_FLAGGED: return (m->getStdFlags() & Message::F_FLAGGED); - //-------------------------------------------------------------------- case S_FROM: return m->headerContains("from", astring); - //-------------------------------------------------------------------- case S_KEYWORD: // the server does not support keywords return false; - //-------------------------------------------------------------------- case S_NEW: return (m->getStdFlags() & Message::F_RECENT) && !(m->getStdFlags() & Message::F_SEEN); - //-------------------------------------------------------------------- case S_OLD: return !(m->getStdFlags() & Message::F_RECENT); - //-------------------------------------------------------------------- case S_ON: { time_t mtime = m->getInternalDate(); struct tm *mtime_ = localtime(&mtime); @@ -180,13 +165,11 @@ bool SearchOperator::SearchNode::match(Mailbox *mailbox, } return mtime == atime; - } //-------------------------------------------------------------------- + } case S_RECENT: return (m->getStdFlags() & Message::F_RECENT); - //-------------------------------------------------------------------- case S_SEEN: return (m->getStdFlags() & Message::F_SEEN); - //-------------------------------------------------------------------- case S_SINCE: { time_t mtime = m->getInternalDate(); struct tm *mtime_ = localtime(&mtime); @@ -205,52 +188,39 @@ bool SearchOperator::SearchNode::match(Mailbox *mailbox, } return mtime >= atime; - } //-------------------------------------------------------------------- + } case S_SUBJECT: return m->headerContains("subject", astring); - //-------------------------------------------------------------------- case S_TEXT: return m->textContains(astring); - //-------------------------------------------------------------------- case S_TO: return m->headerContains("to", astring); - //-------------------------------------------------------------------- case S_UNANSWERED: return !(m->getStdFlags() & Message::F_ANSWERED); - //-------------------------------------------------------------------- case S_UNDELETED: return !(m->getStdFlags() & Message::F_DELETED); - //-------------------------------------------------------------------- case S_UNFLAGGED: return !(m->getStdFlags() & Message::F_FLAGGED); - //-------------------------------------------------------------------- case S_UNKEYWORD: // the server does not support keywords return true; - //-------------------------------------------------------------------- case S_UNSEEN: return !(m->getStdFlags() & Message::F_SEEN); - //-------------------------------------------------------------------- case S_DRAFT: return (m->getStdFlags() & Message::F_DRAFT); - //-------------------------------------------------------------------- case S_HEADER: return m->headerContains(astring, bstring); - //-------------------------------------------------------------------- case S_LARGER: { return (m->getSize(true) > number); } - //-------------------------------------------------------------------- case S_NOT: - for (vector<SearchNode>::const_iterator i = children.begin(); i != children.end(); ++i) - if ((*i).match(mailbox, m, seqnr, lastmessage, lastuid)) return false; + for (const auto &i : children) + if (i.match(mailbox, m, seqnr, lastmessage, lastuid)) return false; return true; - //-------------------------------------------------------------------- case S_OR: - for (vector<SearchNode>::const_iterator i = children.begin(); i != children.end(); ++i) - if ((*i).match(mailbox, m, seqnr, lastmessage, lastuid)) return true; + for (const auto &i : children) + if (i.match(mailbox, m, seqnr, lastmessage, lastuid)) return true; return false; - //-------------------------------------------------------------------- case S_SENTBEFORE: { string tmp = m->getHeader("date"); if (tmp == "") return false; @@ -269,7 +239,7 @@ bool SearchOperator::SearchNode::match(Mailbox *mailbox, } return mtime < atime; - } //-------------------------------------------------------------------- + } case S_SENTON: { string tmp = m->getHeader("date"); if (tmp == "") return false; @@ -288,7 +258,7 @@ bool SearchOperator::SearchNode::match(Mailbox *mailbox, } return mtime == atime; - } //-------------------------------------------------------------------- + } case S_SENTSINCE: { string tmp = m->getHeader("date"); if (tmp == "") return false; @@ -307,33 +277,30 @@ bool SearchOperator::SearchNode::match(Mailbox *mailbox, } return mtime >= atime; - } //-------------------------------------------------------------------- + } case S_SMALLER: return (m->getSize(true) < number); - //-------------------------------------------------------------------- case S_UID: - if (!bset->isInSet(m->getUID())) + if (!bset->isInSet(m->getUID())) { if (!(m->getUID() == lastuid && !bset->isLimited())) return false; + } return true; - //-------------------------------------------------------------------- case S_UNDRAFT: return !(m->getStdFlags() & Message::F_DRAFT); - //-------------------------------------------------------------------- case S_SET: - if (!bset->isInSet(seqnr)) + if (!bset->isInSet(seqnr)) { if (!(seqnr == lastmessage && !bset->isLimited())) return false; + } return true; - //-------------------------------------------------------------------- case S_AND: - for (vector<SearchNode>::const_iterator i = children.begin(); i != children.end(); ++i) - if (!(*i).match(mailbox, m, seqnr, lastmessage, lastuid)) return false; + for (const auto &i : children) + if (!i.match(mailbox, m, seqnr, lastmessage, lastuid)) return false; return true; } return false; } -//---------------------------------------------------------------------- void SearchOperator::SearchNode::init(const BincImapParserSearchKey &a) { astring = a.astring; @@ -490,45 +457,37 @@ void SearchOperator::SearchNode::init(const BincImapParserSearchKey &a) } } -//---------------------------------------------------------------------- int SearchOperator::SearchNode::getWeight(void) const { return weight; } -//---------------------------------------------------------------------- void SearchOperator::SearchNode::setWeight(int i) { weight = i; } -//---------------------------------------------------------------------- void SearchOperator::SearchNode::order(void) { - for (vector<SearchNode>::iterator i = children.begin(); i != children.end(); ++i) - (*i).order(); - ::stable_sort(children.begin(), children.end(), compareNodes); + for (auto &i : children) + i.order(); + stable_sort(children.begin(), children.end(), compareNodes); } -//---------------------------------------------------------------------- SearchOperator::SearchOperator(void) {} -//---------------------------------------------------------------------- SearchOperator::~SearchOperator(void) {} -//---------------------------------------------------------------------- const string SearchOperator::getName(void) const { return "SEARCH"; } -//---------------------------------------------------------------------- int SearchOperator::getState(void) const { return Session::SELECTED; } -//------------------------------------------------------------------------ Operator::ProcessResult SearchOperator::process(Depot &depot, Request &command) { Session &session = Session::getInstance(); @@ -566,7 +525,6 @@ Operator::ProcessResult SearchOperator::process(Depot &depot, Request &command) return OK; } -//------------------------------------------------------------------------ Operator::ParseResult SearchOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); @@ -627,18 +585,17 @@ Operator::ParseResult SearchOperator::parse(Request &c_in) const return ACCEPT; } -//---------------------------------------------------------------------- Operator::ParseResult SearchOperator::expectSearchKey(BincImapParserSearchKey &s_in) const { Session &session = Session::getInstance(); Operator::ParseResult res; s_in.type = BincImapParserSearchKey::KEY_OTHER; - if ((res = expectThisString("ALL")) == ACCEPT) + if ((res = expectThisString("ALL")) == ACCEPT) { s_in.name = "ALL"; - else if ((res = expectThisString("ANSWERED")) == ACCEPT) + } else if ((res = expectThisString("ANSWERED")) == ACCEPT) { s_in.name = "ANSWERED"; - else if ((res = expectThisString("BCC")) == ACCEPT) { + } else if ((res = expectThisString("BCC")) == ACCEPT) { s_in.name = "BCC"; if ((res = expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); @@ -683,11 +640,11 @@ Operator::ParseResult SearchOperator::expectSearchKey(BincImapParserSearchKey &s session.setLastError("Expected astring"); return res; } - } else if ((res = expectThisString("DELETED")) == ACCEPT) + } else if ((res = expectThisString("DELETED")) == ACCEPT) { s_in.name = "DELETED"; - else if ((res = expectThisString("FLAGGED")) == ACCEPT) + } else if ((res = expectThisString("FLAGGED")) == ACCEPT) { s_in.name = "FLAGGED"; - else if ((res = expectThisString("FROM")) == ACCEPT) { + } else if ((res = expectThisString("FROM")) == ACCEPT) { s_in.name = "FROM"; if ((res = expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); @@ -709,11 +666,11 @@ Operator::ParseResult SearchOperator::expectSearchKey(BincImapParserSearchKey &s session.setLastError("Expected flag_keyword"); return res; } - } else if ((res = expectThisString("NEW")) == ACCEPT) + } else if ((res = expectThisString("NEW")) == ACCEPT) { s_in.name = "NEW"; - else if ((res = expectThisString("OLD")) == ACCEPT) + } else if ((res = expectThisString("OLD")) == ACCEPT) { s_in.name = "OLD"; - else if ((res = expectThisString("ON")) == ACCEPT) { + } else if ((res = expectThisString("ON")) == ACCEPT) { s_in.name = "ON"; if ((res = expectSPACE()) != ACCEPT) { @@ -725,11 +682,11 @@ Operator::ParseResult SearchOperator::expectSearchKey(BincImapParserSearchKey &s session.setLastError("Expected date"); return res; } - } else if ((res = expectThisString("RECENT")) == ACCEPT) + } else if ((res = expectThisString("RECENT")) == ACCEPT) { s_in.name = "RECENT"; - else if ((res = expectThisString("SEEN")) == ACCEPT) + } else if ((res = expectThisString("SEEN")) == ACCEPT) { s_in.name = "SEEN"; - else if ((res = expectThisString("SINCE")) == ACCEPT) { + } else if ((res = expectThisString("SINCE")) == ACCEPT) { s_in.name = "SINCE"; if ((res = expectSPACE()) != ACCEPT) { @@ -774,13 +731,13 @@ Operator::ParseResult SearchOperator::expectSearchKey(BincImapParserSearchKey &s session.setLastError("Expected astring"); return res; } - } else if ((res = expectThisString("UNANSWERED")) == ACCEPT) + } else if ((res = expectThisString("UNANSWERED")) == ACCEPT) { s_in.name = "UNANSWERED"; - else if ((res = expectThisString("UNDELETED")) == ACCEPT) + } else if ((res = expectThisString("UNDELETED")) == ACCEPT) { s_in.name = "UNDELETED"; - else if ((res = expectThisString("UNFLAGGED")) == ACCEPT) + } else if ((res = expectThisString("UNFLAGGED")) == ACCEPT) { s_in.name = "UNFLAGGED"; - else if ((res = expectThisString("UNKEYWORD")) == ACCEPT) { + } else if ((res = expectThisString("UNKEYWORD")) == ACCEPT) { s_in.name = "UNKEYWORD"; if ((res = expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); @@ -791,11 +748,11 @@ Operator::ParseResult SearchOperator::expectSearchKey(BincImapParserSearchKey &s session.setLastError("Expected flag_keyword"); return res; } - } else if ((res = expectThisString("UNSEEN")) == ACCEPT) + } else if ((res = expectThisString("UNSEEN")) == ACCEPT) { s_in.name = "UNSEEN"; - else if ((res = expectThisString("DRAFT")) == ACCEPT) + } else if ((res = expectThisString("DRAFT")) == ACCEPT) { s_in.name = "DRAFT"; - else if ((res = expectThisString("HEADER")) == ACCEPT) { + } else if ((res = expectThisString("HEADER")) == ACCEPT) { s_in.name = "HEADER"; if ((res = expectSPACE()) != ACCEPT) { @@ -929,9 +886,9 @@ Operator::ParseResult SearchOperator::expectSearchKey(BincImapParserSearchKey &s session.setLastError("Expected number"); return res; } - } else if ((res = expectThisString("UNDRAFT")) == ACCEPT) + } else if ((res = expectThisString("UNDRAFT")) == ACCEPT) { s_in.name = "UNDRAFT"; - else if ((res = expectSet(s_in.bset)) == ACCEPT) { + } else if ((res = expectSet(s_in.bset)) == ACCEPT) { s_in.name = ""; s_in.type = BincImapParserSearchKey::KEY_SET; } else if ((res = expectThisString("(")) == ACCEPT) { @@ -953,8 +910,9 @@ Operator::ParseResult SearchOperator::expectSearchKey(BincImapParserSearchKey &s session.setLastError("Expected )"); return res; } - } else + } else { return REJECT; + } return ACCEPT; } diff --git a/src/operator-select.cc b/src/operator-select.cc index 64c4be6..1b0f5a4 100644 --- a/src/operator-select.cc +++ b/src/operator-select.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file operator-select.cc * @brief Implementation of the SELECT command. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "convert.h" #include "depot.h" #include "iodevice.h" @@ -16,28 +17,24 @@ #include <string> -using namespace ::std; using namespace Binc; +using std::endl; +using std::string; -//---------------------------------------------------------------------- SelectOperator::SelectOperator(void) {} -//---------------------------------------------------------------------- SelectOperator::~SelectOperator(void) {} -//---------------------------------------------------------------------- const string SelectOperator::getName(void) const { return "SELECT"; } -//---------------------------------------------------------------------- int SelectOperator::getState(void) const { return Session::NONAUTHENTICATED | Session::AUTHENTICATED | Session::SELECTED; } -//------------------------------------------------------------------------ Operator::ProcessResult SelectOperator::process(Depot &depot, Request &command) { Session &session = Session::getInstance(); @@ -47,14 +44,14 @@ Operator::ProcessResult SelectOperator::process(Depot &depot, Request &command) const string &canonmailbox = toCanonMailbox(srcmailbox); Mailbox *mailbox = depot.getSelected(); - if (mailbox != 0) { + if (mailbox != nullptr) { mailbox->closeMailbox(); depot.resetSelected(); - mailbox = 0; + mailbox = nullptr; } mailbox = depot.get(canonmailbox); - if (mailbox == 0) { + if (mailbox == nullptr) { session.setLastError(depot.getLastError()); return NO; } @@ -84,9 +81,10 @@ Operator::ProcessResult SelectOperator::process(Depot &depot, Request &command) pendingUpdates(mailbox, PendingUpdates::EXISTS | PendingUpdates::RECENT, false, true); // unseen - if (unseen != -1) + if (unseen != -1) { bincClient << "*" << " OK [UNSEEN " << unseen << "] Message " << unseen << " is first unseen" << endl; + } // uidvalidity bincClient << "*" @@ -113,7 +111,6 @@ Operator::ProcessResult SelectOperator::process(Depot &depot, Request &command) return OK; } -//---------------------------------------------------------------------- Operator::ParseResult SelectOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); diff --git a/src/operator-starttls.cc b/src/operator-starttls.cc index 3ba5dd0..c127e1a 100644 --- a/src/operator-starttls.cc +++ b/src/operator-starttls.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file operator-starttls.cc * @brief Implementation of the STARTTLS command - based on sslserver * @author Andreas Aardal Hanssen, Erwin Hoffmann * @date 2002-2005, 2023 - * ----------------------------------------------------------------- **/ + */ + #include "depot.h" #include "iodevice.h" #include "iofactory.h" @@ -17,34 +18,28 @@ #include <fcntl.h> #include <unistd.h> -using namespace ::std; using namespace Binc; -//---------------------------------------------------------------------- StarttlsOperator::StarttlsOperator(void) {} -//---------------------------------------------------------------------- StarttlsOperator::~StarttlsOperator(void) {} -//---------------------------------------------------------------------- -const string StarttlsOperator::getName(void) const +const std::string StarttlsOperator::getName(void) const { return "STARTTLS"; } -//---------------------------------------------------------------------- int StarttlsOperator::getState(void) const { return Session::NONAUTHENTICATED | Session::AUTHENTICATED | Session::SELECTED; } -//---------------------------------------------------------------------- int StarttlsOperator::goStartTLS(void) const { Session &session = Session::getInstance(); if (getenv("UCSPITLS")) { - string fdstr; + std::string fdstr; int fd; fdstr = session.getEnv("SSLCTLFD"); @@ -70,7 +65,6 @@ int StarttlsOperator::goStartTLS(void) const return ACCEPT; } -//------------------------------------------------------------------------ Operator::ProcessResult StarttlsOperator::process(Depot &depot, Request &command) { Session &session = Session::getInstance(); @@ -79,8 +73,8 @@ Operator::ProcessResult StarttlsOperator::process(Depot &depot, Request &command return BAD; } - bincClient << "* ENABLED StartTLS - begin negotiation now" << endl; - bincClient << command.getTag() << " OK STARTTLS completed" << endl; + bincClient << "* ENABLED StartTLS - begin negotiation now" << std::endl; + bincClient << command.getTag() << " OK STARTTLS completed" << std::endl; if (goStartTLS() == ACCEPT) session.command.ssl = true; @@ -90,7 +84,6 @@ Operator::ProcessResult StarttlsOperator::process(Depot &depot, Request &command return NOTHING; } -//---------------------------------------------------------------------- Operator::ParseResult StarttlsOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); diff --git a/src/operator-status.cc b/src/operator-status.cc index 82c3bcf..2422747 100644 --- a/src/operator-status.cc +++ b/src/operator-status.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file operator-status.cc * @brief Implementation of the STATUS command. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "convert.h" #include "depot.h" #include "iodevice.h" @@ -21,28 +22,22 @@ #include <sys/stat.h> #include <sys/types.h> -using namespace ::std; using namespace Binc; -//---------------------------------------------------------------------- StatusOperator::StatusOperator(void) {} -//---------------------------------------------------------------------- StatusOperator::~StatusOperator(void) {} -//---------------------------------------------------------------------- -const string StatusOperator::getName(void) const +const std::string StatusOperator::getName(void) const { return "STATUS"; } -//---------------------------------------------------------------------- int StatusOperator::getState(void) const { return Session::AUTHENTICATED | Session::SELECTED; } -//------------------------------------------------------------------------ Operator::ProcessResult StatusOperator::process(Depot &depot, Request &command) { Session &session = Session::getInstance(); @@ -55,9 +50,8 @@ Operator::ProcessResult StatusOperator::process(Depot &depot, Request &command) bincClient << "* STATUS " << toImapString(command.getMailbox()) << " ("; - string prefix; - for (vector<string>::const_iterator i = command.statuses.begin(); i != command.statuses.end(); ++i) { - string tmp = *i; + std::string prefix; + for (auto tmp : command.statuses) { uppercase(tmp); if (tmp == "UIDNEXT") { bincClient << prefix << "UIDNEXT " << status.getUidNext(); @@ -76,12 +70,11 @@ Operator::ProcessResult StatusOperator::process(Depot &depot, Request &command) prefix = " "; } } - bincClient << ")" << endl; + bincClient << ")" << std::endl; return OK; } -//---------------------------------------------------------------------- Operator::ParseResult StatusOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); @@ -94,7 +87,7 @@ Operator::ParseResult StatusOperator::parse(Request &c_in) const return res; } - string mailbox; + std::string mailbox; if ((res = expectMailbox(mailbox)) != ACCEPT) { session.setLastError("Expected mailbox"); return res; @@ -113,17 +106,17 @@ Operator::ParseResult StatusOperator::parse(Request &c_in) const } while (1) { - if ((res = expectThisString("MESSAGES")) == ACCEPT) + if ((res = expectThisString("MESSAGES")) == ACCEPT) { c_in.getStatuses().push_back("MESSAGES"); - else if ((res = expectThisString("RECENT")) == ACCEPT) + } else if ((res = expectThisString("RECENT")) == ACCEPT) { c_in.getStatuses().push_back("RECENT"); - else if ((res = expectThisString("UIDNEXT")) == ACCEPT) + } else if ((res = expectThisString("UIDNEXT")) == ACCEPT) { c_in.getStatuses().push_back("UIDNEXT"); - else if ((res = expectThisString("UIDVALIDITY")) == ACCEPT) + } else if ((res = expectThisString("UIDVALIDITY")) == ACCEPT) { c_in.getStatuses().push_back("UIDVALIDITY"); - else if ((res = expectThisString("UNSEEN")) == ACCEPT) + } else if ((res = expectThisString("UNSEEN")) == ACCEPT) { c_in.getStatuses().push_back("UNSEEN"); - else { + } else { session.setLastError("Expected status_att"); return res; } diff --git a/src/operator-store.cc b/src/operator-store.cc index b6e1b99..160002a 100644 --- a/src/operator-store.cc +++ b/src/operator-store.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file operator-store.cc * @brief Implementation of the STORE command * @author Andreas Aardal Hanssen * @date 2002-2005 - * ------------------------------------------------------------------ **/ + */ + #include "depot.h" #include "imapparser.h" #include "mailbox.h" @@ -15,28 +16,24 @@ #include <iostream> #include <string> -using namespace ::std; using namespace Binc; +using std::string; +using std::vector; -//---------------------------------------------------------------------- StoreOperator::StoreOperator(void) {} -//---------------------------------------------------------------------- StoreOperator::~StoreOperator(void) {} -//---------------------------------------------------------------------- const string StoreOperator::getName(void) const { return "STORE"; } -//---------------------------------------------------------------------- int StoreOperator::getState(void) const { return Session::SELECTED; } -//------------------------------------------------------------------------ Operator::ProcessResult StoreOperator::process(Depot &depot, Request &command) { Mailbox *mailbox = depot.getSelected(); @@ -44,22 +41,19 @@ Operator::ProcessResult StoreOperator::process(Depot &depot, Request &command) // mask all passed flags together unsigned int newflags = (unsigned int)Message::F_NONE; vector<string> newCustomFlags; - vector<string>::const_iterator f_i = command.flags.begin(); - while (f_i != command.flags.end()) { - if (*f_i == "\\Deleted") + for (const auto &f_i : command.flags) { + if (f_i == "\\Deleted") newflags |= Message::F_DELETED; - else if (*f_i == "\\Answered") + else if (f_i == "\\Answered") newflags |= Message::F_ANSWERED; - else if (*f_i == "\\Seen") + else if (f_i == "\\Seen") newflags |= Message::F_SEEN; - else if (*f_i == "\\Draft") + else if (f_i == "\\Draft") newflags |= Message::F_DRAFT; - else if (*f_i == "\\Flagged") + else if (f_i == "\\Flagged") newflags |= Message::F_FLAGGED; else - newCustomFlags.push_back(*f_i); - - ++f_i; + newCustomFlags.push_back(f_i); } // pass through all messages @@ -80,19 +74,19 @@ Operator::ProcessResult StoreOperator::process(Depot &depot, Request &command) switch (command.getMode()[0]) { case '+': flags |= newflags; - for (vector<string>::const_iterator it = newCustomFlags.begin(); it != newCustomFlags.end(); ++it) - message.setCustomFlag(*it); + for (const auto &it : newCustomFlags) + message.setCustomFlag(it); break; case '-': flags &= ~newflags; - for (vector<string>::const_iterator it = newCustomFlags.begin(); it != newCustomFlags.end(); ++it) - message.removeCustomFlag(*it); + for (const auto &it : newCustomFlags) + message.removeCustomFlag(it); break; default: flags = newflags; message.resetCustomFlags(); - for (vector<string>::const_iterator it = newCustomFlags.begin(); it != newCustomFlags.end(); ++it) - message.setCustomFlag(*it); + for (const auto &it : newCustomFlags) + message.setCustomFlag(it); break; }; @@ -106,14 +100,14 @@ Operator::ProcessResult StoreOperator::process(Depot &depot, Request &command) mailbox->updateFlags(); // check mailbox for updates, and report them - if (command.getMode().find(".SILENT") != string::npos) + if (command.getMode().find(".SILENT") != string::npos) { pendingUpdates(mailbox, PendingUpdates::EXISTS | PendingUpdates::RECENT, false, false, false, command.getUidMode()); - else + } else { pendingUpdates(mailbox, PendingUpdates::EXISTS | PendingUpdates::RECENT | PendingUpdates::EXPUNGE | PendingUpdates::FLAGS, @@ -121,11 +115,11 @@ Operator::ProcessResult StoreOperator::process(Depot &depot, Request &command) false, false, command.getUidMode()); + } return OK; } -//---------------------------------------------------------------------- Operator::ParseResult StoreOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); @@ -155,8 +149,9 @@ Operator::ParseResult StoreOperator::parse(Request &c_in) const if ((res = expectThisString("FLAGS")) != ACCEPT) { session.setLastError("Expected FLAGS"); return res; - } else + } else { mode += "FLAGS"; + } if ((res = expectThisString(".SILENT")) == ACCEPT) mode += ".SILENT"; @@ -170,7 +165,7 @@ Operator::ParseResult StoreOperator::parse(Request &c_in) const bool paren = false; if ((res = expectThisString("(")) == ACCEPT) paren = true; - if ((res = expectFlag(c_in.getFlags())) == ACCEPT) + if ((res = expectFlag(c_in.getFlags())) == ACCEPT) { while (1) { if ((res = expectSPACE()) != ACCEPT) break; @@ -179,12 +174,14 @@ Operator::ParseResult StoreOperator::parse(Request &c_in) const return res; } } + } - if (paren) + if (paren) { if ((res = expectThisString(")")) != ACCEPT) { session.setLastError("Expected )"); return res; } + } if ((res = expectCRLF()) != ACCEPT) { session.setLastError("Expected CRLF"); diff --git a/src/operator-subscribe.cc b/src/operator-subscribe.cc index 7626844..2a7ca51 100644 --- a/src/operator-subscribe.cc +++ b/src/operator-subscribe.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file operator-subscribe.cc * @brief Implementation of the SUBSCRIBE command. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "convert.h" #include "depot.h" #include "operators.h" @@ -15,28 +16,23 @@ #include <sys/stat.h> -using namespace ::std; using namespace Binc; +using std::string; -//---------------------------------------------------------------------- SubscribeOperator::SubscribeOperator(void) {} -//---------------------------------------------------------------------- SubscribeOperator::~SubscribeOperator(void) {} -//---------------------------------------------------------------------- const string SubscribeOperator::getName(void) const { return "SUBSCRIBE"; } -//---------------------------------------------------------------------- int SubscribeOperator::getState(void) const { return Session::AUTHENTICATED | Session::SELECTED; } -//------------------------------------------------------------------------ Operator::ProcessResult SubscribeOperator::process(Depot &depot, Request &command) { const string &srcmailbox = command.getMailbox(); @@ -49,7 +45,6 @@ Operator::ProcessResult SubscribeOperator::process(Depot &depot, Request &comman return OK; } -//---------------------------------------------------------------------- Operator::ParseResult SubscribeOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); diff --git a/src/operator-unsubscribe.cc b/src/operator-unsubscribe.cc index ae900a8..b4a197e 100644 --- a/src/operator-unsubscribe.cc +++ b/src/operator-unsubscribe.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file operator-unsubscribe.cc * @brief Implementation of the UNSUBSCRIBE command. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "convert.h" #include "depot.h" #include "operators.h" @@ -16,28 +17,23 @@ #include <sys/stat.h> -using namespace ::std; using namespace Binc; +using std::string; -//---------------------------------------------------------------------- UnsubscribeOperator::UnsubscribeOperator(void) {} -//---------------------------------------------------------------------- UnsubscribeOperator::~UnsubscribeOperator(void) {} -//---------------------------------------------------------------------- const string UnsubscribeOperator::getName(void) const { return "UNSUBSCRIBE"; } -//---------------------------------------------------------------------- int UnsubscribeOperator::getState(void) const { return Session::AUTHENTICATED | Session::SELECTED; } -//------------------------------------------------------------------------ Operator::ProcessResult UnsubscribeOperator::process(Depot &depot, Request &command) { const string &mailbox = command.getMailbox(); @@ -55,7 +51,6 @@ Operator::ProcessResult UnsubscribeOperator::process(Depot &depot, Request &comm return OK; } -//---------------------------------------------------------------------- Operator::ParseResult UnsubscribeOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); diff --git a/src/pendingupdates.cc b/src/pendingupdates.cc index 1e4af8d..bf4e0f2 100644 --- a/src/pendingupdates.cc +++ b/src/pendingupdates.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file pendingupdates.cc * @brief <---> * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "pendingupdates.h" #include "iodevice.h" @@ -16,10 +17,9 @@ #include <string> #include <vector> -using namespace ::std; +using namespace std; using namespace Binc; -//------------------------------------------------------------------------ PendingUpdates::PendingUpdates(void) : expunges(), flagupdates() { recent = 0; @@ -29,16 +29,13 @@ PendingUpdates::PendingUpdates(void) : expunges(), flagupdates() newexists = false; } -//------------------------------------------------------------------------ PendingUpdates::~PendingUpdates(void) {} -//------------------------------------------------------------------------ void PendingUpdates::addExpunged(unsigned int uid) { expunges.push_back(uid); } -//------------------------------------------------------------------------ void PendingUpdates::addFlagUpdates(unsigned int sqnr, unsigned int uid, unsigned int flags, @@ -49,92 +46,76 @@ void PendingUpdates::addFlagUpdates(unsigned int sqnr, sqnrtocflags[sqnr] = cflags; } -//------------------------------------------------------------------------ void PendingUpdates::setExists(unsigned int n) { exists = n; newexists = true; } -//------------------------------------------------------------------------ void PendingUpdates::setRecent(unsigned int n) { recent = n; newrecent = true; } -//------------------------------------------------------------------------ unsigned int PendingUpdates::getExists(void) const { return exists; } -//------------------------------------------------------------------------ unsigned int PendingUpdates::getRecent(void) const { return recent; } -//------------------------------------------------------------------------ bool PendingUpdates::newExists(void) const { return newexists; } -//------------------------------------------------------------------------ bool PendingUpdates::newRecent(void) const { return newrecent; } -//------------------------------------------------------------------------ PendingUpdates::expunged_const_iterator::expunged_const_iterator(void) {} -//------------------------------------------------------------------------ PendingUpdates::expunged_const_iterator::expunged_const_iterator(vector<unsigned int>::iterator i) : internal(i) {} -//------------------------------------------------------------------------ unsigned int PendingUpdates::expunged_const_iterator::operator*(void) const { return *internal; } -//------------------------------------------------------------------------ void PendingUpdates::expunged_const_iterator::operator++(void) { ++internal; } -//------------------------------------------------------------------------ bool PendingUpdates::expunged_const_iterator::operator==(expunged_const_iterator i) const { return internal == i.internal; } -//------------------------------------------------------------------------ bool PendingUpdates::expunged_const_iterator::operator!=(expunged_const_iterator i) const { return internal != i.internal; } -//------------------------------------------------------------------------ PendingUpdates::expunged_const_iterator PendingUpdates::beginExpunged(void) { return expunged_const_iterator(expunges.begin()); } -//------------------------------------------------------------------------ PendingUpdates::expunged_const_iterator PendingUpdates::endExpunged(void) { return expunged_const_iterator(expunges.end()); } -//------------------------------------------------------------------------ PendingUpdates::flagupdates_const_iterator::flagupdates_const_iterator(void) {} -//------------------------------------------------------------------------ PendingUpdates::flagupdates_const_iterator::flagupdates_const_iterator( map<unsigned int, unsigned int>::iterator i, map<unsigned int, vector<string>> *j, @@ -145,55 +126,46 @@ PendingUpdates::flagupdates_const_iterator::flagupdates_const_iterator( sqnrtouid = sqnrmap; } -//------------------------------------------------------------------------ void PendingUpdates::flagupdates_const_iterator::operator++(void) { ++internal; } -//------------------------------------------------------------------------ bool PendingUpdates::flagupdates_const_iterator::operator!=(flagupdates_const_iterator i) const { return internal != i.internal; } -//------------------------------------------------------------------------ PendingUpdates::flagupdates_const_iterator PendingUpdates::beginFlagUpdates(void) { return flagupdates_const_iterator(flagupdates.begin(), &sqnrtocflags, &sqnrtouid); } -//------------------------------------------------------------------------ PendingUpdates::flagupdates_const_iterator PendingUpdates::endFlagUpdates(void) { return flagupdates_const_iterator(flagupdates.end(), &sqnrtocflags, &sqnrtouid); } -//------------------------------------------------------------------------ unsigned int PendingUpdates::flagupdates_const_iterator::first(void) const { return internal->first; } -//------------------------------------------------------------------------ unsigned int PendingUpdates::flagupdates_const_iterator::second(void) const { return internal->second; } -//------------------------------------------------------------------------ vector<string> PendingUpdates::flagupdates_const_iterator::getCustomFlags(void) const { return (*sqnrtocflags)[internal->first]; } -//------------------------------------------------------------------------ unsigned int PendingUpdates::flagupdates_const_iterator::getUID(void) const { return (*sqnrtouid)[internal->first]; } -//-------------------------------------------------------------------- bool Binc::pendingUpdates(Mailbox *mailbox, int type, bool rescan, @@ -203,7 +175,7 @@ bool Binc::pendingUpdates(Mailbox *mailbox, { Session &session = Session::getInstance(); - if (mailbox == 0) return true; + if (mailbox == nullptr) return true; PendingUpdates p; if (!mailbox->getUpdates(rescan, type, p, forceScan)) { diff --git a/src/recursivedescent.cc b/src/recursivedescent.cc index 0f0cf8d..e490865 100644 --- a/src/recursivedescent.cc +++ b/src/recursivedescent.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file recursivedescent.cc * @brief Implementation of a recursive descent IMAP command parser. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "recursivedescent.h" #include "convert.h" @@ -19,13 +20,12 @@ #include <ctype.h> #include <stdio.h> -using namespace ::std; using namespace Binc; +using std::string; -stack<int> Binc::inputBuffer; +std::stack<int> Binc::inputBuffer; int Binc::charnr = 0; -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectThisString(const string &s_in) { Session &session = Session::getInstance(); @@ -53,11 +53,11 @@ Operator::ParseResult Binc::expectThisString(const string &s_in) if (!match) { bincClient.unreadStr(tmp); return Operator::REJECT; - } else + } else { return Operator::ACCEPT; + } } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectDateTime(string &s_in) { Session &session = Session::getInstance(); @@ -102,31 +102,31 @@ Operator::ParseResult Binc::expectDateTime(string &s_in) s_in += "-"; /* month */ - if ((res = expectThisString("Jan")) == Operator::ACCEPT) + if ((res = expectThisString("Jan")) == Operator::ACCEPT) { s_in += "Jan"; - else if ((res = expectThisString("Feb")) == Operator::ACCEPT) + } else if ((res = expectThisString("Feb")) == Operator::ACCEPT) { s_in += "Feb"; - else if ((res = expectThisString("Mar")) == Operator::ACCEPT) + } else if ((res = expectThisString("Mar")) == Operator::ACCEPT) { s_in += "Mar"; - else if ((res = expectThisString("Apr")) == Operator::ACCEPT) + } else if ((res = expectThisString("Apr")) == Operator::ACCEPT) { s_in += "Apr"; - else if ((res = expectThisString("May")) == Operator::ACCEPT) + } else if ((res = expectThisString("May")) == Operator::ACCEPT) { s_in += "May"; - else if ((res = expectThisString("Jun")) == Operator::ACCEPT) + } else if ((res = expectThisString("Jun")) == Operator::ACCEPT) { s_in += "Jun"; - else if ((res = expectThisString("Jul")) == Operator::ACCEPT) + } else if ((res = expectThisString("Jul")) == Operator::ACCEPT) { s_in += "Jul"; - else if ((res = expectThisString("Aug")) == Operator::ACCEPT) + } else if ((res = expectThisString("Aug")) == Operator::ACCEPT) { s_in += "Aug"; - else if ((res = expectThisString("Sep")) == Operator::ACCEPT) + } else if ((res = expectThisString("Sep")) == Operator::ACCEPT) { s_in += "Sep"; - else if ((res = expectThisString("Oct")) == Operator::ACCEPT) + } else if ((res = expectThisString("Oct")) == Operator::ACCEPT) { s_in += "Oct"; - else if ((res = expectThisString("Nov")) == Operator::ACCEPT) + } else if ((res = expectThisString("Nov")) == Operator::ACCEPT) { s_in += "Nov"; - else if ((res = expectThisString("Dec")) == Operator::ACCEPT) + } else if ((res = expectThisString("Dec")) == Operator::ACCEPT) { s_in += "Dec"; - else { + } else { session.setLastError("expected month"); return res; } @@ -204,7 +204,6 @@ Operator::ParseResult Binc::expectDateTime(string &s_in) return Operator::ACCEPT; } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectTime(string &s_in) { Session &session = Session::getInstance(); @@ -279,7 +278,6 @@ Operator::ParseResult Binc::expectTime(string &s_in) return Operator::ACCEPT; } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectZone(string &s_in) { Session &session = Session::getInstance(); @@ -328,7 +326,6 @@ Operator::ParseResult Binc::expectZone(string &s_in) return Operator::ACCEPT; } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectListWildcards(int &c_in) { Operator::ParseResult res; @@ -338,11 +335,11 @@ Operator::ParseResult Binc::expectListWildcards(int &c_in) } else if ((res = expectThisString("*")) == Operator::ACCEPT) { c_in = '*'; return Operator::ACCEPT; - } else + } else { return res; + } } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectListMailbox(string &s_in) { Operator::ParseResult res; @@ -357,7 +354,9 @@ Operator::ParseResult Binc::expectListMailbox(string &s_in) if ((res = expectAtomChar(c)) != Operator::ACCEPT && (res = expectListWildcards(c)) != Operator::ACCEPT && (res = expectThisString("]")) != Operator::ACCEPT) + { return Operator::ACCEPT; + } } while (1); } @@ -366,44 +365,41 @@ Operator::ParseResult Binc::expectListMailbox(string &s_in) return res; } -//---------------------------------------------------------------------- -Operator::ParseResult Binc::expectFlag(vector<string> &v_in) +Operator::ParseResult Binc::expectFlag(std::vector<string> &v_in) { Session &session = Session::getInstance(); Operator::ParseResult res; string flag; - if ((res = expectThisString("\\Answered")) == Operator::ACCEPT) + if ((res = expectThisString("\\Answered")) == Operator::ACCEPT) { v_in.push_back("\\Answered"); - else if ((res = expectThisString("\\Flagged")) == Operator::ACCEPT) + } else if ((res = expectThisString("\\Flagged")) == Operator::ACCEPT) { v_in.push_back("\\Flagged"); - else if ((res = expectThisString("\\Deleted")) == Operator::ACCEPT) + } else if ((res = expectThisString("\\Deleted")) == Operator::ACCEPT) { v_in.push_back("\\Deleted"); - else if ((res = expectThisString("\\Seen")) == Operator::ACCEPT) + } else if ((res = expectThisString("\\Seen")) == Operator::ACCEPT) { v_in.push_back("\\Seen"); - else if ((res = expectThisString("\\Draft")) == Operator::ACCEPT) + } else if ((res = expectThisString("\\Draft")) == Operator::ACCEPT) { v_in.push_back("\\Draft"); - else if ((res = expectThisString("\\Answered")) == Operator::ACCEPT) + } else if ((res = expectThisString("\\Answered")) == Operator::ACCEPT) { v_in.push_back("\\Answered"); - else { - if ((res = expectThisString("\\")) == Operator::ACCEPT) { - if ((res = expectAtom(flag)) == Operator::ACCEPT) - v_in.push_back("\\" + flag); - else { - session.setLastError("expected atom"); - return res; - } - - } else if (expectAtom(flag) == Operator::ACCEPT) { - v_in.push_back(flag); - } else + } else if ((res = expectThisString("\\")) == Operator::ACCEPT) { + if ((res = expectAtom(flag)) == Operator::ACCEPT) { + v_in.push_back("\\" + flag); + } else { + session.setLastError("expected atom"); return res; + } + + } else if (expectAtom(flag) == Operator::ACCEPT) { + v_in.push_back(flag); + } else { + return res; } return Operator::ACCEPT; } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectDate(string &s_in) { Session &session = Session::getInstance(); @@ -437,31 +433,31 @@ Operator::ParseResult Binc::expectDate(string &s_in) s_in += '-'; /* month */ - if ((res = expectThisString("Jan")) == Operator::ACCEPT) + if ((res = expectThisString("Jan")) == Operator::ACCEPT) { s_in += "Jan"; - else if ((res = expectThisString("Feb")) == Operator::ACCEPT) + } else if ((res = expectThisString("Feb")) == Operator::ACCEPT) { s_in += "Feb"; - else if ((res = expectThisString("Mar")) == Operator::ACCEPT) + } else if ((res = expectThisString("Mar")) == Operator::ACCEPT) { s_in += "Mar"; - else if ((res = expectThisString("Apr")) == Operator::ACCEPT) + } else if ((res = expectThisString("Apr")) == Operator::ACCEPT) { s_in += "Apr"; - else if ((res = expectThisString("May")) == Operator::ACCEPT) + } else if ((res = expectThisString("May")) == Operator::ACCEPT) { s_in += "May"; - else if ((res = expectThisString("Jun")) == Operator::ACCEPT) + } else if ((res = expectThisString("Jun")) == Operator::ACCEPT) { s_in += "Jun"; - else if ((res = expectThisString("Jul")) == Operator::ACCEPT) + } else if ((res = expectThisString("Jul")) == Operator::ACCEPT) { s_in += "Jul"; - else if ((res = expectThisString("Aug")) == Operator::ACCEPT) + } else if ((res = expectThisString("Aug")) == Operator::ACCEPT) { s_in += "Aug"; - else if ((res = expectThisString("Sep")) == Operator::ACCEPT) + } else if ((res = expectThisString("Sep")) == Operator::ACCEPT) { s_in += "Sep"; - else if ((res = expectThisString("Oct")) == Operator::ACCEPT) + } else if ((res = expectThisString("Oct")) == Operator::ACCEPT) { s_in += "Oct"; - else if ((res = expectThisString("Nov")) == Operator::ACCEPT) + } else if ((res = expectThisString("Nov")) == Operator::ACCEPT) { s_in += "Nov"; - else if ((res = expectThisString("Dec")) == Operator::ACCEPT) + } else if ((res = expectThisString("Dec")) == Operator::ACCEPT) { s_in += "Dec"; - else { + } else { session.setLastError("expected month"); return res; } @@ -508,16 +504,16 @@ Operator::ParseResult Binc::expectDate(string &s_in) s_in += yearstr.str(); - if (quoted) + if (quoted) { if ((res = expectThisString("\"")) != Operator::ACCEPT) { session.setLastError("expected \""); return res; } + } return Operator::ACCEPT; } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectCRLF(void) { Operator::ParseResult res; @@ -527,7 +523,6 @@ Operator::ParseResult Binc::expectCRLF(void) return res; } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectCR(void) { Session &session = Session::getInstance(); @@ -540,15 +535,14 @@ Operator::ParseResult Binc::expectCR(void) return Operator::ERROR; } - if (c == 0x0d) + if (c == 0x0d) { return Operator::ACCEPT; - else { + } else { bincClient.unreadChar(c); return Operator::REJECT; } } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectLF(void) { Session &session = Session::getInstance(); @@ -561,15 +555,14 @@ Operator::ParseResult Binc::expectLF(void) return Operator::ERROR; } - if (c == 0x0a) + if (c == 0x0a) { return Operator::ACCEPT; - else { + } else { bincClient.unreadChar(c); return Operator::REJECT; } } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectTagChar(int &c_in) { Session &session = Session::getInstance(); @@ -680,20 +673,19 @@ Operator::ParseResult Binc::expectTagChar(int &c_in) return Operator::REJECT; } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectTag(string &s_in) { string tag; int tagchar; int eres = expectTagChar(tagchar); - if (eres == Operator::REJECT) + if (eres == Operator::REJECT) { return Operator::REJECT; - else if (eres == Operator::ERROR) + } else if (eres == Operator::ERROR) { return Operator::ERROR; - else if (eres == Operator::TIMEOUT) + } else if (eres == Operator::TIMEOUT) { return Operator::TIMEOUT; - else { + } else { tag += tagchar; bool done = false; @@ -719,7 +711,6 @@ Operator::ParseResult Binc::expectTag(string &s_in) return Operator::ACCEPT; } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectSPACE(void) { Session &session = Session::getInstance(); @@ -732,21 +723,19 @@ Operator::ParseResult Binc::expectSPACE(void) return Operator::ERROR; } - if (c == ' ') + if (c == ' ') { return Operator::ACCEPT; - else { + } else { bincClient.unreadChar(c); return Operator::REJECT; } } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectMailbox(string &s_in) { return expectAstring(s_in); } -//---------------------------------------------------------------------- // FIXME: This rule is wrong. Operator::ParseResult Binc::expectAstring(string &s_in) { @@ -758,7 +747,6 @@ Operator::ParseResult Binc::expectAstring(string &s_in) return res; } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectAtomChar(int &c_in) { Session &session = Session::getInstance(); @@ -869,7 +857,6 @@ Operator::ParseResult Binc::expectAtomChar(int &c_in) return Operator::REJECT; } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectAtom(string &s_in) { string atom; @@ -882,13 +869,13 @@ Operator::ParseResult Binc::expectAtom(string &s_in) if (atom == "") { bincClient.unreadStr(atom); return res; - } else + } else { s_in = atom; + } return Operator::ACCEPT; } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectString(string &s_in) { Operator::ParseResult res; @@ -899,7 +886,6 @@ Operator::ParseResult Binc::expectString(string &s_in) return res; } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectQuoted(string &s_in) { string quoted; @@ -920,7 +906,6 @@ Operator::ParseResult Binc::expectQuoted(string &s_in) return Operator::ACCEPT; } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectQuotedChar(int &c_in) { Session &session = Session::getInstance(); @@ -1085,7 +1070,6 @@ Operator::ParseResult Binc::expectQuotedChar(int &c_in) return Operator::REJECT; } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectLiteral(string &s_in) { Session &session = Session::getInstance(); @@ -1121,7 +1105,7 @@ Operator::ParseResult Binc::expectLiteral(string &s_in) // Only send the reply if the client did not send a LITERAL+ // request. if (!literalPlus) { - bincClient << "+ ok, send " << nchar << " bytes of data." << endl; + bincClient << "+ ok, send " << nchar << " bytes of data." << std::endl; bincClient.flush(); } @@ -1141,26 +1125,23 @@ Operator::ParseResult Binc::expectLiteral(string &s_in) return Operator::ACCEPT; } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectNumber(unsigned int &i_in) { i_in = 0; unsigned int n; Operator::ParseResult res; - while ((res = expectDigit(n)) == Operator::ACCEPT) { + while ((res = expectDigit(n)) == Operator::ACCEPT) if (i_in == 0) i_in = n; else i_in = (i_in * 10) + n; - } if (res == Operator::TIMEOUT) return res; return Operator::ACCEPT; } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectDigit(unsigned int &i_in) { Session &session = Session::getInstance(); @@ -1176,15 +1157,15 @@ Operator::ParseResult Binc::expectDigit(unsigned int &i_in) if (c == '0') { i_in = 0; return Operator::ACCEPT; - } else + } else { bincClient.unreadChar(c); + } if (expectDigitNZ(i_in) != Operator::ACCEPT) return Operator::REJECT; return Operator::ACCEPT; } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectDigitNZ(unsigned int &i_in) { Session &session = Session::getInstance(); @@ -1238,7 +1219,6 @@ Operator::ParseResult Binc::expectDigitNZ(unsigned int &i_in) return Operator::ACCEPT; } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectSet(SequenceSet &s_in) { Session &session = Session::getInstance(); @@ -1268,16 +1248,16 @@ Operator::ParseResult Binc::expectSet(SequenceSet &s_in) /* if _after_ a set there is a ',', then there will always be * a set after the comma. if not, it's a syntax error. */ - if ((res = expectThisString(",")) == Operator::ACCEPT) + if ((res = expectThisString(",")) == Operator::ACCEPT) { if ((res = expectSet(s_in)) != Operator::ACCEPT) { session.setLastError("expected set"); return res; } + } return Operator::ACCEPT; } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectSequenceNum(unsigned int &i_in) { Session &session = Session::getInstance(); @@ -1293,8 +1273,9 @@ Operator::ParseResult Binc::expectSequenceNum(unsigned int &i_in) if (c == '*') { i_in = (unsigned int)-1; return Operator::ACCEPT; - } else + } else { bincClient.unreadChar(c); + } if (expectNZNumber(i_in) != Operator::ACCEPT) return Operator::REJECT; @@ -1302,7 +1283,6 @@ Operator::ParseResult Binc::expectSequenceNum(unsigned int &i_in) return Operator::ACCEPT; } -//---------------------------------------------------------------------- Operator::ParseResult Binc::expectNZNumber(unsigned int &i_in) { unsigned int c; diff --git a/src/regmatch.cc b/src/regmatch.cc index 6e4b261..0942ad9 100644 --- a/src/regmatch.cc +++ b/src/regmatch.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file regex.cc * @brief Implementation of miscellaneous regexp functions * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "regmatch.h" #include <string> @@ -13,10 +14,7 @@ #include <regex.h> #include <sys/types.h> -using namespace ::std; - -//------------------------------------------------------------------------ -int Binc::regexMatch(const string &data_in, const string &p_in) +int Binc::regexMatch(const std::string &data_in, const std::string &p_in) { regex_t r; regmatch_t rm[2]; diff --git a/src/session-initialize-bincimap-up.cc b/src/session-initialize-bincimap-up.cc index 12c099c..c18ef26 100644 --- a/src/session-initialize-bincimap-up.cc +++ b/src/session-initialize-bincimap-up.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file session-initialize-bincimap-up.cc * @brief bincimap-up requires sslserver * @author Andreas Aardal Hanssen, Erwin Hoffmann * @date 2002-2005, 2023 - * ----------------------------------------------------------------- **/ + */ + #include "broker.h" #include "convert.h" #include "globals.h" @@ -23,12 +24,11 @@ #include <fcntl.h> #include <syslog.h> -using namespace ::std; using namespace Binc; +using std::string; extern char **environ; -//---------------------------------------------------------------------- bool Session::initialize(int argc, char *argv[]) { IOFactory &ioFactory = IOFactory::getInstance(); @@ -76,30 +76,28 @@ bool Session::initialize(int argc, char *argv[]) const string f = session.getEnv("SYSLOG_FACILITY"); int facility; - if (isdigit(f[0])) { + if (isdigit(f[0])) facility = atoi(f); - } else { - if (f == "LOG_USER") - facility = LOG_USER; - else if (f == "LOG_LOCAL0") - facility = LOG_LOCAL0; - else if (f == "LOG_LOCAL1") - facility = LOG_LOCAL1; - else if (f == "LOG_LOCAL2") - facility = LOG_LOCAL2; - else if (f == "LOG_LOCAL3") - facility = LOG_LOCAL3; - else if (f == "LOG_LOCAL4") - facility = LOG_LOCAL4; - else if (f == "LOG_LOCAL5") - facility = LOG_LOCAL5; - else if (f == "LOG_LOCAL6") - facility = LOG_LOCAL6; - else if (f == "LOG_LOCAL7") - facility = LOG_LOCAL7; - else - facility = LOG_DAEMON; - } + else if (f == "LOG_USER") + facility = LOG_USER; + else if (f == "LOG_LOCAL0") + facility = LOG_LOCAL0; + else if (f == "LOG_LOCAL1") + facility = LOG_LOCAL1; + else if (f == "LOG_LOCAL2") + facility = LOG_LOCAL2; + else if (f == "LOG_LOCAL3") + facility = LOG_LOCAL3; + else if (f == "LOG_LOCAL4") + facility = LOG_LOCAL4; + else if (f == "LOG_LOCAL5") + facility = LOG_LOCAL5; + else if (f == "LOG_LOCAL6") + facility = LOG_LOCAL6; + else if (f == "LOG_LOCAL7") + facility = LOG_LOCAL7; + else + facility = LOG_DAEMON; SyslogDevice *device = new SyslogDevice(IODevice::IsEnabled | IODevice::FlushesOnEndl, "bincimap-up", @@ -112,7 +110,6 @@ bool Session::initialize(int argc, char *argv[]) IOFactory::getLogger().setFlags(IODevice::FlushesOnEndl); IOFactory::getLogger().setOutputLevelLimit(IODevice::InfoLevel); - // imaps (port 993) -- requires sslserver with option -e int stls = 0; diff --git a/src/session-initialize-bincimapd.cc b/src/session-initialize-bincimapd.cc index 057accd..a574363 100644 --- a/src/session-initialize-bincimapd.cc +++ b/src/session-initialize-bincimapd.cc @@ -1,10 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file session-initialize-bincimapd.cc * @brief <---> * @author Andreas Aardal Hanssen, Erwin Hoffmann * @date 2002-2005, 2023 - * -------------------------------------------------------------------- */ + #include "broker.h" #include "convert.h" #include "depot.h" @@ -28,12 +28,12 @@ #include <syslog.h> #include <unistd.h> -using namespace ::std; using namespace Binc; +using std::endl; +using std::string; extern char **environ; -//---------------------------------------------------------------------- bool Session::initialize(int argc, char *argv[]) { IOFactory &ioFactory = IOFactory::getInstance(); @@ -82,28 +82,26 @@ bool Session::initialize(int argc, char *argv[]) if (isdigit(f[0])) facility = atoi(f); - else { - if (f == "LOG_USER") - facility = LOG_USER; - else if (f == "LOG_LOCAL0") - facility = LOG_LOCAL0; - else if (f == "LOG_LOCAL1") - facility = LOG_LOCAL1; - else if (f == "LOG_LOCAL2") - facility = LOG_LOCAL2; - else if (f == "LOG_LOCAL3") - facility = LOG_LOCAL3; - else if (f == "LOG_LOCAL4") - facility = LOG_LOCAL4; - else if (f == "LOG_LOCAL5") - facility = LOG_LOCAL5; - else if (f == "LOG_LOCAL6") - facility = LOG_LOCAL6; - else if (f == "LOG_LOCAL7") - facility = LOG_LOCAL7; - else - facility = LOG_DAEMON; - } + else if (f == "LOG_USER") + facility = LOG_USER; + else if (f == "LOG_LOCAL0") + facility = LOG_LOCAL0; + else if (f == "LOG_LOCAL1") + facility = LOG_LOCAL1; + else if (f == "LOG_LOCAL2") + facility = LOG_LOCAL2; + else if (f == "LOG_LOCAL3") + facility = LOG_LOCAL3; + else if (f == "LOG_LOCAL4") + facility = LOG_LOCAL4; + else if (f == "LOG_LOCAL5") + facility = LOG_LOCAL5; + else if (f == "LOG_LOCAL6") + facility = LOG_LOCAL6; + else if (f == "LOG_LOCAL7") + facility = LOG_LOCAL7; + else + facility = LOG_DAEMON; session.setEnv("SYSLOG_FACILITY", toString(facility)); @@ -116,10 +114,10 @@ bool Session::initialize(int argc, char *argv[]) IOFactory::getLogger().setFlags(IODevice::FlushesOnEndl); IOFactory::getLogger().setOutputLevelLimit(IODevice::InfoLevel); - string pid = to_string(session.getPid()); + string pid = std::to_string(session.getPid()); char *logindetails = getenv("BINCIMAP_LOGIN"); - if (logindetails == 0) { + if (logindetails == nullptr) { bincLog << "bincimapd: pid " << pid << " BINCIMAP_LOGIN missing from environment (are you sure you invoked " << argv[0] << " properly?)\n"; @@ -133,7 +131,7 @@ bool Session::initialize(int argc, char *argv[]) string depottype = session.getEnv("DEPOT"); if (depottype == "") depottype = "Maildir++"; - if ((depot = depotfactory.get(depottype)) == 0) { + if ((depot = depotfactory.get(depottype)) == nullptr) { bincLog << "bincimapd: pid " << pid << " Found no Depot for: " << depottype << ". Please check your configurations file under the Mailbox section\n"; bincLog.flush(); @@ -177,9 +175,9 @@ bool Session::initialize(int argc, char *argv[]) // automatically create depot directory if it's not there already string path; if (session.args.getUnqualifiedArgs().size() > 0) path = session.args.getUnqualifiedArgs()[0]; - if (path == "") + if (path == "") { path = "."; - else if (chdir(path.c_str()) != 0) { + } else if (chdir(path.c_str()) != 0) { mkdir(path.c_str(), 0777); if (chdir(path.c_str()) != 0) { bincLog << "bincimapd: pid" << pid << " Error entering depot " + toImapString(path) + ": " diff --git a/src/session.cc b/src/session.cc index b6a0834..41192cb 100644 --- a/src/session.cc +++ b/src/session.cc @@ -1,7 +1,8 @@ -/** -------------------------------------------------------------------- +/** * @file session.cc * @brief Implementation of the Session class. - * ------------------------------------------------------------------ **/ + */ + #include "session.h" #include "argparser.h" @@ -15,12 +16,11 @@ #include <syslog.h> #include <unistd.h> -using namespace ::std; using namespace Binc; +using std::string; extern char **environ; -//---------------------------------------------------------------------- Session::Session(void) { readbytes = 0; @@ -31,110 +31,92 @@ Session::Session(void) logfacility = LOG_DAEMON; } -//---------------------------------------------------------------------- Session &Session::getInstance(void) { static Session session; return session; } -//---------------------------------------------------------------------- -const int Session::getState(void) const +int Session::getState(void) const { return state; } -//---------------------------------------------------------------------- void Session::setState(int n) { state = n; } -//---------------------------------------------------------------------- const string &Session::getUserID(void) const { return userid; } -//---------------------------------------------------------------------- void Session::setUserID(const string &s) { userid = s; } -//---------------------------------------------------------------------- const string &Session::getIP(void) const { return ip; } -//---------------------------------------------------------------------- void Session::setIP(const string &s) { ip = s; } -//---------------------------------------------------------------------- void Session::setLogFacility(int facility) { logfacility = facility; } -//---------------------------------------------------------------------- int Session::getLogFacility(void) const { return logfacility; } -//---------------------------------------------------------------------- void Session::addBody(void) { ++bodies; } -//---------------------------------------------------------------------- void Session::addStatement(void) { ++statements; } -//---------------------------------------------------------------------- void Session::addReadBytes(int i) { readbytes += i; } -//---------------------------------------------------------------------- void Session::addWriteBytes(int i) { writebytes += i; } -//---------------------------------------------------------------------- int Session::getBodies(void) const { return bodies; } -//---------------------------------------------------------------------- int Session::getStatements(void) const { return statements; } -//---------------------------------------------------------------------- int Session::getWriteBytes(void) const { return writebytes; } -//---------------------------------------------------------------------- int Session::getReadBytes(void) const { return readbytes; } -//---------------------------------------------------------------------- bool Session::parseCommandLine(int argc, char *argv[]) { args.addOptional("h|help", "Display this help screen", true); @@ -158,7 +140,6 @@ bool Session::parseCommandLine(int argc, char *argv[]) return true; } -//---------------------------------------------------------------------- void Session::assignCommandLineArgs(void) { if (args.hasArg("allow-plain")) setEnv("ALLOW_NONSSL_PLAINTEXT_LOGINS", "yes"); @@ -172,37 +153,31 @@ void Session::assignCommandLineArgs(void) if (args.hasArg("delimiter")) setEnv("DELIMITER", args["delimiter"]); } -//---------------------------------------------------------------------- const string &Session::getLastError(void) const { return lastError; } -//---------------------------------------------------------------------- void Session::setLastError(const string &error) const { lastError = error; } -//---------------------------------------------------------------------- const string &Session::getResponseCode(void) const { return responseCode; } -//---------------------------------------------------------------------- void Session::setResponseCode(const string &code) const { responseCode = "[" + code + "] "; } -//---------------------------------------------------------------------- void Session::clearResponseCode(void) const { responseCode = ""; } -//---------------------------------------------------------------------- pid_t Session::getPid(void) { if (pid == 0) pid = getpid(); @@ -210,26 +185,22 @@ pid_t Session::getPid(void) return pid; } -//---------------------------------------------------------------------- int Session::timeout() const { return state == NONAUTHENTICATED ? AUTH_TIMEOUT : IDLE_TIMEOUT; } -//---------------------------------------------------------------------- bool Session::hasEnv(const string &key) const { - return getenv(key.c_str()) != 0; + return getenv(key.c_str()) != nullptr; } -//---------------------------------------------------------------------- string Session::getEnv(const string &key) { char *c = getenv(key.c_str()); return c ? c : ""; } -//---------------------------------------------------------------------- void Session::setEnv(const string &key, const string &value) { string env = key + "=" + value; diff --git a/src/status.cc b/src/status.cc index 8b481ef..341c04f 100644 --- a/src/status.cc +++ b/src/status.cc @@ -1,16 +1,14 @@ -/** -------------------------------------------------------------------- +/** * @file status.cc * @brief Implementation of the Status class. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "status.h" -using namespace ::std; using namespace Binc; -//------------------------------------------------------------------------ Status::Status(void) {} -//------------------------------------------------------------------------ Status::~Status(void) {} diff --git a/src/stdiodevice.cc b/src/stdiodevice.cc index a9cce91..b078c7a 100644 --- a/src/stdiodevice.cc +++ b/src/stdiodevice.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file stdiodevice.cc * @brief Implementation of the StdIODevice class * @author Andreas Aardal Hanssen * @date 2003/2023 - * ---------------------------------------------------------------- **/ + */ + #include "stdiodevice.h" #include <string> @@ -16,29 +17,23 @@ #include <sys/types.h> #include <unistd.h> -using namespace ::std; -using namespace ::Binc; +using namespace Binc; -//------------------------------------------------------------------------ StdIODevice::StdIODevice(int f) : IODevice(f) {} -//------------------------------------------------------------------------ StdIODevice::~StdIODevice(void) {} -//------------------------------------------------------------------------ -string StdIODevice::service(void) const +std::string StdIODevice::service(void) const { return "client"; } -//------------------------------------------------------------------------ bool StdIODevice::canRead(void) const { size_t bytes; return ioctl(fileno(stdin), FIONREAD, (char *)&bytes) > 0; } -//------------------------------------------------------------------------ bool StdIODevice::waitForWrite(void) const { fd_set writeMask; @@ -49,12 +44,11 @@ bool StdIODevice::waitForWrite(void) const tv.tv_sec = timeout; tv.tv_usec = 0; - int result = select(fileno(stdout) + 1, 0, &writeMask, 0, timeout ? &tv : 0); + int result = select(fileno(stdout) + 1, nullptr, &writeMask, nullptr, timeout ? &tv : nullptr); if (result == 0) error = Timeout; return result > 0; } -//------------------------------------------------------------------------ bool StdIODevice::waitForRead(void) const { fd_set readMask; @@ -65,12 +59,11 @@ bool StdIODevice::waitForRead(void) const tv.tv_sec = timeout; tv.tv_usec = 0; - int result = select(fileno(stdin) + 1, &readMask, 0, 0, timeout ? &tv : 0); + int result = select(fileno(stdin) + 1, &readMask, nullptr, nullptr, timeout ? &tv : nullptr); if (result == 0) error = Timeout; return result > 0; } -//------------------------------------------------------------------------ IODevice::WriteResult StdIODevice::write(void) { for (;;) { @@ -90,7 +83,6 @@ IODevice::WriteResult StdIODevice::write(void) } } -//------------------------------------------------------------------------ bool StdIODevice::fillInputBuffer(void) { if (!waitForRead()) return false; diff --git a/src/syslogdevice.cc b/src/syslogdevice.cc index f694835..49162a4 100644 --- a/src/syslogdevice.cc +++ b/src/syslogdevice.cc @@ -1,22 +1,21 @@ -/** -------------------------------------------------------------------- +/** * @file syslogdevice.cc * @brief Implementation of the SyslogDevice class. * @author Andreas Aardal Hanssen * @date 2002, 2003 - * ----------------------------------------------------------------- **/ + */ + #include "syslogdevice.h" #include <string> #include <syslog.h> -using namespace ::std; -using namespace ::Binc; +using namespace Binc; +using std::string; -//------------------------------------------------------------------------ string SyslogDevice::ident; -//------------------------------------------------------------------------ SyslogDevice::SyslogDevice(int f, const char *i, int o, int fa) : IODevice(f) , option(o) @@ -27,31 +26,26 @@ SyslogDevice::SyslogDevice(int f, const char *i, int o, int fa) openlog(ident.c_str(), option, facility); } -//------------------------------------------------------------------------ SyslogDevice::~SyslogDevice(void) { closelog(); } -//------------------------------------------------------------------------ string SyslogDevice::service(void) const { return "log"; } -//------------------------------------------------------------------------ bool SyslogDevice::waitForWrite(void) const { return true; } -//------------------------------------------------------------------------ bool SyslogDevice::waitForRead(void) const { return false; } -//------------------------------------------------------------------------ IODevice::WriteResult SyslogDevice::write(void) { string out; @@ -62,8 +56,9 @@ IODevice::WriteResult SyslogDevice::write(void) if (*i == '\n') { syslog(priority, out.c_str(), out.size()); out = ""; - } else if (*i != '\r') + } else if (*i != '\r') { out += *i; + } } if (out != "") syslog(priority, out.c_str(), out.size()); @@ -72,7 +67,6 @@ IODevice::WriteResult SyslogDevice::write(void) return WriteDone; } -//------------------------------------------------------------------------ bool SyslogDevice::fillInputBuffer(void) { return false; diff --git a/src/tools.cc b/src/tools.cc index 95c28d6..1b6e28a 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -1,42 +1,39 @@ -/** -------------------------------------------------------------------- +/** * @file tools.cc * @brief Implementation of miscellaneous tools. * @author Andreas Aardal Hanssen * @date 2002-2005 - * ------------------------------------------------------------------ **/ + */ + #include "tools.h" #include <cstring> #include <errno.h> -using namespace ::std; using namespace Binc; +using std::string; -//------------------------------------------------------------------------ Tools::Tools(void) {} -//------------------------------------------------------------------------ Tools &Tools::getInstance(void) { static Tools tools; return tools; } -//------------------------------------------------------------------------ void Tools::setenv(const string &key, const string &value) const { char *c = strdup((key + "=" + value).c_str()); putenv(c); } -//------------------------------------------------------------------------ string Tools::getenv(const string &key) const { static const string NIL = ""; const char *c = ::getenv((char *)key.c_str()); - if (c == 0) + if (c == nullptr) return NIL; else return string(c); |