summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorWojciech Polak <polak@gnu.org>2009-01-30 10:42:08 +0100
committerWojciech Polak <polak@gnu.org>2009-01-30 20:43:44 +0100
commitb2a91252acdd910a3ac5e866c0ecc578d86c4f94 (patch)
treeedc2d26dee289c2e4b575e102cb5aad3b8d49877 /examples
parent24d5aa4cbd4b2aec73dc9b275e8bc172973ed234 (diff)
downloadmailutils-b2a91252acdd910a3ac5e866c0ecc578d86c4f94.tar.gz
mailutils-b2a91252acdd910a3ac5e866c0ecc578d86c4f94.tar.bz2
Add Folder class to libmu_cpp. Provide new examples lsf.cc and msg-send.cc.
* examples/cpp/lsf.cc, examples/cpp/msg-send.cc, include/mailutils/cpp/folder.h, libmu_cpp/folder.cc: New files.
Diffstat (limited to 'examples')
-rw-r--r--examples/cpp/Makefile.am5
-rw-r--r--examples/cpp/lsf.cc91
-rw-r--r--examples/cpp/msg-send.cc113
3 files changed, 209 insertions, 0 deletions
diff --git a/examples/cpp/Makefile.am b/examples/cpp/Makefile.am
index 79ac8d724..c7395e1d6 100644
--- a/examples/cpp/Makefile.am
+++ b/examples/cpp/Makefile.am
@@ -22,8 +22,10 @@ CXX_EXAMPLES = \
http\
iconv\
listop\
+ lsf\
mailcap\
mimetest\
+ msg-send\
murun\
sfrom\
url-parse
@@ -43,8 +45,10 @@ addr_SOURCES = addr.cc
http_SOURCES = http.cc
iconv_SOURCES = iconv.cc
listop_SOURCES = listop.cc
+lsf_SOURCES = lsf.cc
mailcap_SOURCES = mailcap.cc
mimetest_SOURCES = mimetest.cc
+msg_send_SOURCES = msg-send.cc
murun_SOURCES = murun.cc
sfrom_SOURCES = sfrom.cc
url_parse_SOURCES = url-parse.cc
@@ -59,5 +63,6 @@ LDADD =\
${MU_LIB_MH}\
${MU_LIB_MAILDIR}\
${MU_LIB_AUTH}\
+ ${MU_LIB_MAILER}\
@MU_AUTHLIBS@\
${MU_LIB_MAILUTILS}
diff --git a/examples/cpp/lsf.cc b/examples/cpp/lsf.cc
new file mode 100644
index 000000000..4dff682a2
--- /dev/null
+++ b/examples/cpp/lsf.cc
@@ -0,0 +1,91 @@
+/* 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 <mailutils/cpp/mailutils.h>
+
+using namespace std;
+using namespace mailutils;
+
+static int
+enumfun (mu_folder_t folder, struct mu_list_response *resp, void *data)
+{
+ printf ("%c%c %c %4d %s\n",
+ (resp->type & MU_FOLDER_ATTRIBUTE_DIRECTORY) ? 'd' : '-',
+ (resp->type & MU_FOLDER_ATTRIBUTE_FILE) ? 'f' : '-',
+ resp->separator,
+ resp->level,
+ resp->name);
+ return 0;
+}
+
+int
+ls_folders (const string& fname, const string& ref, void* pattern, int level)
+{
+ try {
+ Folder folder (fname);
+ folder.open ();
+
+ List list = folder.enumerate (ref, pattern, 0, level, enumfun, NULL);
+ cout << "Number of folders: " << list.count () << endl;
+
+ folder.close ();
+ }
+ catch (Exception& e)
+ {
+ if (e.status () == MU_ERR_NOENT) {
+ cout << "No folders matching " << ref << " " << pattern
+ << " in " << fname << endl;
+ }
+ else {
+ cerr << e.method () << ": " << e.what () << endl;
+ return 1;
+ }
+ }
+ return 0;
+}
+
+int
+main (int argc, char *argv[])
+{
+ string folder;
+ string ref;
+ char *pattern = "*";
+ int level = 0;
+
+ switch (argc)
+ {
+ case 5:
+ level = atoi (argv[4]);
+ case 4:
+ pattern = argv[3];
+ case 3:
+ ref = argv[2];
+ case 2:
+ folder = argv[1];
+ break;
+ default:
+ error ("usage: lsf folder [ref] [pattern] [recursion-level]\n");
+ return 1;
+ }
+
+ register_all_mbox_formats ();
+
+ return ls_folders (folder, ref, pattern, level);
+}
+
diff --git a/examples/cpp/msg-send.cc b/examples/cpp/msg-send.cc
new file mode 100644
index 000000000..0d5a11329
--- /dev/null
+++ b/examples/cpp/msg-send.cc
@@ -0,0 +1,113 @@
+/* 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 <mailutils/cpp/mailutils.h>
+
+using namespace std;
+using namespace mailutils;
+
+const char USAGE[] =
+"usage: mailer [-hd] [-m mailer] [-f from] [to]..."
+ ;
+const char HELP[] =
+" -h print this helpful message\n"
+" -m a mailer URL (default is \"sendmail:\")\n"
+" -f the envelope from address (default is from user environment)\n"
+" to a list of envelope to addresses (default is from message)\n"
+"\n"
+"An RFC2822 formatted message is read from stdin and delivered using\n"
+"the mailer.\n"
+ ;
+
+int
+main (int argc, char *argv[])
+{
+ int opt;
+ int optdebug = 0;
+ char *optmailer = "sendmail:";
+ char *optfrom = 0;
+
+ while ((opt = getopt (argc, argv, "hdm:f:")) != -1)
+ {
+ switch (opt)
+ {
+ case 'h':
+ cout << USAGE << endl << HELP;
+ return 0;
+
+ case 'd':
+ optdebug++;
+ break;
+
+ case 'm':
+ optmailer = optarg;
+ break;
+
+ case 'f':
+ optfrom = optarg;
+ break;
+
+ default:
+ cerr << USAGE << endl;
+ exit (1);
+ }
+ }
+
+ /* Register mailers. */
+ register_all_mailer_formats ();
+
+ Address from;
+ Address to;
+
+ if (optfrom)
+ {
+ from = Address (optfrom);
+ }
+
+ if (argv[optind])
+ {
+ char **av = argv + optind;
+ to = Address ((const char **) av, -1);
+ }
+
+ try {
+ StdioStream in (stdin, MU_STREAM_SEEKABLE);
+ in.open ();
+
+ Message msg;
+ msg.set_stream (in);
+
+ Mailer mailer (optmailer);
+ if (optdebug)
+ {
+ Debug debug = mailer.get_debug ();
+ debug.set_level (MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT));
+ }
+ mailer.open ();
+ mailer.send_message (msg, from, to);
+ mailer.close ();
+ }
+ catch (Exception& e) {
+ cerr << e.method () << ": " << e.what () << endl;
+ exit (1);
+ }
+
+ return 0;
+}
+

Return to:

Send suggestions and report system problems to the System administrator.