summaryrefslogtreecommitdiffabout
Unidiff
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 @@
27 27
28#define WY_MODULE mod_mailutils 28#define WY_MODULE mod_mailutils
29 29
30static mu_mailer_t mailer; 30static char *mailer_url;
31static pthread_mutex_t mailer_mutex = PTHREAD_MUTEX_INITIALIZER;
32
33static mu_address_t admin_address; 31static mu_address_t admin_address;
34static mu_address_t from_address; 32static mu_address_t from_address;
35unsigned long mail_admin_mask; 33unsigned long mail_admin_mask;
@@ -318,6 +316,7 @@ static void
318mail_send_message(mu_address_t rcpt, const char *text, const char *signer_key) 316mail_send_message(mu_address_t rcpt, const char *text, const char *signer_key)
319{ 317{
320 int rc; 318 int rc;
319 mu_mailer_t mailer;
321 mu_message_t msg; 320 mu_message_t msg;
322 mu_stream_t stream = NULL; 321 mu_stream_t stream = NULL;
323 mu_header_t hdr; 322 mu_header_t hdr;
@@ -356,7 +355,12 @@ mail_send_message(mu_address_t rcpt, const char *text, const char *signer_key)
356 mu_debug_set_category_level(MU_DEBCAT_MAILER, level); 355 mu_debug_set_category_level(MU_DEBCAT_MAILER, level);
357 } 356 }
358 357
359 pthread_mutex_lock(&mailer_mutex); 358 rc = mu_mailer_create(&mailer, mailer_url);
359 if (rc) {
360 wy_log(LOG_CRIT, _("cannot create mailer `%s': %s"),
361 mailer_url,
362 mu_strerror(rc));
363 } else {
360 if ((rc = mu_mailer_open(mailer, 0))) { 364 if ((rc = mu_mailer_open(mailer, 0))) {
361 mu_url_t url = NULL; 365 mu_url_t url = NULL;
362 mu_mailer_get_url(mailer, &url); 366 mu_mailer_get_url(mailer, &url);
@@ -370,12 +374,14 @@ mail_send_message(mu_address_t rcpt, const char *text, const char *signer_key)
370 if (!wy_dry_run) { 374 if (!wy_dry_run) {
371 rc = mu_mailer_send_message(mailer, msg, from_address, rcpt); 375 rc = mu_mailer_send_message(mailer, msg, from_address, rcpt);
372 if (rc) 376 if (rc)
373 wy_log(LOG_CRIT, _("cannot send message: %s"), mu_strerror(rc)); 377 wy_log(LOG_CRIT, _("cannot send message: %s"),
378 mu_strerror(rc));
374 } 379 }
375 380
376 mu_mailer_close(mailer); 381 mu_mailer_close(mailer);
377 } 382 }
378 pthread_mutex_unlock(&mailer_mutex); 383 mu_mailer_destroy(&mailer);
384 }
379 385
380 mu_message_destroy(&msg, mu_message_get_owner(msg)); 386 mu_message_destroy(&msg, mu_message_get_owner(msg));
381} 387}
@@ -387,6 +393,7 @@ cb_mailer(enum grecs_callback_command cmd, grecs_node_t *node,
387 int rc; 393 int rc;
388 grecs_locus_t *locus = &node->locus; 394 grecs_locus_t *locus = &node->locus;
389 grecs_value_t *value = node->v.value; 395 grecs_value_t *value = node->v.value;
396 mu_mailer_t mailer;
390 397
391 if (wy_assert_string_arg(locus, cmd, value)) 398 if (wy_assert_string_arg(locus, cmd, value))
392 return 1; 399 return 1;
@@ -396,6 +403,10 @@ cb_mailer(enum grecs_callback_command cmd, grecs_node_t *node,
396 _("cannot create mailer `%s': %s"), 403 _("cannot create mailer `%s': %s"),
397 value->v.string, 404 value->v.string,
398 mu_strerror(rc)); 405 mu_strerror(rc));
406 else {
407 mu_mailer_destroy(&mailer);
408 mailer_url = grecs_strdup(value->v.string);
409 }
399 return rc; 410 return rc;
400} 411}
401 412
@@ -467,7 +478,7 @@ static struct grecs_keyword mail_statistics_kw[] = {
467 478
468static struct grecs_keyword mail_kw[] = { 479static struct grecs_keyword mail_kw[] = {
469 { "mailer", N_("url"), N_("Set mailer URL"), 480 { "mailer", N_("url"), N_("Set mailer URL"),
470 grecs_type_string, GRECS_DFLT, &mailer, 0, cb_mailer }, 481 grecs_type_string, GRECS_DFLT, NULL, 0, cb_mailer },
471 { "admin-address", N_("email"), N_("Set admin email address"), 482 { "admin-address", N_("email"), N_("Set admin email address"),
472 grecs_type_string, GRECS_DFLT, &admin_address, 0, cb_email_address }, 483 grecs_type_string, GRECS_DFLT, &admin_address, 0, cb_email_address },
473 { "from-address", N_("email"), N_("Set sender email address"), 484 { "from-address", N_("email"), N_("Set sender email address"),
@@ -499,12 +510,6 @@ wy_open(grecs_node_t *node)
499 if (rc) 510 if (rc)
500 return rc; 511 return rc;
501 } 512 }
502 if (!mailer && (rc = mu_mailer_create(&mailer, NULL))) {
503 const char *url = NULL;
504 mu_mailer_get_url_default(&url);
505 wy_log(LOG_ERR, _("cannot create default mailer `%s': %s"), url,
506 mu_strerror(rc));
507 }
508 return rc; 513 return rc;
509 } 514 }
510 515
@@ -776,7 +781,7 @@ mail_stats(struct mailevt *evt)
776 const char *tmpl; 781 const char *tmpl;
777 char *text; 782 char *text;
778 783
779 if (!admin_stat_message || !wy_stat_mask_p(mail_admin_mask) || !mailer) 784 if (!admin_stat_message || !wy_stat_mask_p(mail_admin_mask))
780 return; 785 return;
781 786
782 if (!admin_address) { 787 if (!admin_address) {

Return to:

Send suggestions and report system problems to the System administrator.