aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/net/fetchAttributes.cpp94
-rw-r--r--src/net/imap/IMAPFolder.cpp11
-rw-r--r--src/net/imap/IMAPMessage.cpp9
-rw-r--r--src/net/imap/IMAPUtils.cpp22
-rw-r--r--src/net/maildir/maildirFolder.cpp11
-rw-r--r--src/net/maildir/maildirMessage.cpp26
-rw-r--r--src/net/pop3/POP3Folder.cpp18
-rw-r--r--src/net/pop3/POP3Message.cpp18
8 files changed, 155 insertions, 54 deletions
diff --git a/src/net/fetchAttributes.cpp b/src/net/fetchAttributes.cpp
new file mode 100644
index 00000000..b98e573f
--- /dev/null
+++ b/src/net/fetchAttributes.cpp
@@ -0,0 +1,94 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2013 Vincent Richard <[email protected]>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 3 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// Linking this library statically or dynamically with other modules is making
+// a combined work based on this library. Thus, the terms and conditions of
+// the GNU General Public License cover the whole combination.
+//
+
+#include "vmime/config.hpp"
+
+
+#if VMIME_HAVE_MESSAGING_FEATURES
+
+
+#include "vmime/net/fetchAttributes.hpp"
+
+#include "vmime/utility/stringUtils.hpp"
+
+#include <algorithm>
+
+
+namespace vmime {
+namespace net {
+
+
+fetchAttributes::fetchAttributes()
+ : m_predefinedAttribs(0)
+{
+}
+
+
+fetchAttributes::fetchAttributes(const int attribs)
+ : m_predefinedAttribs(attribs)
+{
+}
+
+
+fetchAttributes::fetchAttributes(const fetchAttributes& attribs)
+{
+ m_predefinedAttribs = attribs.m_predefinedAttribs;
+ m_headers = attribs.m_headers;
+}
+
+
+void fetchAttributes::add(const int attribs)
+{
+ m_predefinedAttribs = attribs;
+}
+
+
+void fetchAttributes::add(const string& header)
+{
+ m_headers.push_back(utility::stringUtils::toLower(header));
+}
+
+
+bool fetchAttributes::has(const int attribs) const
+{
+ return (m_predefinedAttribs & attribs) != 0;
+}
+
+
+bool fetchAttributes::has(const string& header) const
+{
+ return std::find(m_headers.begin(), m_headers.end(), utility::stringUtils::toLower(header)) != m_headers.end();
+}
+
+
+const std::vector <string> fetchAttributes::getHeaderFields() const
+{
+ return m_headers;
+}
+
+
+} // net
+} // vmime
+
+
+#endif // VMIME_HAVE_MESSAGING_FEATURES
diff --git a/src/net/imap/IMAPFolder.cpp b/src/net/imap/IMAPFolder.cpp
index 94d7ab13..3a3615e6 100644
--- a/src/net/imap/IMAPFolder.cpp
+++ b/src/net/imap/IMAPFolder.cpp
@@ -751,7 +751,7 @@ std::vector <ref <folder> > IMAPFolder::getFolders(const bool recursive)
}
-void IMAPFolder::fetchMessages(std::vector <ref <message> >& msg, const int options,
+void IMAPFolder::fetchMessages(std::vector <ref <message> >& msg, const fetchAttributes& options,
utility::progressListener* progress)
{
ref <IMAPStore> store = m_store.acquire();
@@ -845,7 +845,7 @@ void IMAPFolder::fetchMessages(std::vector <ref <message> >& msg, const int opti
}
-void IMAPFolder::fetchMessage(ref <message> msg, const int options)
+void IMAPFolder::fetchMessage(ref <message> msg, const fetchAttributes& options)
{
std::vector <ref <message> > msgs;
msgs.push_back(msg);
@@ -856,9 +856,10 @@ void IMAPFolder::fetchMessage(ref <message> msg, const int options)
int IMAPFolder::getFetchCapabilities() const
{
- return (FETCH_ENVELOPE | FETCH_CONTENT_INFO | FETCH_STRUCTURE |
- FETCH_FLAGS | FETCH_SIZE | FETCH_FULL_HEADER | FETCH_UID |
- FETCH_IMPORTANCE);
+ return fetchAttributes::ENVELOPE | fetchAttributes::CONTENT_INFO |
+ fetchAttributes::STRUCTURE | fetchAttributes::FLAGS |
+ fetchAttributes::SIZE | fetchAttributes::FULL_HEADER |
+ fetchAttributes::UID | fetchAttributes::IMPORTANCE;
}
diff --git a/src/net/imap/IMAPMessage.cpp b/src/net/imap/IMAPMessage.cpp
index 33599689..d512e752 100644
--- a/src/net/imap/IMAPMessage.cpp
+++ b/src/net/imap/IMAPMessage.cpp
@@ -366,7 +366,7 @@ void IMAPMessage::extractImpl(ref <const messagePart> p, utility::outputStream&
int IMAPMessage::processFetchResponse
- (const int options, const IMAPParser::message_data* msgData)
+ (const fetchAttributes& options, const IMAPParser::message_data* msgData)
{
ref <IMAPFolder> folder = m_folder.acquire();
@@ -403,7 +403,7 @@ int IMAPMessage::processFetchResponse
}
case IMAPParser::msg_att_item::ENVELOPE:
{
- if (!(options & folder::FETCH_FULL_HEADER))
+ if (!options.has(fetchAttributes::FULL_HEADER))
{
const IMAPParser::envelope* env = (*it)->envelope();
ref <vmime::header> hdr = getOrCreateHeader();
@@ -478,7 +478,7 @@ int IMAPMessage::processFetchResponse
}
case IMAPParser::msg_att_item::BODY_SECTION:
{
- if (!(options & folder::FETCH_FULL_HEADER))
+ if (!options.has(fetchAttributes::FULL_HEADER))
{
if ((*it)->section()->section_text1() &&
(*it)->section()->section_text1()->type()
@@ -599,7 +599,8 @@ ref <vmime::message> IMAPMessage::getParsedMessage()
std::vector <ref <message> > msgs;
msgs.push_back(thisRef().dynamicCast <IMAPMessage>());
- m_folder.acquire()->fetchMessages(msgs, IMAPFolder::FETCH_STRUCTURE, /* progress */ NULL);
+ m_folder.acquire()->fetchMessages
+ (msgs, fetchAttributes(fetchAttributes::STRUCTURE), /* progress */ NULL);
structure = getStructure();
}
diff --git a/src/net/imap/IMAPUtils.cpp b/src/net/imap/IMAPUtils.cpp
index 13373012..caaf6575 100644
--- a/src/net/imap/IMAPUtils.cpp
+++ b/src/net/imap/IMAPUtils.cpp
@@ -544,7 +544,7 @@ const string IMAPUtils::dateTime(const vmime::datetime& date)
// static
const string IMAPUtils::buildFetchRequest
- (ref <IMAPConnection> cnt, const messageSet& msgs, const int options)
+ (ref <IMAPConnection> cnt, const messageSet& msgs, const fetchAttributes& options)
{
// Example:
// C: A654 FETCH 2:4 (FLAGS BODY[HEADER.FIELDS (DATE FROM)])
@@ -555,16 +555,16 @@ const string IMAPUtils::buildFetchRequest
std::vector <string> items;
- if (options & folder::FETCH_SIZE)
+ if (options.has(fetchAttributes::SIZE))
items.push_back("RFC822.SIZE");
- if (options & folder::FETCH_FLAGS)
+ if (options.has(fetchAttributes::FLAGS))
items.push_back("FLAGS");
- if (options & folder::FETCH_STRUCTURE)
+ if (options.has(fetchAttributes::STRUCTURE))
items.push_back("BODYSTRUCTURE");
- if (options & folder::FETCH_UID)
+ if (options.has(fetchAttributes::UID))
{
items.push_back("UID");
@@ -573,24 +573,28 @@ const string IMAPUtils::buildFetchRequest
items.push_back("MODSEQ");
}
- if (options & folder::FETCH_FULL_HEADER)
+ if (options.has(fetchAttributes::FULL_HEADER))
items.push_back("RFC822.HEADER");
else
{
- if (options & folder::FETCH_ENVELOPE)
+ if (options.has(fetchAttributes::ENVELOPE))
items.push_back("ENVELOPE");
std::vector <string> headerFields;
- if (options & folder::FETCH_CONTENT_INFO)
+ if (options.has(fetchAttributes::CONTENT_INFO))
headerFields.push_back("CONTENT_TYPE");
- if (options & folder::FETCH_IMPORTANCE)
+ if (options.has(fetchAttributes::IMPORTANCE))
{
headerFields.push_back("IMPORTANCE");
headerFields.push_back("X-PRIORITY");
}
+ // Also add custom header fields to fetch, if any
+ const std::vector <string> customHeaderFields = options.getHeaderFields();
+ std::copy(customHeaderFields.begin(), customHeaderFields.end(), std::back_inserter(headerFields));
+
if (!headerFields.empty())
{
string list;
diff --git a/src/net/maildir/maildirFolder.cpp b/src/net/maildir/maildirFolder.cpp
index 42a2c5ff..ae4c17e0 100644
--- a/src/net/maildir/maildirFolder.cpp
+++ b/src/net/maildir/maildirFolder.cpp
@@ -1178,7 +1178,7 @@ ref <store> maildirFolder::getStore()
void maildirFolder::fetchMessages(std::vector <ref <message> >& msg,
- const int options, utility::progressListener* progress)
+ const fetchAttributes& options, utility::progressListener* progress)
{
ref <maildirStore> store = m_store.acquire();
@@ -1209,7 +1209,7 @@ void maildirFolder::fetchMessages(std::vector <ref <message> >& msg,
}
-void maildirFolder::fetchMessage(ref <message> msg, const int options)
+void maildirFolder::fetchMessage(ref <message> msg, const fetchAttributes& options)
{
ref <maildirStore> store = m_store.acquire();
@@ -1225,9 +1225,10 @@ void maildirFolder::fetchMessage(ref <message> msg, const int options)
int maildirFolder::getFetchCapabilities() const
{
- return (FETCH_ENVELOPE | FETCH_STRUCTURE | FETCH_CONTENT_INFO |
- FETCH_FLAGS | FETCH_SIZE | FETCH_FULL_HEADER | FETCH_UID |
- FETCH_IMPORTANCE);
+ return fetchAttributes::ENVELOPE | fetchAttributes::STRUCTURE |
+ fetchAttributes::CONTENT_INFO | fetchAttributes::FLAGS |
+ fetchAttributes::SIZE | fetchAttributes::FULL_HEADER |
+ fetchAttributes::UID | fetchAttributes::IMPORTANCE;
}
diff --git a/src/net/maildir/maildirMessage.cpp b/src/net/maildir/maildirMessage.cpp
index a7c2a22f..d20481d4 100644
--- a/src/net/maildir/maildirMessage.cpp
+++ b/src/net/maildir/maildirMessage.cpp
@@ -246,7 +246,7 @@ void maildirMessage::fetchPartHeader(ref <messagePart> p)
}
-void maildirMessage::fetch(ref <maildirFolder> msgFolder, const int options)
+void maildirMessage::fetch(ref <maildirFolder> msgFolder, const fetchAttributes& options)
{
ref <maildirFolder> folder = m_folder.acquire();
@@ -258,18 +258,18 @@ void maildirMessage::fetch(ref <maildirFolder> msgFolder, const int options)
const utility::file::path path = folder->getMessageFSPath(m_num);
ref <utility::file> file = fsf->create(path);
- if (options & folder::FETCH_FLAGS)
+ if (options.has(fetchAttributes::FLAGS))
m_flags = maildirUtils::extractFlags(path.getLastComponent());
- if (options & folder::FETCH_SIZE)
+ if (options.has(fetchAttributes::SIZE))
m_size = file->getLength();
- if (options & folder::FETCH_UID)
+ if (options.has(fetchAttributes::UID))
m_uid = maildirUtils::extractId(path.getLastComponent()).getBuffer();
- if (options & (folder::FETCH_ENVELOPE | folder::FETCH_CONTENT_INFO |
- folder::FETCH_FULL_HEADER | folder::FETCH_STRUCTURE |
- folder::FETCH_IMPORTANCE))
+ if (options.has(fetchAttributes::ENVELOPE | fetchAttributes::CONTENT_INFO |
+ fetchAttributes::FULL_HEADER | fetchAttributes::STRUCTURE |
+ fetchAttributes::IMPORTANCE))
{
string contents;
@@ -277,7 +277,7 @@ void maildirMessage::fetch(ref <maildirFolder> msgFolder, const int options)
ref <utility::inputStream> is = reader->getInputStream();
// Need whole message contents for structure
- if (options & folder::FETCH_STRUCTURE)
+ if (options.has(fetchAttributes::STRUCTURE))
{
utility::stream::value_type buffer[16384];
@@ -321,16 +321,16 @@ void maildirMessage::fetch(ref <maildirFolder> msgFolder, const int options)
msg.parse(contents);
// Extract structure
- if (options & folder::FETCH_STRUCTURE)
+ if (options.has(fetchAttributes::STRUCTURE))
{
m_structure = vmime::create <maildirMessageStructure>(null, msg);
}
// Extract some header fields or whole header
- if (options & (folder::FETCH_ENVELOPE |
- folder::FETCH_CONTENT_INFO |
- folder::FETCH_FULL_HEADER |
- folder::FETCH_IMPORTANCE))
+ if (options.has(fetchAttributes::ENVELOPE |
+ fetchAttributes::CONTENT_INFO |
+ fetchAttributes::FULL_HEADER |
+ fetchAttributes::IMPORTANCE))
{
getOrCreateHeader()->copyFrom(*(msg.getHeader()));
}
diff --git a/src/net/pop3/POP3Folder.cpp b/src/net/pop3/POP3Folder.cpp
index 6a652de0..ffff121e 100644
--- a/src/net/pop3/POP3Folder.cpp
+++ b/src/net/pop3/POP3Folder.cpp
@@ -308,7 +308,7 @@ std::vector <ref <folder> > POP3Folder::getFolders(const bool /* recursive */)
}
-void POP3Folder::fetchMessages(std::vector <ref <message> >& msg, const int options,
+void POP3Folder::fetchMessages(std::vector <ref <message> >& msg, const fetchAttributes& options,
utility::progressListener* progress)
{
ref <POP3Store> store = m_store.acquire();
@@ -334,7 +334,7 @@ void POP3Folder::fetchMessages(std::vector <ref <message> >& msg, const int opti
progress->progress(++current, total);
}
- if (options & FETCH_SIZE)
+ if (options.has(fetchAttributes::SIZE))
{
// Send the "LIST" command
POP3Command::LIST()->send(store->getConnection());
@@ -374,7 +374,7 @@ void POP3Folder::fetchMessages(std::vector <ref <message> >& msg, const int opti
}
- if (options & FETCH_UID)
+ if (options.has(fetchAttributes::UID))
{
// Send the "UIDL" command
POP3Command::UIDL()->send(store->getConnection());
@@ -411,7 +411,7 @@ void POP3Folder::fetchMessages(std::vector <ref <message> >& msg, const int opti
}
-void POP3Folder::fetchMessage(ref <message> msg, const int options)
+void POP3Folder::fetchMessage(ref <message> msg, const fetchAttributes& options)
{
ref <POP3Store> store = m_store.acquire();
@@ -423,7 +423,7 @@ void POP3Folder::fetchMessage(ref <message> msg, const int options)
msg.dynamicCast <POP3Message>()->fetch
(thisRef().dynamicCast <POP3Folder>(), options);
- if (options & FETCH_SIZE)
+ if (options.has(fetchAttributes::SIZE))
{
// Send the "LIST" command
POP3Command::LIST(msg->getNumber())->send(store->getConnection());
@@ -456,7 +456,7 @@ void POP3Folder::fetchMessage(ref <message> msg, const int options)
}
}
- if (options & FETCH_UID)
+ if (options.has(fetchAttributes::UID))
{
// Send the "UIDL" command
POP3Command::UIDL(msg->getNumber())->send(store->getConnection());
@@ -489,9 +489,9 @@ void POP3Folder::fetchMessage(ref <message> msg, const int options)
int POP3Folder::getFetchCapabilities() const
{
- return (FETCH_ENVELOPE | FETCH_CONTENT_INFO |
- FETCH_SIZE | FETCH_FULL_HEADER | FETCH_UID |
- FETCH_IMPORTANCE);
+ return fetchAttributes::ENVELOPE | fetchAttributes::CONTENT_INFO |
+ fetchAttributes::SIZE | fetchAttributes::FULL_HEADER |
+ fetchAttributes::UID | fetchAttributes::IMPORTANCE;
}
diff --git a/src/net/pop3/POP3Message.cpp b/src/net/pop3/POP3Message.cpp
index 5b883e15..bad25cb9 100644
--- a/src/net/pop3/POP3Message.cpp
+++ b/src/net/pop3/POP3Message.cpp
@@ -172,28 +172,28 @@ void POP3Message::fetchPartHeader(ref <messagePart> /* p */)
}
-void POP3Message::fetch(ref <POP3Folder> msgFolder, const int options)
+void POP3Message::fetch(ref <POP3Folder> msgFolder, const fetchAttributes& options)
{
ref <POP3Folder> folder = m_folder.acquire();
if (folder != msgFolder)
throw exceptions::folder_not_found();
- // FETCH_STRUCTURE and FETCH_FLAGS are not supported by POP3.
- if (options & (folder::FETCH_STRUCTURE | folder::FETCH_FLAGS))
+ // STRUCTURE and FLAGS attributes are not supported by POP3
+ if (options.has(fetchAttributes::STRUCTURE | fetchAttributes::FLAGS))
throw exceptions::operation_not_supported();
// Check for the real need to fetch the full header
static const int optionsRequiringHeader =
- folder::FETCH_ENVELOPE | folder::FETCH_CONTENT_INFO |
- folder::FETCH_FULL_HEADER | folder::FETCH_IMPORTANCE;
+ fetchAttributes::ENVELOPE | fetchAttributes::CONTENT_INFO |
+ fetchAttributes::FULL_HEADER | fetchAttributes::IMPORTANCE;
- if (!(options & optionsRequiringHeader))
+ if (!options.has(optionsRequiringHeader))
return;
- // No need to differenciate between FETCH_ENVELOPE,
- // FETCH_CONTENT_INFO, ... since POP3 only permits to
- // retrieve the whole header and not fields in particular.
+ // No need to differenciate between ENVELOPE, CONTENT_INFO, ...
+ // since POP3 only permits to retrieve the whole header and not
+ // fields in particular.
// Emit the "TOP" command
ref <POP3Store> store = folder->m_store.acquire();