aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/imap/IMAPMessagePart.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/imap/IMAPMessagePart.cpp')
-rw-r--r--src/net/imap/IMAPMessagePart.cpp161
1 files changed, 161 insertions, 0 deletions
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 <[email protected]>
+//
+// 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 <IMAPMessagePart> 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 <IMAPMessagePart> 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 <const messageStructure> IMAPMessagePart::getStructure() const
+{
+ if (m_structure != NULL)
+ return m_structure;
+ else
+ return IMAPMessageStructure::emptyStructure();
+}
+
+
+ref <messageStructure> IMAPMessagePart::getStructure()
+{
+ if (m_structure != NULL)
+ return m_structure;
+ else
+ return IMAPMessageStructure::emptyStructure();
+}
+
+
+ref <const IMAPMessagePart> 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 <const header> IMAPMessagePart::getHeader() const
+{
+ if (m_header == NULL)
+ throw exceptions::unfetched_object();
+ else
+ return m_header;
+}
+
+
+// static
+ref <IMAPMessagePart> IMAPMessagePart::create
+ (ref <IMAPMessagePart> parent, const int number, const IMAPParser::body* body)
+{
+ if (body->body_type_mpart())
+ {
+ ref <IMAPMessagePart> part = vmime::create <IMAPMessagePart>(parent, number, body->body_type_mpart());
+ part->m_structure = vmime::create <IMAPMessageStructure>(part, body->body_type_mpart()->list());
+
+ return part;
+ }
+ else
+ {
+ return vmime::create <IMAPMessagePart>(parent, number, body->body_type_1part());
+ }
+}
+
+
+header& IMAPMessagePart::getOrCreateHeader()
+{
+ if (m_header != NULL)
+ return *m_header;
+ else
+ return *(m_header = vmime::create <header>());
+}
+
+
+} // imap
+} // net
+} // vmime
+
+
+#endif // VMIME_HAVE_MESSAGING_FEATURES && VMIME_HAVE_MESSAGING_PROTO_IMAP
+