Commit b4b7a4a6 b4b7a4a68868d9943b9a4c946c1e0b21b2c3d49f by Wojciech Polak

Add Envelope class to libmu_cpp. Add new methods.

* include/mailutils/cpp/envelope.h, libmu_cpp/envelope.cc: New files.
1 parent 29b072f7
......@@ -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) {
......
......@@ -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];
......
......@@ -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 ();
......
......@@ -21,6 +21,7 @@ MU_CXX_INCLUDES = \
attribute.h\
body.h\
debug.h\
envelope.h\
error.h\
filter.h\
folder.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:
......
......@@ -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&);
};
}
......
......@@ -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
......
......@@ -22,7 +22,9 @@
#define _MUCPP_DEBUG_H
#include <string>
#include <errno.h>
#include <mailutils/debug.h>
#include <mailutils/cpp/error.h>
namespace mailutils
{
......
/*
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
......@@ -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 ();
};
}
......
......@@ -22,7 +22,9 @@
#define _MUCPP_HEADER_H
#include <string>
#include <errno.h>
#include <mailutils/header.h>
#include <mailutils/cpp/error.h>
namespace mailutils
{
......
......@@ -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
......
......@@ -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*);
......
......@@ -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);
......
......@@ -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
......
......@@ -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>
......
......@@ -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);
......
......@@ -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
......
......@@ -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>
......
......@@ -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
......
......@@ -22,6 +22,7 @@
#define _MUCPP_STREAM_H
#include <string>
#include <errno.h>
#include <mailutils/stream.h>
#include <mailutils/cpp/error.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&);
};
}
......
......@@ -28,6 +28,7 @@ libmu_cpp_la_SOURCES = \
attribute.cc\
body.cc\
debug.cc\
envelope.cc\
filter.cc\
folder.cc\
header.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 ();
};
}
......
......@@ -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 ();
};
}
......
......@@ -19,8 +19,6 @@
*/
#include <mailutils/cpp/body.h>
#include <mailutils/cpp/error.h>
#include <errno.h>
using namespace mailutils;
......
......@@ -19,8 +19,6 @@
*/
#include <mailutils/cpp/debug.h>
#include <mailutils/cpp/error.h>
#include <errno.h>
using namespace mailutils;
......
/*
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;
}
......@@ -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);
}
......
......@@ -19,8 +19,6 @@
*/
#include <mailutils/cpp/header.h>
#include <mailutils/cpp/error.h>
#include <errno.h>
using namespace mailutils;
......
......@@ -19,8 +19,6 @@
*/
#include <mailutils/cpp/iterator.h>
#include <mailutils/cpp/error.h>
#include <errno.h>
using namespace mailutils;
......
......@@ -19,8 +19,6 @@
*/
#include <mailutils/cpp/list.h>
#include <mailutils/cpp/error.h>
#include <errno.h>
using namespace mailutils;
......
......@@ -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
//
......
......@@ -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;
......
......@@ -19,7 +19,6 @@
*/
#include <mailutils/cpp/mailer.h>
#include <errno.h>
using namespace mailutils;
......
......@@ -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 ()
{
......
......@@ -19,8 +19,6 @@
*/
#include <mailutils/cpp/mime.h>
#include <mailutils/cpp/error.h>
#include <errno.h>
using namespace mailutils;
......
......@@ -18,7 +18,6 @@
Boston, MA 02110-1301 USA
*/
#include <string>
#include <mailutils/cpp/mutil.h>
using namespace mailutils;
......
......@@ -19,8 +19,6 @@
*/
#include <mailutils/cpp/pop3.h>
#include <mailutils/cpp/iterator.h>
#include <errno.h>
using namespace mailutils;
......
......@@ -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;
......
......@@ -19,7 +19,6 @@
*/
#include <mailutils/cpp/stream.h>
#include <errno.h>
using namespace mailutils;
......
......@@ -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 ();
};
}
......