From 9479afa20688778dbd4d04834dcca4ee18793cd6 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Fri, 27 May 2005 19:43:20 +0000 Subject: [PATCH] Added 'peek' parameter to extract() and extractPart(). --- ChangeLog | 5 +++++ src/messaging/imap/IMAPMessage.cpp | 16 +++++++++------- src/messaging/maildir/maildirMessage.cpp | 16 +++++++++++----- src/messaging/pop3/POP3Message.cpp | 6 ++++-- vmime/messaging/imap/IMAPMessage.hpp | 6 +++--- vmime/messaging/maildir/maildirMessage.hpp | 6 +++--- vmime/messaging/message.hpp | 10 ++++++++-- vmime/messaging/pop3/POP3Message.hpp | 4 ++-- 8 files changed, 45 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 122d7c2a..294050e3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,11 @@ VERSION 0.7.1cvs ================ +2005-05-27 Vincent Richard + + * messaging/*/*Message.{hpp|cpp}: added a 'peek' parameter to extract + message contents without marking the message as seen. + 2005-05-19 Vincent Richard * messaging/imap/IMAPFolder.cpp: fixed bug in subfolders enumeration. diff --git a/src/messaging/imap/IMAPMessage.cpp b/src/messaging/imap/IMAPMessage.cpp index a2220c68..03af67c6 100644 --- a/src/messaging/imap/IMAPMessage.cpp +++ b/src/messaging/imap/IMAPMessage.cpp @@ -367,23 +367,23 @@ const header& IMAPMessage::getHeader() const 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) throw exceptions::folder_not_found(); - extract(NULL, os, progress, start, length, false); + extract(NULL, os, progress, start, length, false, peek); } void IMAPMessage::extractPart (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) 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; utility::outputStreamAdapter ossAdapter(oss); - extract(&p, ossAdapter, NULL, 0, -1, true); + extract(&p, ossAdapter, NULL, 0, -1, true, true); static_cast (p).getOrCreateHeader().parse(oss.str()); } @@ -403,7 +403,7 @@ void IMAPMessage::fetchPartHeader(part& p) void IMAPMessage::extract(const part* p, utility::outputStream& os, 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); @@ -436,7 +436,9 @@ void IMAPMessage::extract(const part* p, utility::outputStream& os, // Build the request text std::ostringstream command; - command << "FETCH " << m_num << " BODY["; + command << "FETCH " << m_num << " BODY"; + if (peek) command << ".PEEK"; + command << "["; command << section.str(); if (headerOnly) command << ".MIME"; // "MIME" not "HEADER" for parts command << "]"; diff --git a/src/messaging/maildir/maildirMessage.cpp b/src/messaging/maildir/maildirMessage.cpp index 2815e980..9a56a472 100644 --- a/src/messaging/maildir/maildirMessage.cpp +++ b/src/messaging/maildir/maildirMessage.cpp @@ -309,23 +309,27 @@ void maildirMessage::setFlags(const int flags, const int mode) 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, - 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 (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, - 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(); @@ -363,6 +367,8 @@ void maildirMessage::extractImpl(utility::outputStream& os, utility::progression if (progress) progress->stop(total); + + // TODO: mark as read unless 'peek' is set } diff --git a/src/messaging/pop3/POP3Message.cpp b/src/messaging/pop3/POP3Message.cpp index 46d57ba9..e4833583 100644 --- a/src/messaging/pop3/POP3Message.cpp +++ b/src/messaging/pop3/POP3Message.cpp @@ -111,7 +111,8 @@ const header& POP3Message::getHeader() const 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) throw exceptions::illegal_state("Folder closed"); @@ -148,7 +149,8 @@ void POP3Message::extract(utility::outputStream& os, void POP3Message::extractPart (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 { throw exceptions::operation_not_supported(); } diff --git a/vmime/messaging/imap/IMAPMessage.hpp b/vmime/messaging/imap/IMAPMessage.hpp index f9c22a75..229709c3 100644 --- a/vmime/messaging/imap/IMAPMessage.hpp +++ b/vmime/messaging/imap/IMAPMessage.hpp @@ -64,8 +64,8 @@ public: const int getFlags() const; 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 extractPart(const part& p, 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 bool peek = false) const; void fetchPartHeader(part& p); @@ -75,7 +75,7 @@ private: 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); diff --git a/vmime/messaging/maildir/maildirMessage.hpp b/vmime/messaging/maildir/maildirMessage.hpp index cd345784..6eb8a7d2 100644 --- a/vmime/messaging/maildir/maildirMessage.hpp +++ b/vmime/messaging/maildir/maildirMessage.hpp @@ -65,8 +65,8 @@ public: const int getFlags() const; 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 extractPart(const part& p, 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 bool peek = false) const; void fetchPartHeader(part& p); @@ -78,7 +78,7 @@ private: 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; diff --git a/vmime/messaging/message.hpp b/vmime/messaging/message.hpp index 4ae10270..b423e039 100644 --- a/vmime/messaging/message.hpp +++ b/vmime/messaging/message.hpp @@ -256,8 +256,11 @@ public: * @param progress progression listener, or NULL if not used * @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 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). * @@ -268,8 +271,11 @@ public: * @param progress progression listener, or NULL if not used * @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 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. * diff --git a/vmime/messaging/pop3/POP3Message.hpp b/vmime/messaging/pop3/POP3Message.hpp index c19d7579..3ac3cedb 100644 --- a/vmime/messaging/pop3/POP3Message.hpp +++ b/vmime/messaging/pop3/POP3Message.hpp @@ -64,8 +64,8 @@ public: const int getFlags() const; 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 extractPart(const part& p, 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 bool peek = false) const; void fetchPartHeader(part& p);