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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
/* $Id: smapfetch.C,v 1.2 2004/06/14 00:18:43 mrsam Exp $
**
** Copyright 2003, Double Precision Inc.
**
** See COPYING for distribution information.
*/
#include "smapfetch.H"
using namespace std;
const char *mail::smapFETCH::getName()
{
return "FETCHMESSAGE";
}
mail::smapFETCH::smapFETCH(const std::vector<size_t> &messages,
bool peek,
std::string mime_id,
mail::readMode getType,
const char *decoded,
mail::callback::message &msgcallbackArg,
mail::imap &imapAccount)
: uidSet(imapAccount, messages),
msgcallback(msgcallbackArg),
expectedCount(messages.size()),
countProcessed(0)
{
defaultCB= &msgcallbackArg;
string element;
switch (getType) {
case mail::readHeadersFolded:
element="HEADERS";
break;
case mail::readContents:
element="BODY";
break;
case mail::readBoth:
element="ALL";
break;
case mail::readHeaders:
element="RAWHEADERS";
break;
}
fetchingMessageNum=0;
if (decoded && *decoded)
element += decoded;
if (mime_id.size() > 0)
mime_id="[" + mime_id + "]";
fetchCmd= mail::imap::quoteSMAP((peek ? "CONTENTS.PEEK=":"CONTENTS=")
+ element + mime_id);
}
mail::smapFETCH::~smapFETCH()
{
}
void mail::smapFETCH::installed(imap &imapAccount)
{
msgRange.init(imapAccount, uidSet);
uidSet.clear();
if (go())
return;
ok("OK");
imapAccount.uninstallHandler(this);
}
bool mail::smapFETCH::ok(std::string msg)
{
if (go())
{
doDestroy=false;
return true;
}
return smapHandler::ok(msg);
}
bool mail::smapFETCH::go()
{
ostringstream msgList;
msgList << "FETCH";
if (!myimap->currentFolder ||
myimap->currentFolder->closeInProgress ||
!(msgRange >> msgList))
return false;
msgList << " " << fetchCmd << "\n";
myimap->imapcmd("", msgList.str());
return true;
}
void mail::smapFETCH::beginProcessData(imap &imapAccount,
std::vector<const char *> &words,
unsigned long estimatedSizeArg)
{
estimatedSize=estimatedSizeArg;
sizeDone=0;
if (words.size() >= 2 && strcasecmp(words[0], "FETCH") == 0)
{
string n=words[1];
istringstream i(n);
fetchingMessageNum=0;
i >> fetchingMessageNum;
}
}
void mail::smapFETCH::processData(imap &imapAccount,
std::string data)
{
if (fetchingMessageNum > 0)
{
if ((sizeDone += data.size()) > estimatedSize)
estimatedSize=sizeDone;
msgcallback.reportProgress(sizeDone, estimatedSize,
countProcessed, expectedCount);
msgcallback.messageTextCallback(fetchingMessageNum-1,
data);
}
}
void mail::smapFETCH::endData(imap &imapAccount)
{
if (++countProcessed > expectedCount)
expectedCount=countProcessed;
msgcallback.reportProgress(sizeDone, sizeDone, countProcessed,
expectedCount);
}
|