aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2013-11-14 22:17:40 +0000
committerVincent Richard <[email protected]>2013-11-14 22:17:40 +0000
commit5915ca4e34d2192cb3ef06c8f47aaa4b16cf7f53 (patch)
treedf93293cf51e856abb91d8391cea9242362cefd7
parentAdded missing export specifiers. (diff)
downloadvmime-5915ca4e34d2192cb3ef06c8f47aaa4b16cf7f53.tar.gz
vmime-5915ca4e34d2192cb3ef06c8f47aaa4b16cf7f53.zip
Custom fetch attributes.
-rw-r--r--SConstruct7
-rw-r--r--doc/book/net.tex21
-rw-r--r--examples/example6.cpp8
-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
-rw-r--r--tests/net/maildir/maildirStoreTest.cpp2
-rw-r--r--vmime/net/fetchAttributes.hpp142
-rw-r--r--vmime/net/folder.hpp27
-rw-r--r--vmime/net/imap/IMAPFolder.hpp4
-rw-r--r--vmime/net/imap/IMAPMessage.hpp4
-rw-r--r--vmime/net/imap/IMAPUtils.hpp2
-rw-r--r--vmime/net/maildir/maildirFolder.hpp4
-rw-r--r--vmime/net/maildir/maildirMessage.hpp2
-rw-r--r--vmime/net/pop3/POP3Folder.hpp4
-rw-r--r--vmime/net/pop3/POP3Message.hpp2
21 files changed, 344 insertions, 94 deletions
diff --git a/SConstruct b/SConstruct
index 9874e19a..2da57e1f 100644
--- a/SConstruct
+++ b/SConstruct
@@ -203,6 +203,7 @@ libvmime_messaging_sources = [
'net/connectionInfos.hpp',
'net/defaultConnectionInfos.cpp', 'net/defaultConnectionInfos.hpp',
'net/events.cpp', 'net/events.hpp',
+ 'net/fetchAttributes.cpp', 'net/fetchAttributes.hpp',
'net/folder.cpp', 'net/folder.hpp',
'net/folderStatus.hpp',
'net/message.cpp', 'net/message.hpp',
@@ -828,6 +829,12 @@ export_hpp = open('vmime/export-static.hpp', 'w')
export_hpp.write("""
#define VMIME_EXPORT
#define VMIME_NO_EXPORT
+
+#ifndef VMIME_DEPRECATED
+# define VMIME_DEPRECATED __attribute__ ((__deprecated__))
+# define VMIME_DEPRECATED_EXPORT VMIME_EXPORT __attribute__ ((__deprecated__))
+# define VMIME_DEPRECATED_NO_EXPORT VMIME_NO_EXPORT __attribute__ ((__deprecated__))
+#endif
""")
export_hpp.close()
diff --git a/doc/book/net.tex b/doc/book/net.tex
index 8b1c7fa7..88249c1c 100644
--- a/doc/book/net.tex
+++ b/doc/book/net.tex
@@ -560,8 +560,8 @@ std::vector <ref <vmime::net::message> > allMessages =
// -1 is a special value to mean "the number of the last message in the folder"
folder->fetchMessages(allMessages,
- vmime::net::folder::FETCH_FLAGS |
- vmime::net::folder::FETCH_ENVELOPE);
+ vmime::net::fetchAttributes::FLAGS |
+ vmime::net::fetchAttributes::ENVELOPE);
for (unsigned int i = 0 ; i < allMessages.size() ; ++i)
{
@@ -583,6 +583,21 @@ for (unsigned int i = 0 ; i < allMessages.size() ; ++i)
}
\end{lstlisting}
+IMAP supports fetching specific header fields of a message. Here is how to use
+the {\vcode fetchAttributes} object to do it:
+
+\begin{lstlisting}[caption={Using fetchAttributes object to fetch specific header fields of a message}]
+
+// Fetch message flags and the "Received" and "X-Mailer" header fields
+vmime::net::fetchAttributes fetchAttribs;
+fetchAttribs.add(vmime::net::fetchAttributes::FLAGS);
+fetchAttribs.add("Received");
+fetchAttribs.add("X-Mailer");
+
+folder->fetchMessages(allMessages, fetchAttribs);
+\end{lstlisting}
+
+
\subsection{Extracting messages and parts}
To extract the whole contents of a message (including headers), use the
@@ -605,7 +620,7 @@ and time. The method {\vcode extractPart()} is used in this case:
\begin{lstlisting}[caption={Extracting a specific MIME part of a message}]
// Fetching structure is required before extracting a part
-folder->fetchMessage(msg, vmime::net::folder::FETCH_STRUCTURE);
+folder->fetchMessage(msg, vmime::net::fetchAttributes::STRUCTURE);
// Now, we can extract the part
msg->extractPart(msg->getStructure()->getPartAt(0)->getPartAt(1));
diff --git a/examples/example6.cpp b/examples/example6.cpp
index e4b272a5..721f7624 100644
--- a/examples/example6.cpp
+++ b/examples/example6.cpp
@@ -608,7 +608,7 @@ static void connectStore()
// Show message flags
case 1:
- f->fetchMessage(msg, vmime::net::folder::FETCH_FLAGS);
+ f->fetchMessage(msg, vmime::net::fetchAttributes::FLAGS);
if (msg->getFlags() & vmime::net::message::FLAG_SEEN)
std::cout << "FLAG_SEEN" << std::endl;
@@ -628,21 +628,21 @@ static void connectStore()
// Show message structure
case 2:
- f->fetchMessage(msg, vmime::net::folder::FETCH_STRUCTURE);
+ f->fetchMessage(msg, vmime::net::fetchAttributes::STRUCTURE);
printStructure(msg->getStructure());
break;
// Show message header
case 3:
- f->fetchMessage(msg, vmime::net::folder::FETCH_FULL_HEADER);
+ f->fetchMessage(msg, vmime::net::fetchAttributes::FULL_HEADER);
std::cout << msg->getHeader()->generate() << std::endl;
break;
// Show message envelope
case 4:
- f->fetchMessage(msg, vmime::net::folder::FETCH_ENVELOPE);
+ f->fetchMessage(msg, vmime::net::fetchAttributes::ENVELOPE);
#define ENV_HELPER(x) \
try { std::cout << msg->getHeader()->x()->generate() << std::endl; } \
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();
diff --git a/tests/net/maildir/maildirStoreTest.cpp b/tests/net/maildir/maildirStoreTest.cpp
index 10de80df..358e095f 100644
--- a/tests/net/maildir/maildirStoreTest.cpp
+++ b/tests/net/maildir/maildirStoreTest.cpp
@@ -300,7 +300,7 @@ public:
vmime::ref <vmime::net::message> msg = folder->getMessage(1);
- folder->fetchMessage(msg, vmime::net::folder::FETCH_SIZE);
+ folder->fetchMessage(msg, vmime::net::fetchAttributes::SIZE);
VASSERT_EQ("Message size", TEST_MESSAGE_1.length(), msg->getSize());
diff --git a/vmime/net/fetchAttributes.hpp b/vmime/net/fetchAttributes.hpp
new file mode 100644
index 00000000..d01e9f50
--- /dev/null
+++ b/vmime/net/fetchAttributes.hpp
@@ -0,0 +1,142 @@
+//
+// 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.
+//
+
+#ifndef VMIME_NET_FETCHATTRIBUTES_HPP_INCLUDED
+#define VMIME_NET_FETCHATTRIBUTES_HPP_INCLUDED
+
+
+#include "vmime/config.hpp"
+
+
+#if VMIME_HAVE_MESSAGING_FEATURES
+
+
+#include <vector>
+
+#include "vmime/types.hpp"
+
+
+namespace vmime {
+namespace net {
+
+
+/** Holds a set of attributes to fetch for a message.
+ */
+class VMIME_EXPORT fetchAttributes : public object
+{
+public:
+
+ /** Predefined attributes that can be fetched.
+ */
+ enum PredefinedFetchAttributes
+ {
+ ENVELOPE = (1 << 0), /**< Sender, recipients, date, subject. */
+ STRUCTURE = (1 << 1), /**< MIME structure (body parts). */
+ CONTENT_INFO = (1 << 2), /**< Top-level content type. */
+ FLAGS = (1 << 3), /**< Message flags. */
+ SIZE = (1 << 4), /**< Message size (exact or estimated). */
+ FULL_HEADER = (1 << 5), /**< Full RFC-[2]822 header. */
+ UID = (1 << 6), /**< Unique identifier (protocol specific). */
+ IMPORTANCE = (1 << 7), /**< Header fields suitable for use with misc::importanceHelper. */
+
+ CUSTOM = (1 << 16) /**< Reserved for future use. */
+ };
+
+ /** Constructs an empty fetchAttributes object.
+ */
+ fetchAttributes();
+
+ /** Constructs a new fetchAttributes object by specifying one or more
+ * predefined objects.
+ *
+ * @param attribs one or more OR-ed values of the PredefinedFetchAttributes enum
+ */
+ fetchAttributes(const int attribs);
+
+ /** Constructs a new fetchAttributes object by copying an existing object.
+ *
+ * @param attribs object to copy
+ */
+ fetchAttributes(const fetchAttributes& attribs);
+
+ /** Adds the specified predefined attribute to the set of attributes to fetch.
+ *
+ * @param attribs one or more OR-ed values of the PredefinedFetchAttributes enum
+ */
+ void add(const int attribs);
+
+ /** Adds the specified header field to the set of attributes to fetch.
+ * Fetching custom header fields is not supported by all protocols.
+ * At this time, only IMAP supports this.
+ *
+ * @param header name of header field (eg. "X-Mailer")
+ */
+ void add(const string& header);
+
+ /** Returns true if the set contains the specified attribute(s).
+ *
+ * @param attribs one or more OR-ed values of the PredefinedFetchAttributes enum
+ * @return true if the specified attributes are to be fetched
+ */
+ bool has(const int attribs) const;
+
+ /** Returns true if the set contains the specified header field.
+ *
+ * @param header name of header field (eg. "X-Mailer")
+ * @return true if the specified header fields are to be fetched
+ */
+ bool has(const string& header) const;
+
+ /** Returns true if the set contains the specified attribute(s).
+ *
+ * \deprecated Use the has() methods instead
+ *
+ * @param attribs one or more OR-ed values of the PredefinedFetchAttributes enum
+ * @return true if the specified attributes are to be fetched
+ */
+ VMIME_DEPRECATED inline bool operator&(const int attribs) const
+ {
+ return has(attribs);
+ }
+
+ /** Returns a list of header fields to fetch.
+ *
+ * @return list of header names (eg. "X-Mailer")
+ */
+ const std::vector <string> getHeaderFields() const;
+
+private:
+
+ int m_predefinedAttribs;
+ std::vector <string> m_headers;
+};
+
+
+} // net
+} // vmime
+
+
+#endif // VMIME_HAVE_MESSAGING_FEATURES
+
+
+#endif // VMIME_NET_FETCHATTRIBUTES_HPP_INCLUDED
diff --git a/vmime/net/folder.hpp b/vmime/net/folder.hpp
index fc878fbf..643a323b 100644
--- a/vmime/net/folder.hpp
+++ b/vmime/net/folder.hpp
@@ -41,6 +41,7 @@
#include "vmime/net/messageSet.hpp"
#include "vmime/net/events.hpp"
#include "vmime/net/folderStatus.hpp"
+#include "vmime/net/fetchAttributes.hpp"
#include "vmime/utility/path.hpp"
#include "vmime/utility/stream.hpp"
@@ -332,41 +333,25 @@ public:
*/
virtual ref <store> getStore() = 0;
- /** Fetchable objects.
- */
- enum FetchOptions
- {
- FETCH_ENVELOPE = (1 << 0), /**< Fetch sender, recipients, date, subject. */
- FETCH_STRUCTURE = (1 << 1), /**< Fetch structure (body parts). */
- FETCH_CONTENT_INFO = (1 << 2), /**< Fetch top-level content type. */
- FETCH_FLAGS = (1 << 3), /**< Fetch message flags. */
- FETCH_SIZE = (1 << 4), /**< Fetch message size (exact or estimated). */
- FETCH_FULL_HEADER = (1 << 5), /**< Fetch full RFC-[2]822 header. */
- FETCH_UID = (1 << 6), /**< Fetch unique identifier (protocol specific). */
- FETCH_IMPORTANCE = (1 << 7), /**< Fetch header fields suitable for use with misc::importanceHelper. */
-
- FETCH_CUSTOM = (1 << 16) /**< Reserved for future use. */
- };
-
/** Fetch objects for the specified messages.
*
* @param msg list of message sequence numbers
- * @param options objects to fetch (combination of folder::FetchOptions flags)
+ * @param attribs set of attributes to fetch
* @param progress progress listener, or NULL if not used
* @throw exceptions::net_exception if an error occurs
*/
- virtual void fetchMessages(std::vector <ref <message> >& msg, const int options, utility::progressListener* progress = NULL) = 0;
+ virtual void fetchMessages(std::vector <ref <message> >& msg, const fetchAttributes& attribs, utility::progressListener* progress = NULL) = 0;
/** Fetch objects for the specified message.
*
* @param msg the message
- * @param options objects to fetch (combination of folder::FetchOptions flags)
+ * @param attribs set of attributes to fetch
* @throw exceptions::net_exception if an error occurs
*/
- virtual void fetchMessage(ref <message> msg, const int options) = 0;
+ virtual void fetchMessage(ref <message> msg, const fetchAttributes& attribs) = 0;
/** Return the list of fetchable objects supported by
- * the underlying protocol (see folder::FetchOptions).
+ * the underlying protocol (see folder::fetchAttributes).
*
* @return list of supported fetchable objects
*/
diff --git a/vmime/net/imap/IMAPFolder.hpp b/vmime/net/imap/IMAPFolder.hpp
index b7fc46a1..7bb9c0af 100644
--- a/vmime/net/imap/IMAPFolder.hpp
+++ b/vmime/net/imap/IMAPFolder.hpp
@@ -124,8 +124,8 @@ public:
ref <store> getStore();
- void fetchMessages(std::vector <ref <message> >& msg, const int options, utility::progressListener* progress = NULL);
- void fetchMessage(ref <message> msg, const int options);
+ void fetchMessages(std::vector <ref <message> >& msg, const fetchAttributes& options, utility::progressListener* progress = NULL);
+ void fetchMessage(ref <message> msg, const fetchAttributes& options);
int getFetchCapabilities() const;
diff --git a/vmime/net/imap/IMAPMessage.hpp b/vmime/net/imap/IMAPMessage.hpp
index 59f9fc83..b57ae332 100644
--- a/vmime/net/imap/IMAPMessage.hpp
+++ b/vmime/net/imap/IMAPMessage.hpp
@@ -114,12 +114,12 @@ private:
/** Processes the parsed response to fill in the attributes
* and metadata of this message.
*
- * @param options one or more fetch options (see folder::FetchOptions)
+ * @param options one or more fetch options (see folder::fetchAttributes)
* @param msgData pointer to message_data component of the parsed response
* @return a combination of flags that specify what changed exactly on
* this message (see events::messageChangedEvent::Types)
*/
- int processFetchResponse(const int options, const IMAPParser::message_data* msgData);
+ int processFetchResponse(const fetchAttributes& options, const IMAPParser::message_data* msgData);
/** Recursively fetch part header for all parts in the structure.
*
diff --git a/vmime/net/imap/IMAPUtils.hpp b/vmime/net/imap/IMAPUtils.hpp
index 1dfde7a9..76c44494 100644
--- a/vmime/net/imap/IMAPUtils.hpp
+++ b/vmime/net/imap/IMAPUtils.hpp
@@ -89,7 +89,7 @@ public:
* @return fetch request
*/
static const string buildFetchRequest
- (ref <IMAPConnection> cnt, const messageSet& msgs, const int options);
+ (ref <IMAPConnection> cnt, const messageSet& msgs, const fetchAttributes& options);
/** Convert a parser-style address list to a mailbox list.
*
diff --git a/vmime/net/maildir/maildirFolder.hpp b/vmime/net/maildir/maildirFolder.hpp
index 2b6f8b4d..92de4d0d 100644
--- a/vmime/net/maildir/maildirFolder.hpp
+++ b/vmime/net/maildir/maildirFolder.hpp
@@ -118,8 +118,8 @@ public:
ref <store> getStore();
- void fetchMessages(std::vector <ref <message> >& msg, const int options, utility::progressListener* progress = NULL);
- void fetchMessage(ref <message> msg, const int options);
+ void fetchMessages(std::vector <ref <message> >& msg, const fetchAttributes& options, utility::progressListener* progress = NULL);
+ void fetchMessage(ref <message> msg, const fetchAttributes& options);
int getFetchCapabilities() const;
diff --git a/vmime/net/maildir/maildirMessage.hpp b/vmime/net/maildir/maildirMessage.hpp
index 08c13daa..527461ff 100644
--- a/vmime/net/maildir/maildirMessage.hpp
+++ b/vmime/net/maildir/maildirMessage.hpp
@@ -85,7 +85,7 @@ public:
private:
- void fetch(ref <maildirFolder> folder, const int options);
+ void fetch(ref <maildirFolder> folder, const fetchAttributes& options);
void onFolderClosed();
diff --git a/vmime/net/pop3/POP3Folder.hpp b/vmime/net/pop3/POP3Folder.hpp
index 93c1d257..5dbb8d1d 100644
--- a/vmime/net/pop3/POP3Folder.hpp
+++ b/vmime/net/pop3/POP3Folder.hpp
@@ -115,8 +115,8 @@ public:
ref <store> getStore();
- void fetchMessages(std::vector <ref <message> >& msg, const int options, utility::progressListener* progress = NULL);
- void fetchMessage(ref <message> msg, const int options);
+ void fetchMessages(std::vector <ref <message> >& msg, const fetchAttributes& options, utility::progressListener* progress = NULL);
+ void fetchMessage(ref <message> msg, const fetchAttributes& options);
int getFetchCapabilities() const;
diff --git a/vmime/net/pop3/POP3Message.hpp b/vmime/net/pop3/POP3Message.hpp
index 113d0e86..573fe808 100644
--- a/vmime/net/pop3/POP3Message.hpp
+++ b/vmime/net/pop3/POP3Message.hpp
@@ -85,7 +85,7 @@ public:
private:
- void fetch(ref <POP3Folder> folder, const int options);
+ void fetch(ref <POP3Folder> folder, const fetchAttributes& options);
void onFolderClosed();