summaryrefslogtreecommitdiff
path: root/libmu_cpp
diff options
context:
space:
mode:
authorWojciech Polak <polak@gnu.org>2009-03-05 20:39:24 +0100
committerWojciech Polak <polak@gnu.org>2009-03-05 20:39:24 +0100
commitb4b7a4a68868d9943b9a4c946c1e0b21b2c3d49f (patch)
tree72bbbb9c370e897053d8c27ed8b65a4e027e5a54 /libmu_cpp
parent29b072f730bbe6b96d8518987ed125a6020fb5d4 (diff)
downloadmailutils-b4b7a4a68868d9943b9a4c946c1e0b21b2c3d49f.tar.gz
mailutils-b4b7a4a68868d9943b9a4c946c1e0b21b2c3d49f.tar.bz2
Add Envelope class to libmu_cpp. Add new methods.
* include/mailutils/cpp/envelope.h, libmu_cpp/envelope.cc: New files.
Diffstat (limited to 'libmu_cpp')
-rw-r--r--libmu_cpp/Makefile.am1
-rw-r--r--libmu_cpp/address.cc49
-rw-r--r--libmu_cpp/attribute.cc18
-rw-r--r--libmu_cpp/body.cc2
-rw-r--r--libmu_cpp/debug.cc2
-rw-r--r--libmu_cpp/envelope.cc69
-rw-r--r--libmu_cpp/folder.cc17
-rw-r--r--libmu_cpp/header.cc2
-rw-r--r--libmu_cpp/iterator.cc2
-rw-r--r--libmu_cpp/list.cc2
-rw-r--r--libmu_cpp/mailbox.cc96
-rw-r--r--libmu_cpp/mailcap.cc3
-rw-r--r--libmu_cpp/mailer.cc1
-rw-r--r--libmu_cpp/message.cc41
-rw-r--r--libmu_cpp/mime.cc2
-rw-r--r--libmu_cpp/mutil.cc1
-rw-r--r--libmu_cpp/pop3.cc2
-rw-r--r--libmu_cpp/registrar.cc3
-rw-r--r--libmu_cpp/stream.cc1
-rw-r--r--libmu_cpp/url.cc46
20 files changed, 281 insertions, 79 deletions
diff --git a/libmu_cpp/Makefile.am b/libmu_cpp/Makefile.am
index aca3f9cbf..947f3db23 100644
--- a/libmu_cpp/Makefile.am
+++ b/libmu_cpp/Makefile.am
@@ -28,6 +28,7 @@ libmu_cpp_la_SOURCES = \
attribute.cc\
body.cc\
debug.cc\
+ envelope.cc\
filter.cc\
folder.cc\
header.cc\
diff --git a/libmu_cpp/address.cc b/libmu_cpp/address.cc
index ee9c6fb61..250aa7196 100644
--- a/libmu_cpp/address.cc
+++ b/libmu_cpp/address.cc
@@ -19,8 +19,6 @@
*/
#include <mailutils/cpp/address.h>
-#include <mailutils/cpp/error.h>
-#include <errno.h>
using namespace mailutils;
@@ -97,72 +95,97 @@ Address :: get_count ()
std::string
Address :: get_email (size_t n)
{
- int status = mu_address_get_email (addr, n, buf, sizeof (buf), 0);
+ char *buf = NULL;
+ int status = mu_address_aget_email (addr, n, &buf);
if (status == EINVAL)
throw Address::EInval ("Address::get_email", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::get_email", status);
- return std::string (buf);
+ return std::string (buf ? buf : "");
}
std::string
Address :: get_local_part (size_t n)
{
- int status = mu_address_get_local_part (addr, n, buf, sizeof (buf), 0);
+ char *buf = NULL;
+ int status = mu_address_aget_local_part (addr, n, &buf);
if (status == EINVAL)
throw Address::EInval ("Address::get_local_part", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::get_local_part", status);
- return std::string (buf);
+ return std::string (buf ? buf : "");
}
std::string
Address :: get_domain (size_t n)
{
- int status = mu_address_get_domain (addr, n, buf, sizeof (buf), 0);
+ char *buf = NULL;
+ int status = mu_address_aget_domain (addr, n, &buf);
if (status == EINVAL)
throw Address::EInval ("Address::get_domain", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::get_domain", status);
- return std::string (buf);
+ return std::string (buf ? buf : "");
}
std::string
Address :: get_personal (size_t n)
{
- int status = mu_address_get_personal (addr, n, buf, sizeof (buf), 0);
+ char *buf = NULL;
+ int status = mu_address_aget_personal (addr, n, &buf);
if (status == EINVAL)
throw Address::EInval ("Address::get_personal", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::get_personal", status);
- return std::string (buf);
+ return std::string (buf ? buf : "");
}
std::string
Address :: get_comments (size_t n)
{
- int status = mu_address_get_comments (addr, n, buf, sizeof (buf), 0);
+ char *buf = NULL;
+ int status = mu_address_aget_comments (addr, n, &buf);
if (status == EINVAL)
throw Address::EInval ("Address::get_comments", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::get_comments", status);
- return std::string (buf);
+ return std::string (buf ? buf : "");
}
std::string
Address :: get_route (size_t n)
{
- int status = mu_address_get_route (addr, n, buf, sizeof (buf), 0);
+ char *buf = NULL;
+ int status = mu_address_aget_route (addr, n, &buf);
if (status == EINVAL)
throw Address::EInval ("Address::get_route", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::get_route", status);
+ return std::string (buf ? buf : "");
+}
+
+std::string
+Address :: to_string ()
+{
+ size_t n;
+ char buf[1024];
+ int status = mu_address_to_string (addr, buf, sizeof (buf), &n);
+ if (status)
+ throw Exception ("Address::to_string", status);
+
return std::string (buf);
}
+namespace mailutils
+{
+ std::ostream& operator << (std::ostream& os, Address& addr) {
+ return os << addr.to_string ();
+ };
+}
+
diff --git a/libmu_cpp/attribute.cc b/libmu_cpp/attribute.cc
index 3532a130e..377115838 100644
--- a/libmu_cpp/attribute.cc
+++ b/libmu_cpp/attribute.cc
@@ -19,8 +19,6 @@
*/
#include <mailutils/cpp/attribute.h>
-#include <mailutils/cpp/error.h>
-#include <errno.h>
using namespace mailutils;
@@ -213,3 +211,19 @@ Attribute :: unset_read ()
mu_attribute_unset_read (attr);
}
+std::string
+Attribute :: to_string ()
+{
+ char buf[MU_STATUS_BUF_SIZE];
+ size_t na = 0;
+ mu_attribute_to_string (attr, buf, sizeof (buf), &na);
+ return std::string (buf);
+}
+
+namespace mailutils
+{
+ std::ostream& operator << (std::ostream& os, Attribute& attr) {
+ return os << attr.to_string ();
+ };
+}
+
diff --git a/libmu_cpp/body.cc b/libmu_cpp/body.cc
index 5d561dfc9..8d8667d41 100644
--- a/libmu_cpp/body.cc
+++ b/libmu_cpp/body.cc
@@ -19,8 +19,6 @@
*/
#include <mailutils/cpp/body.h>
-#include <mailutils/cpp/error.h>
-#include <errno.h>
using namespace mailutils;
diff --git a/libmu_cpp/debug.cc b/libmu_cpp/debug.cc
index 4d9fa65ce..99483b83d 100644
--- a/libmu_cpp/debug.cc
+++ b/libmu_cpp/debug.cc
@@ -19,8 +19,6 @@
*/
#include <mailutils/cpp/debug.h>
-#include <mailutils/cpp/error.h>
-#include <errno.h>
using namespace mailutils;
diff --git a/libmu_cpp/envelope.cc b/libmu_cpp/envelope.cc
new file mode 100644
index 000000000..c9b56b181
--- /dev/null
+++ b/libmu_cpp/envelope.cc
@@ -0,0 +1,69 @@
+/*
+ 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/envelope.h>
+
+using namespace mailutils;
+
+//
+// Envelope
+//
+
+Envelope :: Envelope ()
+{
+ this->env = NULL;
+}
+
+Envelope :: Envelope (const mu_envelope_t env)
+{
+ if (env == 0)
+ throw Exception ("Envelope::Envelope", EINVAL);
+
+ this->env = env;
+}
+
+std::string
+Envelope :: get_sender ()
+{
+ char* c_val = NULL;
+
+ int status = mu_envelope_aget_sender (env, &c_val);
+ if (status)
+ throw Exception ("Envelope::get_sender", status);
+
+ std::string val (c_val);
+ free (c_val);
+ return val;
+}
+
+std::string
+Envelope :: get_date ()
+{
+ char* c_val;
+
+ int status = mu_envelope_aget_date (env, &c_val);
+ if (status)
+ throw Exception ("Envelope::get_date", status);
+
+ std::string val (c_val);
+ free (c_val);
+ return val;
+}
+
diff --git a/libmu_cpp/folder.cc b/libmu_cpp/folder.cc
index d4dc2afb5..8d3155c1a 100644
--- a/libmu_cpp/folder.cc
+++ b/libmu_cpp/folder.cc
@@ -19,8 +19,6 @@
*/
#include <mailutils/cpp/folder.h>
-#include <mailutils/cpp/error.h>
-#include <errno.h>
using namespace mailutils;
@@ -86,7 +84,8 @@ Folder :: close ()
}
List&
-Folder :: list (const std::string& dirname, void* pattern, size_t max_level)
+Folder :: list (const std::string& dirname, void* pattern,
+ size_t max_level = 0)
{
mu_list_t c_list;
@@ -134,3 +133,15 @@ Folder :: set_stream (const Stream& stream)
throw Exception ("Folder::set_stream", status);
}
+Url&
+Folder :: get_url ()
+{
+ mu_url_t c_url;
+
+ int status = mu_folder_get_url (folder, &c_url);
+ if (status)
+ throw Exception ("Folder::get_url", status);
+
+ return *new Url (c_url);
+}
+
diff --git a/libmu_cpp/header.cc b/libmu_cpp/header.cc
index 196ea33bd..bd25c79b2 100644
--- a/libmu_cpp/header.cc
+++ b/libmu_cpp/header.cc
@@ -19,8 +19,6 @@
*/
#include <mailutils/cpp/header.h>
-#include <mailutils/cpp/error.h>
-#include <errno.h>
using namespace mailutils;
diff --git a/libmu_cpp/iterator.cc b/libmu_cpp/iterator.cc
index 7b8bc9c22..75861a2e4 100644
--- a/libmu_cpp/iterator.cc
+++ b/libmu_cpp/iterator.cc
@@ -19,8 +19,6 @@
*/
#include <mailutils/cpp/iterator.h>
-#include <mailutils/cpp/error.h>
-#include <errno.h>
using namespace mailutils;
diff --git a/libmu_cpp/list.cc b/libmu_cpp/list.cc
index 74663b7b7..b023abc4f 100644
--- a/libmu_cpp/list.cc
+++ b/libmu_cpp/list.cc
@@ -19,8 +19,6 @@
*/
#include <mailutils/cpp/list.h>
-#include <mailutils/cpp/error.h>
-#include <errno.h>
using namespace mailutils;
diff --git a/libmu_cpp/mailbox.cc b/libmu_cpp/mailbox.cc
index 2864b24f8..462f1e348 100644
--- a/libmu_cpp/mailbox.cc
+++ b/libmu_cpp/mailbox.cc
@@ -19,8 +19,6 @@
*/
#include <mailutils/cpp/mailbox.h>
-#include <mailutils/cpp/error.h>
-#include <errno.h>
using namespace mailutils;
@@ -52,23 +50,21 @@ MailboxBase :: close ()
throw Exception ("MailboxBase::close", status);
}
-Debug&
-MailboxBase :: get_debug ()
+void
+MailboxBase :: flush (bool expunge = false)
{
- mu_debug_t c_dbg;
-
- int status = mu_mailbox_get_debug (mbox, &c_dbg);
+ int status = mu_mailbox_flush (mbox, expunge);
if (status)
- throw Exception ("MailboxBase::get_debug", status);
-
- return *new Debug (c_dbg);
+ throw Exception ("MailboxBase::flush", status);
}
size_t
MailboxBase :: messages_count ()
{
size_t total;
- mu_mailbox_messages_count (mbox, &total);
+ int status = mu_mailbox_messages_count (mbox, &total);
+ if (status)
+ throw Exception ("MailboxBase::messages_count", status);
return total;
}
@@ -76,7 +72,9 @@ size_t
MailboxBase :: messages_recent ()
{
size_t recent;
- mu_mailbox_messages_recent (mbox, &recent);
+ int status = mu_mailbox_messages_recent (mbox, &recent);
+ if (status)
+ throw Exception ("MailboxBase::messages_recent", status);
return recent;
}
@@ -84,7 +82,9 @@ size_t
MailboxBase :: message_unseen ()
{
size_t unseen;
- mu_mailbox_message_unseen (mbox, &unseen);
+ int status = mu_mailbox_message_unseen (mbox, &unseen);
+ if (status)
+ throw Exception ("MailboxBase::message_unseen", status);
return unseen;
}
@@ -116,6 +116,76 @@ MailboxBase :: expunge ()
throw Exception ("MailboxBase::expunge", status);
}
+void
+MailboxBase :: sync ()
+{
+ int status = mu_mailbox_sync (mbox);
+ if (status)
+ throw Exception ("MailboxBase::sync", status);
+}
+
+void
+MailboxBase :: lock ()
+{
+ int status = mu_mailbox_lock (mbox);
+ if (status)
+ throw Exception ("MailboxBase::lock", status);
+}
+
+void
+MailboxBase :: unlock ()
+{
+ int status = mu_mailbox_unlock (mbox);
+ if (status)
+ throw Exception ("MailboxBase::unlock", status);
+}
+
+mu_off_t
+MailboxBase :: get_size ()
+{
+ mu_off_t size;
+ int status = mu_mailbox_get_size (mbox, &size);
+ if (status)
+ throw Exception ("MailboxBase::get_size", status);
+ return size;
+}
+
+Debug&
+MailboxBase :: get_debug ()
+{
+ mu_debug_t c_dbg;
+
+ int status = mu_mailbox_get_debug (mbox, &c_dbg);
+ if (status)
+ throw Exception ("MailboxBase::get_debug", status);
+
+ return *new Debug (c_dbg);
+}
+
+Folder&
+MailboxBase :: get_folder ()
+{
+ mu_folder_t c_folder;
+
+ int status = mu_mailbox_get_folder (mbox, &c_folder);
+ if (status)
+ throw Exception ("MailboxBase::get_folder", status);
+
+ return *new Folder (c_folder);
+}
+
+Url&
+MailboxBase :: get_url ()
+{
+ mu_url_t c_url;
+
+ int status = mu_mailbox_get_url (mbox, &c_url);
+ if (status)
+ throw Exception ("MailboxBase::get_url", status);
+
+ return *new Url (c_url);
+}
+
//
// Mailbox
//
diff --git a/libmu_cpp/mailcap.cc b/libmu_cpp/mailcap.cc
index d0be5faf0..07ff5e097 100644
--- a/libmu_cpp/mailcap.cc
+++ b/libmu_cpp/mailcap.cc
@@ -19,9 +19,6 @@
*/
#include <mailutils/cpp/mailcap.h>
-#include <mailutils/cpp/stream.h>
-#include <mailutils/cpp/error.h>
-#include <errno.h>
using namespace mailutils;
diff --git a/libmu_cpp/mailer.cc b/libmu_cpp/mailer.cc
index a693906b9..02ca3206d 100644
--- a/libmu_cpp/mailer.cc
+++ b/libmu_cpp/mailer.cc
@@ -19,7 +19,6 @@
*/
#include <mailutils/cpp/mailer.h>
-#include <errno.h>
using namespace mailutils;
diff --git a/libmu_cpp/message.cc b/libmu_cpp/message.cc
index 7b0ea2c44..a3ae8d564 100644
--- a/libmu_cpp/message.cc
+++ b/libmu_cpp/message.cc
@@ -19,11 +19,6 @@
*/
#include <mailutils/cpp/message.h>
-#include <mailutils/cpp/header.h>
-#include <mailutils/cpp/body.h>
-#include <mailutils/cpp/stream.h>
-#include <mailutils/cpp/error.h>
-#include <errno.h>
using namespace mailutils;
@@ -72,16 +67,16 @@ Message :: ~Message ()
mu_message_destroy (&msg, this);
}
-Header&
-Message :: get_header ()
+Attribute&
+Message :: get_attribute ()
{
- mu_header_t c_hdr;
+ mu_attribute_t c_attr;
- int status = mu_message_get_header (msg, &c_hdr);
+ int status = mu_message_get_attribute (msg, &c_attr);
if (status)
- throw Exception ("Message::get_header", status);
+ throw Exception ("Message::get_attribute", status);
- return *new Header (c_hdr);
+ return *new Attribute (c_attr);
}
Body&
@@ -96,6 +91,30 @@ Message :: get_body ()
return *new Body (c_body);
}
+Envelope&
+Message :: get_envelope ()
+{
+ mu_envelope_t c_env;
+
+ int status = mu_message_get_envelope (msg, &c_env);
+ if (status)
+ throw Exception ("Message::get_envelope", status);
+
+ return *new Envelope (c_env);
+}
+
+Header&
+Message :: get_header ()
+{
+ mu_header_t c_hdr;
+
+ int status = mu_message_get_header (msg, &c_hdr);
+ if (status)
+ throw Exception ("Message::get_header", status);
+
+ return *new Header (c_hdr);
+}
+
Stream&
Message :: get_stream ()
{
diff --git a/libmu_cpp/mime.cc b/libmu_cpp/mime.cc
index fd7e6f609..d5519e05d 100644
--- a/libmu_cpp/mime.cc
+++ b/libmu_cpp/mime.cc
@@ -19,8 +19,6 @@
*/
#include <mailutils/cpp/mime.h>
-#include <mailutils/cpp/error.h>
-#include <errno.h>
using namespace mailutils;
diff --git a/libmu_cpp/mutil.cc b/libmu_cpp/mutil.cc
index 6375b72c5..07280fdab 100644
--- a/libmu_cpp/mutil.cc
+++ b/libmu_cpp/mutil.cc
@@ -18,7 +18,6 @@
Boston, MA 02110-1301 USA
*/
-#include <string>
#include <mailutils/cpp/mutil.h>
using namespace mailutils;
diff --git a/libmu_cpp/pop3.cc b/libmu_cpp/pop3.cc
index 06ec46bd1..3808c8325 100644
--- a/libmu_cpp/pop3.cc
+++ b/libmu_cpp/pop3.cc
@@ -19,8 +19,6 @@
*/
#include <mailutils/cpp/pop3.h>
-#include <mailutils/cpp/iterator.h>
-#include <errno.h>
using namespace mailutils;
diff --git a/libmu_cpp/registrar.cc b/libmu_cpp/registrar.cc
index 66c4f5f75..a502d0515 100644
--- a/libmu_cpp/registrar.cc
+++ b/libmu_cpp/registrar.cc
@@ -18,10 +18,7 @@
Boston, MA 02110-1301 USA
*/
-#include <string>
#include <mailutils/cpp/registrar.h>
-#include <mailutils/cpp/error.h>
-#include <errno.h>
using namespace mailutils;
diff --git a/libmu_cpp/stream.cc b/libmu_cpp/stream.cc
index c4ed8d593..7fdcb4696 100644
--- a/libmu_cpp/stream.cc
+++ b/libmu_cpp/stream.cc
@@ -19,7 +19,6 @@
*/
#include <mailutils/cpp/stream.h>
-#include <errno.h>
using namespace mailutils;
diff --git a/libmu_cpp/url.cc b/libmu_cpp/url.cc
index 8c346947e..4740ae920 100644
--- a/libmu_cpp/url.cc
+++ b/libmu_cpp/url.cc
@@ -19,8 +19,6 @@
*/
#include <mailutils/cpp/url.h>
-#include <mailutils/cpp/error.h>
-#include <errno.h>
using namespace mailutils;
@@ -76,67 +74,73 @@ Url :: get_port ()
std::string
Url :: get_scheme ()
{
- int status = mu_url_get_scheme (url, buf, sizeof (buf), NULL);
+ char *buf = NULL;
+ int status = mu_url_aget_scheme (url, &buf);
if (status == MU_ERR_NOENT)
return "";
else if (status)
throw Exception ("Url::get_scheme", status);
- return std::string (buf);
+ return std::string (buf ? buf : "");
}
std::string
Url :: get_user ()
{
- int status = mu_url_get_user (url, buf, sizeof (buf), NULL);
+ char *buf = NULL;
+ int status = mu_url_aget_user (url, &buf);
if (status == MU_ERR_NOENT)
return "";
else if (status)
throw Exception ("Url::get_user", status);
- return std::string (buf);
+ return std::string (buf ? buf : "");
}
std::string
Url :: get_passwd ()
{
- int status = mu_url_get_passwd (url, buf, sizeof (buf), NULL);
+ char *buf = NULL;
+ int status = mu_url_aget_passwd (url, &buf);
if (status == MU_ERR_NOENT)
return "";
else if (status)
throw Exception ("Url::get_passwd", status);
- return std::string (buf);
+ return std::string (buf ? buf : "");
}
std::string
Url :: get_auth ()
{
- int status = mu_url_get_auth (url, buf, sizeof (buf), NULL);
+ char *buf = NULL;
+ int status = mu_url_aget_auth (url, &buf);
if (status == MU_ERR_NOENT)
return "";
else if (status)
throw Exception ("Url::get_auth", status);
- return std::string (buf);
+ return std::string (buf ? buf : "");
}
std::string
Url :: get_host ()
{
- int status = mu_url_get_host (url, buf, sizeof (buf), NULL);
+ char *buf = NULL;
+ int status = mu_url_aget_host (url, &buf);
if (status == MU_ERR_NOENT)
return "";
else if (status)
throw Exception ("Url::get_host", status);
- return std::string (buf);
+ return std::string (buf ? buf : "");
}
std::string
Url :: get_path ()
{
- int status = mu_url_get_path (url, buf, sizeof (buf), NULL);
+ char *buf = NULL;
+ int status = mu_url_aget_path (url, &buf);
if (status == MU_ERR_NOENT)
return "";
else if (status)
throw Exception ("Url::get_path", status);
- return std::string (buf);
+ return std::string (buf ? buf : "");
}
std::vector<std::string>
@@ -157,3 +161,17 @@ Url :: get_query ()
return params;
}
+std::string
+Url :: to_string ()
+{
+ const char *str = mu_url_to_string (url);
+ return std::string (str ? str : "");
+}
+
+namespace mailutils
+{
+ std::ostream& operator << (std::ostream& os, Url& url) {
+ return os << url.to_string ();
+ };
+}
+

Return to:

Send suggestions and report system problems to the System administrator.