summaryrefslogtreecommitdiff
path: root/src/maildirmessage.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/maildirmessage.cc')
-rw-r--r--src/maildirmessage.cc543
1 files changed, 255 insertions, 288 deletions
diff --git a/src/maildirmessage.cc b/src/maildirmessage.cc
index a78a5b9..ee1d889 100644
--- a/src/maildirmessage.cc
+++ b/src/maildirmessage.cc
@@ -4,24 +4,26 @@
* @author Andreas Aardal Hanssen
* @date Copyright 2002-2005
* ----------------------------------------------------------------- **/
-#include <string>
-
-#include <stack>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
-#include <ctype.h>
-#include <time.h>
-#include <utime.h>
-
-#include "maildir.h"
#include "maildirmessage.h"
+
#include "convert.h"
-#include "mime.h"
#include "iodevice.h"
#include "iofactory.h"
-#include "mime-utils.h"
+#include "maildir.h"
#include "mime-inputsource.h"
+#include "mime-utils.h"
+#include "mime.h"
+
+#include <stack>
+#include <string>
+
+#include <ctype.h>
+#include <errno.h>
+#include <time.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <utime.h>
using namespace ::std;
using namespace Binc;
@@ -31,8 +33,10 @@ string MaildirMessage::storage;
namespace {
//----------------------------------------------------------------------
- void printOneHeader(IODevice &io, const MimePart *message,
- const string &s_in, bool removecomments = true)
+ void printOneHeader(IODevice &io,
+ const MimePart *message,
+ const string &s_in,
+ bool removecomments = true)
{
string tmp = "";
HeaderItem hitem;
@@ -45,8 +49,10 @@ namespace {
}
//----------------------------------------------------------------------
- void printOneAddressList(IODevice &io, const MimePart *message,
- const string &s_in, bool removecomments = true)
+ void printOneAddressList(IODevice &io,
+ const MimePart *message,
+ const string &s_in,
+ bool removecomments = true)
{
string tmp = "";
HeaderItem hitem;
@@ -57,12 +63,12 @@ namespace {
splitAddr(unfold(tmp, removecomments), addr);
if (addr.size() != 0) {
io << "(";
- for (vector<string>::const_iterator i = addr.begin();
- i != addr.end(); ++i)
+ for (vector<string>::const_iterator i = addr.begin(); i != addr.end(); ++i)
- io << Address(*i).toParenList();
+ io << Address(*i).toParenList();
io << ")";
- } else io << "NIL";
+ } else
+ io << "NIL";
} else
io << "NIL";
}
@@ -78,13 +84,15 @@ namespace {
io << " ";
printOneAddressList(io, message, "from", false);
io << " ";
- printOneAddressList(io, message,
- message->h.getFirstHeader("sender", hitem)
- ? "sender" : "from", false);
+ printOneAddressList(io,
+ message,
+ message->h.getFirstHeader("sender", hitem) ? "sender" : "from",
+ false);
io << " ";
- printOneAddressList(io, message,
- message->h.getFirstHeader("reply-to", hitem)
- ? "reply-to" : "from", false);
+ printOneAddressList(io,
+ message,
+ message->h.getFirstHeader("reply-to", hitem) ? "reply-to" : "from",
+ false);
io << " ";
printOneAddressList(io, message, "to", false);
io << " ";
@@ -104,9 +112,9 @@ namespace {
HeaderItem hitem;
if (message->isMultipart() && message->members.size() > 0) {
io << "(";
-
- for (vector<MimePart>::const_iterator i = message->members.begin();
- i != message->members.end(); ++i)
+
+ for (vector<MimePart>::const_iterator i = message->members.begin(); i != message->members.end();
+ ++i)
bodyStructure(io, &(*i), extended);
io << " ";
@@ -128,7 +136,7 @@ namespace {
vector<string> v;
split(tmp, ";", v);
-
+
for (vector<string>::const_iterator i = v.begin(); i != v.end(); ++i) {
string element = *i;
trim(element);
@@ -145,18 +153,17 @@ namespace {
if (parameters.size() != 0) {
io << "(";
- for (vector<string>::const_iterator i = parameters.begin();
- i != parameters.end(); ++i) {
+ for (vector<string>::const_iterator i = parameters.begin(); i != parameters.end(); ++i) {
if (i != parameters.begin()) io << " ";
io << toImapString(*i);
- }
+ }
io << ")";
} else
io << "NIL";
} else
io << "NIL";
- // CONTENT-DISPOSITION
+ // CONTENT-DISPOSITION
io << " ";
tmp = "";
if (message->h.getFirstHeader("content-disposition", hitem)) {
@@ -188,8 +195,10 @@ namespace {
trim(key, " \"");
trim(value, " \"");
- if (!wrote) wrote = true;
- else io << " ";
+ if (!wrote)
+ wrote = true;
+ else
+ io << " ";
io << toImapString(key);
io << " ";
@@ -198,15 +207,15 @@ namespace {
++i;
}
io << ")";
- } else
- io << "NIL";
- io << ")";
+ } else
+ io << "NIL";
+ io << ")";
} else
- io << "NIL";
+ io << "NIL";
} else
- io << "NIL";
+ io << "NIL";
- // CONTENT-LANGUAGE
+ // CONTENT-LANGUAGE
io << " ";
printOneHeader(io, message, "content-language");
}
@@ -224,38 +233,38 @@ namespace {
if (message->h.getFirstHeader("content-type", hitem)) {
tmp = unfold(hitem.getValue());
- vector<string> v;
- split(tmp, ";", v);
-
- if (v.size() > 0) {
- vector<string> b;
- split(v[0], "/", b);
-
- if (b.size() > 0)
- type = b[0];
- else
- type = "text";
-
- if (b.size() > 1)
- subtype = b[1];
- else
- subtype = "plain";
- }
-
- for (vector<string>::const_iterator i = v.begin(); i != v.end(); ++i) {
- if (i == v.begin()) continue;
- string element = *i;
- trim(element);
- if (element.find('=') != string::npos) {
- string::size_type pos = element.find('=');
- string s = element.substr(0, pos);
- string t = element.substr(pos + 1);
- trim(s, " \"");
- trim(t, " \"");
- parameters.push_back(s);
- parameters.push_back(t);
+ vector<string> v;
+ split(tmp, ";", v);
+
+ if (v.size() > 0) {
+ vector<string> b;
+ split(v[0], "/", b);
+
+ if (b.size() > 0)
+ type = b[0];
+ else
+ type = "text";
+
+ if (b.size() > 1)
+ subtype = b[1];
+ else
+ subtype = "plain";
+ }
+
+ for (vector<string>::const_iterator i = v.begin(); i != v.end(); ++i) {
+ if (i == v.begin()) continue;
+ string element = *i;
+ trim(element);
+ if (element.find('=') != string::npos) {
+ string::size_type pos = element.find('=');
+ string s = element.substr(0, pos);
+ string t = element.substr(pos + 1);
+ trim(s, " \"");
+ trim(t, " \"");
+ parameters.push_back(s);
+ parameters.push_back(t);
+ }
}
- }
} else {
type = "text";
@@ -269,15 +278,13 @@ namespace {
io << " ";
if (parameters.size() != 0) {
io << "(";
- for (vector<string>::const_iterator i = parameters.begin();
- i != parameters.end(); ++i) {
- if (i != parameters.begin())
- io << " ";
+ for (vector<string>::const_iterator i = parameters.begin(); i != parameters.end(); ++i) {
+ if (i != parameters.begin()) io << " ";
io << toImapString(*i);
}
io << ")";
} else
- io << "NIL";
+ io << "NIL";
// CONTENT-ID
io << " ";
@@ -317,59 +324,61 @@ namespace {
// Extension data follows
if (extended) {
- // CONTENT-MD5
- io << " ";
- printOneHeader(io, message, "content-md5");
-
- // CONTENT-DISPOSITION
- io << " ";
- tmp = "";
- if (message->h.getFirstHeader("content-disposition", hitem)) {
- tmp = hitem.getValue();
- trim(tmp);
- vector<string> v;
- split(tmp, ";", v);
- if (v.size() > 0) {
- string disp = v[0];
- trim(disp);
- io << "(" << toImapString(disp);
- io << " ";
- if (v.size() > 1) {
- io << "(";
- vector<string>::const_iterator i = v.begin();
- ++i;
- bool wrote = false;
- while (i != v.end()) {
- string s = *i;
- trim(s);
- string::size_type pos = s.find('=');
- string key = s.substr(0, pos);
- string value = s.substr(pos + 1);
- trim(key);
- trim(value);
- trim(key, " \"");
- trim(value, " \"");
- if (!wrote) wrote = true;
- else io << " ";
- io << toImapString(key);
- io << " ";
- io << toImapString(value);
- ++i;
- }
- io << ")";
- } else
- io << "NIL";
- io << ")";
- } else
- io << "NIL";
- } else
- io << "NIL";
-
- // CONTENT-LANGUAGE
+ // CONTENT-MD5
+ io << " ";
+ printOneHeader(io, message, "content-md5");
+
+ // CONTENT-DISPOSITION
+ io << " ";
+ tmp = "";
+ if (message->h.getFirstHeader("content-disposition", hitem)) {
+ tmp = hitem.getValue();
+ trim(tmp);
+ vector<string> v;
+ split(tmp, ";", v);
+ if (v.size() > 0) {
+ string disp = v[0];
+ trim(disp);
+ io << "(" << toImapString(disp);
+ io << " ";
+ if (v.size() > 1) {
+ io << "(";
+ vector<string>::const_iterator i = v.begin();
+ ++i;
+ bool wrote = false;
+ while (i != v.end()) {
+ string s = *i;
+ trim(s);
+ string::size_type pos = s.find('=');
+ string key = s.substr(0, pos);
+ string value = s.substr(pos + 1);
+ trim(key);
+ trim(value);
+ trim(key, " \"");
+ trim(value, " \"");
+ if (!wrote)
+ wrote = true;
+ else
+ io << " ";
+ io << toImapString(key);
+ io << " ";
+ io << toImapString(value);
+ ++i;
+ }
+ io << ")";
+ } else
+ io << "NIL";
+ io << ")";
+ } else
+ io << "NIL";
+ } else
+ io << "NIL";
+
+ // CONTENT-LANGUAGE
io << " ";
printOneHeader(io, message, "content-language");
- // CONTENT-LOCATION
+ // CONTENT-LOCATION
io << " ";
printOneHeader(io, message, "content-location");
}
@@ -380,19 +389,32 @@ namespace {
}
//------------------------------------------------------------------------
-MaildirMessage::MaildirMessage(Maildir &hom)
- : fd(-1), doc(0), internalFlags(None), stdflags(F_NONE),
- uid(0), size(0), unique(""), safeName(""), internaldate(0),
- home(hom), customFlags(0)
-{
-}
+MaildirMessage::MaildirMessage(Maildir &hom)
+ : fd(-1)
+ , doc(0)
+ , internalFlags(None)
+ , stdflags(F_NONE)
+ , uid(0)
+ , size(0)
+ , unique("")
+ , safeName("")
+ , internaldate(0)
+ , home(hom)
+ , customFlags(0)
+{}
//------------------------------------------------------------------------
-MaildirMessage::MaildirMessage(const MaildirMessage &copy)
- : fd(copy.fd), doc(copy.doc), internalFlags(copy.internalFlags),
- stdflags(copy.stdflags), uid(copy.uid), size(copy.size),
- unique(copy.unique), safeName(copy.safeName),
- internaldate(copy.internaldate), home(copy.home)
+MaildirMessage::MaildirMessage(const MaildirMessage &copy)
+ : fd(copy.fd)
+ , doc(copy.doc)
+ , internalFlags(copy.internalFlags)
+ , stdflags(copy.stdflags)
+ , uid(copy.uid)
+ , size(copy.size)
+ , unique(copy.unique)
+ , safeName(copy.safeName)
+ , internaldate(copy.internaldate)
+ , home(copy.home)
{
if (copy.customFlags) {
customFlags = new vector<string>;
@@ -409,15 +431,15 @@ MaildirMessage::~MaildirMessage(void)
}
//------------------------------------------------------------------------
-MaildirMessage &MaildirMessage::operator =(const MaildirMessage &copy)
+MaildirMessage &MaildirMessage::operator=(const MaildirMessage &copy)
{
fd = copy.fd;
- doc = copy.doc;
+ doc = copy.doc;
internalFlags = copy.internalFlags;
stdflags = copy.stdflags;
uid = copy.uid;
size = copy.size;
- unique = copy.unique;
+ unique = copy.unique;
safeName = copy.safeName;
internaldate = copy.internaldate;
home = copy.home;
@@ -433,16 +455,16 @@ MaildirMessage &MaildirMessage::operator =(const MaildirMessage &copy)
}
//------------------------------------------------------------------------
-bool MaildirMessage::operator <(const MaildirMessage &a) const
+bool MaildirMessage::operator<(const MaildirMessage &a) const
{
return uid < a.uid;
}
+
//------------------------------------------------------------------------
void MaildirMessage::close(void)
{
if (fd != -1) {
- if ((internalFlags & WasWrittenTo) && fsync(fd) != 0
- && errno != EINVAL && errno != EROFS) {
+ if ((internalFlags & WasWrittenTo) && fsync(fd) != 0 && errno != EINVAL && errno != EROFS) {
// FIXME: report this error
}
@@ -582,14 +604,13 @@ void MaildirMessage::setUnique(const string &s_in)
//------------------------------------------------------------------------
int MaildirMessage::getFile(void) const
{
- if (fd != -1)
- return fd;
+ if (fd != -1) return fd;
const string &id = getUnique();
MaildirIndexItem *item = home.index.find(id);
if (item) {
string fpath = home.path + "/cur/" + item->fileName;
-
+
unsigned int oflags = O_RDONLY;
#ifdef HAVE_OLARGEFILE
oflags |= O_LARGEFILE;
@@ -598,20 +619,19 @@ int MaildirMessage::getFile(void) const
if (errno == ENOENT) {
struct stat st;
if (lstat(fpath.c_str(), &st) != -1) {
- bincWarning << "dangling symlink: " << fpath << endl;
- return -1;
+ bincWarning << "dangling symlink: " << fpath << endl;
+ return -1;
}
} else {
- bincWarning << "unable to open " << fpath << ": "
- << strerror(errno) << endl;
- return -1;
+ bincWarning << "unable to open " << fpath << ": " << strerror(errno) << endl;
+ return -1;
}
home.scanFileNames();
if ((item = home.index.find(id)) == 0)
- break;
+ break;
else
- fpath = home.path + "/cur/" + item->fileName;
+ fpath = home.path + "/cur/" + item->fileName;
}
MaildirMessageCache &cache = MaildirMessageCache::getInstance();
@@ -648,8 +668,7 @@ string MaildirMessage::getFileName(void) const
if (!item) {
home.scanFileNames();
- if ((item = home.index.find(getUnique())) == 0)
- return "";
+ if ((item = home.index.find(getUnique())) == 0) return "";
}
return item->fileName;
@@ -659,15 +678,13 @@ string MaildirMessage::getFileName(void) const
int MaildirMessage::readChunk(string &chunk)
{
if (fd == -1) {
- if ((fd = getFile()) == -1)
- return -1;
+ if ((fd = getFile()) == -1) return -1;
}
char buffer[1024];
- ssize_t readBytes = read(fd, buffer, (size_t) sizeof(buffer));
+ ssize_t readBytes = read(fd, buffer, (size_t)sizeof(buffer));
if (readBytes == -1) {
- setLastError("Error reading from " + getFileName()
- + ": " + string(strerror(errno)));
+ setLastError("Error reading from " + getFileName() + ": " + string(strerror(errno)));
return -1;
}
@@ -679,8 +696,7 @@ int MaildirMessage::readChunk(string &chunk)
bool MaildirMessage::appendChunk(const string &chunk)
{
if (fd == -1) {
- setLastError("Error writing to " + getSafeName()
- + ": File is not open");
+ setLastError("Error writing to " + getSafeName() + ": File is not open");
return false;
}
@@ -689,27 +705,23 @@ bool MaildirMessage::appendChunk(const string &chunk)
string out;
for (string::const_iterator i = chunk.begin(); i != chunk.end(); ++i) {
const char c = *i;
- if (c != '\r')
- out += c;
+ if (c != '\r') out += c;
}
ssize_t wroteBytes = 0;
for (;;) {
- wroteBytes = write(fd, out.c_str(), (size_t) out.length());
+ wroteBytes = write(fd, out.c_str(), (size_t)out.length());
if (wroteBytes == -1) {
- if (errno == EINTR)
- continue;
+ if (errno == EINTR) continue;
wroteBytes = 0;
}
break;
}
- if (wroteBytes == (ssize_t) out.length())
- return true;
+ if (wroteBytes == (ssize_t)out.length()) return true;
- setLastError("Error writing to " + getSafeName()
- + ": " + string(strerror(errno)));
+ setLastError("Error writing to " + getSafeName() + ": " + string(strerror(errno)));
return false;
}
@@ -718,16 +730,13 @@ bool MaildirMessage::parseFull(void) const
{
MaildirMessageCache &cache = MaildirMessageCache::getInstance();
MaildirMessageCache::ParseStatus ps = cache.getStatus(this);
- if (ps == MaildirMessageCache::AllParsed && doc)
- return true;
+ if (ps == MaildirMessageCache::AllParsed && doc) return true;
int fd = getFile();
- if (fd == -1)
- return false;
+ if (fd == -1) return false;
// FIXME: parse errors
- if (!doc)
- doc = new MimeDocument;
+ if (!doc) doc = new MimeDocument;
doc->parseFull(fd);
cache.addStatus(this, MaildirMessageCache::AllParsed);
@@ -740,17 +749,14 @@ bool MaildirMessage::parseHeaders(void) const
{
MaildirMessageCache &cache = MaildirMessageCache::getInstance();
MaildirMessageCache::ParseStatus ps = cache.getStatus(this);
- if ((ps == MaildirMessageCache::AllParsed
- || ps == MaildirMessageCache::HeaderParsed) && doc)
+ if ((ps == MaildirMessageCache::AllParsed || ps == MaildirMessageCache::HeaderParsed) && doc)
return true;
int fd = getFile();
- if (fd == -1)
- return false;
+ if (fd == -1) return false;
// FIXME: parse errors
- if (!doc)
- doc = new MimeDocument;
+ if (!doc) doc = new MimeDocument;
doc->parseOnlyHeader(fd);
cache.addStatus(this, MaildirMessageCache::HeaderParsed);
@@ -761,8 +767,7 @@ bool MaildirMessage::parseHeaders(void) const
//------------------------------------------------------------------------
bool MaildirMessage::printBodyStructure(bool extended) const
{
- if (!parseFull())
- return false;
+ if (!parseFull()) return false;
bodyStructure(bincClient, doc, extended);
return true;
@@ -771,8 +776,7 @@ bool MaildirMessage::printBodyStructure(bool extended) const
//------------------------------------------------------------------------
bool MaildirMessage::printEnvelope(void) const
{
- if (!parseFull())
- return false;
+ if (!parseFull()) return false;
envelope(bincClient, doc);
return true;
@@ -780,11 +784,11 @@ bool MaildirMessage::printEnvelope(void) const
//------------------------------------------------------------------------
bool MaildirMessage::printHeader(const std::string &section,
- std::vector<std::string> headers,
- bool includeHeaders,
- unsigned int startOffset,
- unsigned int length,
- bool mime) const
+ std::vector<std::string> headers,
+ bool includeHeaders,
+ unsigned int startOffset,
+ unsigned int length,
+ bool mime) const
{
bincClient << storage;
storage = "";
@@ -793,44 +797,38 @@ bool MaildirMessage::printHeader(const std::string &section,
//------------------------------------------------------------------------
unsigned int MaildirMessage::getHeaderSize(const std::string &section,
- std::vector<std::string> headers,
- bool includeHeaders,
- unsigned int startOffset,
- unsigned int length,
- bool mime) const
+ std::vector<std::string> headers,
+ bool includeHeaders,
+ unsigned int startOffset,
+ unsigned int length,
+ bool mime) const
{
if (section == "") {
- if (!parseHeaders())
- return 0;
+ if (!parseHeaders()) return 0;
} else if (!parseFull())
return 0;
- const MimePart *part = doc->getPart(section, "", mime ? MimePart::FetchMime
- : MimePart::FetchHeader);
+ const MimePart *part = doc->getPart(section, "", mime ? MimePart::FetchMime : MimePart::FetchHeader);
if (!part) {
storage = "";
return 0;
}
int fd = getFile();
- if (fd == -1)
- return 0;
+ if (fd == -1) return 0;
storage = "";
- part->printHeader(fd, bincClient, headers,
- includeHeaders, startOffset,
- length, storage);
+ part->printHeader(fd, bincClient, headers, includeHeaders, startOffset, length, storage);
return storage.size();
}
//------------------------------------------------------------------------
bool MaildirMessage::printBody(const std::string &section,
- unsigned int startOffset,
- unsigned int length) const
+ unsigned int startOffset,
+ unsigned int length) const
{
- if (!parseFull())
- return false;
+ if (!parseFull()) return false;
const MimePart *part = doc->getPart(section, "");
if (!part) {
@@ -839,8 +837,7 @@ bool MaildirMessage::printBody(const std::string &section,
}
int fd = getFile();
- if (fd == -1)
- return false;
+ if (fd == -1) return false;
storage = "";
part->printBody(fd, bincClient, startOffset, length);
@@ -849,11 +846,10 @@ bool MaildirMessage::printBody(const std::string &section,
//------------------------------------------------------------------------
unsigned int MaildirMessage::getBodySize(const std::string &section,
- unsigned int startOffset,
- unsigned int length) const
+ unsigned int startOffset,
+ unsigned int length) const
{
- if (!parseFull())
- return false;
+ if (!parseFull()) return false;
const MimePart *part = doc->getPart(section, "");
if (!part) {
@@ -861,26 +857,21 @@ unsigned int MaildirMessage::getBodySize(const std::string &section,
return 0;
}
- if (startOffset > part->bodylength)
- return 0;
-
+ if (startOffset > part->bodylength) return 0;
+
unsigned int s = part->bodylength - startOffset;
return s < length ? s : length;
}
//------------------------------------------------------------------------
-bool MaildirMessage::printDoc(unsigned int startOffset,
- unsigned int length, bool onlyText) const
+bool MaildirMessage::printDoc(unsigned int startOffset, unsigned int length, bool onlyText) const
{
- if (!parseFull())
- return false;
+ if (!parseFull()) return false;
int fd = getFile();
- if (fd == -1)
- return false;
+ if (fd == -1) return false;
- if (onlyText)
- startOffset += doc->bodystartoffsetcrlf;
+ if (onlyText) startOffset += doc->bodystartoffsetcrlf;
storage = "";
doc->printDoc(fd, bincClient, startOffset, length);
@@ -889,32 +880,27 @@ bool MaildirMessage::printDoc(unsigned int startOffset,
//------------------------------------------------------------------------
unsigned int MaildirMessage::getDocSize(unsigned int startOffset,
- unsigned int length,
- bool onlyText) const
+ unsigned int length,
+ bool onlyText) const
{
- if (!parseFull())
- return false;
+ if (!parseFull()) return false;
unsigned int s = doc->size;
if (onlyText) s -= doc->bodystartoffsetcrlf;
- if (startOffset > s)
- return 0;
+ if (startOffset > s) return 0;
s -= startOffset;
return s < length ? s : length;
}
//------------------------------------------------------------------------
-bool MaildirMessage::headerContains(const std::string &header,
- const std::string &text)
+bool MaildirMessage::headerContains(const std::string &header, const std::string &text)
{
- if (!parseHeaders())
- return false;
+ if (!parseHeaders()) return false;
HeaderItem hitem;
- if (!doc->h.getFirstHeader(header, hitem))
- return false;
+ if (!doc->h.getFirstHeader(header, hitem)) return false;
string tmp = hitem.getValue();
uppercase(tmp);
@@ -926,21 +912,18 @@ bool MaildirMessage::headerContains(const std::string &header,
//------------------------------------------------------------------------
bool MaildirMessage::bodyContains(const std::string &text)
{
- if (!parseFull())
- return false;
+ if (!parseFull()) return false;
// search the body part of the message..
int fd = getFile();
- if (fd == -1)
- return false;
+ if (fd == -1) return false;
MimeInputSource mimeSource(fd);
char c;
for (unsigned int i = 0; i < doc->getBodyStartOffset(); ++i)
- if (!mimeSource.getChar(&c))
- break;
-
+ if (!mimeSource.getChar(&c)) break;
+
char *ring = new char[text.length()];
int pos = 0;
int length = doc->getBodyLength();
@@ -948,15 +931,15 @@ bool MaildirMessage::bodyContains(const std::string &text)
unsigned int textLength = text.length();
while (mimeSource.getChar(&c) && length--) {
ring[pos % textLength] = toupper(c);
-
+
if (compareStringToQueue(textStr, ring, pos + 1, textLength)) {
delete[] ring;
return true;
}
-
+
++pos;
}
-
+
delete[] ring;
return false;
}
@@ -966,8 +949,7 @@ bool MaildirMessage::textContains(const std::string &text)
{
// search the body part of the message..
int fd = getFile();
- if (fd == -1)
- return false;
+ if (fd == -1) return false;
MimeInputSource mimeSource(fd);
@@ -978,15 +960,15 @@ bool MaildirMessage::textContains(const std::string &text)
unsigned int textLength = text.length();
while (mimeSource.getChar(&c)) {
ring[pos % textLength] = toupper(c);
-
+
if (compareStringToQueue(textStr, ring, pos + 1, textLength)) {
delete[] ring;
return true;
}
-
+
++pos;
}
-
+
delete[] ring;
return false;
}
@@ -996,20 +978,16 @@ const std::string &MaildirMessage::getHeader(const std::string &header)
{
static string NIL = "";
- if (!parseHeaders())
- return NIL;
+ if (!parseHeaders()) return NIL;
HeaderItem hitem;
- if (!doc->h.getFirstHeader(header, hitem))
- return NIL;
-
- return hitem.getValue();
+ if (!doc->h.getFirstHeader(header, hitem)) return NIL;
+
+ return hitem.getValue();
}
//------------------------------------------------------------------------
-MaildirMessageCache::MaildirMessageCache(void)
-{
-}
+MaildirMessageCache::MaildirMessageCache(void) {}
//------------------------------------------------------------------------
MaildirMessageCache::~MaildirMessageCache(void)
@@ -1025,8 +1003,7 @@ MaildirMessageCache &MaildirMessageCache::getInstance(void)
}
//------------------------------------------------------------------------
-void MaildirMessageCache::addStatus(const MaildirMessage *m,
- ParseStatus s)
+void MaildirMessageCache::addStatus(const MaildirMessage *m, ParseStatus s)
{
if (statuses.find(m) == statuses.end()) {
// Insert status. Perhaps remove oldest status.
@@ -1043,11 +1020,9 @@ void MaildirMessageCache::addStatus(const MaildirMessage *m,
}
//------------------------------------------------------------------------
-MaildirMessageCache::ParseStatus
-MaildirMessageCache::getStatus(const MaildirMessage *m) const
+MaildirMessageCache::ParseStatus MaildirMessageCache::getStatus(const MaildirMessage *m) const
{
- if (statuses.find(m) == statuses.end())
- return NotParsed;
+ if (statuses.find(m) == statuses.end()) return NotParsed;
return statuses[m];
}
@@ -1055,8 +1030,7 @@ MaildirMessageCache::getStatus(const MaildirMessage *m) const
//------------------------------------------------------------------------
void MaildirMessageCache::clear(void)
{
- for (deque<const MaildirMessage *>::iterator i = parsed.begin();
- i != parsed.end(); ++i)
+ for (deque<const MaildirMessage *>::iterator i = parsed.begin(); i != parsed.end(); ++i)
const_cast<MaildirMessage *>(*i)->close();
parsed.clear();
@@ -1066,13 +1040,11 @@ void MaildirMessageCache::clear(void)
//------------------------------------------------------------------------
void MaildirMessageCache::removeStatus(const MaildirMessage *m)
{
- if (statuses.find(m) == statuses.end())
- return;
+ if (statuses.find(m) == statuses.end()) return;
statuses.erase(statuses.find(m));
- for (deque<const MaildirMessage *>::iterator i = parsed.begin();
- i != parsed.end(); ++i) {
+ for (deque<const MaildirMessage *>::iterator i = parsed.begin(); i != parsed.end(); ++i) {
if (*i == m) {
const_cast<MaildirMessage *>(*i)->close();
parsed.erase(i);
@@ -1107,10 +1079,8 @@ void MaildirMessage::setCustomFlag(const string &flag)
customFlags = new vector<string>;
}
- for (vector<string>::const_iterator it = customFlags->begin();
- it != customFlags->end(); ++it) {
- if (*it == flag)
- return;
+ for (vector<string>::const_iterator it = customFlags->begin(); it != customFlags->end(); ++it) {
+ if (*it == flag) return;
}
internalFlags |= FlagsChanged | CustomFlagsChanged;
@@ -1122,11 +1092,9 @@ void MaildirMessage::removeCustomFlag(const string &flag)
{
internalFlags |= FlagsChanged | CustomFlagsChanged;
- if (!customFlags)
- return;
+ if (!customFlags) return;
- for (vector<string>::iterator it = customFlags->begin();
- it != customFlags->end(); ++it) {
+ for (vector<string>::iterator it = customFlags->begin(); it != customFlags->end(); ++it) {
if (*it == flag) {
customFlags->erase(it);
return;
@@ -1146,8 +1114,7 @@ void MaildirMessage::resetCustomFlags(void)
//------------------------------------------------------------------------
vector<string> MaildirMessage::getCustomFlags(void) const
{
- if (!customFlags)
- return vector<string>();
+ if (!customFlags) return vector<string>();
return *customFlags;
}