Commit 24d5aa4c 24d5aa4cbd4b2aec73dc9b275e8bc172973ed234 by Wojciech Polak

Add Debug class to libmu_cpp.

* include/mailutils/cpp/debug.h, libmu_cpp/debug.cc: New files.
* examples/cpp/mimetest.cc, examples/cpp/sfrom.cc, libmu_cpp/header.cc,
include/mailutils/cpp/header.h: Accept default header value if missing.
1 parent f5191b73
......@@ -74,7 +74,12 @@ main (int argc, char **argv)
MailboxDefault mbox (argv[i]);
/* Debugging trace. FIXME: ADD MISSING */
/* Debugging trace. */
if (debug)
{
Debug debug = mbox.get_debug ();
debug.set_level (MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT));
}
/* Open the mailbox for reading only. */
mbox.open ();
......@@ -89,7 +94,7 @@ main (int argc, char **argv)
cout << "Message: " << i << endl;
cout << "From: " << hdr[MU_HEADER_FROM] << endl;
cout << "Subject: " << hdr[MU_HEADER_SUBJECT] << endl;
cout << "Subject: " << hdr.get_value (MU_HEADER_SUBJECT, "[none]") << endl;
cout << "Number of parts in message - " << msg.get_num_parts () << endl;
cout << "Total message size - "
<< msg.size () << "/" << msg.lines () << endl;
......@@ -162,7 +167,7 @@ message_display_parts (Message& msg, int indent)
Header hdr = part.get_header ();
string from = hdr[MU_HEADER_FROM];
string subject = hdr[MU_HEADER_SUBJECT];
string subject = hdr.get_value (MU_HEADER_SUBJECT, "[none]");
cout << setw (indent) << setfill (' ')
<< "Encapsulated message : " << from << "\t" << subject << endl;
......
......@@ -43,7 +43,7 @@ int main (int argc, char* argv[])
Message msg = mbox[msgno];
Header hdr = msg.get_header ();
cout << hdr[MU_HEADER_FROM] << " "
<< hdr[MU_HEADER_SUBJECT] << endl;
<< hdr.get_value (MU_HEADER_SUBJECT, "[none]") << endl;
}
mbox.close ();
......
......@@ -20,6 +20,7 @@ MU_CXX_INCLUDES = \
address.h\
attribute.h\
body.h\
debug.h\
error.h\
filter.h\
header.h\
......
/*
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_DEBUG_H
#define _MUCPP_DEBUG_H
#include <string>
#include <mailutils/debug.h>
namespace mailutils
{
class Debug
{
protected:
mu_debug_t debug;
public:
Debug ();
Debug (const mu_debug_t);
void set_level (const mu_log_level_t level);
};
}
#endif // not _MUCPP_DEBUG_H
......@@ -37,6 +37,7 @@ class Header
Header (const mu_header_t);
std::string get_value (const std::string& name);
std::string get_value (const std::string& name, const std::string& def);
size_t size ();
size_t lines ();
......
......@@ -22,6 +22,7 @@
#define _MUCPP_MAILBOX_H
#include <mailutils/mailbox.h>
#include <mailutils/cpp/debug.h>
#include <mailutils/cpp/message.h>
namespace mailutils
......@@ -37,6 +38,8 @@ class MailboxBase
void open (int flag);
void close ();
Debug& get_debug ();
size_t messages_count ();
Message& get_message (size_t num);
......
......@@ -27,6 +27,7 @@ libmu_cpp_la_SOURCES = \
address.cc\
attribute.cc\
body.cc\
debug.cc\
filter.cc\
header.cc\
iterator.cc\
......
/*
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/debug.h>
#include <mailutils/cpp/error.h>
#include <errno.h>
using namespace mailutils;
//
// Debug
//
Debug :: Debug ()
{
this->debug = NULL;
}
Debug :: Debug (const mu_debug_t debug)
{
if (debug == 0)
throw Exception ("Debug::Debug", EINVAL);
this->debug = debug;
}
void
Debug :: set_level (const mu_log_level_t level)
{
int status = mu_debug_set_level (debug, level);
if (status)
throw Exception ("Debug::set_level", status);
}
......@@ -30,6 +30,7 @@ using namespace mailutils;
Header :: Header ()
{
this->hdr = NULL;
}
Header :: Header (const mu_header_t hdr)
......@@ -54,6 +55,22 @@ Header :: get_value (const std::string& name)
return val;
}
std::string
Header :: get_value (const std::string& name, const std::string& def)
{
char* c_val;
int status = mu_header_aget_value (hdr, name.c_str (), &c_val);
if (status == MU_ERR_NOENT)
return std::string (def);
else if (status)
throw Exception ("Header::get_value", status);
std::string val (c_val);
free (c_val);
return val;
}
size_t
Header :: size ()
{
......
......@@ -19,7 +19,6 @@
*/
#include <mailutils/cpp/mailbox.h>
#include <mailutils/cpp/message.h>
#include <mailutils/cpp/error.h>
#include <errno.h>
......@@ -53,6 +52,18 @@ MailboxBase :: close ()
throw Exception ("MailboxBase::close", status);
}
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);
}
size_t
MailboxBase :: messages_count ()
{
......