diff options
author | Jannis M. Hoffmann <jannis@fehcom.de> | 2023-10-07 22:33:50 +0200 |
---|---|---|
committer | Jannis M. Hoffmann <jannis@fehcom.de> | 2023-10-08 11:35:51 +0200 |
commit | 1978c49bea5b439d993067c055cec47e70db8fd6 (patch) | |
tree | 255caea96a13f95564e6b631be9a4ac55ce33cd9 /src/operator-fetch.cc | |
parent | 3b1278f5459514a6d6364f068ff97b8a0432057b (diff) |
minor refactoring
Diffstat (limited to 'src/operator-fetch.cc')
-rw-r--r-- | src/operator-fetch.cc | 73 |
1 files changed, 35 insertions, 38 deletions
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; } |