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
|
/*
** Copyright 2003, Double Precision Inc.
**
** See COPYING for distribution information.
*/
#include "smap.H"
#include "imapfolder.H"
#include "smapopen.H"
#include "smapnewmail.H"
#include <string.h>
#include <sstream>
using namespace std;
const char *mail::smapNEWMAIL::getName()
{
return "NEWMAIL";
}
mail::smapNEWMAIL::smapNEWMAIL(mail::callback *callbackArg,
bool isOpenArg)
: isOpen(isOpenArg), expectedFetchCount(0), fetchCount(0),
noopSent(false)
{
defaultCB= callbackArg;
}
mail::smapNEWMAIL::~smapNEWMAIL()
{
}
void mail::smapNEWMAIL::installed(imap &imapAccount)
{
imapFOLDERinfo *p=myimap->currentFolder;
if (p)
{
size_t n=p->index.size();
if (p->exists < n)
{
ostringstream o;
o << "FETCH " << p->exists+1 << "-" << n
<< " FLAGS UID\n" << flush;
expectedFetchCount=(n - p->exists)*2;
imapAccount.imapcmd("", o.str());
return;
}
}
smapHandler::ok("OK");
imapAccount.uninstallHandler(this);
}
//
// Report on our progress
//
void mail::smapNEWMAIL::fetchedIndexInfo()
{
++fetchCount;
if (fetchCount <= expectedFetchCount && defaultCB)
defaultCB->reportProgress(0, 0,
fetchCount/2,
expectedFetchCount/2);
}
bool mail::smapNEWMAIL::ok(std::string str)
{
if (!noopSent)
{
imapFOLDERinfo *p=myimap->currentFolder;
while (p && p->exists < p->index.size() &&
p->index[p->exists].uid.size() > 0)
++p->exists;
noopSent=true;
doDestroy=false;
myimap->imapcmd("", "NOOP\n"); // Get a snapshot
return true;
}
if (myimap->currentFolder)
{
if (isOpen)
myimap->currentFolder->opened();
else
myimap->currentFolder->folderCallback.newMessages();
}
return smapHandler::ok(str);
}
bool mail::smapNEWMAIL::fail(std::string str)
{
if (myimap->currentFolder)
{
if (isOpen)
myimap->currentFolder->opened();
else
myimap->currentFolder->folderCallback.newMessages();
}
return smapHandler::fail(str);
}
|