Added 'peek' parameter to extract() and extractPart().

This commit is contained in:
Vincent Richard 2005-05-27 19:43:20 +00:00
parent b3ddee2ea7
commit 9479afa206
8 changed files with 45 additions and 24 deletions

View File

@ -2,6 +2,11 @@
VERSION 0.7.1cvs VERSION 0.7.1cvs
================ ================
2005-05-27 Vincent Richard <vincent@vincent-richard.net>
* messaging/*/*Message.{hpp|cpp}: added a 'peek' parameter to extract
message contents without marking the message as seen.
2005-05-19 Vincent Richard <vincent@vincent-richard.net> 2005-05-19 Vincent Richard <vincent@vincent-richard.net>
* messaging/imap/IMAPFolder.cpp: fixed bug in subfolders enumeration. * messaging/imap/IMAPFolder.cpp: fixed bug in subfolders enumeration.

View File

@ -367,23 +367,23 @@ const header& IMAPMessage::getHeader() const
void IMAPMessage::extract(utility::outputStream& os, utility::progressionListener* progress, void IMAPMessage::extract(utility::outputStream& os, utility::progressionListener* progress,
const int start, const int length) const const int start, const int length, const bool peek) const
{ {
if (!m_folder) if (!m_folder)
throw exceptions::folder_not_found(); throw exceptions::folder_not_found();
extract(NULL, os, progress, start, length, false); extract(NULL, os, progress, start, length, false, peek);
} }
void IMAPMessage::extractPart void IMAPMessage::extractPart
(const part& p, utility::outputStream& os, utility::progressionListener* progress, (const part& p, utility::outputStream& os, utility::progressionListener* progress,
const int start, const int length) const const int start, const int length, const bool peek) const
{ {
if (!m_folder) if (!m_folder)
throw exceptions::folder_not_found(); throw exceptions::folder_not_found();
extract(&p, os, progress, start, length, false); extract(&p, os, progress, start, length, false, peek);
} }
@ -395,7 +395,7 @@ void IMAPMessage::fetchPartHeader(part& p)
std::ostringstream oss; std::ostringstream oss;
utility::outputStreamAdapter ossAdapter(oss); utility::outputStreamAdapter ossAdapter(oss);
extract(&p, ossAdapter, NULL, 0, -1, true); extract(&p, ossAdapter, NULL, 0, -1, true, true);
static_cast <IMAPpart&>(p).getOrCreateHeader().parse(oss.str()); static_cast <IMAPpart&>(p).getOrCreateHeader().parse(oss.str());
} }
@ -403,7 +403,7 @@ void IMAPMessage::fetchPartHeader(part& p)
void IMAPMessage::extract(const part* p, utility::outputStream& os, void IMAPMessage::extract(const part* p, utility::outputStream& os,
utility::progressionListener* progress, const int start, utility::progressionListener* progress, const int start,
const int length, const bool headerOnly) const const int length, const bool headerOnly, const bool peek) const
{ {
IMAPMessage_literalHandler literalHandler(os, progress); IMAPMessage_literalHandler literalHandler(os, progress);
@ -436,7 +436,9 @@ void IMAPMessage::extract(const part* p, utility::outputStream& os,
// Build the request text // Build the request text
std::ostringstream command; std::ostringstream command;
command << "FETCH " << m_num << " BODY["; command << "FETCH " << m_num << " BODY";
if (peek) command << ".PEEK";
command << "[";
command << section.str(); command << section.str();
if (headerOnly) command << ".MIME"; // "MIME" not "HEADER" for parts if (headerOnly) command << ".MIME"; // "MIME" not "HEADER" for parts
command << "]"; command << "]";

View File

@ -309,23 +309,27 @@ void maildirMessage::setFlags(const int flags, const int mode)
void maildirMessage::extract(utility::outputStream& os, void maildirMessage::extract(utility::outputStream& os,
utility::progressionListener* progress, const int start, const int length) const utility::progressionListener* progress, const int start,
const int length, const bool peek) const
{ {
extractImpl(os, progress, 0, m_size, start, length); extractImpl(os, progress, 0, m_size, start, length, peek);
} }
void maildirMessage::extractPart(const part& p, utility::outputStream& os, void maildirMessage::extractPart(const part& p, utility::outputStream& os,
utility::progressionListener* progress, const int start, const int length) const utility::progressionListener* progress, const int start,
const int length, const bool peek) const
{ {
const maildirPart& mp = dynamic_cast <const maildirPart&>(p); const maildirPart& mp = dynamic_cast <const maildirPart&>(p);
extractImpl(os, progress, mp.getBodyParsedOffset(), mp.getBodyParsedLength(), start, length); extractImpl(os, progress, mp.getBodyParsedOffset(), mp.getBodyParsedLength(),
start, length, peek);
} }
void maildirMessage::extractImpl(utility::outputStream& os, utility::progressionListener* progress, void maildirMessage::extractImpl(utility::outputStream& os, utility::progressionListener* progress,
const int start, const int length, const int partialStart, const int partialLength) const const int start, const int length, const int partialStart, const int partialLength,
const bool peek) const
{ {
utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory(); utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory();
@ -363,6 +367,8 @@ void maildirMessage::extractImpl(utility::outputStream& os, utility::progression
if (progress) if (progress)
progress->stop(total); progress->stop(total);
// TODO: mark as read unless 'peek' is set
} }

View File

@ -111,7 +111,8 @@ const header& POP3Message::getHeader() const
void POP3Message::extract(utility::outputStream& os, void POP3Message::extract(utility::outputStream& os,
utility::progressionListener* progress, const int start, const int length) const utility::progressionListener* progress, const int start,
const int length, const bool /* peek */) const
{ {
if (!m_folder) if (!m_folder)
throw exceptions::illegal_state("Folder closed"); throw exceptions::illegal_state("Folder closed");
@ -148,7 +149,8 @@ void POP3Message::extract(utility::outputStream& os,
void POP3Message::extractPart void POP3Message::extractPart
(const part& /* p */, utility::outputStream& /* os */, (const part& /* p */, utility::outputStream& /* os */,
utility::progressionListener* /* progress */, utility::progressionListener* /* progress */,
const int /* start */, const int /* length */) const const int /* start */, const int /* length */,
const bool /* peek */) const
{ {
throw exceptions::operation_not_supported(); throw exceptions::operation_not_supported();
} }

View File

@ -64,8 +64,8 @@ public:
const int getFlags() const; const int getFlags() const;
void setFlags(const int flags, const int mode = FLAG_MODE_SET); void setFlags(const int flags, const int mode = FLAG_MODE_SET);
void extract(utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1) const; void extract(utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const;
void extractPart(const part& p, utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1) const; void extractPart(const part& p, utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const;
void fetchPartHeader(part& p); void fetchPartHeader(part& p);
@ -75,7 +75,7 @@ private:
void processFetchResponse(const int options, const IMAPParser::msg_att* msgAtt); void processFetchResponse(const int options, const IMAPParser::msg_att* msgAtt);
void extract(const part* p, utility::outputStream& os, utility::progressionListener* progress, const int start, const int length, const bool headerOnly) const; void extract(const part* p, utility::outputStream& os, utility::progressionListener* progress, const int start, const int length, const bool headerOnly, const bool peek) const;
void convertAddressList(const IMAPParser::address_list& src, mailboxList& dest); void convertAddressList(const IMAPParser::address_list& src, mailboxList& dest);

View File

@ -65,8 +65,8 @@ public:
const int getFlags() const; const int getFlags() const;
void setFlags(const int flags, const int mode = FLAG_MODE_SET); void setFlags(const int flags, const int mode = FLAG_MODE_SET);
void extract(utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1) const; void extract(utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const;
void extractPart(const part& p, utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1) const; void extractPart(const part& p, utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const;
void fetchPartHeader(part& p); void fetchPartHeader(part& p);
@ -78,7 +78,7 @@ private:
header& getOrCreateHeader(); header& getOrCreateHeader();
void extractImpl(utility::outputStream& os, utility::progressionListener* progress, const int start, const int length, const int partialStart, const int partialLength) const; void extractImpl(utility::outputStream& os, utility::progressionListener* progress, const int start, const int length, const int partialStart, const int partialLength, const bool peek) const;
maildirFolder* m_folder; maildirFolder* m_folder;

View File

@ -256,8 +256,11 @@ public:
* @param progress progression listener, or NULL if not used * @param progress progression listener, or NULL if not used
* @param start index of the first byte to retrieve (used for partial fetch) * @param start index of the first byte to retrieve (used for partial fetch)
* @param length number of bytes to retrieve (used for partial fetch) * @param length number of bytes to retrieve (used for partial fetch)
* @param peek if true, try not to mark the message as read. This may not
* be supported by the protocol (IMAP supports this), but it will NOT throw
* an exception if not supported.
*/ */
virtual void extract(utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1) const = 0; virtual void extract(utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const = 0;
/** Extract the specified (MIME) part of the message (header + contents). /** Extract the specified (MIME) part of the message (header + contents).
* *
@ -268,8 +271,11 @@ public:
* @param progress progression listener, or NULL if not used * @param progress progression listener, or NULL if not used
* @param start index of the first byte to retrieve (used for partial fetch) * @param start index of the first byte to retrieve (used for partial fetch)
* @param length number of bytes to retrieve (used for partial fetch) * @param length number of bytes to retrieve (used for partial fetch)
* @param peek if true, try not to mark the message as read. This may not
* be supported by the protocol (IMAP supports this), but it will NOT throw
* an exception if not supported.
*/ */
virtual void extractPart(const part& p, utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1) const = 0; virtual void extractPart(const part& p, utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const = 0;
/** Fetch the MIME header for the specified part. /** Fetch the MIME header for the specified part.
* *

View File

@ -64,8 +64,8 @@ public:
const int getFlags() const; const int getFlags() const;
void setFlags(const int flags, const int mode = FLAG_MODE_SET); void setFlags(const int flags, const int mode = FLAG_MODE_SET);
void extract(utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1) const; void extract(utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const;
void extractPart(const part& p, utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1) const; void extractPart(const part& p, utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const;
void fetchPartHeader(part& p); void fetchPartHeader(part& p);