From 62828e20d483647a9d27bb42cb65943da0f75b78 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Tue, 16 Jul 2013 12:09:37 +0200 Subject: Renamed net::*{part|structure} to net::*message{Part|Structure}. Splitted code in multiple files. --- src/net/imap/IMAPMessage.cpp | 33 ++--- src/net/imap/IMAPMessagePart.cpp | 161 +++++++++++++++++++++++++ src/net/imap/IMAPMessagePartContentHandler.cpp | 10 +- src/net/imap/IMAPMessageStructure.cpp | 94 +++++++++++++++ src/net/imap/IMAPPart.cpp | 161 ------------------------- src/net/imap/IMAPStructure.cpp | 94 --------------- 6 files changed, 277 insertions(+), 276 deletions(-) create mode 100644 src/net/imap/IMAPMessagePart.cpp create mode 100644 src/net/imap/IMAPMessageStructure.cpp delete mode 100644 src/net/imap/IMAPPart.cpp delete mode 100644 src/net/imap/IMAPStructure.cpp (limited to 'src/net/imap') 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/IMAPMessagePart.cpp b/src/net/imap/IMAPMessagePart.cpp new file mode 100644 index 00000000..48e063e8 --- /dev/null +++ b/src/net/imap/IMAPMessagePart.cpp @@ -0,0 +1,161 @@ +// +// 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_IMAP + + +#include "vmime/net/imap/IMAPMessagePart.hpp" +#include "vmime/net/imap/IMAPMessageStructure.hpp" + + +namespace vmime { +namespace net { +namespace imap { + + +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 + ("multipart", mpart->media_subtype()->value()); +} + + +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()) + { + m_mediaType = vmime::mediaType + ("text", part->body_type_text()-> + media_text()->media_subtype()->value()); + + m_size = part->body_type_text()->body_fields()->body_fld_octets()->value(); + } + else if (part->body_type_msg()) + { + m_mediaType = vmime::mediaType + ("message", part->body_type_msg()-> + media_message()->media_subtype()->value()); + } + else + { + m_mediaType = vmime::mediaType + (part->body_type_basic()->media_basic()->media_type()->value(), + part->body_type_basic()->media_basic()->media_subtype()->value()); + + m_size = part->body_type_basic()->body_fields()->body_fld_octets()->value(); + } + + m_structure = NULL; +} + + +ref IMAPMessagePart::getStructure() const +{ + if (m_structure != NULL) + return m_structure; + else + return IMAPMessageStructure::emptyStructure(); +} + + +ref IMAPMessagePart::getStructure() +{ + if (m_structure != NULL) + return m_structure; + else + return IMAPMessageStructure::emptyStructure(); +} + + +ref IMAPMessagePart::getParent() const +{ + return m_parent.acquire(); +} + + +const mediaType& IMAPMessagePart::getType() const +{ + return m_mediaType; +} + + +int IMAPMessagePart::getSize() const +{ + return m_size; +} + + +int IMAPMessagePart::getNumber() const +{ + return m_number; +} + + +ref IMAPMessagePart::getHeader() const +{ + if (m_header == NULL) + throw exceptions::unfetched_object(); + else + return m_header; +} + + +// static +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()); + + return part; + } + else + { + return vmime::create (parent, number, body->body_type_1part()); + } +} + + +header& IMAPMessagePart::getOrCreateHeader() +{ + if (m_header != NULL) + return *m_header; + else + return *(m_header = vmime::create
()); +} + + +} // imap +} // net +} // vmime + + +#endif // VMIME_HAVE_MESSAGING_FEATURES && VMIME_HAVE_MESSAGING_PROTO_IMAP + 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/IMAPMessageStructure.cpp b/src/net/imap/IMAPMessageStructure.cpp new file mode 100644 index 00000000..60f26c68 --- /dev/null +++ b/src/net/imap/IMAPMessageStructure.cpp @@ -0,0 +1,94 @@ +// +// 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_IMAP + + +#include "vmime/net/imap/IMAPMessageStructure.hpp" +#include "vmime/net/imap/IMAPMessagePart.hpp" + + +namespace vmime { +namespace net { +namespace imap { + + +IMAPMessageStructure::IMAPMessageStructure() +{ +} + + +IMAPMessageStructure::IMAPMessageStructure(const IMAPParser::body* body) +{ + m_parts.push_back(IMAPMessagePart::create(NULL, 0, body)); +} + + +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(IMAPMessagePart::create(parent, number, *it)); + } +} + + +ref IMAPMessageStructure::getPartAt(const size_t x) const +{ + return m_parts[x]; +} + + +ref IMAPMessageStructure::getPartAt(const size_t x) +{ + return m_parts[x]; +} + + +size_t IMAPMessageStructure::getPartCount() const +{ + return m_parts.size(); +} + + +// static +ref IMAPMessageStructure::emptyStructure() +{ + static ref emptyStructure = vmime::create (); + return emptyStructure; +} + + +} // imap +} // net +} // vmime + + +#endif // VMIME_HAVE_MESSAGING_FEATURES && VMIME_HAVE_MESSAGING_PROTO_IMAP + diff --git a/src/net/imap/IMAPPart.cpp b/src/net/imap/IMAPPart.cpp deleted file mode 100644 index b5b754cb..00000000 --- a/src/net/imap/IMAPPart.cpp +++ /dev/null @@ -1,161 +0,0 @@ -// -// 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_IMAP - - -#include "vmime/net/imap/IMAPPart.hpp" -#include "vmime/net/imap/IMAPStructure.hpp" - - -namespace vmime { -namespace net { -namespace imap { - - -IMAPPart::IMAPPart(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 - ("multipart", mpart->media_subtype()->value()); -} - - -IMAPPart::IMAPPart(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()) - { - m_mediaType = vmime::mediaType - ("text", part->body_type_text()-> - media_text()->media_subtype()->value()); - - m_size = part->body_type_text()->body_fields()->body_fld_octets()->value(); - } - else if (part->body_type_msg()) - { - m_mediaType = vmime::mediaType - ("message", part->body_type_msg()-> - media_message()->media_subtype()->value()); - } - else - { - m_mediaType = vmime::mediaType - (part->body_type_basic()->media_basic()->media_type()->value(), - part->body_type_basic()->media_basic()->media_subtype()->value()); - - m_size = part->body_type_basic()->body_fields()->body_fld_octets()->value(); - } - - m_structure = NULL; -} - - -ref IMAPPart::getStructure() const -{ - if (m_structure != NULL) - return m_structure; - else - return IMAPStructure::emptyStructure(); -} - - -ref IMAPPart::getStructure() -{ - if (m_structure != NULL) - return m_structure; - else - return IMAPStructure::emptyStructure(); -} - - -ref IMAPPart::getParent() const -{ - return m_parent.acquire(); -} - - -const mediaType& IMAPPart::getType() const -{ - return m_mediaType; -} - - -int IMAPPart::getSize() const -{ - return m_size; -} - - -int IMAPPart::getNumber() const -{ - return m_number; -} - - -ref IMAPPart::getHeader() const -{ - if (m_header == NULL) - throw exceptions::unfetched_object(); - else - return m_header; -} - - -// static -ref IMAPPart::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()); - - return part; - } - else - { - return vmime::create (parent, number, body->body_type_1part()); - } -} - - -header& IMAPPart::getOrCreateHeader() -{ - if (m_header != NULL) - return *m_header; - else - return *(m_header = vmime::create
()); -} - - -} // imap -} // net -} // vmime - - -#endif // VMIME_HAVE_MESSAGING_FEATURES && VMIME_HAVE_MESSAGING_PROTO_IMAP - diff --git a/src/net/imap/IMAPStructure.cpp b/src/net/imap/IMAPStructure.cpp deleted file mode 100644 index 4e04aa95..00000000 --- a/src/net/imap/IMAPStructure.cpp +++ /dev/null @@ -1,94 +0,0 @@ -// -// 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_IMAP - - -#include "vmime/net/imap/IMAPStructure.hpp" -#include "vmime/net/imap/IMAPPart.hpp" - - -namespace vmime { -namespace net { -namespace imap { - - -IMAPStructure::IMAPStructure() -{ -} - - -IMAPStructure::IMAPStructure(const IMAPParser::body* body) -{ - m_parts.push_back(IMAPPart::create(NULL, 0, body)); -} - - -IMAPStructure::IMAPStructure(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)); - } -} - - -ref IMAPStructure::getPartAt(const size_t x) const -{ - return m_parts[x]; -} - - -ref IMAPStructure::getPartAt(const size_t x) -{ - return m_parts[x]; -} - - -size_t IMAPStructure::getPartCount() const -{ - return m_parts.size(); -} - - -// static -ref IMAPStructure::emptyStructure() -{ - static ref emptyStructure = vmime::create (); - return emptyStructure; -} - - -} // imap -} // net -} // vmime - - -#endif // VMIME_HAVE_MESSAGING_FEATURES && VMIME_HAVE_MESSAGING_PROTO_IMAP - -- cgit v1.2.3