diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-12-06 12:20:08 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-12-06 12:20:08 +0200 |
commit | a1d560a878d1dfe4ed751cb3f99b1ee67755f489 (patch) | |
tree | 0c7e45d5ba14c309fe67929245d8a75df6d3692a | |
parent | 565650272f219fd372347f0ff3375b09caa18952 (diff) | |
download | wydawca-a1d560a878d1dfe4ed751cb3f99b1ee67755f489.tar.gz wydawca-a1d560a878d1dfe4ed751cb3f99b1ee67755f489.tar.bz2 |
Allow to specify arbitrary notification recipients.
* src/wydawca.h (enum notification_target): New value notify_read,
meaning "read recipient addresses from the message headers".
* src/config.c (target_args): New values: "read" and "message".
(target_types): New value 'notify_read'.
* src/mail.c (mail_send_message): Handle NULL rcpt.
(do_notify): Handle notify_read.
-rw-r--r-- | src/config.c | 4 | ||||
-rw-r--r-- | src/mail.c | 57 | ||||
-rw-r--r-- | src/vtab.c | 2 | ||||
-rw-r--r-- | src/wydawca.h | 1 |
4 files changed, 41 insertions, 23 deletions
diff --git a/src/config.c b/src/config.c index c877c26..559f766 100644 --- a/src/config.c +++ b/src/config.c @@ -179,19 +179,23 @@ string_to_notification_event (grecs_locus_t *locus, const char *val, locus); *pret = res; return rc; } static const char *target_args[] = { + "read", + "message", "admin", "owner", "user", NULL }; static int target_types[] = { + notify_read, /* Read recipients from the message headers */ + notify_read, notify_admin, /* System administrator */ notify_owner, /* Project admin */ notify_user /* User (uploader) */ }; ARGMATCH_VERIFY (target_args, target_types); @@ -61,28 +61,31 @@ mail_send_message (mu_address_t rcpt, const char *text) mu_message_get_stream (msg, &stream); mu_stream_write (stream, text, strlen (text), 0, NULL); mu_message_get_header (msg, &hdr); mu_header_append (hdr, "X-Mailer", x_mailer); - mu_address_to_string (rcpt, NULL, 0, &size); - buf = xmalloc (size + 1); - mu_address_to_string (rcpt, buf, size + 1, NULL); - - mu_header_set_value (hdr, "To", buf, 1); - free (buf); - - if (from_address && mu_header_sget_value (hdr, "From", &sval)) + if (rcpt) { - mu_address_to_string (from_address, NULL, 0, &size); + mu_address_to_string (rcpt, NULL, 0, &size); buf = xmalloc (size + 1); - mu_address_to_string (from_address, buf, size + 1, NULL); - mu_header_set_value (hdr, "From", buf, 1); + mu_address_to_string (rcpt, buf, size + 1, NULL); + + mu_header_set_value (hdr, "To", buf, 1); free (buf); - } + if (from_address && mu_header_sget_value (hdr, "From", &sval)) + { + mu_address_to_string (from_address, NULL, 0, &size); + buf = xmalloc (size + 1); + mu_address_to_string (from_address, buf, size + 1, NULL); + mu_header_set_value (hdr, "From", buf, 1); + free (buf); + } + } + if (debug_level > 1) { mu_debug_t debug; mu_mailer_get_debug (mailer, &debug); mu_debug_set_level (debug, MU_DEBUG_TRACE | MU_DEBUG_PROT); if (debug_level > 2) @@ -362,12 +365,16 @@ do_notify (struct file_triplet *trp, enum notification_event ev, struct notification *ntf) { mu_address_t rcpt = NULL; const char *errp; switch (ntf->tgt) { + case notify_read: + rcpt = NULL; + break; + case notify_admin: rcpt = mu_address_dup (admin_address); break; case notify_user: rcpt = get_uploader_email (trp->uploader, trp, &errp); @@ -375,33 +382,39 @@ do_notify (struct file_triplet *trp, enum notification_event ev, case notify_owner: rcpt = get_recipient (trp->spool->access_method[project_owner_method], trp, &errp); } - if (!rcpt) + if (!rcpt && ntf->tgt != notify_read) { logmsg (LOG_ERR, _("not notifying %s (project %s) about %s: %s"), notification_target_str (ntf->tgt), trp->project, notification_event_str (ev), gettext (errp)); return; } if (debug_level) { - size_t size; - char *buf; - mu_address_to_string (rcpt, NULL, 0, &size); - buf = xmalloc (size + 1); - mu_address_to_string (rcpt, buf, size + 1, NULL); - logmsg (LOG_DEBUG, _("notifying %s (project %s) about %s"), - buf, trp->project, notification_event_str (ev)); - free (buf); + if (rcpt) + { + size_t size; + char *buf; + mu_address_to_string (rcpt, NULL, 0, &size); + buf = xmalloc (size + 1); + mu_address_to_string (rcpt, buf, size + 1, NULL); + logmsg (LOG_DEBUG, _("notifying %s (project %s) about %s"), + buf, trp->project, notification_event_str (ev)); + free (buf); + } + else + logmsg (LOG_DEBUG, _("notifying message recipients (project %s) about %s"), + trp->project, notification_event_str (ev)); } - + if (!dry_run_mode) { const char *msg = resolve_message_template (ntf->msg); if (!msg) logmsg (LOG_ERR, _("undefined message reference: %s"), ntf->msg); else @@ -51,13 +51,13 @@ url_to_vtab (mu_url_t url, struct virt_tab *vtab) } return 1; } int -move_file (struct file_triplet *trp, const const struct spool *spool, +move_file (struct file_triplet *trp, const struct spool *spool, enum file_type file_id, const char *reldir) { int rc = spool->vtab.move_file (trp, spool, file_id, reldir); report_add ("Move %s to %s: %s", trp->file[file_id].name, reldir, rc == 0 ? "OK" : "FAILED"); return rc; diff --git a/src/wydawca.h b/src/wydawca.h index bd81b88..805b72b 100644 --- a/src/wydawca.h +++ b/src/wydawca.h @@ -267,12 +267,13 @@ enum notification_event ev_bad_detached_signature, MAX_EVENT }; enum notification_target { + notify_read, /* Read recipients from the message headers */ notify_admin, /* System administrator */ notify_owner, /* Project admin */ notify_user /* User (uploader) */ }; struct notification |