Commit 026e47c0 026e47c0ad9a02c51f0afb56c2a04ae308efbea6 by Sam Roberts

mailer_check_to(): ensures that there all the to addresses are

qualified.
mailer_check_from(): ensures that there is only one address, and it
is qualified.
1 parent 15f1743e
......@@ -24,26 +24,29 @@
extern "C" {
#endif
extern int mailer_create __P ((mailer_t *, const char *));
extern void mailer_destroy __P ((mailer_t *));
extern int mailer_open __P ((mailer_t, int flags));
extern int mailer_close __P ((mailer_t));
extern int mailer_send_message __P ((mailer_t, message_t, address_t from, address_t to));
extern int mailer_get_property __P ((mailer_t, property_t *));
/* stream settings */
extern int mailer_get_stream __P ((mailer_t, stream_t *));
extern int mailer_set_stream __P ((mailer_t, stream_t));
/* stream settings */
extern int mailer_get_debug __P ((mailer_t, mu_debug_t *));
extern int mailer_set_debug __P ((mailer_t, mu_debug_t));
extern int mailer_create __P ((mailer_t *, const char *));
extern void mailer_destroy __P ((mailer_t *));
extern int mailer_open __P ((mailer_t, int flags));
extern int mailer_close __P ((mailer_t));
extern int mailer_send_message __P ((mailer_t, message_t, address_t from, address_t to));
/* Accessor functions. */
extern int mailer_get_property __P ((mailer_t, property_t *));
extern int mailer_get_stream __P ((mailer_t, stream_t *));
extern int mailer_set_stream __P ((mailer_t, stream_t));
extern int mailer_get_debug __P ((mailer_t, mu_debug_t *));
extern int mailer_set_debug __P ((mailer_t, mu_debug_t));
extern int mailer_get_observable __P ((mailer_t, observable_t *));
extern int mailer_get_url __P ((mailer_t, url_t *));
/* Utility functions, primarily for use of implementing concrete mailers. */
extern int mailer_get_url __P ((mailer_t, url_t *));
/* A valid from address_t contains a single address that has a qualified
email address. */
extern int mailer_check_from __P((address_t from));
/* A valid to address_t contains 1 or more addresses, that are
qualified email addresses. */
extern int mailer_check_to __P((address_t to));
#ifdef __cplusplus
}
......
......@@ -27,6 +27,7 @@
#include <mailutils/address.h>
#include <mailutils/debug.h>
#include <mailutils/errno.h>
#include <mailutils/iterator.h>
#include <mailutils/observer.h>
#include <mailutils/property.h>
......@@ -174,34 +175,75 @@ mailer_close (mailer_t mailer)
return mailer->_close (mailer);
}
/* messages */
int
mailer_check_from(address_t from)
{
size_t n = 0;
if(!from)
return EINVAL;
if(address_get_count(from, &n) || n != 1)
return MU_ERR_MAILER_BAD_FROM;
if(address_get_email_count(from, &n) || n == 0)
return MU_ERR_MAILER_BAD_FROM;
return 0;
}
int
mailer_check_to(address_t to)
{
size_t count = 0;
size_t emails = 0;
size_t groups = 0;
if(!to)
return EINVAL;
if(address_get_count(to, &count))
return MU_ERR_MAILER_BAD_TO;
if(address_get_email_count(to, &emails))
return MU_ERR_MAILER_BAD_TO;
if(emails == 0)
return MU_ERR_MAILER_NO_RCPT_TO;
if(address_get_group_count(to, &groups))
return MU_ERR_MAILER_BAD_TO;
if(count - emails - groups != 0)
/* then not everything is a group or an email address */
return MU_ERR_MAILER_BAD_TO;
return 0;
}
int
mailer_send_message (mailer_t mailer, message_t msg, address_t from, address_t to)
{
int status;
size_t count = 0;
if (mailer == NULL || mailer->_send_message == NULL)
return ENOSYS;
/* Common API checking. */
/* FIXME: this should be done in the concrete APIs, sendmail doesn't
yet, though, so do it here. */
if (from)
{
if ((status = address_get_email_count (from, &count)) != 0)
if ((status = mailer_check_from (from)) != 0)
return status;
if (count != 1)
return EINVAL;
}
if (to)
{
if ((status = address_get_email_count (to, &count)) != 0)
if ((status = mailer_check_to (to)) != 0)
return status;
if (count < 1)
return EINVAL;
}
return mailer->_send_message (mailer, msg, from, to);
......