diff --git a/SConstruct b/SConstruct index e4f149f3..ed0a4d03 100644 --- a/SConstruct +++ b/SConstruct @@ -275,11 +275,11 @@ libvmime_messaging_proto_sources = [ 'net/imap/IMAPFolder.cpp', 'net/imap/IMAPFolder.hpp', 'net/imap/IMAPFolderStatus.cpp', 'net/imap/IMAPFolderStatus.hpp', 'net/imap/IMAPMessage.cpp', 'net/imap/IMAPMessage.hpp', + 'net/imap/IMAPMessagePart.cpp', 'net/imap/IMAPMessagePart.hpp', + 'net/imap/IMAPMessagePartContentHandler.cpp', 'net/imap/IMAPMessagePartContentHandler.hpp', + 'net/imap/IMAPMessageStructure.cpp', 'net/imap/IMAPMessageStructure.hpp', 'net/imap/IMAPTag.cpp', 'net/imap/IMAPTag.hpp', 'net/imap/IMAPUtils.cpp', 'net/imap/IMAPUtils.hpp', - 'net/imap/IMAPMessagePartContentHandler.cpp', 'net/imap/IMAPMessagePartContentHandler.hpp', - 'net/imap/IMAPStructure.cpp', 'net/imap/IMAPStructure.hpp', - 'net/imap/IMAPPart.cpp', 'net/imap/IMAPPart.hpp', 'net/imap/IMAPParser.hpp', ] ], @@ -291,6 +291,8 @@ libvmime_messaging_proto_sources = [ 'net/maildir/maildirFolder.cpp', 'net/maildir/maildirFolder.hpp', 'net/maildir/maildirFolderStatus.cpp', 'net/maildir/maildirFolderStatus.hpp', 'net/maildir/maildirMessage.cpp', 'net/maildir/maildirMessage.hpp', + 'net/maildir/maildirMessagePart.cpp', 'net/maildir/maildirMessagePart.hpp', + 'net/maildir/maildirMessageStructure.cpp', 'net/maildir/maildirMessageStructure.hpp', 'net/maildir/maildirUtils.cpp', 'net/maildir/maildirUtils.hpp', 'net/maildir/maildirFormat.cpp', 'net/maildir/maildirFormat.hpp', 'net/maildir/format/kmailMaildirFormat.cpp', 'net/maildir/format/kmailMaildirFormat.hpp', diff --git a/src/net/imap/IMAPMessage.cpp b/src/net/imap/IMAPMessage.cpp index 7e88ef85..185af73e 100644 --- a/src/net/imap/IMAPMessage.cpp +++ b/src/net/imap/IMAPMessage.cpp @@ -33,8 +33,8 @@ #include "vmime/net/imap/IMAPStore.hpp" #include "vmime/net/imap/IMAPConnection.hpp" #include "vmime/net/imap/IMAPUtils.hpp" -#include "vmime/net/imap/IMAPStructure.hpp" -#include "vmime/net/imap/IMAPPart.hpp" +#include "vmime/net/imap/IMAPMessageStructure.hpp" +#include "vmime/net/imap/IMAPMessagePart.hpp" #include "vmime/net/imap/IMAPMessagePartContentHandler.hpp" #include "vmime/utility/outputStreamAdapter.hpp" @@ -169,7 +169,7 @@ int IMAPMessage::getFlags() const } -ref IMAPMessage::getStructure() const +ref IMAPMessage::getStructure() const { if (m_structure == NULL) throw exceptions::unfetched_object(); @@ -178,7 +178,7 @@ ref IMAPMessage::getStructure() const } -ref IMAPMessage::getStructure() +ref IMAPMessage::getStructure() { if (m_structure == NULL) throw exceptions::unfetched_object(); @@ -209,7 +209,7 @@ void IMAPMessage::extract(utility::outputStream& os, utility::progressListener* void IMAPMessage::extractPart - (ref p, utility::outputStream& os, utility::progressListener* progress, + (ref p, utility::outputStream& os, utility::progressListener* progress, const int start, const int length, const bool peek) const { ref folder = m_folder.acquire(); @@ -221,7 +221,7 @@ void IMAPMessage::extractPart } -void IMAPMessage::fetchPartHeader(ref p) +void IMAPMessage::fetchPartHeader(ref p) { ref folder = m_folder.acquire(); @@ -233,15 +233,15 @@ void IMAPMessage::fetchPartHeader(ref p) extractImpl(p, ossAdapter, NULL, 0, -1, EXTRACT_HEADER | EXTRACT_PEEK); - p.dynamicCast ()->getOrCreateHeader().parse(oss.str()); + p.dynamicCast ()->getOrCreateHeader().parse(oss.str()); } -void IMAPMessage::fetchPartHeaderForStructure(ref str) +void IMAPMessage::fetchPartHeaderForStructure(ref str) { for (size_t i = 0, n = str->getPartCount() ; i < n ; ++i) { - ref part = str->getPartAt(i); + ref part = str->getPartAt(i); // Fetch header of current part fetchPartHeader(part); @@ -252,7 +252,7 @@ void IMAPMessage::fetchPartHeaderForStructure(ref str) } -void IMAPMessage::extractImpl(ref p, utility::outputStream& os, +void IMAPMessage::extractImpl(ref p, utility::outputStream& os, utility::progressListener* progress, const int start, const int length, const int extractFlags) const { @@ -266,7 +266,7 @@ void IMAPMessage::extractImpl(ref p, utility::outputStream& os, if (p != NULL) { - ref currentPart = p.dynamicCast (); + ref currentPart = p.dynamicCast (); std::vector numbers; numbers.push_back(currentPart->getNumber()); @@ -456,7 +456,7 @@ void IMAPMessage::processFetchResponse } case IMAPParser::msg_att_item::BODY_STRUCTURE: { - m_structure = vmime::create ((*it)->body()); + m_structure = vmime::create ((*it)->body()); break; } case IMAPParser::msg_att_item::RFC822_HEADER: @@ -632,11 +632,12 @@ void IMAPMessage::setFlags(const int flags, const int mode) } -void IMAPMessage::constructParsedMessage(ref parentPart, ref str, int level) +void IMAPMessage::constructParsedMessage + (ref parentPart, ref str, int level) { if (level == 0) { - ref part = str->getPartAt(0); + ref part = str->getPartAt(0); // Copy header ref hdr = part->getHeader(); @@ -654,7 +655,7 @@ void IMAPMessage::constructParsedMessage(ref parentPart, ref getPartCount() ; i < n ; ++i) { - ref part = str->getPartAt(i); + ref part = str->getPartAt(i); ref childPart = vmime::create (); @@ -681,7 +682,7 @@ void IMAPMessage::constructParsedMessage(ref parentPart, ref IMAPMessage::getParsedMessage() { // Fetch structure - ref structure = NULL; + ref structure = NULL; try { diff --git a/src/net/imap/IMAPPart.cpp b/src/net/imap/IMAPMessagePart.cpp similarity index 68% rename from src/net/imap/IMAPPart.cpp rename to src/net/imap/IMAPMessagePart.cpp index b5b754cb..48e063e8 100644 --- a/src/net/imap/IMAPPart.cpp +++ b/src/net/imap/IMAPMessagePart.cpp @@ -27,8 +27,8 @@ #if VMIME_HAVE_MESSAGING_FEATURES && VMIME_HAVE_MESSAGING_PROTO_IMAP -#include "vmime/net/imap/IMAPPart.hpp" -#include "vmime/net/imap/IMAPStructure.hpp" +#include "vmime/net/imap/IMAPMessagePart.hpp" +#include "vmime/net/imap/IMAPMessageStructure.hpp" namespace vmime { @@ -36,7 +36,7 @@ namespace net { namespace imap { -IMAPPart::IMAPPart(ref parent, const int number, const IMAPParser::body_type_mpart* mpart) +IMAPMessagePart::IMAPMessagePart(ref parent, const int number, const IMAPParser::body_type_mpart* mpart) : m_parent(parent), m_header(NULL), m_number(number), m_size(0) { m_mediaType = vmime::mediaType @@ -44,7 +44,7 @@ IMAPPart::IMAPPart(ref parent, const int number, const IMAPParser::bo } -IMAPPart::IMAPPart(ref parent, const int number, const IMAPParser::body_type_1part* part) +IMAPMessagePart::IMAPMessagePart(ref parent, const int number, const IMAPParser::body_type_1part* part) : m_parent(parent), m_header(NULL), m_number(number), m_size(0) { if (part->body_type_text()) @@ -74,49 +74,49 @@ IMAPPart::IMAPPart(ref parent, const int number, const IMAPParser::bo } -ref IMAPPart::getStructure() const +ref IMAPMessagePart::getStructure() const { if (m_structure != NULL) return m_structure; else - return IMAPStructure::emptyStructure(); + return IMAPMessageStructure::emptyStructure(); } -ref IMAPPart::getStructure() +ref IMAPMessagePart::getStructure() { if (m_structure != NULL) return m_structure; else - return IMAPStructure::emptyStructure(); + return IMAPMessageStructure::emptyStructure(); } -ref IMAPPart::getParent() const +ref IMAPMessagePart::getParent() const { return m_parent.acquire(); } -const mediaType& IMAPPart::getType() const +const mediaType& IMAPMessagePart::getType() const { return m_mediaType; } -int IMAPPart::getSize() const +int IMAPMessagePart::getSize() const { return m_size; } -int IMAPPart::getNumber() const +int IMAPMessagePart::getNumber() const { return m_number; } -ref IMAPPart::getHeader() const +ref IMAPMessagePart::getHeader() const { if (m_header == NULL) throw exceptions::unfetched_object(); @@ -126,24 +126,24 @@ ref IMAPPart::getHeader() const // static -ref IMAPPart::create - (ref parent, const int number, const IMAPParser::body* body) +ref IMAPMessagePart::create + (ref parent, const int number, const IMAPParser::body* body) { if (body->body_type_mpart()) { - ref part = vmime::create (parent, number, body->body_type_mpart()); - part->m_structure = vmime::create (part, body->body_type_mpart()->list()); + ref part = vmime::create (parent, number, body->body_type_mpart()); + part->m_structure = vmime::create (part, body->body_type_mpart()->list()); return part; } else { - return vmime::create (parent, number, body->body_type_1part()); + return vmime::create (parent, number, body->body_type_1part()); } } -header& IMAPPart::getOrCreateHeader() +header& IMAPMessagePart::getOrCreateHeader() { if (m_header != NULL) return *m_header; diff --git a/src/net/imap/IMAPMessagePartContentHandler.cpp b/src/net/imap/IMAPMessagePartContentHandler.cpp index c34dc076..34d53ac5 100644 --- a/src/net/imap/IMAPMessagePartContentHandler.cpp +++ b/src/net/imap/IMAPMessagePartContentHandler.cpp @@ -39,7 +39,7 @@ namespace imap { IMAPMessagePartContentHandler::IMAPMessagePartContentHandler - (ref msg, ref part, const vmime::encoding& encoding) + (ref msg, ref part, const vmime::encoding& encoding) : m_message(msg), m_part(part), m_encoding(encoding) { } @@ -49,7 +49,7 @@ ref IMAPMessagePartContentHandler::clone() const { return create (m_message.acquire().constCast (), - m_part.acquire().constCast (), + m_part.acquire().constCast (), m_encoding); } @@ -58,7 +58,7 @@ void IMAPMessagePartContentHandler::generate (utility::outputStream& os, const vmime::encoding& enc, const string::size_type maxLineLength) const { ref msg = m_message.acquire().constCast (); - ref part = m_part.acquire().constCast (); + ref part = m_part.acquire().constCast (); // Data is already encoded if (isEncoded()) @@ -125,7 +125,7 @@ void IMAPMessagePartContentHandler::extract (utility::outputStream& os, utility::progressListener* progress) const { ref msg = m_message.acquire().constCast (); - ref part = m_part.acquire().constCast (); + ref part = m_part.acquire().constCast (); // No decoding to perform if (!isEncoded()) @@ -155,7 +155,7 @@ void IMAPMessagePartContentHandler::extractRaw (utility::outputStream& os, utility::progressListener* progress) const { ref msg = m_message.acquire().constCast (); - ref part = m_part.acquire().constCast (); + ref part = m_part.acquire().constCast (); msg->extractPart(part, os, progress); } diff --git a/src/net/imap/IMAPStructure.cpp b/src/net/imap/IMAPMessageStructure.cpp similarity index 66% rename from src/net/imap/IMAPStructure.cpp rename to src/net/imap/IMAPMessageStructure.cpp index 4e04aa95..60f26c68 100644 --- a/src/net/imap/IMAPStructure.cpp +++ b/src/net/imap/IMAPMessageStructure.cpp @@ -27,8 +27,8 @@ #if VMIME_HAVE_MESSAGING_FEATURES && VMIME_HAVE_MESSAGING_PROTO_IMAP -#include "vmime/net/imap/IMAPStructure.hpp" -#include "vmime/net/imap/IMAPPart.hpp" +#include "vmime/net/imap/IMAPMessageStructure.hpp" +#include "vmime/net/imap/IMAPMessagePart.hpp" namespace vmime { @@ -36,51 +36,51 @@ namespace net { namespace imap { -IMAPStructure::IMAPStructure() +IMAPMessageStructure::IMAPMessageStructure() { } -IMAPStructure::IMAPStructure(const IMAPParser::body* body) +IMAPMessageStructure::IMAPMessageStructure(const IMAPParser::body* body) { - m_parts.push_back(IMAPPart::create(NULL, 0, body)); + m_parts.push_back(IMAPMessagePart::create(NULL, 0, body)); } -IMAPStructure::IMAPStructure(ref parent, const std::vector & list) +IMAPMessageStructure::IMAPMessageStructure(ref parent, const std::vector & list) { int number = 0; for (std::vector ::const_iterator it = list.begin() ; it != list.end() ; ++it, ++number) { - m_parts.push_back(IMAPPart::create(parent, number, *it)); + m_parts.push_back(IMAPMessagePart::create(parent, number, *it)); } } -ref IMAPStructure::getPartAt(const size_t x) const +ref IMAPMessageStructure::getPartAt(const size_t x) const { return m_parts[x]; } -ref IMAPStructure::getPartAt(const size_t x) +ref IMAPMessageStructure::getPartAt(const size_t x) { return m_parts[x]; } -size_t IMAPStructure::getPartCount() const +size_t IMAPMessageStructure::getPartCount() const { return m_parts.size(); } // static -ref IMAPStructure::emptyStructure() +ref IMAPMessageStructure::emptyStructure() { - static ref emptyStructure = vmime::create (); + static ref emptyStructure = vmime::create (); return emptyStructure; } diff --git a/src/net/maildir/maildirMessage.cpp b/src/net/maildir/maildirMessage.cpp index b6c12053..e63d5edf 100644 --- a/src/net/maildir/maildirMessage.cpp +++ b/src/net/maildir/maildirMessage.cpp @@ -28,6 +28,8 @@ #include "vmime/net/maildir/maildirMessage.hpp" +#include "vmime/net/maildir/maildirMessagePart.hpp" +#include "vmime/net/maildir/maildirMessageStructure.hpp" #include "vmime/net/maildir/maildirFolder.hpp" #include "vmime/net/maildir/maildirUtils.hpp" #include "vmime/net/maildir/maildirStore.hpp" @@ -45,193 +47,6 @@ namespace net { namespace maildir { -// -// maildirPart -// - -class maildirStructure; - -class maildirPart : public part -{ -public: - - maildirPart(ref parent, const int number, const bodyPart& part); - ~maildirPart(); - - - ref getStructure() const; - ref getStructure(); - - weak_ref getParent() const { return (m_parent); } - - const mediaType& getType() const { return (m_mediaType); } - int getSize() const { return (m_size); } - int getNumber() const { return (m_number); } - - ref getHeader() const - { - if (m_header == NULL) - throw exceptions::unfetched_object(); - else - return m_header; - } - - header& getOrCreateHeader() - { - if (m_header != NULL) - return (*m_header); - else - return (*(m_header = vmime::create
())); - } - - int getHeaderParsedOffset() const { return (m_headerParsedOffset); } - int getHeaderParsedLength() const { return (m_headerParsedLength); } - - int getBodyParsedOffset() const { return (m_bodyParsedOffset); } - int getBodyParsedLength() const { return (m_bodyParsedLength); } - - void initStructure(const bodyPart& part); - -private: - - ref m_structure; - weak_ref m_parent; - ref
m_header; - - int m_number; - int m_size; - mediaType m_mediaType; - - int m_headerParsedOffset; - int m_headerParsedLength; - - int m_bodyParsedOffset; - int m_bodyParsedLength; -}; - - - -// -// maildirStructure -// - -class maildirStructure : public structure -{ -public: - - maildirStructure() - { - } - - maildirStructure(ref parent, const bodyPart& part) - { - vmime::ref mpart = vmime::create (parent, 0, part); - mpart->initStructure(part); - - m_parts.push_back(mpart); - } - - maildirStructure(ref parent, const std::vector >& list) - { - for (unsigned int i = 0 ; i < list.size() ; ++i) - { - vmime::ref mpart = vmime::create (parent, i, *list[i]); - mpart->initStructure(*list[i]); - - m_parts.push_back(mpart); - } - } - - - ref getPartAt(const size_t x) const - { - return m_parts[x]; - } - - ref getPartAt(const size_t x) - { - return m_parts[x]; - } - - size_t getPartCount() const - { - return m_parts.size(); - } - - - static ref emptyStructure() - { - return m_emptyStructure; - } - -private: - - static ref m_emptyStructure; - - std::vector > m_parts; -}; - - -ref maildirStructure::m_emptyStructure = vmime::create (); - - - -maildirPart::maildirPart(ref parent, const int number, const bodyPart& part) - : m_parent(parent), m_header(NULL), m_number(number) -{ - m_headerParsedOffset = part.getHeader()->getParsedOffset(); - m_headerParsedLength = part.getHeader()->getParsedLength(); - - m_bodyParsedOffset = part.getBody()->getParsedOffset(); - m_bodyParsedLength = part.getBody()->getParsedLength(); - - m_size = part.getBody()->getContents()->getLength(); - - m_mediaType = part.getBody()->getContentType(); -} - - -maildirPart::~maildirPart() -{ -} - - -void maildirPart::initStructure(const bodyPart& part) -{ - if (part.getBody()->getPartList().size() == 0) - m_structure = NULL; - else - { - m_structure = vmime::create - (thisRef().dynamicCast (), - part.getBody()->getPartList()); - } -} - - -ref maildirPart::getStructure() const -{ - if (m_structure != NULL) - return m_structure; - else - return maildirStructure::emptyStructure(); -} - - -ref maildirPart::getStructure() -{ - if (m_structure != NULL) - return m_structure; - else - return maildirStructure::emptyStructure(); -} - - - -// -// maildirMessage -// - maildirMessage::maildirMessage(ref folder, const int num) : m_folder(folder), m_num(num), m_size(-1), m_flags(FLAG_UNDEFINED), m_expunged(false), m_structure(NULL) @@ -282,7 +97,7 @@ bool maildirMessage::isExpunged() const } -ref maildirMessage::getStructure() const +ref maildirMessage::getStructure() const { if (m_structure == NULL) throw exceptions::unfetched_object(); @@ -291,7 +106,7 @@ ref maildirMessage::getStructure() const } -ref maildirMessage::getStructure() +ref maildirMessage::getStructure() { if (m_structure == NULL) throw exceptions::unfetched_object(); @@ -337,11 +152,11 @@ void maildirMessage::extract(utility::outputStream& os, } -void maildirMessage::extractPart(ref p, utility::outputStream& os, +void maildirMessage::extractPart(ref p, utility::outputStream& os, utility::progressListener* progress, const int start, const int length, const bool peek) const { - ref mp = p.dynamicCast (); + ref mp = p.dynamicCast (); extractImpl(os, progress, mp->getBodyParsedOffset(), mp->getBodyParsedLength(), start, length, peek); @@ -395,11 +210,11 @@ void maildirMessage::extractImpl(utility::outputStream& os, utility::progressLis } -void maildirMessage::fetchPartHeader(ref p) +void maildirMessage::fetchPartHeader(ref p) { ref folder = m_folder.acquire(); - ref mp = p.dynamicCast (); + ref mp = p.dynamicCast (); ref fsf = platform::getHandler()->getFileSystemFactory(); @@ -508,7 +323,7 @@ void maildirMessage::fetch(ref msgFolder, const int options) // Extract structure if (options & folder::FETCH_STRUCTURE) { - m_structure = vmime::create (null, msg); + m_structure = vmime::create (null, msg); } // Extract some header fields or whole header diff --git a/src/net/maildir/maildirMessagePart.cpp b/src/net/maildir/maildirMessagePart.cpp new file mode 100644 index 00000000..75086ec3 --- /dev/null +++ b/src/net/maildir/maildirMessagePart.cpp @@ -0,0 +1,155 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2013 Vincent Richard +// +// 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 && VMIME_HAVE_MESSAGING_PROTO_MAILDIR + + +#include "vmime/net/maildir/maildirMessagePart.hpp" +#include "vmime/net/maildir/maildirMessageStructure.hpp" + + +namespace vmime { +namespace net { +namespace maildir { + + +maildirMessagePart::maildirMessagePart(ref parent, const int number, const bodyPart& part) + : m_parent(parent), m_header(NULL), m_number(number) +{ + m_headerParsedOffset = part.getHeader()->getParsedOffset(); + m_headerParsedLength = part.getHeader()->getParsedLength(); + + m_bodyParsedOffset = part.getBody()->getParsedOffset(); + m_bodyParsedLength = part.getBody()->getParsedLength(); + + m_size = part.getBody()->getContents()->getLength(); + + m_mediaType = part.getBody()->getContentType(); +} + + +maildirMessagePart::~maildirMessagePart() +{ +} + + +void maildirMessagePart::initStructure(const bodyPart& part) +{ + if (part.getBody()->getPartList().size() == 0) + m_structure = NULL; + else + { + m_structure = vmime::create + (thisRef().dynamicCast (), + part.getBody()->getPartList()); + } +} + + +ref maildirMessagePart::getStructure() const +{ + if (m_structure != NULL) + return m_structure; + else + return maildirMessageStructure::emptyStructure(); +} + + +ref maildirMessagePart::getStructure() +{ + if (m_structure != NULL) + return m_structure; + else + return maildirMessageStructure::emptyStructure(); +} + + +const mediaType& maildirMessagePart::getType() const +{ + return m_mediaType; +} + + +int maildirMessagePart::getSize() const +{ + return m_size; +} + + +int maildirMessagePart::getNumber() const +{ + return m_number; +} + + +ref maildirMessagePart::getHeader() const +{ + if (m_header == NULL) + throw exceptions::unfetched_object(); + else + return m_header; +} + + +header& maildirMessagePart::getOrCreateHeader() +{ + if (m_header != NULL) + return *m_header; + else + return *(m_header = vmime::create
()); +} + + +int maildirMessagePart::getHeaderParsedOffset() const +{ + return m_headerParsedOffset; +} + + +int maildirMessagePart::getHeaderParsedLength() const +{ + return m_headerParsedLength; +} + + +int maildirMessagePart::getBodyParsedOffset() const +{ + return m_bodyParsedOffset; +} + + +int maildirMessagePart::getBodyParsedLength() const +{ + return m_bodyParsedLength; +} + + +} // maildir +} // net +} // vmime + + +#endif // VMIME_HAVE_MESSAGING_FEATURES && VMIME_HAVE_MESSAGING_PROTO_MAILDIR diff --git a/src/net/maildir/maildirMessageStructure.cpp b/src/net/maildir/maildirMessageStructure.cpp new file mode 100644 index 00000000..a0473f9e --- /dev/null +++ b/src/net/maildir/maildirMessageStructure.cpp @@ -0,0 +1,98 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2013 Vincent Richard +// +// 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 && VMIME_HAVE_MESSAGING_PROTO_MAILDIR + + +#include "vmime/net/maildir/maildirMessageStructure.hpp" +#include "vmime/net/maildir/maildirMessagePart.hpp" + + +namespace vmime { +namespace net { +namespace maildir { + + +ref maildirMessageStructure::m_emptyStructure = vmime::create (); + + +maildirMessageStructure::maildirMessageStructure() +{ +} + + +maildirMessageStructure::maildirMessageStructure(ref parent, const bodyPart& part) +{ + vmime::ref mpart = vmime::create (parent, 0, part); + mpart->initStructure(part); + + m_parts.push_back(mpart); +} + + +maildirMessageStructure::maildirMessageStructure(ref parent, const std::vector >& list) +{ + for (unsigned int i = 0 ; i < list.size() ; ++i) + { + vmime::ref mpart = vmime::create (parent, i, *list[i]); + mpart->initStructure(*list[i]); + + m_parts.push_back(mpart); + } +} + + +ref maildirMessageStructure::getPartAt(const size_t x) const +{ + return m_parts[x]; +} + + +ref maildirMessageStructure::getPartAt(const size_t x) +{ + return m_parts[x]; +} + + +size_t maildirMessageStructure::getPartCount() const +{ + return m_parts.size(); +} + + +// static +ref maildirMessageStructure::emptyStructure() +{ + return m_emptyStructure; +} + + +} // maildir +} // net +} // vmime + + +#endif // VMIME_HAVE_MESSAGING_FEATURES && VMIME_HAVE_MESSAGING_PROTO_MAILDIR diff --git a/src/net/message.cpp b/src/net/message.cpp index 88360064..1024bcba 100644 --- a/src/net/message.cpp +++ b/src/net/message.cpp @@ -34,19 +34,19 @@ namespace vmime { namespace net { -ref part::getPartAt(const size_t pos) const +ref messagePart::getPartAt(const size_t pos) const { return getStructure()->getPartAt(pos); } -ref part::getPartAt(const size_t pos) +ref messagePart::getPartAt(const size_t pos) { return getStructure()->getPartAt(pos); } -size_t part::getPartCount() const +size_t messagePart::getPartCount() const { return getStructure()->getPartCount(); } diff --git a/src/net/pop3/POP3Message.cpp b/src/net/pop3/POP3Message.cpp index 659e3d79..5b883e15 100644 --- a/src/net/pop3/POP3Message.cpp +++ b/src/net/pop3/POP3Message.cpp @@ -104,13 +104,13 @@ int POP3Message::getFlags() const } -ref POP3Message::getStructure() const +ref POP3Message::getStructure() const { throw exceptions::operation_not_supported(); } -ref POP3Message::getStructure() +ref POP3Message::getStructure() { throw exceptions::operation_not_supported(); } @@ -157,7 +157,7 @@ void POP3Message::extract(utility::outputStream& os, void POP3Message::extractPart - (ref /* p */, utility::outputStream& /* os */, + (ref /* p */, utility::outputStream& /* os */, utility::progressListener* /* progress */, const int /* start */, const int /* length */, const bool /* peek */) const @@ -166,7 +166,7 @@ void POP3Message::extractPart } -void POP3Message::fetchPartHeader(ref /* p */) +void POP3Message::fetchPartHeader(ref /* p */) { throw exceptions::operation_not_supported(); } diff --git a/vmime/net/imap/IMAPMessage.hpp b/vmime/net/imap/IMAPMessage.hpp index fb86696f..fdda139a 100644 --- a/vmime/net/imap/IMAPMessage.hpp +++ b/vmime/net/imap/IMAPMessage.hpp @@ -84,8 +84,8 @@ public: bool isExpunged() const; - ref getStructure() const; - ref getStructure(); + ref getStructure() const; + ref getStructure(); ref getHeader() const; @@ -93,9 +93,9 @@ public: void setFlags(const int flags, const int mode = FLAG_MODE_SET); void extract(utility::outputStream& os, utility::progressListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; - void extractPart(ref p, utility::outputStream& os, utility::progressListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; + void extractPart(ref p, utility::outputStream& os, utility::progressListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; - void fetchPartHeader(ref p); + void fetchPartHeader(ref p); ref getParsedMessage(); @@ -107,7 +107,7 @@ private: * * @param str structure for which to fetch parts headers */ - void fetchPartHeaderForStructure(ref str); + void fetchPartHeaderForStructure(ref str); /** Recursively contruct parsed message from structure. * Called by getParsedMessage(). @@ -116,7 +116,7 @@ private: * @param str structure for which to construct part * @param level current nesting level (0 is root) */ - void constructParsedMessage(ref parentPart, ref str, int level = 0); + void constructParsedMessage(ref parentPart, ref str, int level = 0); enum ExtractFlags @@ -126,7 +126,7 @@ private: EXTRACT_PEEK = 0x10 }; - void extractImpl(ref p, utility::outputStream& os, utility::progressListener* progress, + void extractImpl(ref p, utility::outputStream& os, utility::progressListener* progress, const int start, const int length, const int extractFlags) const; @@ -145,7 +145,7 @@ private: vmime_uint64 m_modseq; ref
m_header; - ref m_structure; + ref m_structure; }; diff --git a/vmime/net/imap/IMAPPart.hpp b/vmime/net/imap/IMAPMessagePart.hpp similarity index 68% rename from vmime/net/imap/IMAPPart.hpp rename to vmime/net/imap/IMAPMessagePart.hpp index 2422f5a1..5c38501d 100644 --- a/vmime/net/imap/IMAPPart.hpp +++ b/vmime/net/imap/IMAPMessagePart.hpp @@ -21,8 +21,8 @@ // the GNU General Public License cover the whole combination. // -#ifndef VMIME_NET_IMAP_IMAPPART_HPP_INCLUDED -#define VMIME_NET_IMAP_IMAPPART_HPP_INCLUDED +#ifndef VMIME_NET_IMAP_IMAPMESSAGEPART_HPP_INCLUDED +#define VMIME_NET_IMAP_IMAPMESSAGEPART_HPP_INCLUDED #include "vmime/config.hpp" @@ -41,24 +41,24 @@ namespace net { namespace imap { -class IMAPStructure; +class IMAPMessageStructure; -class VMIME_EXPORT IMAPPart : public part +class VMIME_EXPORT IMAPMessagePart : public messagePart { private: friend class vmime::creator; - IMAPPart(ref parent, const int number, const IMAPParser::body_type_mpart* mpart); - IMAPPart(ref parent, const int number, const IMAPParser::body_type_1part* part); + IMAPMessagePart(ref parent, const int number, const IMAPParser::body_type_mpart* mpart); + IMAPMessagePart(ref parent, const int number, const IMAPParser::body_type_1part* part); public: - ref getStructure() const; - ref getStructure(); + ref getStructure() const; + ref getStructure(); - ref getParent() const; + ref getParent() const; const mediaType& getType() const; int getSize() const; @@ -67,16 +67,16 @@ public: ref getHeader() const; - static ref create - (ref parent, const int number, const IMAPParser::body* body); + static ref create + (ref parent, const int number, const IMAPParser::body* body); header& getOrCreateHeader(); private: - ref m_structure; - weak_ref m_parent; + ref m_structure; + weak_ref m_parent; ref
m_header; int m_number; @@ -92,5 +92,5 @@ private: #endif // VMIME_HAVE_MESSAGING_FEATURES && VMIME_HAVE_MESSAGING_PROTO_IMAP -#endif // VMIME_NET_IMAP_IMAPPART_HPP_INCLUDED +#endif // VMIME_NET_IMAP_IMAPMESSAGEPART_HPP_INCLUDED diff --git a/vmime/net/imap/IMAPMessagePartContentHandler.hpp b/vmime/net/imap/IMAPMessagePartContentHandler.hpp index 602b0879..ac273151 100644 --- a/vmime/net/imap/IMAPMessagePartContentHandler.hpp +++ b/vmime/net/imap/IMAPMessagePartContentHandler.hpp @@ -44,7 +44,7 @@ class VMIME_EXPORT IMAPMessagePartContentHandler : public contentHandler { public: - IMAPMessagePartContentHandler(ref msg, ref part, const vmime::encoding& encoding); + IMAPMessagePartContentHandler(ref msg, ref part, const vmime::encoding& encoding); ref clone() const; @@ -69,7 +69,7 @@ public: private: weak_ref m_message; - weak_ref m_part; + weak_ref m_part; vmime::encoding m_encoding; vmime::mediaType m_contentType; diff --git a/vmime/net/imap/IMAPStructure.hpp b/vmime/net/imap/IMAPMessageStructure.hpp similarity index 69% rename from vmime/net/imap/IMAPStructure.hpp rename to vmime/net/imap/IMAPMessageStructure.hpp index 95cdfcbf..e2a9f169 100644 --- a/vmime/net/imap/IMAPStructure.hpp +++ b/vmime/net/imap/IMAPMessageStructure.hpp @@ -21,8 +21,8 @@ // the GNU General Public License cover the whole combination. // -#ifndef VMIME_NET_IMAP_IMAPSTRUCTURE_HPP_INCLUDED -#define VMIME_NET_IMAP_IMAPSTRUCTURE_HPP_INCLUDED +#ifndef VMIME_NET_IMAP_IMAPMESSAGESTRUCTURE_HPP_INCLUDED +#define VMIME_NET_IMAP_IMAPMESSAGESTRUCTURE_HPP_INCLUDED #include "vmime/config.hpp" @@ -41,26 +41,26 @@ namespace net { namespace imap { -class IMAPPart; +class IMAPMessagePart; -class VMIME_EXPORT IMAPStructure : public structure +class VMIME_EXPORT IMAPMessageStructure : public messageStructure { public: - IMAPStructure(); - IMAPStructure(const IMAPParser::body* body); - IMAPStructure(ref parent, const std::vector & list); + IMAPMessageStructure(); + IMAPMessageStructure(const IMAPParser::body* body); + IMAPMessageStructure(ref parent, const std::vector & list); - ref getPartAt(const size_t x) const; - ref getPartAt(const size_t x); + ref getPartAt(const size_t x) const; + ref getPartAt(const size_t x); size_t getPartCount() const; - static ref emptyStructure(); + static ref emptyStructure(); private: - std::vector > m_parts; + std::vector > m_parts; }; @@ -71,5 +71,5 @@ private: #endif // VMIME_HAVE_MESSAGING_FEATURES && VMIME_HAVE_MESSAGING_PROTO_IMAP -#endif // VMIME_NET_IMAP_IMAPSTRUCTURE_HPP_INCLUDED +#endif // VMIME_NET_IMAP_IMAPMESSAGESTRUCTURE_HPP_INCLUDED diff --git a/vmime/net/maildir/maildirMessage.hpp b/vmime/net/maildir/maildirMessage.hpp index de8c1751..08c13daa 100644 --- a/vmime/net/maildir/maildirMessage.hpp +++ b/vmime/net/maildir/maildirMessage.hpp @@ -68,8 +68,8 @@ public: bool isExpunged() const; - ref getStructure() const; - ref getStructure(); + ref getStructure() const; + ref getStructure(); ref getHeader() const; @@ -77,9 +77,9 @@ public: void setFlags(const int flags, const int mode = FLAG_MODE_SET); void extract(utility::outputStream& os, utility::progressListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; - void extractPart(ref p, utility::outputStream& os, utility::progressListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; + void extractPart(ref p, utility::outputStream& os, utility::progressListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; - void fetchPartHeader(ref p); + void fetchPartHeader(ref p); ref getParsedMessage(); @@ -103,7 +103,7 @@ private: uid m_uid; ref
m_header; - ref m_structure; + ref m_structure; }; diff --git a/vmime/net/maildir/maildirMessagePart.hpp b/vmime/net/maildir/maildirMessagePart.hpp new file mode 100644 index 00000000..f79804ca --- /dev/null +++ b/vmime/net/maildir/maildirMessagePart.hpp @@ -0,0 +1,99 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2013 Vincent Richard +// +// 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_MAILDIR_MAILDIRMESSAGEPART_HPP_INCLUDED +#define VMIME_NET_MAILDIR_MAILDIRMESSAGEPART_HPP_INCLUDED + + +#include "vmime/config.hpp" + + +#if VMIME_HAVE_MESSAGING_FEATURES && VMIME_HAVE_MESSAGING_PROTO_MAILDIR + + +#include "vmime/net/message.hpp" + + +namespace vmime { +namespace net { +namespace maildir { + + +class maildirMessageStructure; + + +class maildirMessagePart : public messagePart +{ +public: + + maildirMessagePart(ref parent, const int number, const bodyPart& part); + ~maildirMessagePart(); + + + ref getStructure() const; + ref getStructure(); + + weak_ref getParent() const { return (m_parent); } + + const mediaType& getType() const; + int getSize() const; + int getNumber() const; + + ref getHeader() const; + + header& getOrCreateHeader(); + + int getHeaderParsedOffset() const; + int getHeaderParsedLength() const; + + int getBodyParsedOffset() const; + int getBodyParsedLength() const; + + void initStructure(const bodyPart& part); + +private: + + ref m_structure; + weak_ref m_parent; + ref
m_header; + + int m_number; + int m_size; + mediaType m_mediaType; + + int m_headerParsedOffset; + int m_headerParsedLength; + + int m_bodyParsedOffset; + int m_bodyParsedLength; +}; + + +} // maildir +} // net +} // vmime + + +#endif // VMIME_HAVE_MESSAGING_FEATURES && VMIME_HAVE_MESSAGING_PROTO_MAILDIR + +#endif // VMIME_NET_MAILDIR_MAILDIRMESSAGEPART_HPP_INCLUDED diff --git a/vmime/net/maildir/maildirMessageStructure.hpp b/vmime/net/maildir/maildirMessageStructure.hpp new file mode 100644 index 00000000..6d62be2b --- /dev/null +++ b/vmime/net/maildir/maildirMessageStructure.hpp @@ -0,0 +1,76 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2013 Vincent Richard +// +// 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_MAILDIR_MAILDIRMESSAGESTRUCTURE_HPP_INCLUDED +#define VMIME_NET_MAILDIR_MAILDIRMESSAGESTRUCTURE_HPP_INCLUDED + + +#include "vmime/config.hpp" + + +#if VMIME_HAVE_MESSAGING_FEATURES && VMIME_HAVE_MESSAGING_PROTO_MAILDIR + + +#include "vmime/net/message.hpp" + + +namespace vmime { +namespace net { +namespace maildir { + + +class maildirMessagePart; + + +class maildirMessageStructure : public messageStructure +{ +public: + + maildirMessageStructure(); + maildirMessageStructure(ref parent, const bodyPart& part); + maildirMessageStructure(ref parent, const std::vector >& list); + + + ref getPartAt(const size_t x) const; + ref getPartAt(const size_t x); + + size_t getPartCount() const; + + static ref emptyStructure(); + +private: + + static ref m_emptyStructure; + + std::vector > m_parts; +}; + + +} // maildir +} // net +} // vmime + + +#endif // VMIME_HAVE_MESSAGING_FEATURES && VMIME_HAVE_MESSAGING_PROTO_MAILDIR + +#endif // VMIME_NET_MAILDIR_MAILDIRMESSAGESTRUCTURE_HPP_INCLUDED diff --git a/vmime/net/message.hpp b/vmime/net/message.hpp index 3b94fbf3..a0f79aae 100644 --- a/vmime/net/message.hpp +++ b/vmime/net/message.hpp @@ -44,20 +44,20 @@ namespace vmime { namespace net { -class structure; +class messageStructure; /** A MIME part in a message. */ -class VMIME_EXPORT part : public object +class VMIME_EXPORT messagePart : public object { protected: - part() { } - part(const part&) : object() { } + messagePart() { } + messagePart(const messagePart&) : object() { } - virtual ~part() { } + virtual ~messagePart() { } public: @@ -65,13 +65,13 @@ public: * * @return structure of the part */ - virtual ref getStructure() const = 0; + virtual ref getStructure() const = 0; /** Return the structure of this part. * * @return structure of the part */ - virtual ref getStructure() = 0; + virtual ref getStructure() = 0; /** Return the header section for this part (you must fetch header * before using this function: see message::fetchPartHeader). @@ -105,7 +105,7 @@ public: * @param pos index of the sub-part * @return sub-part at position 'pos' */ - ref getPartAt(const size_t pos) const; + ref getPartAt(const size_t pos) const; /** Return the sub-part at the specified position (zero is the * first part). @@ -113,7 +113,7 @@ public: * @param pos index of the sub-part * @return sub-part at position 'pos' */ - ref getPartAt(const size_t pos); + ref getPartAt(const size_t pos); /** Return the number of sub-parts in this part. * @@ -126,16 +126,16 @@ public: /** Structure of a MIME part/message. */ -class VMIME_EXPORT structure : public object +class VMIME_EXPORT messageStructure : public object { protected: - structure() { } - structure(const structure&) : object() { } + messageStructure() { } + messageStructure(const messageStructure&) : object() { } public: - virtual ~structure() { } + virtual ~messageStructure() { } /** Return the part at the specified position (first * part is at position 0). @@ -143,7 +143,7 @@ public: * @param pos position * @return part at position 'pos' */ - virtual ref getPartAt(const size_t pos) const = 0; + virtual ref getPartAt(const size_t pos) const = 0; /** Return the part at the specified position (first * part is at position 0). @@ -151,7 +151,7 @@ public: * @param pos position * @return part at position 'pos' */ - virtual ref getPartAt(const size_t pos) = 0; + virtual ref getPartAt(const size_t pos) = 0; /** Return the number of parts in this part. * @@ -183,13 +183,13 @@ public: * * @return MIME structure of the message */ - virtual ref getStructure() const = 0; + virtual ref getStructure() const = 0; /** Return the MIME structure of the message (must fetch before). * * @return MIME structure of the message */ - virtual ref getStructure() = 0; + virtual ref getStructure() = 0; /** Return a reference to the header fields of the message (must fetch before). * @@ -289,13 +289,19 @@ public: * be supported by the protocol (IMAP supports this), but it will NOT throw * an exception if not supported. */ - virtual void extractPart(ref p, utility::outputStream& os, utility::progressListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const = 0; + virtual void extractPart + (ref p, + utility::outputStream& os, + utility::progressListener* progress = NULL, + const int start = 0, + const int length = -1, + const bool peek = false) const = 0; /** Fetch the MIME header for the specified part. * * @param p the part for which to fetch the header */ - virtual void fetchPartHeader(ref p) = 0; + virtual void fetchPartHeader(ref p) = 0; /** Get the RFC-822 message for this abstract message. * Warning: This may require getting some data (ie: structure and headers) from diff --git a/vmime/net/pop3/POP3Message.hpp b/vmime/net/pop3/POP3Message.hpp index 31b26154..113d0e86 100644 --- a/vmime/net/pop3/POP3Message.hpp +++ b/vmime/net/pop3/POP3Message.hpp @@ -68,8 +68,8 @@ public: bool isExpunged() const; - ref getStructure() const; - ref getStructure(); + ref getStructure() const; + ref getStructure(); ref getHeader() const; @@ -77,9 +77,9 @@ public: void setFlags(const int flags, const int mode = FLAG_MODE_SET); void extract(utility::outputStream& os, utility::progressListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; - void extractPart(ref p, utility::outputStream& os, utility::progressListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; + void extractPart(ref p, utility::outputStream& os, utility::progressListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; - void fetchPartHeader(ref p); + void fetchPartHeader(ref p); ref getParsedMessage();