diff options
Diffstat (limited to 'src/operator-append.cc')
-rw-r--r-- | src/operator-append.cc | 101 |
1 files changed, 56 insertions, 45 deletions
diff --git a/src/operator-append.cc b/src/operator-append.cc index d4650ee..f4eaaa9 100644 --- a/src/operator-append.cc +++ b/src/operator-append.cc @@ -2,34 +2,30 @@ * @file operator-append.cc * @brief Implementation of the APPEND command. * @author Andreas Aardal Hanssen - * @date 2002-2005 + * @date 2002-2005 * ----------------------------------------------------------------- **/ -#include <algorithm> -#include <string> - -#include <fcntl.h> - #include "depot.h" #include "iodevice.h" #include "iofactory.h" #include "mailbox.h" #include "operators.h" -#include "recursivedescent.h" #include "pendingupdates.h" +#include "recursivedescent.h" #include "session.h" +#include <algorithm> +#include <string> + +#include <fcntl.h> + using namespace ::std; using namespace Binc; //---------------------------------------------------------------------- -AppendOperator::AppendOperator(void) -{ -} +AppendOperator::AppendOperator(void) {} //---------------------------------------------------------------------- -AppendOperator::~AppendOperator(void) -{ -} +AppendOperator::~AppendOperator(void) {} //---------------------------------------------------------------------- const string AppendOperator::getName(void) const @@ -44,8 +40,7 @@ int AppendOperator::getState(void) const } //------------------------------------------------------------------------ -Operator::ProcessResult AppendOperator::process(Depot &depot, - Request &command) +Operator::ProcessResult AppendOperator::process(Depot &depot, Request &command) { Session &session = Session::getInstance(); @@ -55,13 +50,12 @@ Operator::ProcessResult AppendOperator::process(Depot &depot, if ((mailbox = depot.get(canonmailbox)) == 0) { session.setResponseCode("TRYCREATE"); - session.setLastError("invalid destination mailbox " - + toImapString(srcmailbox)); + session.setLastError("invalid destination mailbox " + toImapString(srcmailbox)); return NO; } // mask all passed flags together - unsigned int newflags = (unsigned int) Message::F_NONE; + unsigned int newflags = (unsigned int)Message::F_NONE; vector<string>::const_iterator f_i = command.flags.begin(); while (f_i != command.flags.end()) { if (*f_i == "\\Deleted") newflags |= Message::F_DELETED; @@ -71,14 +65,20 @@ Operator::ProcessResult AppendOperator::process(Depot &depot, if (*f_i == "\\Flagged") newflags |= Message::F_FLAGGED; ++f_i; } - + int mday, year, hour, minute, second; char month[4]; struct tm mytm; - if (command.getDate() != "") { - sscanf(command.getDate().c_str(), "%2i-%3s-%4i %2i:%2i:%2i", - &mday, month, &year, &hour, &minute, &second); + if (command.getDate() != "") { + sscanf(command.getDate().c_str(), + "%2i-%3s-%4i %2i:%2i:%2i", + &mday, + month, + &year, + &hour, + &minute, + &second); month[3] = '\0'; string monthstr = month; @@ -88,18 +88,30 @@ Operator::ProcessResult AppendOperator::process(Depot &depot, mytm.tm_hour = hour; mytm.tm_year = year - 1900; mytm.tm_mday = mday; - if (monthstr == "jan") mytm.tm_mon = 0; - else if (monthstr == "feb") mytm.tm_mon = 1; - else if (monthstr == "mar") mytm.tm_mon = 2; - else if (monthstr == "apr") mytm.tm_mon = 3; - else if (monthstr == "may") mytm.tm_mon = 4; - else if (monthstr == "jun") mytm.tm_mon = 5; - else if (monthstr == "jul") mytm.tm_mon = 6; - else if (monthstr == "aug") mytm.tm_mon = 7; - else if (monthstr == "sep") mytm.tm_mon = 8; - else if (monthstr == "oct") mytm.tm_mon = 9; - else if (monthstr == "nov") mytm.tm_mon = 10; - else if (monthstr == "dec") mytm.tm_mon = 11; + if (monthstr == "jan") + mytm.tm_mon = 0; + else if (monthstr == "feb") + mytm.tm_mon = 1; + else if (monthstr == "mar") + mytm.tm_mon = 2; + else if (monthstr == "apr") + mytm.tm_mon = 3; + else if (monthstr == "may") + mytm.tm_mon = 4; + else if (monthstr == "jun") + mytm.tm_mon = 5; + else if (monthstr == "jul") + mytm.tm_mon = 6; + else if (monthstr == "aug") + mytm.tm_mon = 7; + else if (monthstr == "sep") + mytm.tm_mon = 8; + else if (monthstr == "oct") + mytm.tm_mon = 9; + else if (monthstr == "nov") + mytm.tm_mon = 10; + else if (monthstr == "dec") + mytm.tm_mon = 11; mytm.tm_isdst = -1; } @@ -111,7 +123,7 @@ Operator::ProcessResult AppendOperator::process(Depot &depot, session.setLastError("expected literal"); return BAD; } - + string nr; bool literalPlus = false; while (1) { @@ -138,7 +150,7 @@ Operator::ProcessResult AppendOperator::process(Depot &depot, return BAD; } - nr += (char) c; + nr += (char)c; } int nchars = atoi(nr.c_str()); @@ -163,8 +175,7 @@ Operator::ProcessResult AppendOperator::process(Depot &depot, time_t newtime = (command.getDate() != "") ? mktime(&mytm) : time(0); if (newtime == -1) newtime = time(0); - Message *dest = mailbox->createMessage(depot.mailboxToFilename(canonmailbox), - newtime); + Message *dest = mailbox->createMessage(depot.mailboxToFilename(canonmailbox), newtime); if (!dest) { session.setLastError(mailbox->getLastError()); return NO; @@ -222,15 +233,16 @@ Operator::ProcessResult AppendOperator::process(Depot &depot, dest->setInternalDate(mktime(&mytm)); if (!mailbox->commitNewMessages(depot.mailboxToFilename(canonmailbox))) { - session.setLastError("failed to commit after successful APPEND: " - + mailbox->getLastError()); + session.setLastError("failed to commit after successful APPEND: " + mailbox->getLastError()); return NO; } if (mailbox == depot.getSelected()) { - pendingUpdates(mailbox, PendingUpdates::EXISTS - | PendingUpdates::RECENT - | PendingUpdates::FLAGS, true, false, true); + pendingUpdates(mailbox, + PendingUpdates::EXISTS | PendingUpdates::RECENT | PendingUpdates::FLAGS, + true, + false, + true); } return OK; @@ -242,8 +254,7 @@ Operator::ParseResult AppendOperator::parse(Request &c_in) const Session &session = Session::getInstance(); Operator::ParseResult res; - if (c_in.getUidMode()) - return REJECT; + if (c_in.getUidMode()) return REJECT; if ((res = expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE after APPEND"); |