summaryrefslogtreecommitdiff
path: root/libmu_cpp/folder.cc
diff options
context:
space:
mode:
authorWojciech Polak <polak@gnu.org>2009-01-30 10:42:08 +0100
committerWojciech Polak <polak@gnu.org>2009-01-30 20:43:44 +0100
commitb2a91252acdd910a3ac5e866c0ecc578d86c4f94 (patch)
treeedc2d26dee289c2e4b575e102cb5aad3b8d49877 /libmu_cpp/folder.cc
parent24d5aa4cbd4b2aec73dc9b275e8bc172973ed234 (diff)
downloadmailutils-b2a91252acdd910a3ac5e866c0ecc578d86c4f94.tar.gz
mailutils-b2a91252acdd910a3ac5e866c0ecc578d86c4f94.tar.bz2
Add Folder class to libmu_cpp. Provide new examples lsf.cc and msg-send.cc.
* examples/cpp/lsf.cc, examples/cpp/msg-send.cc, include/mailutils/cpp/folder.h, libmu_cpp/folder.cc: New files.
Diffstat (limited to 'libmu_cpp/folder.cc')
-rw-r--r--libmu_cpp/folder.cc136
1 files changed, 136 insertions, 0 deletions
diff --git a/libmu_cpp/folder.cc b/libmu_cpp/folder.cc
new file mode 100644
index 000000000..d4dc2afb5
--- /dev/null
+++ b/libmu_cpp/folder.cc
@@ -0,0 +1,136 @@
+/*
+ GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2009 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301 USA
+*/
+
+#include <mailutils/cpp/folder.h>
+#include <mailutils/cpp/error.h>
+#include <errno.h>
+
+using namespace mailutils;
+
+//
+// Folder
+//
+
+Folder :: Folder (const std::string& name)
+{
+ int status = mu_folder_create (&folder, name.c_str ());
+ if (status)
+ throw Exception ("Folder::Folder", status);
+}
+
+Folder :: Folder (const mu_folder_t folder)
+{
+ if (folder == 0)
+ throw Exception ("Folder::Folder", EINVAL);
+
+ this->folder = folder;
+}
+
+Folder&
+Folder :: operator = (const Folder& f)
+{
+ if (this != &f)
+ {
+ if (this->folder)
+ mu_folder_destroy (&this->folder);
+ this->folder = f.folder;
+ }
+ return *this;
+}
+
+Folder :: ~Folder ()
+{
+ mu_folder_destroy (&folder);
+}
+
+
+void
+Folder :: open ()
+{
+ int status = mu_folder_open (folder, MU_STREAM_READ);
+ if (status)
+ throw Exception ("Folder::open", status);
+}
+
+void
+Folder :: open (int flag)
+{
+ int status = mu_folder_open (folder, flag);
+ if (status)
+ throw Exception ("Folder::open", status);
+}
+
+void
+Folder :: close ()
+{
+ int status = mu_folder_close (folder);
+ if (status)
+ throw Exception ("Folder::close", status);
+}
+
+List&
+Folder :: list (const std::string& dirname, void* pattern, size_t max_level)
+{
+ mu_list_t c_list;
+
+ int status = mu_folder_list (folder, dirname.c_str (), pattern,
+ max_level, &c_list);
+ if (status)
+ throw Exception ("Folder::list", status);
+
+ return *new List (c_list);
+}
+
+List&
+Folder :: enumerate (const std::string& name, void* pattern,
+ int flags, size_t max_level,
+ mu_folder_enumerate_fp enumfun, void* enumdata)
+{
+ mu_list_t c_list;
+
+ int status = mu_folder_enumerate (folder, name.c_str (), pattern,
+ flags, max_level, &c_list,
+ enumfun, enumdata);
+ if (status)
+ throw Exception ("Folder::enumerate", status);
+
+ return *new List (c_list);
+}
+
+Stream&
+Folder :: get_stream ()
+{
+ mu_stream_t c_stream;
+
+ int status = mu_folder_get_stream (folder, &c_stream);
+ if (status)
+ throw Exception ("Folder::get_stream", status);
+
+ return *new Stream (c_stream);
+}
+
+void
+Folder :: set_stream (const Stream& stream)
+{
+ int status = mu_folder_set_stream (folder, stream.stm);
+ if (status)
+ throw Exception ("Folder::set_stream", status);
+}
+

Return to:

Send suggestions and report system problems to the System administrator.