diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2008-10-28 13:24:48 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2008-10-28 13:24:48 +0000 |
commit | 01dabb5cb4cc1d4c849432dd45967ddfc27ab015 (patch) | |
tree | 0c099737380712c102de1099e874b8ae7d394e22 | |
parent | f3106927f5ae62e96f31419f99f1a9e3bdad5c81 (diff) | |
download | mailutils-01dabb5cb4cc1d4c849432dd45967ddfc27ab015.tar.gz mailutils-01dabb5cb4cc1d4c849432dd45967ddfc27ab015.tar.bz2 |
Change mailer creation mechanism.
* include/mailutils/mailer.h (mu_mailer_create_from_url): New
proto.
* mailbox/mailer.c (mu_mailer_create_from_url): New
function.
(mu_mailer_create): Rewrite using mu_mailer_create_from_url.
* libproto/mailer/prog.c (_url_prog_init): Do not call
mu_url_init.
(url_to_argv): Reflect changes to mu_url functions.
* libproto/mailer/url_sendmail.c (_url_sendmail_init): Do not call
mu_url_init.
* libproto/mailer/url_smtp.c (_url_smtp_init): Likewise.
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | include/mailutils/mailer.h | 4 | ||||
-rw-r--r-- | libproto/mailer/prog.c | 68 | ||||
-rw-r--r-- | libproto/mailer/url_sendmail.c | 19 | ||||
-rw-r--r-- | libproto/mailer/url_smtp.c | 9 | ||||
-rw-r--r-- | mailbox/mailer.c | 60 |
6 files changed, 103 insertions, 71 deletions
@@ -1,5 +1,19 @@ 2008-10-28 Sergey Poznyakoff <gray@gnu.org.ua> + Change mailer creation mechanism. + + * include/mailutils/mailer.h (mu_mailer_create_from_url): New + proto. + * mailbox/mailer.c (mu_mailer_create_from_url): New + function. + (mu_mailer_create): Rewrite using mu_mailer_create_from_url. + * libproto/mailer/prog.c (_url_prog_init): Do not call + mu_url_init. + (url_to_argv): Reflect changes to mu_url functions. + * libproto/mailer/url_sendmail.c (_url_sendmail_init): Do not call + mu_url_init. + * libproto/mailer/url_smtp.c (_url_smtp_init): Likewise. + Minor fixes. * mailbox/mailbox.c (_create_mailbox0): Take care not to destroy diff --git a/include/mailutils/mailer.h b/include/mailutils/mailer.h index da4a6518f..4fb4277d2 100644 --- a/include/mailutils/mailer.h +++ b/include/mailutils/mailer.h @@ -1,6 +1,6 @@ /* GNU Mailutils -- a suite of utilities for electronic mail Copyright (C) 1999, 2000, 2001, 2005, - 2007 Free Software Foundation, Inc. + 2007, 2008 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 @@ -31,6 +31,8 @@ extern "C" { /* A url of NULL will cause the default to be used. */ extern int mu_mailer_create (mu_mailer_t *, const char *url); +extern int mu_mailer_create_from_url (mu_mailer_t *pmailer, mu_url_t url); + extern void mu_mailer_destroy (mu_mailer_t *); extern int mu_mailer_open (mu_mailer_t, int flags); extern int mu_mailer_close (mu_mailer_t); diff --git a/libproto/mailer/prog.c b/libproto/mailer/prog.c index 5d56ed206..7d6666e0f 100644 --- a/libproto/mailer/prog.c +++ b/libproto/mailer/prog.c @@ -39,7 +39,6 @@ #include <registrar0.h> static int _url_prog_init (mu_url_t); -static int _url_pipe_init (mu_url_t); static int _mailer_prog_init (mu_mailer_t); static struct _mu_record _prog_record = @@ -64,11 +63,8 @@ mu_record_t mu_prog_record = &_prog_record; static int _url_prog_init (mu_url_t url) { - int status = mu_url_init (url, 0, "prog"); - if (status) - return status; - /* not valid in a sendmail url */ - if (url->user || url->passwd || url->auth || url->host || url->port) + /* not valid in a prog url */ + if (url->passwd || url->auth || url->host || url->port) return EINVAL; if (!url->path) return EINVAL; @@ -283,11 +279,11 @@ url_to_argv (mu_url_t url, mu_message_t msg, int rc; mu_vartab_t vtab; struct ex_rcpt ex_rcpt; - const char *query; - char *cmdargs; - int argc; + char **query; + size_t i; + size_t argc; char **argv; - + ex_rcpt.msg = msg; ex_rcpt.addr = to; ex_rcpt.string = NULL; @@ -295,26 +291,28 @@ url_to_argv (mu_url_t url, mu_message_t msg, mu_vartab_define_exp (vtab, "sender", _expand_sender, NULL, from); mu_vartab_define_exp (vtab, "rcpt", _expand_rcpt, _free_rcpt, &ex_rcpt); - rc = mu_url_sget_query (url, &query); + rc = mu_url_sget_query (url, &argc, &query); if (rc) return rc; + + argv = calloc (argc + 1, sizeof (argv[0])); + if (!argv) + return ENOMEM; + + for (i = 0; i < argc; i++) + { + if ((rc = mu_vartab_expand (vtab, query[i], &argv[i]))) + { + mu_argcv_free (i, argv); + mu_vartab_destroy (&vtab); + return rc; + } + } + argv[i] = NULL; - rc = mu_vartab_expand (vtab, query, &cmdargs); mu_vartab_destroy (&vtab); - if (rc) - return rc; - - rc = mu_argcv_get_np (cmdargs, strlen (cmdargs), - "&", NULL, - 0, &argc, &argv, NULL); - free (cmdargs); - if (rc) - return rc; - argv = realloc (argv, (argc + 2) * sizeof (argv[0])); - memmove (argv + 1, argv, (argc + 1) * sizeof (argv[0])); - mu_url_aget_path (url, &argv[0]); - *pargc = argc + 1; + *pargc = argc; *pargv = argv; return 0; } @@ -327,8 +325,26 @@ prog_send_message (mu_mailer_t mailer, mu_message_t msg, mu_address_t from, int argc; char **argv; int status; + const char *command; - status = url_to_argv(mailer->url, msg, from, to, &argc, &argv); + status = mu_url_sget_path (mailer->url, &command); + if (status && status != MU_ERR_NOENT) + { + MU_DEBUG1 (mailer->debug, MU_DEBUG_ERROR, + "cannot get path from URL: %s\n", + mu_strerror (status)); + return status; + } + status = mu_progmailer_set_command (pm, command); + if (status) + { + MU_DEBUG1 (mailer->debug, MU_DEBUG_ERROR, + "cannot set progmailer command: %s\n", + mu_strerror (status)); + return status; + } + + status = url_to_argv (mailer->url, msg, from, to, &argc, &argv); if (status) { MU_DEBUG1 (mailer->debug, MU_DEBUG_ERROR, diff --git a/libproto/mailer/url_sendmail.c b/libproto/mailer/url_sendmail.c index db7a277bf..8ad8e70ba 100644 --- a/libproto/mailer/url_sendmail.c +++ b/libproto/mailer/url_sendmail.c @@ -37,13 +37,6 @@ #include <registrar0.h> #include <url0.h> -static void url_sendmail_destroy (mu_url_t purl); - -static void -url_sendmail_destroy (mu_url_t url MU_ARG_UNUSED) -{ -} - /* Sendmail URL: sendmail:/path/to/sendmail @@ -52,22 +45,16 @@ url_sendmail_destroy (mu_url_t url MU_ARG_UNUSED) int _url_sendmail_init (mu_url_t url) { - int status = mu_url_init (url, 0, "sendmail"); - if (status) - return status; - - url->_destroy = url_sendmail_destroy; - /* not valid in a sendmail url */ - if (url->user || url->passwd || url->auth || url->query + if (url->user || url->passwd || url->auth || url->qargc || url->host || url->port) return EINVAL; if (url->path == 0) if ((url->path = strdup (_PATH_SENDMAIL)) == 0) - status = ENOMEM; + return ENOMEM; - return status; + return 0; } #endif /* ENABLE_SENDMAIL */ diff --git a/libproto/mailer/url_smtp.c b/libproto/mailer/url_smtp.c index df2959e04..13eb4361a 100644 --- a/libproto/mailer/url_smtp.c +++ b/libproto/mailer/url_smtp.c @@ -32,10 +32,6 @@ int _url_smtp_init (mu_url_t url) { - int status = mu_url_init (url, MU_SMTP_PORT, "smtp"); - if (status) - return status; - /* host isn't optional */ if (!url->host) return EINVAL; @@ -44,9 +40,12 @@ _url_smtp_init (mu_url_t url) for the ESMTP authentication */ /* all other fields must be NULL */ - if (url->path || url->query) + if (url->path || url->qargc) return EINVAL; + if (url->port == 0) + url->port = MU_SMTP_PORT; + return 0; } diff --git a/mailbox/mailer.c b/mailbox/mailer.c index 0b61f0369..59aed1e2e 100644 --- a/mailbox/mailer.c +++ b/mailbox/mailer.c @@ -89,28 +89,21 @@ mu_mailer_get_url_default (const char **url) } int -mu_mailer_create (mu_mailer_t * pmailer, const char *name) +mu_mailer_create_from_url (mu_mailer_t *pmailer, mu_url_t url) { mu_record_t record; - if (pmailer == NULL) - return MU_ERR_OUT_PTR_NULL; - - if (name == NULL) - mu_mailer_get_url_default (&name); - - if (mu_registrar_lookup (name, MU_FOLDER_ATTRIBUTE_FILE, &record, NULL) == 0) + if (mu_registrar_lookup_url (url, MU_FOLDER_ATTRIBUTE_FILE, &record, + NULL) == 0) { int (*m_init) (mu_mailer_t) = NULL; - int (*u_init) (mu_url_t) = NULL; mu_record_get_mailer (record, &m_init); - mu_record_get_url (record, &u_init); - if (m_init && u_init) + if (m_init) { int status; - mu_url_t url; mu_mailer_t mailer; + int (*u_init) (mu_url_t) = NULL; /* Allocate memory for mailer. */ mailer = calloc (1, sizeof (*mailer)); @@ -124,29 +117,50 @@ mu_mailer_create (mu_mailer_t * pmailer, const char *name) return status; } - /* Parse the url, it may be a bad one and we should bail out if this - failed. */ - if ((status = mu_url_create (&url, name)) != 0 - || (status = u_init (url)) != 0) + status = m_init (mailer); + if (status) { mu_mailer_destroy (&mailer); return status; } - mailer->url = url; - status = m_init (mailer); - if (status) - mu_mailer_destroy (&mailer); - else - *pmailer = mailer; + mu_record_get_url (record, &u_init); + if (u_init && (status = u_init (url)) != 0) + { + mu_mailer_destroy (&mailer); + return status; + } + + mailer->url = url; + *pmailer = mailer; return status; } } - + return MU_ERR_MAILER_BAD_URL; } +int +mu_mailer_create (mu_mailer_t * pmailer, const char *name) +{ + int status; + mu_url_t url; + + if (name == NULL) + mu_mailer_get_url_default (&name); + + status = mu_url_create (&url, name); + if (status) + return status; + status = mu_url_parse (url); + if (status == 0) + status = mu_mailer_create_from_url (pmailer, url); + if (status) + mu_url_destroy (&url); + return status; +} + void mu_mailer_destroy (mu_mailer_t * pmailer) { |