aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2012-07-30 18:45:17 +0000
committerVincent Richard <[email protected]>2012-07-30 18:45:17 +0000
commitff462a5ee1077e53e29e49d451f8eb2a74312635 (patch)
treedea394325916f37f5abc7da473dcbd5d07d74117
parentFixed compilation warning. (diff)
downloadvmime-ff462a5ee1077e53e29e49d451f8eb2a74312635.tar.gz
vmime-ff462a5ee1077e53e29e49d451f8eb2a74312635.zip
Fixed body part extraction (only body should be extracted).
-rw-r--r--src/net/imap/IMAPMessage.cpp45
-rw-r--r--src/net/imap/IMAPMessagePartContentHandler.cpp4
-rw-r--r--vmime/net/imap/IMAPMessage.hpp12
3 files changed, 49 insertions, 12 deletions
diff --git a/src/net/imap/IMAPMessage.cpp b/src/net/imap/IMAPMessage.cpp
index 7202a7d2..808f7d1d 100644
--- a/src/net/imap/IMAPMessage.cpp
+++ b/src/net/imap/IMAPMessage.cpp
@@ -192,7 +192,7 @@ void IMAPMessage::extract(utility::outputStream& os, utility::progressListener*
if (!folder)
throw exceptions::folder_not_found();
- extract(NULL, os, progress, start, length, false, peek);
+ extractImpl(NULL, os, progress, start, length, EXTRACT_HEADER | EXTRACT_BODY | (peek ? EXTRACT_PEEK : 0));
}
@@ -205,7 +205,7 @@ void IMAPMessage::extractPart
if (!folder)
throw exceptions::folder_not_found();
- extract(p, os, progress, start, length, false, peek);
+ extractImpl(p, os, progress, start, length, EXTRACT_HEADER | EXTRACT_BODY | (peek ? EXTRACT_PEEK : 0));
}
@@ -219,7 +219,7 @@ void IMAPMessage::fetchPartHeader(ref <part> p)
std::ostringstream oss;
utility::outputStreamAdapter ossAdapter(oss);
- extract(p, ossAdapter, NULL, 0, -1, true, true);
+ extractImpl(p, ossAdapter, NULL, 0, -1, EXTRACT_HEADER | EXTRACT_PEEK);
p.dynamicCast <IMAPPart>()->getOrCreateHeader().parse(oss.str());
}
@@ -240,9 +240,9 @@ void IMAPMessage::fetchPartHeaderForStructure(ref <structure> str)
}
-void IMAPMessage::extract(ref <const part> p, utility::outputStream& os,
+void IMAPMessage::extractImpl(ref <const part> p, utility::outputStream& os,
utility::progressListener* progress, const int start,
- const int length, const bool headerOnly, const bool peek) const
+ const int length, const int extractFlags) const
{
ref <const IMAPFolder> folder = m_folder.acquire();
@@ -284,18 +284,45 @@ void IMAPMessage::extract(ref <const part> p, utility::outputStream& os,
else
command << "UID FETCH " << IMAPUtils::extractUIDFromGlobalUID(m_uid) << " BODY";
- if (peek) command << ".PEEK";
+ /*
+ BODY[] header + body
+ BODY.PEEK[] header + body (peek)
+ BODY[HEADER] header
+ BODY.PEEK[HEADER] header (peek)
+ BODY[TEXT] body
+ BODY.PEEK[TEXT] body (peek)
+ */
+
+ if (extractFlags & EXTRACT_PEEK)
+ command << ".PEEK";
+
command << "[";
if (section.str().empty())
{
- if (headerOnly)
+ // header + body
+ if ((extractFlags & EXTRACT_HEADER) && (extractFlags & EXTRACT_BODY))
+ command << "";
+ // body only
+ else if (extractFlags & EXTRACT_BODY)
+ command << "TEXT";
+ // header only
+ else if (extractFlags & EXTRACT_HEADER)
command << "HEADER";
}
else
{
command << section.str();
- if (headerOnly) command << ".MIME"; // "MIME" not "HEADER" for parts
+
+ // header + body
+ if ((extractFlags & EXTRACT_HEADER) && (extractFlags & EXTRACT_BODY))
+ *((int *) 0)=42;//throw exceptions::operation_not_supported();
+ // body only
+ else if (extractFlags & EXTRACT_BODY)
+ command << ".TEXT";
+ // header only
+ else if (extractFlags & EXTRACT_HEADER)
+ command << ".MIME"; // "MIME" not "HEADER" for parts
}
command << "]";
@@ -318,7 +345,7 @@ void IMAPMessage::extract(ref <const part> p, utility::outputStream& os,
}
- if (!headerOnly)
+ if (extractFlags & EXTRACT_BODY)
{
// TODO: update the flags (eg. flag "\Seen" may have been set)
}
diff --git a/src/net/imap/IMAPMessagePartContentHandler.cpp b/src/net/imap/IMAPMessagePartContentHandler.cpp
index 85c6ec21..c2cd6479 100644
--- a/src/net/imap/IMAPMessagePartContentHandler.cpp
+++ b/src/net/imap/IMAPMessagePartContentHandler.cpp
@@ -121,7 +121,7 @@ void IMAPMessagePartContentHandler::extract
// No decoding to perform
if (!isEncoded())
{
- msg->extractPart(part, os, progress);
+ msg->extractImpl(part, os, progress, 0, -1, IMAPMessage::EXTRACT_BODY);
}
// Need to decode data
else
@@ -130,7 +130,7 @@ void IMAPMessagePartContentHandler::extract
std::ostringstream oss;
utility::outputStreamAdapter tmp(oss);
- msg->extractPart(part, tmp, NULL);
+ msg->extractImpl(part, tmp, NULL, 0, -1, IMAPMessage::EXTRACT_BODY);
// Encode temporary buffer to output stream
utility::inputStreamStringAdapter is(oss.str());
diff --git a/vmime/net/imap/IMAPMessage.hpp b/vmime/net/imap/IMAPMessage.hpp
index fbba6e7d..06f80919 100644
--- a/vmime/net/imap/IMAPMessage.hpp
+++ b/vmime/net/imap/IMAPMessage.hpp
@@ -47,6 +47,7 @@ class IMAPMessage : public message
private:
friend class IMAPFolder;
+ friend class IMAPMessagePartContentHandler;
friend class vmime::creator; // vmime::create <IMAPMessage>
IMAPMessage(ref <IMAPFolder> folder, const int num);
@@ -101,7 +102,16 @@ private:
*/
void constructParsedMessage(ref <bodyPart> parentPart, ref <structure> str, int level = 0);
- void extract(ref <const part> p, utility::outputStream& os, utility::progressListener* progress, const int start, const int length, const bool headerOnly, const bool peek) const;
+
+ enum ExtractFlags
+ {
+ EXTRACT_HEADER = 0x1,
+ EXTRACT_BODY = 0x2,
+ EXTRACT_PEEK = 0x10
+ };
+
+ void extractImpl(ref <const part> p, utility::outputStream& os, utility::progressListener* progress,
+ const int start, const int length, const int extractFlags) const;
ref <header> getOrCreateHeader();