aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/maildir
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/maildir')
-rw-r--r--src/net/maildir/maildirMessage.cpp203
-rw-r--r--src/net/maildir/maildirMessagePart.cpp155
-rw-r--r--src/net/maildir/maildirMessageStructure.cpp98
3 files changed, 262 insertions, 194 deletions
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 <maildirPart> parent, const int number, const bodyPart& part);
- ~maildirPart();
-
-
- ref <const structure> getStructure() const;
- ref <structure> getStructure();
-
- weak_ref <const maildirPart> 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 <const header> 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 <header>()));
- }
-
- 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 <maildirStructure> m_structure;
- weak_ref <maildirPart> m_parent;
- ref <header> 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 <maildirPart> parent, const bodyPart& part)
- {
- vmime::ref <maildirPart> mpart = vmime::create <maildirPart>(parent, 0, part);
- mpart->initStructure(part);
-
- m_parts.push_back(mpart);
- }
-
- maildirStructure(ref <maildirPart> parent, const std::vector <ref <const vmime::bodyPart> >& list)
- {
- for (unsigned int i = 0 ; i < list.size() ; ++i)
- {
- vmime::ref <maildirPart> mpart = vmime::create <maildirPart>(parent, i, *list[i]);
- mpart->initStructure(*list[i]);
-
- m_parts.push_back(mpart);
- }
- }
-
-
- ref <const part> getPartAt(const size_t x) const
- {
- return m_parts[x];
- }
-
- ref <part> getPartAt(const size_t x)
- {
- return m_parts[x];
- }
-
- size_t getPartCount() const
- {
- return m_parts.size();
- }
-
-
- static ref <maildirStructure> emptyStructure()
- {
- return m_emptyStructure;
- }
-
-private:
-
- static ref <maildirStructure> m_emptyStructure;
-
- std::vector <ref <maildirPart> > m_parts;
-};
-
-
-ref <maildirStructure> maildirStructure::m_emptyStructure = vmime::create <maildirStructure>();
-
-
-
-maildirPart::maildirPart(ref <maildirPart> 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 <maildirStructure>
- (thisRef().dynamicCast <maildirPart>(),
- part.getBody()->getPartList());
- }
-}
-
-
-ref <const structure> maildirPart::getStructure() const
-{
- if (m_structure != NULL)
- return m_structure;
- else
- return maildirStructure::emptyStructure();
-}
-
-
-ref <structure> maildirPart::getStructure()
-{
- if (m_structure != NULL)
- return m_structure;
- else
- return maildirStructure::emptyStructure();
-}
-
-
-
-//
-// maildirMessage
-//
-
maildirMessage::maildirMessage(ref <maildirFolder> 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 <const structure> maildirMessage::getStructure() const
+ref <const messageStructure> maildirMessage::getStructure() const
{
if (m_structure == NULL)
throw exceptions::unfetched_object();
@@ -291,7 +106,7 @@ ref <const structure> maildirMessage::getStructure() const
}
-ref <structure> maildirMessage::getStructure()
+ref <messageStructure> maildirMessage::getStructure()
{
if (m_structure == NULL)
throw exceptions::unfetched_object();
@@ -337,11 +152,11 @@ void maildirMessage::extract(utility::outputStream& os,
}
-void maildirMessage::extractPart(ref <const part> p, utility::outputStream& os,
+void maildirMessage::extractPart(ref <const messagePart> p, utility::outputStream& os,
utility::progressListener* progress, const int start,
const int length, const bool peek) const
{
- ref <const maildirPart> mp = p.dynamicCast <const maildirPart>();
+ ref <const maildirMessagePart> mp = p.dynamicCast <const maildirMessagePart>();
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 <part> p)
+void maildirMessage::fetchPartHeader(ref <messagePart> p)
{
ref <maildirFolder> folder = m_folder.acquire();
- ref <maildirPart> mp = p.dynamicCast <maildirPart>();
+ ref <maildirMessagePart> mp = p.dynamicCast <maildirMessagePart>();
ref <utility::fileSystemFactory> fsf = platform::getHandler()->getFileSystemFactory();
@@ -508,7 +323,7 @@ void maildirMessage::fetch(ref <maildirFolder> msgFolder, const int options)
// Extract structure
if (options & folder::FETCH_STRUCTURE)
{
- m_structure = vmime::create <maildirStructure>(null, msg);
+ m_structure = vmime::create <maildirMessageStructure>(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 <[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_MAILDIR
+
+
+#include "vmime/net/maildir/maildirMessagePart.hpp"
+#include "vmime/net/maildir/maildirMessageStructure.hpp"
+
+
+namespace vmime {
+namespace net {
+namespace maildir {
+
+
+maildirMessagePart::maildirMessagePart(ref <maildirMessagePart> 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 <maildirMessageStructure>
+ (thisRef().dynamicCast <maildirMessagePart>(),
+ part.getBody()->getPartList());
+ }
+}
+
+
+ref <const messageStructure> maildirMessagePart::getStructure() const
+{
+ if (m_structure != NULL)
+ return m_structure;
+ else
+ return maildirMessageStructure::emptyStructure();
+}
+
+
+ref <messageStructure> 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 <const header> 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 <header>());
+}
+
+
+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 <[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_MAILDIR
+
+
+#include "vmime/net/maildir/maildirMessageStructure.hpp"
+#include "vmime/net/maildir/maildirMessagePart.hpp"
+
+
+namespace vmime {
+namespace net {
+namespace maildir {
+
+
+ref <maildirMessageStructure> maildirMessageStructure::m_emptyStructure = vmime::create <maildirMessageStructure>();
+
+
+maildirMessageStructure::maildirMessageStructure()
+{
+}
+
+
+maildirMessageStructure::maildirMessageStructure(ref <maildirMessagePart> parent, const bodyPart& part)
+{
+ vmime::ref <maildirMessagePart> mpart = vmime::create <maildirMessagePart>(parent, 0, part);
+ mpart->initStructure(part);
+
+ m_parts.push_back(mpart);
+}
+
+
+maildirMessageStructure::maildirMessageStructure(ref <maildirMessagePart> parent, const std::vector <ref <const vmime::bodyPart> >& list)
+{
+ for (unsigned int i = 0 ; i < list.size() ; ++i)
+ {
+ vmime::ref <maildirMessagePart> mpart = vmime::create <maildirMessagePart>(parent, i, *list[i]);
+ mpart->initStructure(*list[i]);
+
+ m_parts.push_back(mpart);
+ }
+}
+
+
+ref <const messagePart> maildirMessageStructure::getPartAt(const size_t x) const
+{
+ return m_parts[x];
+}
+
+
+ref <messagePart> maildirMessageStructure::getPartAt(const size_t x)
+{
+ return m_parts[x];
+}
+
+
+size_t maildirMessageStructure::getPartCount() const
+{
+ return m_parts.size();
+}
+
+
+// static
+ref <maildirMessageStructure> maildirMessageStructure::emptyStructure()
+{
+ return m_emptyStructure;
+}
+
+
+} // maildir
+} // net
+} // vmime
+
+
+#endif // VMIME_HAVE_MESSAGING_FEATURES && VMIME_HAVE_MESSAGING_PROTO_MAILDIR