Fixed body part extraction (only body should be extracted).

This commit is contained in:
Vincent Richard 2012-07-30 20:45:17 +02:00
parent f0b1be21dc
commit ff462a5ee1
3 changed files with 49 additions and 12 deletions

View File

@ -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)
}

View File

@ -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());

View File

@ -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();