diff options
author | Wojciech Polak <polak@gnu.org> | 2009-01-30 10:42:08 +0100 |
---|---|---|
committer | Wojciech Polak <polak@gnu.org> | 2009-01-30 20:43:44 +0100 |
commit | b2a91252acdd910a3ac5e866c0ecc578d86c4f94 (patch) | |
tree | edc2d26dee289c2e4b575e102cb5aad3b8d49877 /libmu_cpp | |
parent | 24d5aa4cbd4b2aec73dc9b275e8bc172973ed234 (diff) | |
download | mailutils-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')
-rw-r--r-- | libmu_cpp/Makefile.am | 1 | ||||
-rw-r--r-- | libmu_cpp/address.cc | 27 | ||||
-rw-r--r-- | libmu_cpp/folder.cc | 136 | ||||
-rw-r--r-- | libmu_cpp/mailer.cc | 20 | ||||
-rw-r--r-- | libmu_cpp/message.cc | 9 |
5 files changed, 192 insertions, 1 deletions
diff --git a/libmu_cpp/Makefile.am b/libmu_cpp/Makefile.am index e37e6d507..aca3f9cbf 100644 --- a/libmu_cpp/Makefile.am +++ b/libmu_cpp/Makefile.am @@ -29,6 +29,7 @@ libmu_cpp_la_SOURCES = \ body.cc\ debug.cc\ filter.cc\ + folder.cc\ header.cc\ iterator.cc\ list.cc\ diff --git a/libmu_cpp/address.cc b/libmu_cpp/address.cc index 5e097c2a5..ee9c6fb61 100644 --- a/libmu_cpp/address.cc +++ b/libmu_cpp/address.cc @@ -28,6 +28,11 @@ using namespace mailutils; // Address // +Address :: Address () +{ + addr = NULL; +} + Address :: Address (const std::string& str) { int status = mu_address_create (&addr, str.c_str ()); @@ -35,6 +40,13 @@ Address :: Address (const std::string& str) throw Exception ("Address::Address", status); } +Address :: Address (const char *sv[], size_t len) +{ + int status = mu_address_createv (&addr, sv, len); + if (status) + throw Exception ("Address::Address", status); +} + Address :: Address (const mu_address_t addr) { if (addr == 0) @@ -45,7 +57,20 @@ Address :: Address (const mu_address_t addr) Address :: ~Address () { - mu_address_destroy (&addr); + if (addr) + mu_address_destroy (&addr); +} + +Address& +Address :: operator = (const Address& a) +{ + if (this != &a) + { + if (this->addr) + mu_address_destroy (&this->addr); + this->addr = mu_address_dup (a.addr); + } + return *this; } bool 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); +} + diff --git a/libmu_cpp/mailer.cc b/libmu_cpp/mailer.cc index bb781c4ea..a693906b9 100644 --- a/libmu_cpp/mailer.cc +++ b/libmu_cpp/mailer.cc @@ -48,6 +48,14 @@ Mailer :: ~Mailer () } void +Mailer :: open () +{ + int status = mu_mailer_open (mailer, 0); + if (status) + throw Exception ("Mailer::open", status); +} + +void Mailer :: open (int flags) { int status = mu_mailer_open (mailer, flags); @@ -73,3 +81,15 @@ Mailer :: send_message (const Message& msg, const Address& from, throw Exception ("Mailer::send_message", status); } +Debug& +Mailer :: get_debug () +{ + mu_debug_t c_dbg; + + int status = mu_mailer_get_debug (mailer, &c_dbg); + if (status) + throw Exception ("Mailer::get_debug", status); + + return *new Debug (c_dbg); +} + diff --git a/libmu_cpp/message.cc b/libmu_cpp/message.cc index 5d338022c..7b0ea2c44 100644 --- a/libmu_cpp/message.cc +++ b/libmu_cpp/message.cc @@ -108,6 +108,15 @@ Message :: get_stream () return *new Stream (c_stream); } +void +Message :: set_stream (const Stream& stream) +{ + int status = mu_message_set_stream (msg, stream.stm, this); + if (status) + throw Exception ("Message::set_stream", status); +} + + bool Message :: is_multipart () { |