summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/msg-send.c164
-rw-r--r--examples/muemail.c19
-rw-r--r--examples/url-parse.c44
3 files changed, 140 insertions, 87 deletions
diff --git a/examples/msg-send.c b/examples/msg-send.c
index b7f52e5d4..92f3e0fe1 100644
--- a/examples/msg-send.c
+++ b/examples/msg-send.c
@@ -1,3 +1,20 @@
+/* GNU mailutils - a suite of utilities for electronic mail
+ Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
+
+ This program 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 2, or (at your option)
+ any later version.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
#include <sys/types.h>
#include <sys/stat.h>
@@ -16,100 +33,103 @@
#include <mailutils/registrar.h>
#include <mailutils/stream.h>
-#define C(X) {int e; if((e = X) != 0) { \
- fprintf(stderr, "%s failed: %s\n", #X, mu_errstring(e)); \
- exit(1); } }
+#define C(X) do {\
+ int e;\
+ if((e = X) != 0) { \
+ fprintf(stderr, "%s failed: %s\n", #X, mu_errstring(e)); \
+ exit(1);\
+ }\
+} while (0)
const char USAGE[] =
- "usage: mailer [-hd] [-m mailer] [-f from] [to]..."
- ;
+"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"
- ;
+" -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;
-
- stream_t in = 0;
- message_t msg = 0;
- mailer_t mailer = 0;
- address_t from = 0;
- address_t to = 0;
-
- while((opt = getopt(argc, argv, "hdm:f:")) != -1)
- {
- switch(opt)
+ int opt;
+ int optdebug = 0;
+ char *optmailer = "sendmail:";
+ char *optfrom = 0;
+
+ stream_t in = 0;
+ message_t msg = 0;
+ mailer_t mailer = 0;
+ address_t from = 0;
+ address_t to = 0;
+
+ while ((opt = getopt (argc, argv, "hdm:f:")) != -1)
{
- case 'h':
- printf("%s\n%s", USAGE, HELP);
- return 0;
- case 'd':
- optdebug++;
- break;
- case 'm':
- optmailer = optarg;
- break;
- case 'f':
- optfrom = optarg;
- break;
- default:
- fprintf(stderr, "%s\n", USAGE);
- break;
+ switch (opt)
+ {
+ case 'h':
+ printf ("%s\n%s", USAGE, HELP);
+ return 0;
+
+ case 'd':
+ optdebug++;
+ break;
+
+ case 'm':
+ optmailer = optarg;
+ break;
+
+ case 'f':
+ optfrom = optarg;
+ break;
+
+ default:
+ fprintf (stderr, "%s\n", USAGE);
+ exit (1);
+ }
}
- }
/* Register mailers. */
{
list_t bookie;
registrar_get_list (&bookie);
- C( list_append (bookie, smtp_record) )
- C( list_append (bookie, sendmail_record) )
+ list_append (bookie, smtp_record);
+ list_append (bookie, sendmail_record);
}
- if(optfrom)
- {
- C( address_create(&from, optfrom) )
- }
-
- if(argv[optind])
- {
- char** av = argv + optind;
-
- C( address_createv(&to, (const char**) av, -1) )
- }
-
- C( stdio_stream_create(&in, stdin, 0) )
-
- C( stream_open(in) )
+ if (optfrom)
+ {
+ C (address_create (&from, optfrom));
+ }
- C( message_create (&msg, NULL) )
+ if (argv[optind])
+ {
+ char **av = argv + optind;
- C( message_set_stream(msg, in, NULL) )
+ C (address_createv (&to, (const char **) av, -1));
+ }
- C( mailer_create(&mailer, optmailer) )
+ C (stdio_stream_create (&in, stdin, 0));
+ C (stream_open (in));
+ C (message_create (&msg, NULL));
+ C (message_set_stream (msg, in, NULL));
+ C (mailer_create (&mailer, optmailer));
- if(optdebug)
- {
- mu_debug_t debug;
- mailer_get_debug (mailer, &debug);
- mu_debug_set_level (debug, MU_DEBUG_TRACE | MU_DEBUG_PROT);
- }
+ if (optdebug)
+ {
+ mu_debug_t debug;
+ mailer_get_debug (mailer, &debug);
+ mu_debug_set_level (debug, MU_DEBUG_TRACE | MU_DEBUG_PROT);
+ }
- C( mailer_open(mailer, 0) )
+ C (mailer_open (mailer, 0));
- C( mailer_send_message(mailer, msg, from, to) )
+ C (mailer_send_message (mailer, msg, from, to));
return 0;
}
-
diff --git a/examples/muemail.c b/examples/muemail.c
index 275c9b2ce..8e1bf2fb9 100644
--- a/examples/muemail.c
+++ b/examples/muemail.c
@@ -1,5 +1,22 @@
+/* GNU mailutils - a suite of utilities for electronic mail
+ Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
+
+ This program 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 2, or (at your option)
+ any later version.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
#include <mailutils/mutil.h>
-#include "mu_argp.h"
+#include <mailutils/argp.h>
#include <stdio.h>
diff --git a/examples/url-parse.c b/examples/url-parse.c
index b4cf01ba9..7c6b1c856 100644
--- a/examples/url-parse.c
+++ b/examples/url-parse.c
@@ -1,7 +1,24 @@
-#include <mailutils/errno.h>
-#include <mailutils/url.h>
+/* GNU mailutils - a suite of utilities for electronic mail
+ Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
+
+ This program 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 2, or (at your option)
+ any later version.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
#include <stdio.h>
#include <string.h>
+#include <mailutils/errno.h>
+#include <mailutils/url.h>
int
main ()
@@ -17,21 +34,21 @@ main ()
int rc;
str[strlen (str) - 1] = '\0'; /* chop newline */
- if(strspn(str, " \t") == strlen(str))
- continue; /* skip empty lines */
- if ((rc = url_create(&u, str)) != 0)
- {
- fprintf(stderr, "url_create %s ERROR: [%d] %s",
- str, rc, mu_errstring(rc));
- exit (1);
- }
+ if (strspn (str, " \t") == strlen (str))
+ continue; /* skip empty lines */
+ if ((rc = url_create (&u, str)) != 0)
+ {
+ fprintf (stderr, "url_create %s ERROR: [%d] %s",
+ str, rc, mu_errstring (rc));
+ exit (1);
+ }
if ((rc = url_parse (u)) != 0)
{
- printf ("%s --> FAILED: [%d] %s\n",
- str, rc, mu_errstring(rc));
+ printf ("%s => FAILED: [%d] %s\n",
+ str, rc, mu_errstring (rc));
continue;
}
- printf ("%s --> SUCCESS\n", str);
+ printf ("%s => SUCCESS\n", str);
url_get_scheme (u, buffer, len, NULL);
printf (" scheme <%s>\n", buffer);
@@ -62,4 +79,3 @@ main ()
}
return 0;
}
-

Return to:

Send suggestions and report system problems to the System administrator.