29string Message::lastError;
30string MaildirMessage::storage;
35 const string &s_in,
bool removecomments =
true)
49 const string &s_in,
bool removecomments =
true)
58 if (addr.size() != 0) {
60 for (vector<string>::const_iterator i = addr.begin();
75 printOneHeader(io, message,
"date");
77 printOneHeader(io, message,
"subject",
false);
79 printOneAddressList(io, message,
"from",
false);
81 printOneAddressList(io, message,
83 ?
"sender" :
"from",
false);
85 printOneAddressList(io, message,
87 ?
"reply-to" :
"from",
false);
89 printOneAddressList(io, message,
"to",
false);
91 printOneAddressList(io, message,
"cc",
false);
93 printOneAddressList(io, message,
"bcc",
false);
95 printOneHeader(io, message,
"in-reply-to");
97 printOneHeader(io, message,
"message-id");
108 for (vector<MimePart>::const_iterator i = message->
members.begin();
109 i != message->
members.end(); ++i)
110 bodyStructure(io, &(*i), extended);
118 vector<string> parameters;
119 vector<string> headers;
122 string type, subtype;
132 for (vector<string>::const_iterator i = v.begin(); i != v.end(); ++i) {
135 if (element.find(
'=') != string::npos) {
136 string::size_type pos = element.find(
'=');
137 string s = element.substr(0, pos);
138 string t = element.substr(pos + 1);
141 parameters.push_back(s);
142 parameters.push_back(t);
146 if (parameters.size() != 0) {
148 for (vector<string>::const_iterator i = parameters.begin();
149 i != parameters.end(); ++i) {
150 if (i != parameters.begin()) io <<
" ";
175 vector<string>::const_iterator i = v.begin();
178 while (i != v.end()) {
181 string::size_type pos = s.find(
'=');
182 string key = s.substr(0, pos);
183 string value = s.substr(pos + 1);
191 if (!wrote) wrote =
true;
211 printOneHeader(io, message,
"content-language");
217 vector<string> parameters;
218 vector<string> headers;
221 string type, subtype;
245 for (vector<string>::const_iterator i = v.begin(); i != v.end(); ++i) {
246 if (i == v.begin())
continue;
249 if (element.find(
'=') != string::npos) {
250 string::size_type pos = element.find(
'=');
251 string s = element.substr(0, pos);
252 string t = element.substr(pos + 1);
255 parameters.push_back(s);
256 parameters.push_back(t);
270 if (parameters.size() != 0) {
272 for (vector<string>::const_iterator i = parameters.begin();
273 i != parameters.end(); ++i) {
274 if (i != parameters.begin())
284 printOneHeader(io, message,
"content-id");
288 printOneHeader(io, message,
"content-description");
305 if (type ==
"text") {
310 envelope(io, &message->
members[0]);
312 bodyStructure(io, &message->
members[0], extended);
322 printOneHeader(io, message,
"content-md5");
339 vector<string>::const_iterator i = v.begin();
342 while (i != v.end()) {
345 string::size_type pos = s.find(
'=');
346 string key = s.substr(0, pos);
347 string value = s.substr(pos + 1);
352 if (!wrote) wrote =
true;
370 printOneHeader(io, message,
"content-language");
374 printOneHeader(io, message,
"content-location");
384 : fd(-1), doc(0), internalFlags(None), stdflags(F_NONE),
385 uid(0), size(0), unique(
""), safeName(
""), internaldate(0),
386 home(hom), customFlags(0)
392 : fd(copy.fd), doc(copy.doc), internalFlags(copy.internalFlags),
393 stdflags(copy.stdflags), uid(copy.uid), size(copy.size),
394 unique(copy.unique), safeName(copy.safeName),
395 internaldate(copy.internaldate), home(copy.home)
397 if (copy.customFlags) {
398 customFlags =
new vector<string>;
399 *customFlags = *copy.customFlags;
416 internalFlags = copy.internalFlags;
417 stdflags = copy.stdflags;
420 unique = copy.unique;
421 safeName = copy.safeName;
422 internaldate = copy.internaldate;
425 if (copy.customFlags) {
426 customFlags =
new vector<string>;
427 *customFlags = *copy.customFlags;
445 && errno != EINVAL && errno != EROFS) {
459 if (internaldate != 0) {
460 struct utimbuf tim = {internaldate, internaldate};
461 utime(safeName.c_str(), &tim);
464 struct utimbuf tim = {t, t};
465 utime(safeName.c_str(), &tim);
468 internalFlags &= ~WasWrittenTo;
488 internalFlags &= ~Expunged;
494 internalFlags &= ~FlagsChanged;
512 return (internalFlags &
Expunged) != 0;
524 if (size == 0 && render) {
526 home.mailboxchanged =
true;
591 string fpath = home.path +
"/cur/" + item->
fileName;
593 unsigned int oflags = O_RDONLY;
594#ifdef HAVE_OLARGEFILE
595 oflags |= O_LARGEFILE;
597 while ((fd = open(fpath.c_str(), oflags)) == -1) {
598 if (errno == ENOENT) {
600 if (lstat(fpath.c_str(), &st) != -1) {
601 bincWarning <<
"dangling symlink: " << fpath << endl;
606 << strerror(errno) << endl;
611 if ((item = home.index.
find(
id)) == 0)
614 fpath = home.path +
"/cur/" + item->
fileName;
667 ssize_t readBytes = read(fd, buffer, (
size_t)
sizeof(buffer));
668 if (readBytes == -1) {
670 +
": " +
string(strerror(errno)));
674 chunk = string(buffer, readBytes);
683 +
": File is not open");
690 for (string::const_iterator i = chunk.begin(); i != chunk.end(); ++i) {
696 ssize_t wroteBytes = 0;
698 wroteBytes = write(fd, out.c_str(), (
size_t) out.length());
699 if (wroteBytes == -1) {
708 if (wroteBytes == (ssize_t) out.length())
712 +
": " +
string(strerror(errno)));
783 std::vector<std::string> headers,
785 unsigned int startOffset,
796 std::vector<std::string> headers,
798 unsigned int startOffset,
821 includeHeaders, startOffset,
824 return storage.size();
829 unsigned int startOffset,
830 unsigned int length)
const
852 unsigned int startOffset,
853 unsigned int length)
const
867 unsigned int s = part->
bodylength - startOffset;
868 return s < length ? s : length;
873 unsigned int length,
bool onlyText)
const
898 unsigned int s = doc->
size;
905 return s < length ? s : length;
910 const std::string &text)
923 return (tmp.find(tmp2) != string::npos);
944 char *ring =
new char[text.length()];
947 const char *textStr = text.c_str();
948 unsigned int textLength = text.length();
950 ring[pos % textLength] = toupper(c);
975 char *ring =
new char[text.length()];
977 const char *textStr = text.c_str();
978 unsigned int textLength = text.length();
980 ring[pos % textLength] = toupper(c);
997 static string NIL =
"";
1010MaildirMessageCache::MaildirMessageCache(
void)
1031 if (statuses.find(m) == statuses.end()) {
1033 if (statuses.size() > 2) {
1039 parsed.push_back(m);
1049 if (statuses.find(m) == statuses.end())
1058 for (deque<const MaildirMessage *>::iterator i = parsed.begin();
1059 i != parsed.end(); ++i)
1069 if (statuses.find(m) == statuses.end())
1072 statuses.erase(statuses.find(m));
1074 for (deque<const MaildirMessage *>::iterator i = parsed.begin();
1075 i != parsed.end(); ++i) {
1093 return internalFlags;
1099 internalFlags &= ~f;
1107 customFlags =
new vector<string>;
1110 for (vector<string>::const_iterator it = customFlags->begin();
1111 it != customFlags->end(); ++it) {
1117 customFlags->push_back(flag);
1128 for (vector<string>::iterator it = customFlags->begin();
1129 it != customFlags->end(); ++it) {
1131 customFlags->erase(it);
1150 return vector<string>();
1152 return *customFlags;
std::string toParenList(void) const
The IODevice class provides a framework for reading and writing to device.
bool scanFileNames(void) const
MaildirIndexItem * find(const std::string &unique)
void addStatus(const MaildirMessage *, ParseStatus pstat)
static MaildirMessageCache & getInstance(void)
void removeStatus(const MaildirMessage *)
ParseStatus getStatus(const MaildirMessage *) const
The MaildirMessage class provides an interface for IMAP messages.
bool printBody(const std::string §ion="", unsigned int startOffset=0, unsigned int length=UINTMAX) const
void setUnique(const std::string &s_in)
void setInternalDate(time_t internaldate)
bool appendChunk(const std::string &chunk)
unsigned int getBodySize(const std::string §ion, unsigned int startOffset=0, unsigned int length=UINTMAX) const
const std::string & getHeader(const std::string &header)
bool parseHeaders(void) const
unsigned char getInternalFlags(void) const
void setFlagsUnchanged(void)
std::vector< std::string > getCustomFlags(void) const
void setUID(unsigned int uid)
bool printDoc(unsigned int startOffset=0, unsigned int length=UINTMAX, bool onlyText=false) const
void setCustomFlag(const std::string &flag)
bool printBodyStructure(bool extended=true) const
bool textContains(const std::string &text)
bool parseFull(void) const
bool printHeader(const std::string §ion, std::vector< std::string > headers, bool includeHeaders=false, unsigned int startOffset=0, unsigned int length=UINTMAX, bool mime=false) const
bool bodyContains(const std::string &text)
bool printEnvelope(void) const
void resetCustomFlags(void)
bool headerContains(const std::string &header, const std::string &text)
unsigned int getSize(bool determine=false) const
unsigned int getUID(void) const
const std::string & getSafeName(void) const
void setSize(unsigned int size)
unsigned int getDocSize(unsigned int startOffset=0, unsigned int length=UINTMAX, bool onlyText=false) const
MaildirMessage(Maildir &home)
void setSafeName(const std::string &name)
void setInternalFlag(unsigned char flags)
std::string getFileName(void) const
const std::string & getUnique(void) const
bool isExpunged(void) const
unsigned char getStdFlags(void) const
void clearInternalFlag(unsigned char flags)
void setStdFlag(unsigned char flags)
MaildirMessage & operator=(const MaildirMessage ©)
unsigned int getHeaderSize(const std::string §ion, std::vector< std::string > headers, bool includeHeaders=false, unsigned int startOffset=0, unsigned int length=UINTMAX, bool mime=false) const
int readChunk(std::string &chunk)
bool hasFlagsChanged(void) const
bool operator<(const MaildirMessage &a) const
void removeCustomFlag(const std::string &flag)
time_t getInternalDate(void) const
void setLastError(const std::string &) const
void parseFull(int fd) const
void parseOnlyHeader(int fd) const
bool isMessageRFC822(void) const
void printBody(int fd, Binc::IODevice &output, unsigned int startoffset, unsigned int length) const
unsigned int getBodyStartOffset(void) const
std::vector< MimePart > members
unsigned int getNofBodyLines(void) const
void printHeader(int fd, Binc::IODevice &output, std::vector< std::string > headers, bool includeheaders, unsigned int startoffset, unsigned int length, std::string &storage) const
unsigned int getBodyLength(void) const
unsigned int bodystartoffsetcrlf
bool isMultipart(void) const
const MimePart * getPart(const std::string &findpart, std::string genpart, FetchType fetchType=FetchBody) const
const std::string & getSubType(void) const
void printDoc(int fd, Binc::IODevice &output, unsigned int startoffset, unsigned int length) const
Declaration of miscellaneous convertion functions.
Declaration of the IODevice class.
Declaration of the IOFactory class.
Declaration of the Maildir class.
Declaration of the MaildirMessage class.
bool compareStringToQueue(const char *s_in, char *bqueue, int pos, int size)
Declaration of main mime parser components.
std::string toImapString(const std::string &s_in)
void splitAddr(const std::string &s_in, std::vector< std::string > &dest, bool skipempty=true)
const std::string unfold(const std::string &a, bool removecomment=true)
void split(const std::string &s_in, const std::string &delim, std::vector< std::string > &dest, bool skipempty=true)
void uppercase(std::string &input)
void lowercase(std::string &input)
void trim(std::string &s_in, const std::string &chars=" \t\r\n")