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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
|
/*
** Copyright 2002, Double Precision Inc.
**
** See COPYING for distribution information.
*/
#ifndef libmail_generic_H
#define libmail_generic_H
#include "libmail_config.h"
///////////////////////////////////////////////////////////////////////
//
// A primitive set of message access APIs, used by dumb drivers
// to implement the mail::account/IMAP-like message access.
//
// A driver may not have a direct implementation for some of the advanced
// methods (such as the MIME section version of readMessageContent, or
// the MIMESTRUCTURE request of readMessageAttributes).
//
// The alternative, used by the dumb drivers, is to implement the
// mail::generic interface:
//
// genericMessageRead() - read the header, or the body, or both portions of
// the message.
//
// genericMessageSize() - return just the size of the message.
//
// genericGetMessageFd(), genericGetMessageStruct(),
// genericGetMessageFdStruct() - return a descriptor of a temporary file
// with the message's contents, and/or the rfc2045 parse of the message.
// The dumb driver is expected to cache this data. The likelyhood of
// multiple calls to these functions, for the same message, is rather high,
// so the driver should act accordingly.
// The dumb driver does not need to implement genericGetMessageFdStruct,
// if not mail::generic will provide a default, PROVIDED THAT the file
// descriptor is guaranteed to remain valid after genericGetMessageFd()
// if genericGetMessageStruct() is immediately called for the same msg. TODO
//
// genericReadMessageContent()/genericReadMessageContentDecode() - a dumb
// driver can optionally implement these method. If not, mail::generic
// will use the previous three functions to do the job.
//
// genericCachedUid(std::string uid) - return true if the generics subclass
// has message UID cached (used by generics to optimize implementation).
//
// genericAttributes() - implemented entirely by mail::generic.
//
// --
//
// fixMessageNumber() - to handle any concurrency issues, the generic
// functions also keep track of the message's UID. fixMessageNumber()
// updates the message number, based on its uid, in the event that the
// folder's contents were changed in progress.
#include "mail.H"
#include "maildir/maildirkeywords.h"
struct rfc2045;
LIBMAIL_START
class generic {
class Attributes;
public:
generic();
virtual ~generic();
virtual void genericMessageRead(std::string uid,
size_t messageNumber,
bool peek,
mail::readMode
readType,
mail::callback::message &callback)=0;
virtual void genericMessageSize(std::string uid,
size_t messageNumber,
mail::callback::message &callback)=0;
virtual void genericGetMessageFd(std::string uid,
size_t messageNumber,
bool peek,
int &fdRet,
mail::callback &callback)=0;
// NOTE: fdRet gets initialized, then the callback function is invoked.
// The file descriptor remains valid ONLY UNTIL the callback function
// terminates, at which point the file descriptor may be closed.
// The callback function must dup the descriptor, if it needs to.
virtual void genericGetMessageStruct(std::string uid,
size_t messageNumber,
struct rfc2045 *&structRet,
mail::callback &callback)=0;
// NOTE: structRet gets initialized, then the callback function is
// invoked. structRet remains valid ONLY UNTIL the callback function
// terminates, at which point the structure may get deleted.
virtual void genericGetMessageFdStruct(std::string uid,
size_t messageNumber,
bool peek,
int &fdRet,
struct rfc2045 *&structret,
mail::callback &callback);
virtual bool genericCachedUid(std::string uid)=0;
virtual void genericMarkRead(size_t messageNumber)=0;
// Mark this msg as read, invoking a callback, if needed.
// See above.
static void genericReadMessageContent(mail::account *account,
generic *generic,
const std::vector<size_t>
&messages,
bool peek,
enum mail::readMode readType,
mail::callback::message
&callback);
static void genericReadMessageContent(mail::account *account,
generic *generic,
size_t messageNum,
bool peek,
const mimestruct &msginfo,
enum mail::readMode readType,
mail::callback::message
&callback);
static void genericReadMessageContentDecoded(mail::account *account,
generic *generic,
size_t messageNum,
bool peek,
const mimestruct
&info,
mail::callback::message
&callback);
static void genericMoveMessages(mail::account *account,
const std::vector<size_t> &messages,
mail::folder *copyTo,
mail::callback &callback);
//
// Generic keyword update for drivers that implement temporary
// keywords only (keywords are not saved, and are lost when the
// mail account is closed).
//
// genericUpdateKeywords() is intended to be invoked directly by
// updateKeywords(). It will dutifully iterate over the supplied
// message set, and update each message's keywords, one by one.
//
// The interface between the generic implementation, and the
// implementing driver is a bit tricky.
// The driver needs to implement the genericProcessKeyword() method.
// In the method, the driver needs to find the mail::keywords::Message
// object for message #n, and invoke the doUpdateKeyword() method,
// passing the reference to the mail::keywords::Message object as
// the sole argument. if the driver cannot locate the
// mail::keywords::Message object (can happen in the mbox driver, if
// the message was removed by another process, but the application
// hasn't noop-ed or expunged the folder).
class updateKeywordHelper {
public:
const std::set<std::string> &keywords;
bool setOrChange;
bool changeTo;
updateKeywordHelper(const std::set<std::string> &keywordsArg,
bool setOrChangeArg,
bool changeToArg);
~updateKeywordHelper();
bool doUpdateKeyword(mail::keywords::Message &,
mail::keywords::Hashtable &);
};
virtual bool genericProcessKeyword(size_t messageNumber,
updateKeywordHelper &helper);
static void genericUpdateKeywords(const std::vector<size_t> &messages,
const std::set<std::string> &keywords,
bool setOrChange,
// false: set, true: see changeTo
bool changeTo,
mail::callback::folder
*folderCallback,
generic *generic,
callback &cb);
private:
class Move;
class GetMessageFdStruct;
class ReadMultiple;
class ReadMimePart;
class CopyMimePart;
static void genericMakeMimeStructure(mimestruct &s,
int fd, struct rfc2045 *rfcp,
std::string mimeId,
envelope *saveEnvelope);
//
// Create a mimestruct, (and a envelope, if necessary)
// from a rfc2045 parse of a MIME section
public:
static void genericBuildEnvelope(std::string header, std::string value,
envelope &envelope);
class Decode;
static void genericAttributes(mail::account *account,
generic *genericInterface,
const std::vector<size_t> &msgs,
mail::account::MessageAttributes attributes,
mail::callback::message &callback);
static bool fixMessageNumber(mail::account *account,
std::string uid,
size_t &msgNum);
static void genericRemoveMessages(mail::account *account,
const std::vector<size_t> &messages,
callback &cb);
private:
class Remove;
};
LIBMAIL_END
#endif
|