1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
/*
** Copyright 2003, Double Precision Inc.
**
** See COPYING for distribution information.
*/
#include "smap.H"
#include "smapnoopexpunge.H"
#include "imapfolder.H"
#include <sstream>
using namespace std;
const char *mail::smapNoopExpunge::getName()
{
return cmd;
}
mail::smapNoopExpunge::smapNoopExpunge(const char *cmdArg,
mail::callback &callbackArg,
mail::imap &imapAccount)
: cmd(cmdArg), uidSet( imapAccount, vector<size_t>()),
expungeSet(false), existsOrExpungeFlag(false)
{
defaultCB= &callbackArg;
}
mail::smapNoopExpunge::smapNoopExpunge(const vector<size_t> &messageList,
mail::callback &callbackArg,
mail::imap &imapAccount)
: cmd("EXPUNGE"), uidSet( imapAccount, messageList),
expungeSet(true), existsOrExpungeFlag(false)
{
defaultCB= &callbackArg;
}
void mail::smapNoopExpunge::existsOrExpungeSeen()
{
existsOrExpungeFlag=true;
}
mail::smapNoopExpunge::smapNoopExpunge(const char *cmdArg,
mail::imap &imapAccount)
: cmd(cmdArg), uidSet(imapAccount, vector<size_t>()),
expungeSet(false), existsOrExpungeFlag(false)
{
defaultCB=NULL;
}
mail::smapNoopExpunge::~smapNoopExpunge()
{
}
void mail::smapNoopExpunge::installed(imap &imapAccount)
{
string imapCommand=cmd;
if (expungeSet)
{
ostringstream o;
if (!uidSet.getNextRange(imapAccount, o))
{
mail::callback *p=defaultCB;
defaultCB=NULL;
imapAccount.uninstallHandler(this);
if (p)
p->success("OK");
return;
}
imapCommand += o.str();
}
imapAccount.imapcmd("", imapCommand + "\n");
}
bool mail::smapNoopExpunge::ok(std::string okmsg)
{
if (expungeSet)
{
ostringstream o; // More?
o << "EXPUNGE";
if (uidSet.getNextRange(*myimap, o))
{
o << "\n";
myimap->imapcmd("", o.str());
doDestroy=false;
return true;
}
}
// If a NOOP/EXPUNGE found new messages, we don't want to invoke the
// callback function right away, because we must wait for
// smapNEWMAIL to finish populating the message index.
// Simply do this by requeueing another NOOP request at the end of
// the task queue.
//
if (existsOrExpungeFlag && defaultCB)
{
myimap->installForegroundTask(new smapNoopExpunge("NOOP",
*defaultCB,
*myimap)
);
defaultCB=NULL;
}
return smapHandler::ok(okmsg);
}
bool mail::smapNoopExpunge::fail(std::string okmsg)
{
if (existsOrExpungeFlag)
myimap->installForegroundTask(new smapNoopExpunge("NOOP",
*myimap));
return smapHandler::fail(okmsg);
}
|