From 3b1278f5459514a6d6364f068ff97b8a0432057b Mon Sep 17 00:00:00 2001 From: "Jannis M. Hoffmann" Date: Sat, 7 Oct 2023 18:49:13 +0200 Subject: formatted source and header files --- src/operator-fetch.cc | 283 +++++++++++++++++++++++--------------------------- 1 file changed, 129 insertions(+), 154 deletions(-) (limited to 'src/operator-fetch.cc') diff --git a/src/operator-fetch.cc b/src/operator-fetch.cc index 810afb5..8b33d79 100644 --- a/src/operator-fetch.cc +++ b/src/operator-fetch.cc @@ -4,24 +4,24 @@ * @author Andreas Aardal Hanssen * @date 2002-2005 * ----------------------------------------------------------------- **/ -#include - +#include "convert.h" #include "depot.h" +#include "imapparser.h" #include "iodevice.h" #include "iofactory.h" #include "mailbox.h" #include "operators.h" -#include "imapparser.h" #include "pendingupdates.h" #include "recursivedescent.h" #include "session.h" -#include "convert.h" + +#include using namespace ::std; using namespace Binc; namespace { - void outputFlags(const Message & message) + void outputFlags(const Message &message) { bincClient << "FLAGS "; @@ -35,15 +35,13 @@ namespace { if (flags & Message::F_RECENT) flagv.push_back("\\Recent"); if (flags & Message::F_FLAGGED) flagv.push_back("\\Flagged"); - for (vector::const_iterator k - = flagv.begin(); k != flagv.end(); ++k) { + for (vector::const_iterator k = flagv.begin(); k != flagv.end(); ++k) { if (k != flagv.begin()) bincClient << " "; bincClient << *k; } vector customFlags = message.getCustomFlags(); - for (vector::const_iterator it = customFlags.begin(); - it != customFlags.end(); ++it) { + for (vector::const_iterator it = customFlags.begin(); it != customFlags.end(); ++it) { if (flagv.size() > 0 || it != customFlags.begin()) bincClient << " "; bincClient << *it; } @@ -54,14 +52,10 @@ namespace { } //---------------------------------------------------------------------- -FetchOperator::FetchOperator(void) -{ -} +FetchOperator::FetchOperator(void) {} //---------------------------------------------------------------------- -FetchOperator::~FetchOperator(void) -{ -} +FetchOperator::~FetchOperator(void) {} //---------------------------------------------------------------------- const string FetchOperator::getName(void) const @@ -76,8 +70,7 @@ int FetchOperator::getState(void) const } //------------------------------------------------------------------------ -Operator::ProcessResult FetchOperator::process(Depot &depot, - Request &request) +Operator::ProcessResult FetchOperator::process(Depot &depot, Request &request) { Session &session = Session::getInstance(); @@ -137,8 +130,7 @@ Operator::ProcessResult FetchOperator::process(Depot &depot, else mode = Mailbox::SQNR_MODE; - Mailbox::iterator i - = mailbox->begin(req.bset, Mailbox::SKIP_EXPUNGED | mode); + Mailbox::iterator i = mailbox->begin(req.bset, Mailbox::SKIP_EXPUNGED | mode); for (; i != mailbox->end(); ++i) { Message &message = *i; @@ -191,8 +183,7 @@ Operator::ProcessResult FetchOperator::process(Depot &depot, struct tm *_tm = gmtime(&iDate); char internal[64]; string iDateStr; - if (strftime(internal, sizeof(internal), - "%d-%b-%Y %H:%M:%S %z", _tm) != 0) { + if (strftime(internal, sizeof(internal), "%d-%b-%Y %H:%M:%S %z", _tm) != 0) { if (internal[0] == '0') internal[0] = ' '; iDateStr = internal; } else @@ -212,19 +203,16 @@ Operator::ProcessResult FetchOperator::process(Depot &depot, bool fullheader = false; bool bodyfetch = false; - if (fatt.section != "" || fatt.sectiontext == "" - || fatt.sectiontext == "TEXT") { - bodyfetch = true; - fullheader = true; + if (fatt.section != "" || fatt.sectiontext == "" || fatt.sectiontext == "TEXT") { + bodyfetch = true; + fullheader = true; } - if (fatt.sectiontext == "HEADER.FIELDS.NOT") - includeheaders = false; + if (fatt.sectiontext == "HEADER.FIELDS.NOT") includeheaders = false; - if (fatt.sectiontext == "HEADER" - || fatt.sectiontext == "HEADER.FIELDS" - || fatt.sectiontext == "HEADER.FIELDS.NOT" - || fatt.sectiontext == "MIME") { + if (fatt.sectiontext == "HEADER" || fatt.sectiontext == "HEADER.FIELDS" + || fatt.sectiontext == "HEADER.FIELDS.NOT" || fatt.sectiontext == "MIME") + { vector v; if (fatt.sectiontext == "MIME") { @@ -236,120 +224,105 @@ Operator::ProcessResult FetchOperator::process(Depot &depot, v = fatt.headerlist; string dummy; - unsigned int size = fullheader - ? message.getHeaderSize(fatt.section, v, true, - fatt.offsetstart, - fatt.offsetlength, - fatt.sectiontext == "MIME") - : message.getHeaderSize(fatt.section, fatt.headerlist, - includeheaders, - fatt.offsetstart, - fatt.offsetlength, - fatt.sectiontext == "MIME"); + unsigned int size = fullheader ? message.getHeaderSize(fatt.section, + v, + true, + fatt.offsetstart, + fatt.offsetlength, + fatt.sectiontext == "MIME") + : message.getHeaderSize(fatt.section, + fatt.headerlist, + includeheaders, + fatt.offsetstart, + fatt.offsetlength, + fatt.sectiontext == "MIME"); bincClient << "{" << size << "}\r\n"; if (fullheader) { - message.printHeader(fatt.section, v, true, + message.printHeader(fatt.section, + v, + true, fatt.offsetstart, - fatt.offsetlength, + fatt.offsetlength, fatt.sectiontext == "MIME"); } else { - message.printHeader(fatt.section, fatt.headerlist, + message.printHeader(fatt.section, + fatt.headerlist, includeheaders, - fatt.offsetstart, + fatt.offsetstart, fatt.offsetlength, fatt.sectiontext == "MIME"); } } else { unsigned int size; - if ((fatt.sectiontext == "" || fatt.sectiontext == "TEXT") - && fatt.section == "") - size = message.getDocSize(fatt.offsetstart, - fatt.offsetlength, - fatt.sectiontext == "TEXT"); + if ((fatt.sectiontext == "" || fatt.sectiontext == "TEXT") && fatt.section == "") + size = message.getDocSize(fatt.offsetstart, fatt.offsetlength, fatt.sectiontext == "TEXT"); else - size = message.getBodySize(fatt.section, - fatt.offsetstart, - fatt.offsetlength); + size = message.getBodySize(fatt.section, fatt.offsetstart, fatt.offsetlength); - bincClient << "{" << size << "}\r\n"; + bincClient << "{" << size << "}\r\n"; - if ((fatt.sectiontext == "" || fatt.sectiontext == "TEXT") - && fatt.section == "") - message.printDoc(fatt.offsetstart, - fatt.offsetlength, - fatt.sectiontext == "TEXT"); + if ((fatt.sectiontext == "" || fatt.sectiontext == "TEXT") && fatt.section == "") + message.printDoc(fatt.offsetstart, fatt.offsetlength, fatt.sectiontext == "TEXT"); else - message.printBody(fatt.section, fatt.offsetstart, - fatt.offsetlength); - } + message.printBody(fatt.section, fatt.offsetstart, fatt.offsetlength); + } - // set the \Seen flag if .PEEK is not used. - if (!peek) - if ((message.getStdFlags() & Message::F_SEEN) == 0) - message.setStdFlag(Message::F_SEEN); - } else if (fatt.type == "RFC822") { - bincClient << prefix; - hasprinted = true; - session.addBody(); - bincClient << fatt.toString(); - unsigned int size = message.getDocSize(fatt.offsetstart, - fatt.offsetlength); - bincClient << " {" << size << "}\r\n"; - message.printDoc(fatt.offsetstart, fatt.offsetlength); - - // set the \Seen flag - if ((message.getStdFlags() & Message::F_SEEN) == 0) - message.setStdFlag(Message::F_SEEN); - - } else if (fatt.type == "RFC822.HEADER") { - bincClient << prefix; - hasprinted = true; - bincClient << fatt.toString(); - vector v; - string dummy; - unsigned int size = message.getHeaderSize("", v, true, - fatt.offsetstart, - fatt.offsetlength); - bincClient << " {" << size << "}\r\n"; - message.printHeader("", v, true, fatt.offsetstart, - fatt.offsetlength); - } else if (fatt.type == "RFC822.TEXT") { - // RFC822.TEXT - bincClient << prefix; - hasprinted = true; - session.addBody(); - - bincClient << fatt.toString(); - - bool bodyfetch = false; - bodyfetch = true; + // set the \Seen flag if .PEEK is not used. + if (!peek) + if ((message.getStdFlags() & Message::F_SEEN) == 0) message.setStdFlag(Message::F_SEEN); + } else if (fatt.type == "RFC822") { + bincClient << prefix; + hasprinted = true; + session.addBody(); + bincClient << fatt.toString(); + unsigned int size = message.getDocSize(fatt.offsetstart, fatt.offsetlength); + bincClient << " {" << size << "}\r\n"; + message.printDoc(fatt.offsetstart, fatt.offsetlength); - unsigned int size; - if (fatt.sectiontext == "" && fatt.section == "") - size = message.getDocSize(fatt.offsetstart, - fatt.offsetlength, true); - else - size = message.getBodySize(fatt.section, fatt.offsetstart, - fatt.offsetlength); + // set the \Seen flag + if ((message.getStdFlags() & Message::F_SEEN) == 0) message.setStdFlag(Message::F_SEEN); + + } else if (fatt.type == "RFC822.HEADER") { + bincClient << prefix; + hasprinted = true; + bincClient << fatt.toString(); + vector v; + string dummy; + unsigned int size = message.getHeaderSize("", v, true, fatt.offsetstart, fatt.offsetlength); + bincClient << " {" << size << "}\r\n"; + message.printHeader("", v, true, fatt.offsetstart, fatt.offsetlength); + } else if (fatt.type == "RFC822.TEXT") { + // RFC822.TEXT + bincClient << prefix; + hasprinted = true; + session.addBody(); + + bincClient << fatt.toString(); + + bool bodyfetch = false; + bodyfetch = true; + + unsigned int size; + if (fatt.sectiontext == "" && fatt.section == "") + size = message.getDocSize(fatt.offsetstart, fatt.offsetlength, true); + else + size = message.getBodySize(fatt.section, fatt.offsetstart, fatt.offsetlength); bincClient << " {" << size << "}\r\n"; if (fatt.sectiontext == "" && fatt.section == "") - message.printDoc(fatt.offsetstart, - fatt.offsetlength, true); + message.printDoc(fatt.offsetstart, fatt.offsetlength, true); else - message.printBody(fatt.section, fatt.offsetstart, - fatt.offsetlength); + message.printBody(fatt.section, fatt.offsetstart, fatt.offsetlength); // set the \Seen flag - if ((message.getStdFlags() & Message::F_SEEN) == 0) - message.setStdFlag(Message::F_SEEN); + if ((message.getStdFlags() & Message::F_SEEN) == 0) message.setStdFlag(Message::F_SEEN); - } else { - // Unrecognized fetch_att, this is stopped by the parser - // so we never get here. + } else { + // Unrecognized fetch_att, this is stopped by the parser + // so we never get here. } f_i++; @@ -367,14 +340,13 @@ Operator::ProcessResult FetchOperator::process(Depot &depot, message.setFlagsUnchanged(); } } - + if (updateFlags) mailbox->updateFlags(); pendingUpdates(mailbox, - PendingUpdates::FLAGS - | PendingUpdates::EXISTS - | PendingUpdates::EXPUNGE - | PendingUpdates::RECENT, true); + PendingUpdates::FLAGS | PendingUpdates::EXISTS | PendingUpdates::EXPUNGE + | PendingUpdates::RECENT, + true); return OK; } @@ -423,8 +395,10 @@ Operator::ParseResult FetchOperator::parse(Request &c_in) const c_in.fatt.push_back(ftmp); - if ((res = expectSPACE()) == REJECT) break; - else if (res == ERROR) return ERROR; + if ((res = expectSPACE()) == REJECT) + break; + else if (res == ERROR) + return ERROR; } if ((res = expectThisString(")")) != ACCEPT) { @@ -446,8 +420,7 @@ Operator::ParseResult FetchOperator::parse(Request &c_in) const } //---------------------------------------------------------------------- -Operator::ParseResult -FetchOperator::expectSectionText(BincImapParserFetchAtt &f_in) const +Operator::ParseResult FetchOperator::expectSectionText(BincImapParserFetchAtt &f_in) const { Session &session = Session::getInstance(); @@ -458,8 +431,7 @@ FetchOperator::expectSectionText(BincImapParserFetchAtt &f_in) const if ((res = expectThisString(".FIELDS")) == ACCEPT) { f_in.sectiontext += ".FIELDS"; - if ((res = expectThisString(".NOT")) == ACCEPT) - f_in.sectiontext += ".NOT"; + if ((res = expectThisString(".NOT")) == ACCEPT) f_in.sectiontext += ".NOT"; if ((res = expectSPACE()) != ACCEPT) { session.setLastError("expected SPACE"); @@ -477,18 +449,15 @@ FetchOperator::expectSectionText(BincImapParserFetchAtt &f_in) const return REJECT; return ACCEPT; - } //---------------------------------------------------------------------- -Operator::ParseResult -FetchOperator::expectSection(BincImapParserFetchAtt &f_in) const +Operator::ParseResult FetchOperator::expectSection(BincImapParserFetchAtt &f_in) const { Session &session = Session::getInstance(); Operator::ParseResult res; - if ((res = expectThisString("[")) != ACCEPT) - return REJECT; + if ((res = expectThisString("[")) != ACCEPT) return REJECT; if ((res = expectSectionText(f_in)) != ACCEPT) { unsigned int n; @@ -509,7 +478,7 @@ FetchOperator::expectSection(BincImapParserFetchAtt &f_in) const f_in.section += "."; BincStream nstr; nstr << n; - f_in.section += nstr.str(); + f_in.section += nstr.str(); } if (gotadotalready || (res = expectThisString(".")) == ACCEPT) { @@ -532,14 +501,12 @@ FetchOperator::expectSection(BincImapParserFetchAtt &f_in) const } //---------------------------------------------------------------------- -Operator::ParseResult -FetchOperator::expectHeaderList(BincImapParserFetchAtt &f_in) const +Operator::ParseResult FetchOperator::expectHeaderList(BincImapParserFetchAtt &f_in) const { Session &session = Session::getInstance(); Operator::ParseResult res; - if ((res = expectThisString("(")) != ACCEPT) - return REJECT; + if ((res = expectThisString("(")) != ACCEPT) return REJECT; string header_fld_name; while (1) { @@ -550,8 +517,10 @@ FetchOperator::expectHeaderList(BincImapParserFetchAtt &f_in) const f_in.headerlist.push_back(header_fld_name); - if ((res = expectSPACE()) == ACCEPT) continue; - else break; + if ((res = expectSPACE()) == ACCEPT) + continue; + else + break; } if ((res = expectThisString(")")) != ACCEPT) { @@ -563,8 +532,7 @@ FetchOperator::expectHeaderList(BincImapParserFetchAtt &f_in) const } //---------------------------------------------------------------------- -Operator::ParseResult -FetchOperator::expectOffset(BincImapParserFetchAtt &f_in) const +Operator::ParseResult FetchOperator::expectOffset(BincImapParserFetchAtt &f_in) const { Session &session = Session::getInstance(); Operator::ParseResult res; @@ -599,23 +567,28 @@ FetchOperator::expectOffset(BincImapParserFetchAtt &f_in) const } //---------------------------------------------------------------------- -Operator::ParseResult -FetchOperator::expectFetchAtt(BincImapParserFetchAtt &f_in) const +Operator::ParseResult FetchOperator::expectFetchAtt(BincImapParserFetchAtt &f_in) const { Operator::ParseResult res; Session &session = Session::getInstance(); - if ((res = expectThisString("ENVELOPE")) == ACCEPT) f_in.type = "ENVELOPE"; - else if ((res = expectThisString("FLAGS")) == ACCEPT) f_in.type = "FLAGS"; + if ((res = expectThisString("ENVELOPE")) == ACCEPT) + f_in.type = "ENVELOPE"; + else if ((res = expectThisString("FLAGS")) == ACCEPT) + f_in.type = "FLAGS"; else if ((res = expectThisString("INTERNALDATE")) == ACCEPT) f_in.type = "INTERNALDATE"; - else if ((res = expectThisString("UID")) == ACCEPT) f_in.type = "UID"; + else if ((res = expectThisString("UID")) == ACCEPT) + f_in.type = "UID"; else if ((res = expectThisString("RFC822")) == ACCEPT) { f_in.type = "RFC822"; - if ((res = expectThisString(".HEADER")) == ACCEPT) f_in.type += ".HEADER"; - else if ((res = expectThisString(".SIZE")) == ACCEPT) f_in.type += ".SIZE"; - else if ((res = expectThisString(".TEXT")) == ACCEPT) f_in.type += ".TEXT"; + if ((res = expectThisString(".HEADER")) == ACCEPT) + f_in.type += ".HEADER"; + else if ((res = expectThisString(".SIZE")) == ACCEPT) + f_in.type += ".SIZE"; + else if ((res = expectThisString(".TEXT")) == ACCEPT) + f_in.type += ".TEXT"; else if ((res = expectThisString(".")) == ACCEPT) { session.setLastError("Expected RFC822, RFC822.HEADER," " RFC822.SIZE or RFC822.TEXT"); @@ -625,15 +598,17 @@ FetchOperator::expectFetchAtt(BincImapParserFetchAtt &f_in) const } else if ((res = expectThisString("BODY")) == ACCEPT) { f_in.type = "BODY"; - if ((res = expectThisString("STRUCTURE")) == ACCEPT) f_in.type += "STRUCTURE"; - else if ((res = expectThisString(".PEEK")) == ACCEPT) f_in.type += ".PEEK"; + if ((res = expectThisString("STRUCTURE")) == ACCEPT) + f_in.type += "STRUCTURE"; + else if ((res = expectThisString(".PEEK")) == ACCEPT) + f_in.type += ".PEEK"; if ((res = expectSection(f_in)) != ACCEPT) f_in.hassection = false; else { f_in.hassection = true; if ((res = expectOffset(f_in)) == ERROR) return ERROR; - } + } } else return REJECT; -- cgit v1.2.3