diff options
42 files changed, 405 insertions, 107 deletions
diff --git a/examples/cpp/addr.cc b/examples/cpp/addr.cc index 03ef051ca..a14318a3e 100644 --- a/examples/cpp/addr.cc +++ b/examples/cpp/addr.cc @@ -33,7 +33,7 @@ parse (const char *str) try { Address address (str); size_t count = address.get_count (); - cout << str << "=> count " << count << endl; + cout << address << " => count " << count << endl; for (size_t no = 1; no <= count; no++) { @@ -41,17 +41,17 @@ parse (const char *str) cout << no << " "; if (isgroup) - cout << "group " << address.get_personal (no) << endl; + cout << "group <" << address.get_personal (no) << ">" << endl; else - cout << "email " << address.get_email (no) << endl; + cout << "email <" << address.get_email (no) << ">" << endl; if (!isgroup) - cout << " personal " << address.get_personal (no) << endl; + cout << " personal <" << address.get_personal (no) << ">" << endl; - cout << " comments " << address.get_comments (no) << endl; - cout << " local-part " << address.get_local_part (no) - << " domain " << address.get_domain (no) << endl; - cout << " route " << address.get_route (no) << endl; + cout << " comments <" << address.get_comments (no) << ">" << endl; + cout << " local-part <" << address.get_local_part (no) << ">" + << " domain <" << address.get_domain (no) << ">" << endl; + cout << " route <" << address.get_route (no) << ">" << endl; } } catch (Exception& e) { diff --git a/examples/cpp/mimetest.cc b/examples/cpp/mimetest.cc index 128c7331a..fe00331aa 100644 --- a/examples/cpp/mimetest.cc +++ b/examples/cpp/mimetest.cc @@ -127,8 +127,6 @@ print_message_part_sizes (Message& part, int indent) void message_display_parts (Message& msg, int indent) { - size_t nbytes; - /* How many parts does the message has? */ size_t nparts = msg.get_num_parts (); @@ -140,8 +138,8 @@ message_display_parts (Message& msg, int indent) Message part = msg.get_part (j); Header hdr = part.get_header (); - string type; - string encoding (""); + string type ("text/plain"); + string encoding ("7bit"); try { type = hdr[MU_HEADER_CONTENT_TYPE]; encoding = hdr[MU_HEADER_CONTENT_TRANSFER_ENCODING]; diff --git a/examples/cpp/sfrom.cc b/examples/cpp/sfrom.cc index c682f6449..d168c8347 100644 --- a/examples/cpp/sfrom.cc +++ b/examples/cpp/sfrom.cc @@ -26,13 +26,10 @@ using namespace mailutils; int main (int argc, char* argv[]) { - if (argc == 1) - exit (0); - register_local_mbox_formats (); try { - MailboxDefault mbox (argv[1]); + MailboxDefault mbox ((argc > 1) ? argv[1] : ""); mbox.open (); size_t total = mbox.messages_count (); @@ -43,7 +40,7 @@ int main (int argc, char* argv[]) Message msg = mbox[msgno]; Header hdr = msg.get_header (); cout << hdr[MU_HEADER_FROM] << " " - << hdr.get_value (MU_HEADER_SUBJECT, "[none]") << endl; + << hdr.get_value (MU_HEADER_SUBJECT, "(NO SUBJECT)") << endl; } mbox.close (); diff --git a/include/mailutils/cpp/Makefile.am b/include/mailutils/cpp/Makefile.am index f755d3b7c..ab16929c6 100644 --- a/include/mailutils/cpp/Makefile.am +++ b/include/mailutils/cpp/Makefile.am @@ -21,6 +21,7 @@ MU_CXX_INCLUDES = \ attribute.h\ body.h\ debug.h\ + envelope.h\ error.h\ filter.h\ folder.h\ diff --git a/include/mailutils/cpp/address.h b/include/mailutils/cpp/address.h index 1fb2382f4..a41e99167 100644 --- a/include/mailutils/cpp/address.h +++ b/include/mailutils/cpp/address.h @@ -21,6 +21,8 @@ #ifndef _ADDRESS_H #define _ADDRESS_H +#include <ostream> +#include <errno.h> #include <mailutils/address.h> #include <mailutils/cpp/error.h> @@ -29,9 +31,6 @@ namespace mailutils class Address { - private: - char buf[256]; - protected: mu_address_t addr; @@ -56,6 +55,9 @@ class Address std::string get_comments (size_t n); std::string get_route (size_t n); + std::string to_string (); + friend std::ostream& operator << (std::ostream&, Address&); + // Address Exceptions class EInval : public Exception { public: diff --git a/include/mailutils/cpp/attribute.h b/include/mailutils/cpp/attribute.h index c24a40329..5efd65024 100644 --- a/include/mailutils/cpp/attribute.h +++ b/include/mailutils/cpp/attribute.h @@ -21,7 +21,10 @@ #ifndef _MUCPP_ATTRIBUTE_H #define _MUCPP_ATTRIBUTE_H +#include <ostream> +#include <errno.h> #include <mailutils/attribute.h> +#include <mailutils/cpp/error.h> namespace mailutils { @@ -65,6 +68,9 @@ class Attribute void unset_draft (); void unset_recent (); void unset_read (); + + std::string to_string (); + friend std::ostream& operator << (std::ostream&, Attribute&); }; } diff --git a/include/mailutils/cpp/body.h b/include/mailutils/cpp/body.h index fc30accfe..c6dca9e37 100644 --- a/include/mailutils/cpp/body.h +++ b/include/mailutils/cpp/body.h @@ -22,7 +22,9 @@ #define _MUCPP_BODY_H #include <string> +#include <errno.h> #include <mailutils/body.h> +#include <mailutils/cpp/error.h> #include <mailutils/cpp/stream.h> namespace mailutils diff --git a/include/mailutils/cpp/debug.h b/include/mailutils/cpp/debug.h index 003dc2eeb..e0cf97224 100644 --- a/include/mailutils/cpp/debug.h +++ b/include/mailutils/cpp/debug.h @@ -22,7 +22,9 @@ #define _MUCPP_DEBUG_H #include <string> +#include <errno.h> #include <mailutils/debug.h> +#include <mailutils/cpp/error.h> namespace mailutils { diff --git a/include/mailutils/cpp/envelope.h b/include/mailutils/cpp/envelope.h new file mode 100644 index 000000000..5d922b802 --- /dev/null +++ b/include/mailutils/cpp/envelope.h @@ -0,0 +1,48 @@ +/* + 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 +*/ + +#ifndef _MUCPP_ENVELOPE_H +#define _MUCPP_ENVELOPE_H + +#include <string> +#include <errno.h> +#include <mailutils/envelope.h> +#include <mailutils/cpp/error.h> + +namespace mailutils +{ + +class Envelope +{ + protected: + mu_envelope_t env; + + public: + Envelope (); + Envelope (const mu_envelope_t); + + std::string get_sender (); + std::string get_date (); +}; + +} + +#endif // not _MUCPP_ENVELOPE_H + diff --git a/include/mailutils/cpp/folder.h b/include/mailutils/cpp/folder.h index 9eeb2565c..439825c1a 100644 --- a/include/mailutils/cpp/folder.h +++ b/include/mailutils/cpp/folder.h @@ -21,9 +21,12 @@ #ifndef _MUCPP_FOLDER_H #define _MUCPP_FOLDER_H +#include <errno.h> #include <mailutils/folder.h> +#include <mailutils/cpp/error.h> #include <mailutils/cpp/list.h> #include <mailutils/cpp/stream.h> +#include <mailutils/cpp/url.h> namespace mailutils { @@ -50,6 +53,8 @@ class Folder Stream& get_stream (); void set_stream (const Stream& stream); + + Url& get_url (); }; } diff --git a/include/mailutils/cpp/header.h b/include/mailutils/cpp/header.h index 27e1a5f47..16baf6845 100644 --- a/include/mailutils/cpp/header.h +++ b/include/mailutils/cpp/header.h @@ -22,7 +22,9 @@ #define _MUCPP_HEADER_H #include <string> +#include <errno.h> #include <mailutils/header.h> +#include <mailutils/cpp/error.h> namespace mailutils { diff --git a/include/mailutils/cpp/iterator.h b/include/mailutils/cpp/iterator.h index 9b2a7e280..634eb5623 100644 --- a/include/mailutils/cpp/iterator.h +++ b/include/mailutils/cpp/iterator.h @@ -21,7 +21,9 @@ #ifndef _MUCPP_ITERATOR_H #define _MUCPP_ITERATOR_H +#include <errno.h> #include <mailutils/iterator.h> +#include <mailutils/cpp/error.h> #include <mailutils/cpp/list.h> namespace mailutils diff --git a/include/mailutils/cpp/list.h b/include/mailutils/cpp/list.h index 8d31b0b5e..f7ace9c54 100644 --- a/include/mailutils/cpp/list.h +++ b/include/mailutils/cpp/list.h @@ -21,7 +21,9 @@ #ifndef _MUCPP_LIST_H #define _MUCPP_LIST_H +#include <errno.h> #include <mailutils/list.h> +#include <mailutils/cpp/error.h> #include <mailutils/cpp/iterator.h> typedef int mu_list_action_t (void*, void*); diff --git a/include/mailutils/cpp/mailbox.h b/include/mailutils/cpp/mailbox.h index a9bdad268..a0143979a 100644 --- a/include/mailutils/cpp/mailbox.h +++ b/include/mailutils/cpp/mailbox.h @@ -21,9 +21,13 @@ #ifndef _MUCPP_MAILBOX_H #define _MUCPP_MAILBOX_H +#include <errno.h> #include <mailutils/mailbox.h> +#include <mailutils/cpp/error.h> #include <mailutils/cpp/debug.h> +#include <mailutils/cpp/folder.h> #include <mailutils/cpp/message.h> +#include <mailutils/cpp/url.h> namespace mailutils { @@ -37,15 +41,21 @@ class MailboxBase void open (); void open (int flag); void close (); - - Debug& get_debug (); - + void flush (bool expunge); size_t messages_count (); size_t messages_recent (); size_t message_unseen (); Message& get_message (size_t num); void append_message (const Message& msg); void expunge (); + void sync (); + void lock (); + void unlock (); + mu_off_t get_size (); + + Debug& get_debug (); + Folder& get_folder (); + Url& get_url (); inline Message& operator [] (size_t num) { return this->get_message (num); diff --git a/include/mailutils/cpp/mailcap.h b/include/mailutils/cpp/mailcap.h index f5f9a0eef..a5d6ba384 100644 --- a/include/mailutils/cpp/mailcap.h +++ b/include/mailutils/cpp/mailcap.h @@ -21,7 +21,9 @@ #ifndef _MUCPP_MAILCAP_H #define _MUCPP_MAILCAP_H +#include <errno.h> #include <mailutils/mailcap.h> +#include <mailutils/cpp/error.h> #include <mailutils/cpp/stream.h> namespace mailutils diff --git a/include/mailutils/cpp/mailer.h b/include/mailutils/cpp/mailer.h index 3a4e2baf1..40e388421 100644 --- a/include/mailutils/cpp/mailer.h +++ b/include/mailutils/cpp/mailer.h @@ -22,6 +22,7 @@ #define _MUCPP_MAILER_H #include <string> +#include <errno.h> #include <mailutils/mailer.h> #include <mailutils/cpp/debug.h> #include <mailutils/cpp/message.h> diff --git a/include/mailutils/cpp/message.h b/include/mailutils/cpp/message.h index d6d6f23df..a901eb85a 100644 --- a/include/mailutils/cpp/message.h +++ b/include/mailutils/cpp/message.h @@ -21,9 +21,13 @@ #ifndef _MUCPP_MESSAGE_H #define _MUCPP_MESSAGE_H +#include <errno.h> #include <mailutils/message.h> -#include <mailutils/cpp/header.h> +#include <mailutils/cpp/error.h> +#include <mailutils/cpp/attribute.h> #include <mailutils/cpp/body.h> +#include <mailutils/cpp/envelope.h> +#include <mailutils/cpp/header.h> #include <mailutils/cpp/stream.h> namespace mailutils @@ -45,8 +49,10 @@ class Message Message& operator = (const Message&); ~Message (); - Header& get_header (); + Attribute& get_attribute (); Body& get_body (); + Envelope& get_envelope (); + Header& get_header (); Stream& get_stream (); void set_stream (const Stream& stream); diff --git a/include/mailutils/cpp/mime.h b/include/mailutils/cpp/mime.h index 906e218d3..199e28e26 100644 --- a/include/mailutils/cpp/mime.h +++ b/include/mailutils/cpp/mime.h @@ -22,7 +22,9 @@ #define _MUCPP_MIME_H #include <string> +#include <errno.h> #include <mailutils/mime.h> +#include <mailutils/cpp/error.h> #include <mailutils/cpp/message.h> namespace mailutils diff --git a/include/mailutils/cpp/pop3.h b/include/mailutils/cpp/pop3.h index a04aaae34..6f15fc8a1 100644 --- a/include/mailutils/cpp/pop3.h +++ b/include/mailutils/cpp/pop3.h @@ -21,6 +21,7 @@ #ifndef _MUCPP_POP3_H #define _MUCPP_POP3_H +#include <errno.h> #include <mailutils/pop3.h> #include <mailutils/cpp/list.h> #include <mailutils/cpp/iterator.h> diff --git a/include/mailutils/cpp/registrar.h b/include/mailutils/cpp/registrar.h index 7955fb245..c380cea9a 100644 --- a/include/mailutils/cpp/registrar.h +++ b/include/mailutils/cpp/registrar.h @@ -21,7 +21,10 @@ #ifndef _MUCPP_REGISTRAR_H #define _MUCPP_REGISTRAR_H +#include <string> +#include <errno.h> #include <mailutils/registrar.h> +#include <mailutils/cpp/error.h> #include <mailutils/cpp/url.h> namespace mailutils diff --git a/include/mailutils/cpp/stream.h b/include/mailutils/cpp/stream.h index c5ff82702..2d4f52f40 100644 --- a/include/mailutils/cpp/stream.h +++ b/include/mailutils/cpp/stream.h @@ -22,6 +22,7 @@ #define _MUCPP_STREAM_H #include <string> +#include <errno.h> #include <mailutils/stream.h> #include <mailutils/cpp/error.h> diff --git a/include/mailutils/cpp/url.h b/include/mailutils/cpp/url.h index a4acedaa3..bade2b716 100644 --- a/include/mailutils/cpp/url.h +++ b/include/mailutils/cpp/url.h @@ -23,16 +23,16 @@ #include <string> #include <vector> +#include <ostream> +#include <errno.h> #include <mailutils/url.h> +#include <mailutils/cpp/error.h> namespace mailutils { class Url { - private: - char buf[1024]; - protected: mu_url_t url; @@ -51,6 +51,9 @@ class Url std::string get_host (); std::string get_path (); std::vector<std::string> get_query (); + + std::string to_string (); + friend std::ostream& operator << (std::ostream&, Url&); }; } 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 < |