Commit 29b6ab7a 29b6ab7a115af00e066803ab6fac400bccbcad5f by Wojciech Polak

Improve C++ and Python APIs.

* include/mailutils/cpp/header.h (Header.has_key): New method.
* libmu_cpp/header.cc: Likewise.
* include/mailutils/cpp/mailbox.h (MailboxDefault): Make name optional.
* libmu_cpp/mailbox.cc: Likewise.
* python/mailutils/header.py (__contains__, has_key): New method.
1 parent 5d748cfc
......@@ -38,6 +38,7 @@ class Header
Header ();
Header (const mu_header_t);
bool has_key (const std::string& name);
std::string get_value (const std::string& name);
std::string get_value (const std::string& name, const std::string& def);
size_t size ();
......
......@@ -76,6 +76,7 @@ class Mailbox : public MailboxBase
class MailboxDefault : public MailboxBase
{
public:
MailboxDefault ();
MailboxDefault (const std::string&);
MailboxDefault (const mu_mailbox_t);
~MailboxDefault ();
......
......@@ -39,6 +39,20 @@ Header :: Header (const mu_header_t hdr)
this->hdr = hdr;
}
bool
Header :: has_key (const std::string& name)
{
const char* buf = NULL;
int status = mu_header_sget_value (hdr, name.c_str (), &buf);
if (status == MU_ERR_NOENT)
return false;
else if (status)
throw Exception ("Header::has_key", status);
return true;
}
std::string
Header :: get_value (const std::string& name)
{
......
......@@ -226,6 +226,13 @@ Mailbox :: ~Mailbox ()
// MailboxDefault
//
MailboxDefault :: MailboxDefault ()
{
int status = mu_mailbox_create_default (&mbox, NULL);
if (status)
throw Exception ("MailboxDefault::MailboxDefault", status);
}
MailboxDefault :: MailboxDefault (const std::string& name)
{
int status = mu_mailbox_create_default (&mbox, name.c_str ());
......
......@@ -38,6 +38,14 @@ class Header:
def __setitem__ (self, name, value):
self.set_value (name, value)
def __contains__ (self, name):
status, value = header.get_value (self.hdr, name)
if status == MU_ERR_NOENT:
return False
elif status:
raise HeaderError (status)
return True
def __getattr__ (self, name):
if name == 'size':
return self.get_size ()
......@@ -62,6 +70,9 @@ class Header:
self.__count += 1
return self.__getitem__ (self.__count)
def has_key (self, name):
return self.__contains__ (name)
def get_size (self):
status, size = header.size (self.hdr)
if status:
......