Commit f5191b73 f5191b732ac0e4dcc782cb3cc8dfc700a7e4c72a by Wojciech Polak

libmu_cpp refactoring and improvements.

* examples/cpp/mimetest.cc, include/mailutils/cpp/attribute.h,
include/mailutils/cpp/body.h, include/mailutils/cpp/mime.h,
include/mailutils/cpp/mutil.h, include/mailutils/cpp/registrar.h,
libmu_cpp/attribute.cc, libmu_cpp/body.cc, libmu_cpp/mime.cc,
libmu_cpp/mutil.cc, libmu_cpp/registrar.cc: New files.
1 parent 74f736ce
## Process this file with GNU Automake to create Makefile.in
##
## Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
## Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
##
## GNU Mailutils is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
......@@ -23,6 +23,7 @@ CXX_EXAMPLES = \
iconv\
listop\
mailcap\
mimetest\
murun\
sfrom\
url-parse
......@@ -43,6 +44,7 @@ http_SOURCES = http.cc
iconv_SOURCES = iconv.cc
listop_SOURCES = listop.cc
mailcap_SOURCES = mailcap.cc
mimetest_SOURCES = mimetest.cc
murun_SOURCES = murun.cc
sfrom_SOURCES = sfrom.cc
url_parse_SOURCES = url-parse.cc
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -22,47 +22,40 @@
#include <cstring>
#include <mailutils/cpp/mailutils.h>
#include <mailutils/filter.h>
#include <mailutils/mutil.h>
using namespace std;
using namespace mailutils;
static int
parse (const char *str)
{
size_t no = 0;
size_t count = 0;
std::string buf;
mu_set_user_email_domain ("localhost");
set_user_email_domain ("localhost");
try {
Address address (str);
count = address.getCount ();
size_t count = address.get_count ();
cout << str << "=> count " << count << endl;
for (no = 1; no <= count; no++)
for (size_t no = 1; no <= count; no++)
{
bool isgroup = address.isGroup (no);
bool isgroup = address.is_group (no);
cout << no << " ";
if (isgroup)
cout << "group " << address.getPersonal (no) << endl;
cout << "group " << address.get_personal (no) << endl;
else
cout << "email " << address.getEmail (no) << endl;
cout << "email " << address.get_email (no) << endl;
if (!isgroup)
cout << " personal " << address.getPersonal (no) << endl;
cout << " personal " << address.get_personal (no) << endl;
cout << " comments " << address.getComments (no) << endl;
cout << " local-part " << address.getLocalPart (no)
<< " domain " << address.getDomain (no) << endl;
cout << " route " << address.getRoute (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) {
cerr << e.method () << ": " << e.msgError () << endl;
cerr << e.method () << ": " << e.what () << endl;
}
cout << endl;
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -28,8 +28,8 @@
using namespace std;
using namespace mailutils;
std::string wbuf = "GET / HTTP/1.0\r\n\r\n";
std::string rbuf;
string wbuf = "GET / HTTP/1.0\r\n\r\n";
string rbuf;
int
main ()
......@@ -55,13 +55,13 @@ main ()
}
catch (Stream::EAgain) {
stream.wait (MU_STREAM_READY_WR);
off += stream.getWriten ();
off += stream.get_write_count ();
goto write_again;
}
if (stream.getWriten () != wbuf.length ())
if (stream.get_write_count () != wbuf.length ())
{
cerr << "stream.getWriten() != wbuf length" << endl;
cerr << "stream.get_write_count() != wbuf length" << endl;
exit (1);
}
......@@ -75,12 +75,12 @@ main ()
stream.wait (MU_STREAM_READY_RD);
goto read_again;
}
cout << rbuf.substr (0, stream.getReadn ());
cout << rbuf.substr (0, stream.get_read_count ());
}
while (stream.getReadn ());
while (stream.get_read_count ());
}
catch (Exception& e) {
cerr << e.method () << ": " << e.msgError () << endl;
cerr << e.method () << ": " << e.what () << endl;
exit (1);
}
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -41,7 +41,8 @@ main (int argc, char **argv)
in->open ();
FilterStream cvt;
cvt.iconvCreate (*in, (string)argv[1], (string)argv[2], 0, mu_fallback_none);
cvt.iconv_create (*in, (string)argv[1], (string)argv[2], 0,
mu_fallback_none);
cvt.open ();
delete in;
......@@ -50,15 +51,15 @@ main (int argc, char **argv)
do {
cvt.read (buffer, sizeof (buffer), total);
out.sequentialWrite (buffer, cvt.getReadn ());
total += cvt.getReadn ();
} while (cvt.getReadn ());
out.sequential_write (buffer, cvt.get_read_count ());
total += cvt.get_read_count ();
} while (cvt.get_read_count ());
out.flush ();
delete in;
}
catch (Exception& e) {
cerr << e.method () << ": " << e.msgError () << endl;
cerr << e.method () << ": " << e.what () << endl;
exit (1);
}
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -36,11 +36,9 @@ usage (int code)
void
print (List& lst)
{
Iterator itr (lst);
for (itr.first (); !itr.isDone (); itr++)
for (Iterator itr = lst.begin (); !itr.is_done (); itr++)
{
char* text = (char *) itr.current ();
char* text = (char *) *itr;
cout << text << endl;
}
}
......@@ -72,7 +70,7 @@ del (List& lst, int argc, char **argv)
lst.remove (strdup (*++argv));
}
catch (Exception& e) {
cerr << e.method () << ": " << e.msgError () << endl;
cerr << e.method () << ": " << e.what () << endl;
}
}
}
......@@ -94,7 +92,7 @@ add (List& lst, int argc, char **argv)
lst.append (strdup (*++argv));
}
catch (Exception& e) {
cerr << e.method () << ": " << e.msgError () << endl;
cerr << e.method () << ": " << e.what () << endl;
}
}
}
......@@ -115,7 +113,7 @@ prep (List& lst, int argc, char **argv)
lst.prepend (strdup (*++argv));
}
catch (Exception& e) {
cerr << e.method () << ": " << e.msgError () << endl;
cerr << e.method () << ": " << e.what () << endl;
}
}
}
......@@ -134,7 +132,7 @@ repl (List& lst, int argc, char **argv)
lst.replace (argv[1], strdup (argv[2]));
}
catch (Exception& e) {
cerr << e.method () << ": " << e.msgError () << endl;
cerr << e.method () << ": " << e.what () << endl;
}
}
......@@ -170,7 +168,7 @@ find (Iterator* itr, char* arg)
}
itr->current ((void**) &text);
for (itr->first (); !itr->isDone (); itr->next ())
for (itr->first (); !itr->is_done (); itr->next ())
{
char *item;
......@@ -181,7 +179,7 @@ find (Iterator* itr, char* arg)
cerr << arg << " not in list" << endl;
for (itr->first (); !itr->isDone (); itr->next ())
for (itr->first (); !itr->is_done (); itr->next ())
{
char *item;
......@@ -233,7 +231,7 @@ shell (List& lst)
itr[num]->current ((void**) &text);
}
catch (Exception& e) {
cerr << e.method () << ": " << e.msgError () << endl;
cerr << e.method () << ": " << e.what () << endl;
}
cout << num << ":(" << (text ? text : "NULL") << ")> ";
......@@ -246,27 +244,29 @@ shell (List& lst)
if (argc > 0)
{
if (!strcmp (argv[0], "next"))
string cmd (argv[0]);
if (cmd == "next")
next (itr[num], argv[1]);
else if (!strcmp (argv[0], "first"))
else if (cmd == "first")
itr[num]->first ();
else if (!strcmp (argv[0], "del"))
else if (cmd == "del")
del (lst, argc, argv);
else if (!strcmp (argv[0], "add"))
else if (cmd == "add")
add (lst, argc, argv);
else if (!strcmp (argv[0], "prep"))
else if (cmd == "prep")
prep (lst, argc, argv);
else if (!strcmp (argv[0], "repl"))
else if (cmd == "repl")
repl (lst, argc, argv);
else if (!strcmp (argv[0], "print"))
else if (cmd == "print")
print (lst);
else if (!strcmp (argv[0], "quit"))
else if (cmd == "quit")
return;
else if (!strcmp (argv[0], "iter"))
else if (cmd == "iter")
iter (&num, argc, argv);
else if (!strcmp (argv[0], "find"))
else if (cmd == "find")
find (itr[num], argv[1]);
else if (!strcmp (argv[0], "help"))
else if (cmd == "help")
help ();
else if (argc == 1)
{
......@@ -280,7 +280,7 @@ shell (List& lst)
text = (char*) lst[n];
}
catch (Exception& e) {
cerr << e.method () << ": " << e.msgError () << endl;
cerr << e.method () << ": " << e.what () << endl;
}
// else
......@@ -320,7 +320,7 @@ main (int argc, char **argv)
try {
List lst;
lst.setComparator (string_comp);
lst.set_comparator (string_comp);
while (argc--)
{
......@@ -330,7 +330,7 @@ main (int argc, char **argv)
shell (lst);
}
catch (Exception& e) {
cerr << e.method () << ": " << e.msgError () << endl;
cerr << e.method () << ": " << e.what () << endl;
}
return 0;
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -27,58 +27,48 @@ using namespace mailutils;
int
main (int argc, char **argv)
{
int status = 0;
char* file = "/etc/mailcap";
string file ("/etc/mailcap");
try {
FileStream stream ((std::string) file, MU_STREAM_READ);
FileStream stream (file, MU_STREAM_READ);
stream.open ();
Mailcap mailcap (stream);
int i;
size_t count = 0;
string buffer;
int count = mailcap.entries_count ();
count = mailcap.getCount ();
for (i = 1; i <= count; i++)
for (int i = 1; i <= count; i++)
{
size_t j;
size_t fields_count = 0;
cout << "entry[" << i << "]\n";
MailcapEntry entry = mailcap.getEntry (i);
MailcapEntry entry = mailcap[i];
/* typefield. */
buffer = entry.getTypeField ();
cout << "\ttypefield: " << buffer << endl;
/* typefield. */
cout << "\ttypefield: " << entry.get_typefield () << endl;
/* view-command. */
buffer = entry.getViewCommand ();
cout << "\tview-command: " << buffer << endl;
/* view-command. */
cout << "\tview-command: " << entry.get_viewcommand () << endl;
/* fields. */
fields_count = entry.fieldsCount ();
for (j = 1; j <= fields_count; j++)
/* fields. */
size_t fields_count = entry.fields_count ();
for (size_t j = 1; j <= fields_count; j++)
{
try {
buffer = entry.getField (j);
cout << "\tfields[" << j << "]: " << entry[j] << endl;
}
catch (Exception& e) {
cerr << e.method () << ": cannot retrieve field "
<< j << ": " << e.msgError () << endl;
<< j << ": " << e.what () << endl;
}
cout << "\tfields[" << j << "]: " << buffer << endl;
}
cout << endl;
}
}
catch (Exception& e) {
cerr << e.method () << ": " << e.msgError () << endl;
cerr << e.method () << ": " << e.what () << endl;
exit (1);
}
return 0;
}
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Mailutils 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301 USA */
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <mailutils/cpp/mailutils.h>
using namespace std;
using namespace mailutils;
void message_display_parts (Message& msg, int indent);
bool print_attachments = false;
int indent_level = 4;
void
print_file (const std::string& fname, int indent)
{
char buf[128];
FILE *fp = fopen (fname.c_str (), "r");
if (!fp)
{
cerr << "can't open file " << fname << ": " << strerror (errno) << endl;
return;
}
while (fgets (buf, sizeof buf, fp))
cout << setw (indent) << setfill (' ') << buf;
fclose (fp);
unlink (fname.c_str ());
}
int
main (int argc, char **argv)
{
int i = 0;
bool debug = false;
for (i = 1; i < argc; i++)
{
if (strcmp (argv[i], "-d") == 0)
debug = true;
else if (strcmp (argv[i], "-p") == 0)
print_attachments = true;
else if (strcmp (argv[i], "-i") == 0)
indent_level = strtoul (argv[++i], NULL, 0);
else
break;
}
/* Registration. */
registrar_record (mu_imap_record);
registrar_record (mu_pop_record);
registrar_record (mu_mbox_record);
registrar_set_default_record (mu_mbox_record);
MailboxDefault mbox (argv[i]);
/* Debugging trace. FIXME: ADD MISSING */
/* Open the mailbox for reading only. */
mbox.open ();
/* Iterate through the entire message set. */
size_t count = mbox.messages_count ();
for (size_t i = 1; i <= count; ++i)
{
Message msg = mbox.get_message (i);
Header hdr = msg.get_header ();
cout << "Message: " << i << endl;
cout << "From: " << hdr[MU_HEADER_FROM] << endl;
cout << "Subject: " << hdr[MU_HEADER_SUBJECT] << endl;
cout << "Number of parts in message - " << msg.get_num_parts () << endl;
cout << "Total message size - "
<< msg.size () << "/" << msg.lines () << endl;
try {
message_display_parts (msg, 0);
}
catch (Exception& e)
{
cerr << e.method () << ": " << e.what () << endl;
}
}
mbox.close ();
return 0;
}
static void
print_message_part_sizes (Message& part, int indent)
{
Header hdr = part.get_header ();
Body body = part.get_body ();
cout << setw (indent) << setfill (' ') << "Message part size - ";
cout << part.size () << "/" << part.lines () << ": "
<< hdr.size () << "/" << hdr.lines () << ", "
<< body.size () << "/" << body.lines () << endl;
}
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 ();
/* Iterate through all the parts. Treat type "message/rfc822"
differently, since it is a message of its own that can have other
subparts(recursive). */
for (int j = 1; j <= nparts; j++)
{
Message part = msg.get_part (j);
Header hdr = part.get_header ();
string type;
string encoding ("");
try {
type = hdr[MU_HEADER_CONTENT_TYPE];
encoding = hdr[MU_HEADER_CONTENT_TRANSFER_ENCODING];
}
catch (Exception& e)
{
if (e.status () != MU_ERR_NOENT) {
cerr << e.method () << ": " << e.what () << endl;
exit (1);
}
}
cout << setw (indent) << setfill (' ')
<< "Type of part " << j << " = " << type << endl;
print_message_part_sizes (part, indent);
bool ismulti = part.is_multipart ();
if (type == "message/rfc822" || ismulti)
{
if (!ismulti)
part = part.unencapsulate ();
Header hdr = part.get_header ();
string from = hdr[MU_HEADER_FROM];
string subject = hdr[MU_HEADER_SUBJECT];
cout << setw (indent) << setfill (' ')
<< "Encapsulated message : " << from << "\t" << subject << endl;
cout << setw (indent) << setfill (' ') << "Begin" << endl;
size_t nsubparts = part.get_num_parts ();
message_display_parts (part, indent + indent_level);
}
else if (strncasecmp (type.c_str (), "text/plain",
strlen ("text/plain")) == 0 ||
strncasecmp (type.c_str (), "text/html",
strlen ("text/html")) == 0 ||
type.empty ())
{
cout << setw (indent) << setfill (' ') << "Text Message" << endl;
cout << setw (indent) << setfill (' ') << "Begin" << endl;
Body body = part.get_body ();
Stream stream = body.get_stream ();
FilterStream filter;
filter.create (stream, encoding, 0, 0);
int offset = 0;
char buf[2048];
while (filter.readline (buf, sizeof (buf), offset) == 0 &&
filter.get_read_count ())
{
cout << setw (indent) << setfill (' ') << buf;
offset += filter.get_read_count ();
}
}
else
{
/* Save the attachements. */
string fname;
try {
fname = part.get_attachment_name ();
}
catch (Exception& e) {
fname = mailutils::tempname ();
}
cout << setw (indent) << setfill (' ')
<< "Attachment - saving " << "[" << fname << "]" << endl;
cout << setw (indent) << setfill (' ') << "Begin" << endl;
part.save_attachment ();
if (print_attachments)
print_file (fname, indent);
}
cout << endl << setw (indent) << setfill (' ') << "End" << endl;
}
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -32,16 +32,16 @@ read_and_print (Stream *in, Stream& out)
{
char buffer[128];
in->sequentialReadLine (buffer, sizeof (buffer));
while (in->getReadn ())
in->sequential_readline (buffer, sizeof (buffer));
while (in->get_read_count ())
{
out.sequentialWrite (buffer, in->getReadn ());
in->sequentialReadLine (buffer, sizeof (buffer));
out.sequential_write (buffer, in->get_read_count ());
in->sequential_readline (buffer, sizeof (buffer));
}
}
Stream *
createFilter (bool read_stdin, char *cmdline, int flags)
create_filter (bool read_stdin, char *cmdline, int flags)
{
try {
if (read_stdin)
......@@ -61,7 +61,7 @@ createFilter (bool read_stdin, char *cmdline, int flags)
}
catch (Exception& e) {
cerr << progname << ": cannot create program filter stream: "
<< e.method () << ": " << e.msgError () << endl;
<< e.method () << ": " << e.what () << endl;
exit (1);
}
}
......@@ -92,7 +92,7 @@ main (int argc, char *argv[])
mu_argcv_string (argc - i, &argv[i], &cmdline);
stream = createFilter (read_stdin, cmdline, flags);
stream = create_filter (read_stdin, cmdline, flags);
try {
StdioStream out (stdout, 0);
......@@ -103,7 +103,7 @@ main (int argc, char *argv[])
delete stream;
}
catch (Exception& e) {
cerr << e.method () << ": " << e.msgError () << endl;
cerr << e.method () << ": " << e.what () << endl;
exit (1);
}
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -21,36 +21,27 @@
#include <iostream>
#include <mailutils/cpp/mailutils.h>
#include <mailutils/registrar.h> // tmp
#include <mailutils/list.h> // tmp
using namespace std;
using namespace mailutils;
int main (int argc, char* argv[])
{
size_t total = 0;
if (argc == 1)
exit (0);
mu_register_local_mbox_formats ();
Message msg;
Header hdr;
register_local_mbox_formats ();
try {
MailboxDefault mbox (argv[1]);
mbox.open ();
mbox.open (MU_STREAM_READ);
total = mbox.messagesCount ();
size_t total = mbox.messages_count ();
cout << "Total: " << total << endl;
for (int msgno = 1; msgno <= total; msgno++)
{
msg = mbox[msgno];
hdr = msg.getHeader ();
Message msg = mbox[msgno];
Header hdr = msg.get_header ();
cout << hdr[MU_HEADER_FROM] << " "
<< hdr[MU_HEADER_SUBJECT] << endl;
}
......@@ -58,7 +49,7 @@ int main (int argc, char* argv[])
mbox.close ();
}
catch (Exception& e) {
cerr << e.method () << ": " << e.msgError () << endl;
cerr << e.method () << ": " << e.what () << endl;
exit (1);
}
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007, 2008 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -43,21 +43,21 @@ main ()
Url url (str);
url.parse ();
cout << "\tscheme <" << url.getScheme () << ">" << endl;
cout << "\tuser <" << url.getUser () << ">" << endl;
cout << "\tpasswd <" << url.getPasswd () << ">" << endl;
cout << "\tauth <" << url.getAuth () << ">" << endl;
cout << "\thost <" << url.getHost () << ">" << endl;
cout << "\tport " << url.getPort () << endl;
cout << "\tpath <" << url.getPath () << ">" << endl;
cout << "\tscheme <" << url.get_scheme () << ">" << endl;
cout << "\tuser <" << url.get_user () << ">" << endl;
cout << "\tpasswd <" << url.get_passwd () << ">" << endl;
cout << "\tauth <" << url.get_auth () << ">" << endl;
cout << "\thost <" << url.get_host () << ">" << endl;
cout << "\tport " << url.get_port () << endl;
cout << "\tpath <" << url.get_path () << ">" << endl;
vector<string> params = url.getQuery ();
vector<string> params = url.get_query ();
for (vector<string>::size_type i = 0; i != params.size (); i++) {
cout << "\tquery[" << i << "] <" << params[i] << ">" << endl;
}
}
catch (Exception& e) {
cerr << e.method () << ": " << e.msgError () << endl;
cerr << e.method () << ": " << e.what () << endl;
goto again;
}
}
......
## Process this file with GNU Automake to create Makefile.in
##
## Copyright (C) 2004, 2007 Free Software Foundation, Inc.
## Copyright (C) 2004, 2007, 2009 Free Software Foundation, Inc.
##
## GNU Mailutils is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
......@@ -18,6 +18,8 @@
MU_CXX_INCLUDES = \
address.h\
attribute.h\
body.h\
error.h\
filter.h\
header.h\
......@@ -28,7 +30,10 @@ MU_CXX_INCLUDES = \
mailer.h\
mailutils.h\
message.h\
mime.h\
mutil.h\
pop3.h\
registrar.h\
stream.h\
url.h
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -21,7 +21,6 @@
#ifndef _ADDRESS_H
#define _ADDRESS_H
#include <iostream>
#include <mailutils/address.h>
#include <mailutils/cpp/error.h>
......@@ -43,25 +42,25 @@ class Address
Address (const mu_address_t);
~Address ();
size_t getCount ();
bool isGroup (size_t);
size_t get_count ();
bool is_group (size_t n);
std::string getEmail (size_t);
std::string getLocalPart (size_t);
std::string getDomain (size_t);
std::string getPersonal (size_t);
std::string getComments (size_t);
std::string getRoute (size_t);
std::string get_email (size_t n);
std::string get_local_part (size_t n);
std::string get_domain (size_t n);
std::string get_personal (size_t n);
std::string get_comments (size_t n);
std::string get_route (size_t n);
// Address Exceptions
class EInval : public Exception {
public:
EInval (const std::string& m, int s) : Exception (m, s) {}
EInval (const char* m, int s) : Exception (m, s) {}
};
class ENoent : public Exception {
public:
ENoent (const std::string& m, int s) : Exception (m, s) {}
ENoent (const char* m, int s) : Exception (m, s) {}
};
};
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007, 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_ATTRIBUTE_H
#define _MUCPP_ATTRIBUTE_H
#include <mailutils/attribute.h>
namespace mailutils
{
class Attribute
{
protected:
mu_attribute_t attr;
public:
Attribute ();
Attribute (const mu_attribute_t);
bool is_modified ();
void clear_modified ();
void set_modified ();
bool is_userflag (int flag);
bool is_seen ();
bool is_answered ();
bool is_flagged ();
bool is_deleted ();
bool is_draft ();
bool is_recent ();
bool is_read ();
void set_userflag (int flag);
void set_seen ();
void set_answered ();
void set_flagged ();
void set_deleted ();
void set_draft ();
void set_recent ();
void set_read ();
void unset_userflag (int flag);
void unset_seen ();
void unset_answered ();
void unset_flagged ();
void unset_deleted ();
void unset_draft ();
void unset_recent ();
void unset_read ();
};
}
#endif // not _MUCPP_ATTRIBUTE_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_BODY_H
#define _MUCPP_BODY_H
#include <string>
#include <mailutils/body.h>
#include <mailutils/cpp/stream.h>
namespace mailutils
{
class Body
{
protected:
mu_body_t body;
bool owner;
public:
Body ();
Body (const mu_body_t);
~Body ();
bool is_modified ();
void clear_modified ();
Stream& get_stream ();
size_t size ();
size_t lines ();
};
}
#endif // not _MUCPP_BODY_H
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -21,7 +21,6 @@
#ifndef _MUCPP_ERROR_H
#define _MUCPP_ERROR_H
#include <iostream>
#include <string>
#include <mailutils/errno.h>
......@@ -31,20 +30,36 @@ namespace mailutils
class Exception
{
protected:
std::string pmethod;
std::string pmsgerr;
int pstatus;
const char* pmethod;
const char* pmsgerr;
public:
Exception (const std::string m, int s) {
pmethod = m;
pmsgerr = mu_strerror (s);
Exception (const char* method_name, int status) {
pstatus = status;
pmethod = method_name;
pmsgerr = mu_strerror (status);
}
std::string method () const {
Exception (const std::string method_name, int status) {
pstatus = status;
pmethod = method_name.c_str ();
pmsgerr = mu_strerror (status);
}
int status () const {
return pstatus;
}
const char* method () const {
return pmethod;
}
std::string msgError () const {
const char* msg_error () const {
return pmsgerr;
}
const char* what () const {
return pmsgerr;
}
};
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -21,7 +21,6 @@
#ifndef _MUCPP_FILTER_H
#define _MUCPP_FILTER_H
#include <iostream>
#include <mailutils/filter.h>
#include <mailutils/cpp/stream.h>
......@@ -34,10 +33,14 @@ class FilterStream : public Stream
Stream *input;
public:
void create (Stream&, const std::string&, int, int);
void iconvCreate (Stream&, const std::string&,
const std::string&, int,
enum mu_iconv_fallback_mode);
void create (Stream& transport, const std::string& code, int mode,
int flag);
void iconv_create (Stream& transport,
const std::string& fromcode,
const std::string& tocode,
int flags,
enum mu_iconv_fallback_mode fallback_mode);
};
}
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -21,7 +21,6 @@
#ifndef _MUCPP_HEADER_H
#define _MUCPP_HEADER_H
#include <iostream>
#include <string>
#include <mailutils/header.h>
......@@ -37,8 +36,13 @@ class Header
Header ();
Header (const mu_header_t);
std::string getValue (const std::string&);
std::string operator [] (const std::string&);
std::string get_value (const std::string& name);
size_t size ();
size_t lines ();
inline std::string operator [] (const std::string& name) {
return this->get_value (name);
}
};
}
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -21,32 +21,42 @@
#ifndef _MUCPP_ITERATOR_H
#define _MUCPP_ITERATOR_H
#include <iostream>
#include <mailutils/iterator.h>
#include <mailutils/cpp/list.h>
namespace mailutils
{
class List;
class Iterator
{
protected:
mu_iterator_t mu_iter;
List* pList;
friend class List;
public:
Iterator (const List&);
Iterator (const mu_iterator_t);
~Iterator ();
bool operator == (const Iterator&);
bool operator != (const Iterator&);
void dup (Iterator*&, const Iterator&);
void first ();
void next ();
Iterator& operator ++ (int);
void current (void**);
void current (void** pitem);
void* current ();
bool isDone ();
List& getList ();
bool is_done ();
List& get_list ();
inline void* operator * () {
return this->current ();
}
};
}
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -21,8 +21,8 @@
#ifndef _MUCPP_LIST_H
#define _MUCPP_LIST_H
#include <iostream>
#include <mailutils/list.h>
#include <mailutils/cpp/iterator.h>
typedef int mu_list_action_t (void*, void*);
typedef int (*mu_list_comparator_t) (const void*, const void*);
......@@ -30,10 +30,13 @@ typedef int (*mu_list_comparator_t) (const void*, const void*);
namespace mailutils
{
class Iterator;
class List
{
protected:
mu_list_t mu_list;
Iterator* iter;
friend class Iterator;
......@@ -42,25 +45,33 @@ class List
List (const mu_list_t);
~List ();
void append (void*);
void prepend (void*);
void insert (void*, void*, int);
void remove (void*);
void replace (void*, void*);
void append (void* item);
void prepend (void* item);
void insert (void* item, void* new_item, int insert_before);
void remove (void* item);
void replace (void* old_item, void* new_item);
void get (size_t index, void** pitem);
void* get (size_t index);
void* front ();
void* back ();
void get (size_t, void**);
void* get (size_t);
void* operator [] (size_t);
Iterator begin ();
void toArray (void**, size_t, size_t*);
void locate (void*, void**);
void to_array (void** array, size_t count, size_t* pcount);
void locate (void* item, void** ret_item);
void apply (mu_list_action_t*, void*);
mu_list_comparator_t setComparator (mu_list_comparator_t);
void setDestroyItem (void (*mu_destoy_item) (void *));
void apply (mu_list_action_t* action, void* cbdata);
mu_list_comparator_t set_comparator (mu_list_comparator_t comp);
void set_destroy_item (void (*mu_destoy_item) (void *item));
bool isEmpty ();
bool is_empty ();
size_t count ();
size_t size ();
inline void* operator [] (size_t index) {
return this->get (index);
}
};
}
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -21,7 +21,6 @@
#ifndef _MUCPP_MAILBOX_H
#define _MUCPP_MAILBOX_H
#include <iostream>
#include <mailutils/mailbox.h>
#include <mailutils/cpp/message.h>
......@@ -34,12 +33,16 @@ class MailboxBase
mu_mailbox_t mbox;
public:
void open (int);
void open ();
void open (int flag);
void close ();
size_t messagesCount ();
Message& getMessage (size_t);
Message& operator [] (size_t);
size_t messages_count ();
Message& get_message (size_t num);
inline Message& operator [] (size_t num) {
return this->get_message (num);
}
};
class Mailbox : public MailboxBase
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -21,7 +21,6 @@
#ifndef _MUCPP_MAILCAP_H
#define _MUCPP_MAILCAP_H
#include <iostream>
#include <mailutils/mailcap.h>
#include <mailutils/cpp/stream.h>
......@@ -39,10 +38,14 @@ class MailcapEntry
public:
MailcapEntry (mu_mailcap_entry_t);
size_t fieldsCount ();
std::string getTypeField ();
std::string getViewCommand ();
std::string getField (size_t);
size_t fields_count ();
std::string get_typefield ();
std::string get_viewcommand ();
std::string get_field (size_t i);
inline std::string operator [] (size_t i) {
return this->get_field (i);
}
};
class Mailcap
......@@ -55,8 +58,12 @@ class Mailcap
Mailcap (const mu_mailcap_t);
~Mailcap ();
size_t getCount ();
MailcapEntry& getEntry (size_t);
size_t entries_count ();
MailcapEntry& get_entry (size_t i);
inline MailcapEntry& operator [] (size_t i) {
return this->get_entry (i);
}
};
}
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -21,7 +21,6 @@
#ifndef _MUCPP_MAILER_H
#define _MUCPP_MAILER_H
#include <iostream>
#include <string>
#include <mailutils/mailer.h>
#include <mailutils/cpp/message.h>
......@@ -40,9 +39,10 @@ class Mailer
Mailer (const mu_mailer_t);
~Mailer ();
void open (int);
void open (int flags);
void close ();
void sendMessage (const Message&, const Address&, const Address&);
void send_message (const Message& msg, const Address& from,
const Address& to);
};
}
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -19,6 +19,8 @@
*/
#include <mailutils/cpp/address.h>
#include <mailutils/cpp/attribute.h>
#include <mailutils/cpp/body.h>
#include <mailutils/cpp/error.h>
#include <mailutils/cpp/filter.h>
#include <mailutils/cpp/header.h>
......@@ -28,7 +30,10 @@
#include <mailutils/cpp/mailcap.h>
#include <mailutils/cpp/mailer.h>
#include <mailutils/cpp/message.h>
#include <mailutils/cpp/mime.h>
#include <mailutils/cpp/mutil.h>
#include <mailutils/cpp/pop3.h>
#include <mailutils/cpp/registrar.h>
#include <mailutils/cpp/stream.h>
#include <mailutils/cpp/url.h>
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -23,6 +23,8 @@
#include <mailutils/message.h>
#include <mailutils/cpp/header.h>
#include <mailutils/cpp/body.h>
#include <mailutils/cpp/stream.h>
namespace mailutils
{
......@@ -31,14 +33,31 @@ class Message
{
protected:
mu_message_t msg;
bool owner;
friend class Mailer;
friend class Mime;
public:
Message ();
Message (const mu_message_t);
Message& operator = (const Message&);
~Message ();
Header& getHeader ();
Header& get_header ();
Body& get_body ();
Stream& get_stream ();
bool is_multipart ();
size_t size ();
size_t lines ();
size_t get_num_parts ();
Message& get_part (const size_t npart);
void save_attachment ();
void save_attachment (const std::string& filename);
Message& unencapsulate ();
std::string get_attachment_name ();
};
}
......
/*
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_MIME_H
#define _MUCPP_MIME_H
#include <string>
#include <mailutils/mime.h>
#include <mailutils/cpp/message.h>
namespace mailutils
{
class Mime
{
protected:
mu_mime_t mime;
public:
Mime (const Message&, int);
Mime (const mu_mime_t);
~Mime ();
bool is_multipart ();
size_t get_num_parts ();
Message& get_part (size_t part);
void add_part (const Message& msg);
Message& get_message ();
};
extern int rfc2047_decode (const char* tocode, const char* fromstr,
char** ptostr);
extern int rfc2047_encode (const char* charset, const char* encoding,
const char* text, char** result);
}
#endif // not _MUCPP_MIME_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_MUTIL_H
#define _MUCPP_MUTIL_H
#include <string>
#include <mailutils/filter.h>
#include <mailutils/mutil.h>
namespace mailutils
{
int set_user_email (const std::string& email);
int set_user_email_domain (const std::string& domain);
std::string tempname ();
std::string tempname (const std::string& tmpdir);
}
#endif // not _MUCPP_MUTIL_H
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -21,7 +21,6 @@
#ifndef _MUCPP_POP3_H
#define _MUCPP_POP3_H
#include <iostream>
#include <mailutils/pop3.h>
#include <mailutils/cpp/list.h>
#include <mailutils/cpp/iterator.h>
......@@ -41,30 +40,33 @@ class Pop3
Pop3 (const mu_pop3_t);
~Pop3 ();
void setCarrier (const Stream&);
Stream& getCarrier ();
void set_carrier (const Stream& carrier);
Stream& get_carrier ();
void connect ();
void disconnect ();
void setTimeout (int);
int getTimeout ();
void set_timeout (int timeout);
int get_timeout ();
void apop (const char* name, const char* digest);
void stls ();
Iterator& capa ();
void dele (unsigned int);
size_t list (unsigned int);
Iterator& listAll ();
void dele (unsigned int msgno);
size_t list (unsigned int msgno);
Iterator& list_all ();
void noop ();
void pass (const char*);
void pass (const char* pass);
void quit ();
Stream& retr (unsigned int);
Stream& retr (unsigned int msgno);
void rset ();
void stat (unsigned int*, size_t*);
Stream& top (unsigned int, unsigned int);
void user (const char*);
void stat (unsigned int* count, size_t* octets);
Stream& top (unsigned int msgno, unsigned int lines);
std::string uidl (unsigned int msgno);
Iterator& uidl_all ();
void user (const char* user);
size_t readLine (char*, size_t);
size_t response (char*, size_t);
void sendLine (const char*);
size_t readline (char* buf, size_t buflen);
size_t response (char* buf, size_t buflen);
void sendline (const char* line);
void send ();
};
......
/*
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_REGISTRAR_H
#define _MUCPP_REGISTRAR_H
#include <mailutils/registrar.h>
#include <mailutils/cpp/url.h>
namespace mailutils
{
class Record
{
protected:
mu_record_t record;
public:
Record (const mu_record_t);
~Record ();
// Defaults
int set_default_scheme (const std::string&);
std::string get_default_scheme ();
int get_default_record (mu_record_t* prec);
void set_default_record ();
// Registration
int registrar ();
int unregistrar ();
};
// Defaults
inline void
registrar_set_default_record (const mu_record_t record)
{
mu_registrar_set_default_record (record);
}
// Registration
inline int
registrar_record (const mu_record_t record)
{
return mu_registrar_record (record);
}
inline int
unregistrar_record (const mu_record_t record)
{
return mu_unregistrar_record (record);
}
inline void register_all_mbox_formats ()
{
mu_register_all_mbox_formats ();
}
inline void
register_local_mbox_formats ()
{
mu_register_local_mbox_formats ();
}
inline void
register_remote_mbox_formats ()
{
mu_register_remote_mbox_formats ();
}
inline void
register_all_mailer_formats ()
{
mu_register_all_mailer_formats ();
}
inline void
register_extra_formats ()
{
mu_register_extra_formats ();
}
inline void
register_all_formats ()
{
mu_register_all_formats ();
}
}
#endif // not _MUCPP_REGISTRAR_H
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -21,9 +21,7 @@
#ifndef _MUCPP_STREAM_H
#define _MUCPP_STREAM_H
#include <iostream>
#include <string>
#include <cstdio>
#include <mailutils/stream.h>
#include <mailutils/cpp/error.h>
......@@ -34,8 +32,8 @@ class Stream
{
protected:
mu_stream_t stm;
size_t readn;
size_t writen;
size_t read_count;
size_t write_count;
int wflags;
bool opened;
size_t reference_count;
......@@ -62,22 +60,22 @@ class Stream
void open ();
void close ();
void setWaitFlags (int);
void set_waitflags (int flags);
void wait (); // timeval is missing
void wait (int); // timeval is missing
void read (char*, size_t, off_t);
void write (const std::string&, size_t, off_t);
void readLine (char*, size_t, off_t);
void sequentialReadLine (char*, size_t);
void sequentialWrite (const std::string&, size_t);
void wait (int flags); // timeval is missing
int read (char* rbuf, size_t size, off_t offset);
int write (const std::string& wbuf, size_t size, off_t offset);
int readline (char* rbuf, size_t size, off_t offset);
void sequential_readline (char* rbuf, size_t size);
void sequential_write (const std::string& wbuf, size_t size);
void flush ();
// Inlines
size_t getReadn () const {
return readn;
size_t get_read_count () const {
return read_count;
};
size_t getWriten () const {
return writen;
size_t get_write_count () const {
return write_count;
};
friend Stream& operator << (Stream&, const std::string&);
......@@ -86,7 +84,7 @@ class Stream
// Stream Exceptions
class EAgain : public Exception {
public:
EAgain (const std::string& m, int s) : Exception (m, s) {}
EAgain (const char* m, int s) : Exception (m, s) {}
};
};
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007, 2008 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 2008, 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
......@@ -21,7 +21,6 @@
#ifndef _MUCPP_URL_H
#define _MUCPP_URL_H
#include <iostream>
#include <string>
#include <vector>
#include <mailutils/url.h>
......@@ -44,14 +43,14 @@ class Url
~Url ();
void parse ();
long getPort ();
std::string getScheme ();
std::string getUser ();
std::string getPasswd ();
std::string getAuth ();
std::string getHost ();
std::string getPath ();
std::vector<std::string> getQuery ();
long get_port ();
std::string get_scheme ();
std::string get_user ();
std::string get_passwd ();
std::string get_auth ();
std::string get_host ();
std::string get_path ();
std::vector<std::string> get_query ();
};
}
......
## Process this file with GNU Automake to create Makefile.in
##
## Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
## Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
##
## GNU Mailutils is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
......@@ -25,6 +25,8 @@ EXTRA_LTLIBRARIES = $(MU_CXX_LIBS)
libmu_cpp_la_SOURCES = \
address.cc\
attribute.cc\
body.cc\
filter.cc\
header.cc\
iterator.cc\
......@@ -33,7 +35,10 @@ libmu_cpp_la_SOURCES = \
mailcap.cc\
mailer.cc\
message.cc\
mime.cc\
mutil.cc\
pop3.cc\
registrar.cc\
stream.cc\
url.cc
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -49,20 +49,20 @@ Address :: ~Address ()
}
bool
Address :: isGroup (size_t n)
Address :: is_group (size_t n)
{
int isgroup;
int status = mu_address_is_group (addr, n, &isgroup);
if (status == EINVAL)
throw Address::EInval ("Address::isGroup", status);
throw Address::EInval ("Address::is_group", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::isGroup", status);
throw Address::ENoent ("Address::is_group", status);
return (bool) isgroup;
}
size_t
Address :: getCount ()
Address :: get_count ()
{
size_t count;
mu_address_get_count (addr, &count);
......@@ -70,73 +70,73 @@ Address :: getCount ()
}
std::string
Address :: getEmail (size_t n)
Address :: get_email (size_t n)
{
int status = mu_address_get_email (addr, n, buf, sizeof (buf), 0);
if (status == EINVAL)
throw Address::EInval ("Address::getEmail", status);
throw Address::EInval ("Address::get_email", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::getEmail", status);
throw Address::ENoent ("Address::get_email", status);
return std::string (buf);
}
std::string
Address :: getLocalPart (size_t n)
Address :: get_local_part (size_t n)
{
int status = mu_address_get_local_part (addr, n, buf, sizeof (buf), 0);
if (status == EINVAL)
throw Address::EInval ("Address::getLocalPart", status);
throw Address::EInval ("Address::get_local_part", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::getLocalPart", status);
throw Address::ENoent ("Address::get_local_part", status);
return std::string (buf);
}
std::string
Address :: getDomain (size_t n)
Address :: get_domain (size_t n)
{
int status = mu_address_get_domain (addr, n, buf, sizeof (buf), 0);
if (status == EINVAL)
throw Address::EInval ("Address::getDomain", status);
throw Address::EInval ("Address::get_domain", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::getDomain", status);
throw Address::ENoent ("Address::get_domain", status);
return std::string (buf);
}
std::string
Address :: getPersonal (size_t n)
Address :: get_personal (size_t n)
{
int status = mu_address_get_personal (addr, n, buf, sizeof (buf), 0);
if (status == EINVAL)
throw Address::EInval ("Address::getPersonal", status);
throw Address::EInval ("Address::get_personal", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::getPersonal", status);
throw Address::ENoent ("Address::get_personal", status);
return std::string (buf);
}
std::string
Address :: getComments (size_t n)
Address :: get_comments (size_t n)
{
int status = mu_address_get_comments (addr, n, buf, sizeof (buf), 0);
if (status == EINVAL)
throw Address::EInval ("Address::getComments", status);
throw Address::EInval ("Address::get_comments", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::getComments", status);
throw Address::ENoent ("Address::get_comments", status);
return std::string (buf);
}
std::string
Address :: getRoute (size_t n)
Address :: get_route (size_t n)
{
int status = mu_address_get_route (addr, n, buf, sizeof (buf), 0);
if (status == EINVAL)
throw Address::EInval ("Address::getRoute", status);
throw Address::EInval ("Address::get_route", status);
else if (status == ENOENT)
throw Address::ENoent ("Address::getRoute", status);
throw Address::ENoent ("Address::get_route", status);
return std::string (buf);
}
......
/*
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/attribute.h>
#include <mailutils/cpp/error.h>
#include <errno.h>
using namespace mailutils;
//
// Attribute
//
Attribute :: Attribute ()
{
}
Attribute :: Attribute (const mu_attribute_t attr)
{
if (attr == 0)
throw Exception ("Attribute::Attribute", EINVAL);
this->attr = attr;
}
inline bool
Attribute :: is_modified ()
{
return (bool) mu_attribute_is_modified (attr);
}
inline void
Attribute :: clear_modified ()
{
mu_attribute_clear_modified (attr);
}
inline void
Attribute :: set_modified ()
{
mu_attribute_set_modified (attr);
}
//
// is_*
//
inline bool
Attribute :: is_userflag (int flag)
{
return (bool) mu_attribute_is_userflag (attr, flag);
}
inline bool
Attribute :: is_seen ()
{
return (bool) mu_attribute_is_seen (attr);
}
inline bool
Attribute :: is_answered () {
return (bool) mu_attribute_is_answered (attr);
}
inline bool
Attribute :: is_flagged ()
{
return (bool) mu_attribute_is_flagged (attr);
}
inline bool
Attribute :: is_deleted ()
{
return (bool) mu_attribute_is_deleted (attr);
}
inline bool
Attribute :: is_draft ()
{
return (bool) mu_attribute_is_draft (attr);
}
inline bool
Attribute :: is_recent ()
{
return (bool) mu_attribute_is_recent (attr);
}
inline bool
Attribute :: is_read ()
{
return (bool) mu_attribute_is_read (attr);
}
//
// set_*
//
inline void
Attribute :: set_userflag (int flag)
{
mu_attribute_set_userflag (attr, flag);
}
inline void
Attribute :: set_seen ()
{
mu_attribute_set_seen (attr);
}
inline void
Attribute :: set_answered ()
{
mu_attribute_set_answered (attr);
}
inline void
Attribute :: set_flagged ()
{
mu_attribute_set_flagged (attr);
}
inline void
Attribute :: set_deleted ()
{
mu_attribute_set_deleted (attr);
}
inline void
Attribute :: set_draft ()
{
mu_attribute_set_draft (attr);
}
inline void
Attribute :: set_recent ()
{
mu_attribute_set_recent (attr);
}
inline void
Attribute :: set_read ()
{
mu_attribute_set_read (attr);
}
//
// unset_*
//
inline void
Attribute :: unset_userflag (int flag)
{
mu_attribute_unset_userflag (attr, flag);
}
inline void
Attribute :: unset_seen ()
{
mu_attribute_unset_seen (attr);
}
inline void
Attribute :: unset_answered ()
{
mu_attribute_unset_answered (attr);
}
inline void
Attribute :: unset_flagged ()
{
mu_attribute_unset_flagged (attr);
}
inline void
Attribute :: unset_deleted ()
{
mu_attribute_unset_deleted (attr);
}
inline void
Attribute :: unset_draft ()
{
mu_attribute_unset_draft (attr);
}
inline void
Attribute :: unset_recent ()
{
mu_attribute_unset_recent (attr);
}
inline void
Attribute :: unset_read ()
{
mu_attribute_unset_read (attr);
}
/*
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/body.h>
#include <mailutils/cpp/error.h>
#include <errno.h>
using namespace mailutils;
//
// Body
//
Body :: Body ()
{
int status = mu_body_create (&body, this);
if (status)
throw Exception ("Body::Body", status);
this->owner = true;
}
Body :: Body (const mu_body_t body)
{
if (body == 0)
throw Exception ("Body::Body", EINVAL);
this->body = body;
this->owner = false;
}
Body :: ~Body ()
{
if (this->owner)
mu_body_destroy (&body, this);
}
bool
Body :: is_modified ()
{
return (bool) mu_body_is_modified (body);
}
void
Body :: clear_modified ()
{
int status = mu_body_clear_modified (body);
if (status)
throw Exception ("Body::clear_modified", status);
}
Stream&
Body :: get_stream ()
{
mu_stream_t c_stream;
int status = mu_body_get_stream (body, &c_stream);
if (status)
throw Exception ("Body::get_stream", status);
return *new Stream (c_stream);
}
size_t
Body :: size ()
{
size_t c_size;
int status = mu_body_size (body, &c_size);
if (status)
throw Exception ("Body::size", status);
return c_size;
}
size_t
Body :: lines ()
{
size_t c_lines;
int status = mu_body_lines (body, &c_lines);
if (status)
throw Exception ("Body::lines", status);
return c_lines;
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -41,18 +41,18 @@ FilterStream :: create (Stream& transport,
}
void
FilterStream :: iconvCreate (Stream& transport,
const std::string& fromcode,
const std::string& tocode,
int flags,
enum mu_iconv_fallback_mode fallback_mode)
FilterStream :: iconv_create (Stream& transport,
const std::string& fromcode,
const std::string& tocode,
int flags,
enum mu_iconv_fallback_mode fallback_mode)
{
int status = mu_filter_iconv_create (&this->stm, transport.stm,
fromcode.c_str (),
tocode.c_str (),
flags, fallback_mode);
if (status)
throw Exception ("FilterStream::iconvCreate", status);
throw Exception ("FilterStream::iconv_create", status);
this->input = new Stream (transport);
}
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -41,22 +41,36 @@ Header :: Header (const mu_header_t hdr)
}
std::string
Header :: getValue (const std::string& name)
Header :: get_value (const std::string& name)
{
char* c_val;
int status = mu_header_aget_value (hdr, name.c_str (), &c_val);
if (status)
throw Exception ("Header::getValue", status);
throw Exception ("Header::get_value", status);
std::string val (c_val);
free (c_val);
return val;
}
std::string
Header :: operator [] (const std::string& name)
size_t
Header :: size ()
{
size_t c_size;
int status = mu_header_size (hdr, &c_size);
if (status)
throw Exception ("Header::size", status);
return c_size;
}
size_t
Header :: lines ()
{
return this->getValue (name);
size_t c_lines;
int status = mu_header_lines (hdr, &c_lines);
if (status)
throw Exception ("Header::lines", status);
return c_lines;
}
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -51,6 +51,18 @@ Iterator :: ~Iterator ()
mu_iterator_destroy (&mu_iter);
}
bool
Iterator :: operator == (const Iterator& iter)
{
return mu_iter == iter.mu_iter;
}
bool
Iterator :: operator != (const Iterator& iter)
{
return mu_iter != iter.mu_iter;
}
void
Iterator :: first ()
{
......@@ -91,16 +103,16 @@ Iterator :: current ()
}
bool
Iterator :: isDone ()
Iterator :: is_done ()
{
return (bool) mu_iterator_is_done (mu_iter);
}
List&
Iterator :: getList ()
Iterator :: get_list ()
{
if (!pList)
throw Exception ("Iterator::getList", ENOTSUP);
throw Exception ("Iterator::get_list", ENOTSUP);
return *pList;
}
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -108,18 +108,43 @@ List :: get (size_t index)
return pitem;
}
inline void*
List :: front ()
{
return this->get (0);
}
void*
List :: operator [] (size_t index)
List :: back ()
{
size_t count = this->count ();
if (count)
return this->get (count - 1);
else
return NULL;
}
Iterator
List :: begin ()
{
return this->get (index);
mu_iterator_t mu_iter;
int status = mu_list_get_iterator (this->mu_list, &mu_iter);
if (status)
throw Exception ("Iterator::begin", status);
Iterator itr = Iterator (mu_iter);
this->iter = &itr;
this->iter->first ();
return itr;
}
void
List :: toArray (void** array, size_t count, size_t* pcount)
List :: to_array (void** array, size_t count, size_t* pcount)
{
int status = mu_list_to_array (mu_list, array, count, pcount);
if (status)
throw Exception ("List::toArray", status);
throw Exception ("List::to_array", status);
}
void
......@@ -131,7 +156,7 @@ List :: locate (void* item, void** ret_item)
}
bool
List :: isEmpty ()
List :: is_empty ()
{
return (bool) mu_list_is_empty (mu_list);
}
......@@ -148,6 +173,12 @@ List :: count ()
return count;
}
inline size_t
List :: size ()
{
return this->count ();
}
void
List :: apply (mu_list_action_t* action, void* cbdata)
{
......@@ -157,16 +188,16 @@ List :: apply (mu_list_action_t* action, void* cbdata)
}
mu_list_comparator_t
List :: setComparator (mu_list_comparator_t comp)
List :: set_comparator (mu_list_comparator_t comp)
{
return mu_list_set_comparator (mu_list, comp);
}
void
List :: setDestroyItem (void (*mu_destroy_item) (void *item))
List :: set_destroy_item (void (*mu_destroy_item) (void *item))
{
int status = mu_list_set_destroy_item (mu_list, mu_destroy_item);
if (status)
throw Exception ("List::setDestroyItem", status);
throw Exception ("List::set_destroy_item", status);
}
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -30,6 +30,14 @@ using namespace mailutils;
//
void
MailboxBase :: open ()
{
int status = mu_mailbox_open (mbox, MU_STREAM_READ);
if (status)
throw Exception ("MailboxBase::open", status);
}
void
MailboxBase :: open (int flag)
{
int status = mu_mailbox_open (mbox, flag);
......@@ -46,7 +54,7 @@ MailboxBase :: close ()
}
size_t
MailboxBase :: messagesCount ()
MailboxBase :: messages_count ()
{
size_t total;
mu_mailbox_messages_count (mbox, &total);
......@@ -54,23 +62,17 @@ MailboxBase :: messagesCount ()
}
Message&
MailboxBase :: getMessage (size_t num)
MailboxBase :: get_message (size_t num)
{
mu_message_t c_msg;
int status = mu_mailbox_get_message (mbox, num, &c_msg);
if (status)
throw Exception ("MailboxBase::getMessage", status);
throw Exception ("MailboxBase::get_message", status);
return *new Message (c_msg);
}
Message&
MailboxBase :: operator [] (size_t num)
{
return this->getMessage (num);
}
//
// Mailbox
//
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -50,23 +50,23 @@ Mailcap :: ~Mailcap ()
}
size_t
Mailcap :: getCount ()
Mailcap :: entries_count ()
{
size_t count = 0;
int status = mu_mailcap_entries_count (mailcap, &count);
if (status)
throw Exception ("Mailcap::getCount", status);
throw Exception ("Mailcap::entries_count", status);
return count;
}
MailcapEntry&
Mailcap :: getEntry (size_t i)
Mailcap :: get_entry (size_t i)
{
mu_mailcap_entry_t c_entry;
int status = mu_mailcap_get_entry (mailcap, i, &c_entry);
if (status)
throw Exception ("Mailcap::getEntry", status);
throw Exception ("Mailcap::get_entry", status);
MailcapEntry* entry = new MailcapEntry (c_entry);
return *entry;
......@@ -85,42 +85,42 @@ MailcapEntry :: MailcapEntry (mu_mailcap_entry_t entry)
}
size_t
MailcapEntry :: fieldsCount ()
MailcapEntry :: fields_count ()
{
size_t count = 0;
int status = mu_mailcap_entry_fields_count (entry, &count);
if (status)
throw Exception ("MailcapEntry::fieldsCount", status);
throw Exception ("MailcapEntry::fields_count", status);
return count;
}
std::string
MailcapEntry :: getField (size_t i)
MailcapEntry :: get_field (size_t i)
{
int status = mu_mailcap_entry_get_field (entry, i, buf,
sizeof (buf), NULL);
if (status)
throw Exception ("MailcapEntry::getField", status);
throw Exception ("MailcapEntry::get_field", status);
return std::string (buf);
}
std::string
MailcapEntry :: getTypeField ()
MailcapEntry :: get_typefield ()
{
int status = mu_mailcap_entry_get_typefield (entry, buf,
sizeof (buf), NULL);
if (status)
throw Exception ("MailcapEntry::getTypeField", status);
throw Exception ("MailcapEntry::get_typefield", status);
return std::string (buf);
}
std::string
MailcapEntry :: getViewCommand ()
MailcapEntry :: get_viewcommand ()
{
int status = mu_mailcap_entry_get_viewcommand (entry, buf,
sizeof (buf), NULL);
if (status)
throw Exception ("MailcapEntry::getViewCommand", status);
throw Exception ("MailcapEntry::get_viewcommand", status);
return std::string (buf);
}
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -64,12 +64,12 @@ Mailer :: close ()
}
void
Mailer :: sendMessage (const Message& msg, const Address& from,
const Address& to)
Mailer :: send_message (const Message& msg, const Address& from,
const Address& to)
{
int status = mu_mailer_send_message (mailer, msg.msg,
from.addr, to.addr);
if (status)
throw Exception ("Mailer::sendMessage", status);
throw Exception ("Mailer::send_message", status);
}
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -20,6 +20,8 @@
#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>
......@@ -30,7 +32,12 @@ using namespace mailutils;
//
Message :: Message ()
{
{
int status = mu_message_create (&msg, this);
if (status)
throw Exception ("Message::Message", status);
this->owner = true;
}
Message :: Message (const mu_message_t msg)
......@@ -39,17 +46,161 @@ Message :: Message (const mu_message_t msg)
throw Exception ("Message::Message", EINVAL);
this->msg = msg;
this->owner = false;
}
Message&
Message :: operator = (const Message& m)
{
if (this != &m)
{
if (this->owner)
mu_message_destroy (&this->msg, this);
int status = mu_message_create_copy (&this->msg, m.msg);
if (status)
throw Exception ("Message::operator=", status);
this->owner = true;
}
return *this;
}
Message :: ~Message ()
{
if (this->owner)
mu_message_destroy (&msg, this);
}
Header&
Message :: getHeader ()
Message :: get_header ()
{
mu_header_t c_hdr;
int status = mu_message_get_header (msg, &c_hdr);
if (status)
throw Exception ("Message::getHeader", status);
throw Exception ("Message::get_header", status);
return *new Header (c_hdr);
}
Body&
Message :: get_body ()
{
mu_body_t c_body;
int status = mu_message_get_body (msg, &c_body);
if (status)
throw Exception ("Message::get_body", status);
return *new Body (c_body);
}
Stream&
Message :: get_stream ()
{
mu_stream_t c_stream;
int status = mu_message_get_stream (msg, &c_stream);
if (status)
throw Exception ("Message::get_stream", status);
return *new Stream (c_stream);
}
bool
Message :: is_multipart ()
{
int pmulti;
int status = mu_message_is_multipart (msg, &pmulti);
if (status)
throw Exception ("Message::is_multipart", status);
return (bool) pmulti;
}
size_t
Message :: size ()
{
size_t c_size;
int status = mu_message_size (msg, &c_size);
if (status)
throw Exception ("Message::size", status);
return c_size;
}
size_t
Message :: lines ()
{
size_t c_lines;
int status = mu_message_lines (msg, &c_lines);
if (status)
throw Exception ("Message::lines", status);
return c_lines;
}
size_t
Message :: get_num_parts ()
{
size_t c_parts;
int status = mu_message_get_num_parts (msg, &c_parts);
if (status)
throw Exception ("Message::get_num_parts", status);
return c_parts;
}
Message&
Message :: get_part (const size_t npart)
{
mu_message_t c_part;
int status = mu_message_get_part (msg, npart, &c_part);
if (status)
throw Exception ("Message::get_part", status);
return *new Message (c_part);
}
void
Message :: save_attachment ()
{
int status = mu_message_save_attachment (msg, NULL, NULL);
if (status)
throw Exception ("Message::save_attachment", status);
}
void
Message :: save_attachment (const std::string& filename)
{
int status = mu_message_save_attachment (msg, filename.c_str (), NULL);
if (status)
throw Exception ("Message::save_attachment", status);
}
Message&
Message :: unencapsulate ()
{
mu_message_t c_msg;
int status = mu_message_unencapsulate (msg, &c_msg, NULL);
if (status)
throw Exception ("Message::unencapsulate", status);
return *new Message (c_msg);
}
std::string
Message :: get_attachment_name ()
{
char *c_name;
std::string name;
int status = mu_message_aget_attachment_name (msg, &c_name);
if (status)
throw Exception ("Message::get_attachment_name", status);
if (c_name) {
name = c_name;
free (c_name);
}
return name;
}
......
/*
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/mime.h>
#include <mailutils/cpp/error.h>
#include <errno.h>
using namespace mailutils;
//
// Mime
//
Mime :: Mime (const Message& msg, int flags)
{
int status = mu_mime_create (&mime, msg.msg, flags);
if (status)
throw Exception ("Mime::Mime", status);
}
Mime :: Mime (const mu_mime_t mime)
{
if (mime == 0)
throw Exception ("Mime::Mime", EINVAL);
this->mime = mime;
}
Mime :: ~Mime ()
{
mu_mime_destroy (&mime);
}
bool
Mime :: is_multipart ()
{
return (bool) mu_mime_is_multipart (mime);
}
size_t
Mime :: get_num_parts ()
{
size_t nparts;
int status = mu_mime_get_num_parts (mime, &nparts);
if (status)
throw Exception ("Mime::get_num_parts", status);
return nparts;
}
Message&
Mime :: get_part (size_t part)
{
mu_message_t c_msg;
int status = mu_mime_get_part (mime, part, &c_msg);
if (status)
throw Exception ("Mime::get_part", status);
return *new Message (c_msg);
}
void
Mime :: add_part (const Message& msg)
{
int status = mu_mime_add_part (mime, msg.msg);
if (status)
throw Exception ("Mime::add_part", status);
}
Message&
Mime :: get_message ()
{
mu_message_t c_msg;
int status = mu_mime_get_message (mime, &c_msg);
if (status)
throw Exception ("Mime::get_message", status);
return *new Message (c_msg);
}
inline int
rfc2047_decode (const char *tocode, const char *fromstr, char **ptostr)
{
return mu_rfc2047_decode (tocode, fromstr, ptostr);
}
inline int
rfc2047_encode (const char *charset, const char *encoding,
const char *text, char **result)
{
return mu_rfc2047_encode (charset, encoding, text, result);
}
/*
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 <string>
#include <mailutils/cpp/mutil.h>
using namespace mailutils;
//
// MUtil
//
int
mailutils :: set_user_email (const std::string& str)
{
return mu_set_user_email (str.c_str ());
}
int
mailutils :: set_user_email_domain (const std::string& str)
{
return mu_set_user_email_domain (str.c_str ());
}
std::string
mailutils :: tempname ()
{
std::string name;
char *c_str = mu_tempname (NULL);
if (c_str) {
name = c_str;
free (c_str);
}
return name;
}
std::string
mailutils :: tempname (const std::string& tmpdir)
{
std::string name;
char *c_str = mu_tempname (tmpdir.c_str ());
if (c_str) {
name = c_str;
free (c_str);
}
return name;
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -52,17 +52,17 @@ Pop3 :: ~Pop3 ()
}
void
Pop3 :: setCarrier (const Stream& carrier)
Pop3 :: set_carrier (const Stream& carrier)
{
int status = mu_pop3_set_carrier (pop3, carrier.stm);
if (status)
throw Exception ("Pop3::setCarrier", status);
throw Exception ("Pop3::set_carrier", status);
this->pStream = (Stream*) &carrier;
}
Stream&
Pop3 :: getCarrier ()
Pop3 :: get_carrier ()
{
return *pStream;
}
......@@ -84,26 +84,34 @@ Pop3 :: disconnect ()
}
void
Pop3 :: setTimeout (int timeout)
Pop3 :: set_timeout (int timeout)
{
int status = mu_pop3_set_timeout (pop3, timeout);
if (status)
throw Exception ("Pop3::setTimeout", status);
throw Exception ("Pop3::set_timeout", status);
}
int
Pop3 :: getTimeout ()
Pop3 :: get_timeout ()
{
int timeout;
int status = mu_pop3_get_timeout (pop3, &timeout);
if (status)
throw Exception ("Pop3::getTimeout", status);
throw Exception ("Pop3::get_timeout", status);
return timeout;
}
void
Pop3 :: apop (const char* name, const char* digest)
{
int status = mu_pop3_apop (pop3, name, digest);
if (status)
throw Exception ("Pop3::apop", status);
}
void
Pop3 :: stls ()
{
int status = mu_pop3_stls (pop3);
......@@ -144,13 +152,13 @@ Pop3 :: list (unsigned int msgno)
}
Iterator&
Pop3 :: listAll ()
Pop3 :: list_all ()
{
mu_iterator_t mu_itr;
int status = mu_pop3_list_all (pop3, &mu_itr);
if (status)
throw Exception ("Pop3::listAll", status);
throw Exception ("Pop3::list_all", status);
return *new Iterator (mu_itr);
}
......@@ -219,6 +227,35 @@ Pop3 :: top (unsigned int msgno, unsigned int lines)
return *new Stream (c_stm);
}
std::string
Pop3 :: uidl (unsigned int msgno)
{
char *c_uidl = NULL;
int status = mu_pop3_uidl (pop3, msgno, &c_uidl);
if (status)
throw Exception ("Pop3::uidl", status);
if (c_uidl) {
std::string uidl (c_uidl);
free (c_uidl);
return uidl;
}
return NULL;
}
Iterator&
Pop3 :: uidl_all ()
{
mu_iterator_t mu_itr;
int status = mu_pop3_uidl_all (pop3, &mu_itr);
if (status)
throw Exception ("Pop3::uidl_all", status);
return *new Iterator (mu_itr);
}
void
Pop3 :: user (const char* user)
{
......@@ -228,13 +265,13 @@ Pop3 :: user (const char* user)
}
size_t
Pop3 :: readLine (char* buf, size_t buflen)
Pop3 :: readline (char* buf, size_t buflen)
{
size_t nread;
int status = mu_pop3_readline (pop3, buf, buflen, &nread);
if (status)
throw Exception ("Pop3::readLine", status);
throw Exception ("Pop3::readline", status);
}
size_t
......@@ -248,11 +285,11 @@ Pop3 :: response (char* buf, size_t buflen)
}
void
Pop3 :: sendLine (const char* line)
Pop3 :: sendline (const char* line)
{
int status = mu_pop3_sendline (pop3, line);
if (status)
throw Exception ("Pop3::sendLine", status);
throw Exception ("Pop3::sendline", status);
}
void
......
/*
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 <string>
#include <mailutils/cpp/registrar.h>
#include <mailutils/cpp/error.h>
#include <errno.h>
using namespace mailutils;
//
// Registrar
//
Record :: Record (const mu_record_t record)
{
if (record == 0)
throw Exception ("Record::Record", EINVAL);
this->record = record;
}
Record :: ~Record ()
{
}
// Record Class Defaults
int
Record :: set_default_scheme (const std::string& scheme)
{
return mu_registrar_set_default_scheme (scheme.c_str ());
}
std::string
Record :: get_default_scheme ()
{
return std::string (mu_registrar_get_default_scheme ());
}
int
Record :: get_default_record (mu_record_t* prec)
{
return mu_registrar_get_default_record (prec);
}
void
Record :: set_default_record ()
{
mailutils::registrar_set_default_record (this->record);
}
// Record Class Registration
int
Record :: registrar ()
{
return mailutils::registrar_record (this->record);
}
int
Record :: unregistrar ()
{
return mailutils::unregistrar_record (this->record);
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 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
......@@ -86,7 +86,7 @@ Stream :: close ()
}
void
Stream :: setWaitFlags (int flags)
Stream :: set_waitflags (int flags)
{
this->wflags = flags;
}
......@@ -108,50 +108,54 @@ Stream :: wait (int flags)
throw Exception ("Stream::wait", status);
}
void
int
Stream :: read (char* rbuf, size_t size, off_t offset)
{
int status = mu_stream_read (stm, rbuf, size, offset, &readn);
int status = mu_stream_read (stm, rbuf, size, offset, &read_count);
if (status == EAGAIN)
throw Stream::EAgain ("Stream::read", status);
else if (status)
throw Exception ("Stream::read", status);
return status;
}
void
int
Stream :: write (const std::string& wbuf, size_t size, off_t offset)
{
int status = mu_stream_write (stm, wbuf.c_str (), size, offset, &writen);
int status = mu_stream_write (stm, wbuf.c_str (), size, offset,
&write_count);
if (status == EAGAIN)
throw Stream::EAgain ("Stream::write", status);
else if (status)
throw Exception ("Stream::write", status);
return status;
}
void
Stream :: readLine (char* rbuf, size_t size, off_t offset)
int
Stream :: readline (char* rbuf, size_t size, off_t offset)
{
int status = mu_stream_readline (stm, rbuf, size, offset, &readn);
int status = mu_stream_readline (stm, rbuf, size, offset, &read_count);
if (status == EAGAIN)
throw Stream::EAgain ("Stream::readLine", status);
throw Stream::EAgain ("Stream::readline", status);
else if (status)
throw Exception ("Stream::readLine", status);
throw Exception ("Stream::readline", status);
return status;
}
void
Stream :: sequentialReadLine (char* rbuf, size_t size)
Stream :: sequential_readline (char* rbuf, size_t size)
{
int status = mu_stream_sequential_readline (stm, rbuf, size, &readn);
int status = mu_stream_sequential_readline (stm, rbuf, size, &read_count);
if (status)
throw Exception ("Stream::sequentialReadLine", status);
throw Exception ("Stream::sequential_readline", status);
}
void
Stream :: sequentialWrite (const std::string& wbuf, size_t size)
Stream :: sequential_write (const std::string& wbuf, size_t size)
{
int status = mu_stream_sequential_write (stm, wbuf.c_str (), size);
if (status)
throw Exception ("Stream::sequentialWrite", status);
throw Exception ("Stream::sequential_write", status);
}
void
......
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006, 2007, 2008 Free Software Foundation, Inc.
Copyright (C) 2004, 2006, 2007, 2008, 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
......@@ -64,90 +64,90 @@ Url :: parse ()
}
long
Url :: getPort ()
Url :: get_port ()
{
long port;
int status = mu_url_get_port (url, &port);
if (status)
throw Exception ("Url::getPort", status);
throw Exception ("Url::get_port", status);
return port;
}
std::string
Url :: getScheme ()
Url :: get_scheme ()
{
int status = mu_url_get_scheme (url, buf, sizeof (buf), NULL);
if (status == MU_ERR_NOENT)
return "";
else if (status)
throw Exception ("Url::getScheme", status);
throw Exception ("Url::get_scheme", status);
return std::string (buf);
}
std::string
Url :: getUser ()
Url :: get_user ()
{
int status = mu_url_get_user (url, buf, sizeof (buf), NULL);
if (status == MU_ERR_NOENT)
return "";
else if (status)
throw Exception ("Url::getUser", status);
throw Exception ("Url::get_user", status);
return std::string (buf);
}
std::string
Url :: getPasswd ()
Url :: get_passwd ()
{
int status = mu_url_get_passwd (url, buf, sizeof (buf), NULL);
if (status == MU_ERR_NOENT)
return "";
else if (status)
throw Exception ("Url::getPasswd", status);
throw Exception ("Url::get_passwd", status);
return std::string (buf);
}
std::string
Url :: getAuth ()
Url :: get_auth ()
{
int status = mu_url_get_auth (url, buf, sizeof (buf), NULL);
if (status == MU_ERR_NOENT)
return "";
else if (status)
throw Exception ("Url::getAuth", status);
throw Exception ("Url::get_auth", status);
return std::string (buf);
}
std::string
Url :: getHost ()
Url :: get_host ()
{
int status = mu_url_get_host (url, buf, sizeof (buf), NULL);
if (status == MU_ERR_NOENT)
return "";
else if (status)
throw Exception ("Url::getHost", status);
throw Exception ("Url::get_host", status);
return std::string (buf);
}
std::string
Url :: getPath ()
Url :: get_path ()
{
int status = mu_url_get_path (url, buf, sizeof (buf), NULL);
if (status == MU_ERR_NOENT)
return "";
else if (status)
throw Exception ("Url::getPath", status);
throw Exception ("Url::get_path", status);
return std::string (buf);
}
std::vector<std::string>
Url :: getQuery ()
Url :: get_query ()
{
size_t argc;
char **argv;
int status = mu_url_sget_query (url, &argc, &argv);
if (status)
throw Exception ("Url::getQuery", status);
throw Exception ("Url::get_query", status);
std::vector<std::string> params;
......