summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
m---------grecs0
-rw-r--r--modules/mailutils/mod_mailutils.c33
2 files changed, 19 insertions, 14 deletions
diff --git a/grecs b/grecs
-Subproject 893d875a4065acb757fef55876c391b1dd07004
+Subproject b47bfb2cc836d3961bd0b8a4748e5dbb42e3727
diff --git a/modules/mailutils/mod_mailutils.c b/modules/mailutils/mod_mailutils.c
index ca27a8e..34d5127 100644
--- a/modules/mailutils/mod_mailutils.c
+++ b/modules/mailutils/mod_mailutils.c
@@ -27,9 +27,7 @@
#define WY_MODULE mod_mailutils
-static mu_mailer_t mailer;
-static pthread_mutex_t mailer_mutex = PTHREAD_MUTEX_INITIALIZER;
-
+static char *mailer_url;
static mu_address_t admin_address;
static mu_address_t from_address;
unsigned long mail_admin_mask;
@@ -318,6 +316,7 @@ static void
mail_send_message(mu_address_t rcpt, const char *text, const char *signer_key)
{
int rc;
+ mu_mailer_t mailer;
mu_message_t msg;
mu_stream_t stream = NULL;
mu_header_t hdr;
@@ -356,7 +355,12 @@ mail_send_message(mu_address_t rcpt, const char *text, const char *signer_key)
mu_debug_set_category_level(MU_DEBCAT_MAILER, level);
}
- pthread_mutex_lock(&mailer_mutex);
+ rc = mu_mailer_create(&mailer, mailer_url);
+ if (rc) {
+ wy_log(LOG_CRIT, _("cannot create mailer `%s': %s"),
+ mailer_url,
+ mu_strerror(rc));
+ } else {
if ((rc = mu_mailer_open(mailer, 0))) {
mu_url_t url = NULL;
mu_mailer_get_url(mailer, &url);
@@ -370,12 +374,14 @@ mail_send_message(mu_address_t rcpt, const char *text, const char *signer_key)
if (!wy_dry_run) {
rc = mu_mailer_send_message(mailer, msg, from_address, rcpt);
if (rc)
- wy_log(LOG_CRIT, _("cannot send message: %s"), mu_strerror(rc));
+ wy_log(LOG_CRIT, _("cannot send message: %s"),
+ mu_strerror(rc));
}
mu_mailer_close(mailer);
}
- pthread_mutex_unlock(&mailer_mutex);
+ mu_mailer_destroy(&mailer);
+ }
mu_message_destroy(&msg, mu_message_get_owner(msg));
}
@@ -387,6 +393,7 @@ cb_mailer(enum grecs_callback_command cmd, grecs_node_t *node,
int rc;
grecs_locus_t *locus = &node->locus;
grecs_value_t *value = node->v.value;
+ mu_mailer_t mailer;
if (wy_assert_string_arg(locus, cmd, value))
return 1;
@@ -396,6 +403,10 @@ cb_mailer(enum grecs_callback_command cmd, grecs_node_t *node,
_("cannot create mailer `%s': %s"),
value->v.string,
mu_strerror(rc));
+ else {
+ mu_mailer_destroy(&mailer);
+ mailer_url = grecs_strdup(value->v.string);
+ }
return rc;
}
@@ -467,7 +478,7 @@ static struct grecs_keyword mail_statistics_kw[] = {
static struct grecs_keyword mail_kw[] = {
{ "mailer", N_("url"), N_("Set mailer URL"),
- grecs_type_string, GRECS_DFLT, &mailer, 0, cb_mailer },
+ grecs_type_string, GRECS_DFLT, NULL, 0, cb_mailer },
{ "admin-address", N_("email"), N_("Set admin email address"),
grecs_type_string, GRECS_DFLT, &admin_address, 0, cb_email_address },
{ "from-address", N_("email"), N_("Set sender email address"),
@@ -499,12 +510,6 @@ wy_open(grecs_node_t *node)
if (rc)
return rc;
}
- if (!mailer && (rc = mu_mailer_create(&mailer, NULL))) {
- const char *url = NULL;
- mu_mailer_get_url_default(&url);
- wy_log(LOG_ERR, _("cannot create default mailer `%s': %s"), url,
- mu_strerror(rc));
- }
return rc;
}
@@ -776,7 +781,7 @@ mail_stats(struct mailevt *evt)
const char *tmpl;
char *text;
- if (!admin_stat_message || !wy_stat_mask_p(mail_admin_mask) || !mailer)
+ if (!admin_stat_message || !wy_stat_mask_p(mail_admin_mask))
return;
if (!admin_address) {

Return to:

Send suggestions and report system problems to the System administrator.