diff options
| author | Sam Varshavchik | 2013-08-19 16:39:41 -0400 |
|---|---|---|
| committer | Sam Varshavchik | 2013-08-25 14:43:51 -0400 |
| commit | 9c45d9ad13fdf439d44d7443ae75da15ea0223ed (patch) | |
| tree | 7a81a04cb51efb078ee350859a64be2ebc6b8813 /libmail/smapaddmessage.C | |
| parent | a9520698b770168d1f33d6301463bb70a19655ec (diff) | |
| download | courier-libs-9c45d9ad13fdf439d44d7443ae75da15ea0223ed.tar.bz2 | |
Initial checkin
Imported from subversion report, converted to git. Updated all paths in
scripts and makefiles, reflecting the new directory hierarchy.
Diffstat (limited to 'libmail/smapaddmessage.C')
| -rw-r--r-- | libmail/smapaddmessage.C | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/libmail/smapaddmessage.C b/libmail/smapaddmessage.C new file mode 100644 index 0000000..2224eb8 --- /dev/null +++ b/libmail/smapaddmessage.C @@ -0,0 +1,122 @@ +/* +** Copyright 2003-2008, Double Precision Inc. +** +** See COPYING for distribution information. +*/ +#include "smapaddmessage.H" +#include "smapadd.H" +#include "rfc822/rfc822.h" +#include <errno.h> +#include <sstream> +#include <cstring> + +using namespace std; + +mail::smapAddMessage::smapAddMessage(mail::imap &imapAccountArg, + mail::callback &callbackArg) + : addMessage(&imapAccountArg), + imapAccount(imapAccountArg), + callback(&callbackArg), + tfile(tmpfile()) +{ +} + +mail::smapAddMessage::~smapAddMessage() +{ + if (tfile) + fclose(tfile); + if (callback) + callback->fail("Operation aborted."); +} + +void mail::smapAddMessage::saveMessageContents(std::string contents) +{ + size_t n; + + while ((n=contents.find('\r')) != std::string::npos) + contents.erase(contents.begin()+n, + contents.begin()+n+1); + + if (tfile) + if (fwrite(&contents[0], contents.size(), 1, tfile) != 1) + ; // Ignore gcc warning +} + +void mail::smapAddMessage::go() +{ + if (!tfile || ferror(tfile) || fflush(tfile) || + fseek(tfile, 0L, SEEK_SET) < 0) + { + fail(strerror(errno)); + return; + } + + if (!checkServer()) + return; + + { + string flags; + +#define FLAG +#define NOTFLAG ! +#define DOFLAG(NOT, field, name) \ + if (NOT messageInfo.field) flags += "," name + + LIBMAIL_SMAPFLAGS; +#undef DOFLAG +#undef NOTFLAG +#undef FLAG + + if (flags.size() > 0) + flags=flags.substr(1); + + ostringstream o; + + o << "ADD FLAGS=" << flags; + + if (messageDate) + { + char buf[80]; + + rfc822_mkdate_buf(messageDate, buf); + + o << " \"INTERNALDATE=" << buf << "\""; + } + + o << "\n"; + + cmds.push_back(o.str()); + } + + smapAdd *add=new smapAdd(cmds, *callback); + + if (add) + { + callback=NULL; + add->tfile=tfile; + tfile=NULL; + } + + try { + imapAccount.installForegroundTask(add); + } catch (...) { + if (add) + delete add; + delete this; + LIBMAIL_THROW(LIBMAIL_THROW_EMPTY); + } + + delete this; +} + +void mail::smapAddMessage::fail(std::string errmsg) +{ + mail::callback *c=callback; + + callback=NULL; + delete this; + + if (c) + c->fail(errmsg); +} + |
