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 /src/mail.c | |
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.
Diffstat (limited to 'src/mail.c')
-rw-r--r-- | src/mail.c | 57 |
1 files changed, 35 insertions, 22 deletions
@@ -64,22 +64,25 @@ mail_send_message (mu_address_t rcpt, const char *text) | |||
64 | mu_message_get_header (msg, &hdr); | 64 | mu_message_get_header (msg, &hdr); |
65 | mu_header_append (hdr, "X-Mailer", x_mailer); | 65 | mu_header_append (hdr, "X-Mailer", x_mailer); |
66 | 66 | ||
67 | mu_address_to_string (rcpt, NULL, 0, &size); | 67 | if (rcpt) |
68 | buf = xmalloc (size + 1); | ||
69 | mu_address_to_string (rcpt, buf, size + 1, NULL); | ||
70 | |||
71 | mu_header_set_value (hdr, "To", buf, 1); | ||
72 | free (buf); | ||
73 | |||
74 | if (from_address && mu_header_sget_value (hdr, "From", &sval)) | ||
75 | { | 68 | { |
76 | mu_address_to_string (from_address, NULL, 0, &size); | 69 | mu_address_to_string (rcpt, NULL, 0, &size); |
77 | buf = xmalloc (size + 1); | 70 | buf = xmalloc (size + 1); |
78 | mu_address_to_string (from_address, buf, size + 1, NULL); | 71 | mu_address_to_string (rcpt, buf, size + 1, NULL); |
79 | mu_header_set_value (hdr, "From", buf, 1); | 72 | |
73 | mu_header_set_value (hdr, "To", buf, 1); | ||
80 | free (buf); | 74 | free (buf); |
81 | } | ||
82 | 75 | ||
76 | if (from_address && mu_header_sget_value (hdr, "From", &sval)) | ||
77 | { | ||
78 | mu_address_to_string (from_address, NULL, 0, &size); | ||
79 | buf = xmalloc (size + 1); | ||
80 | mu_address_to_string (from_address, buf, size + 1, NULL); | ||
81 | mu_header_set_value (hdr, "From", buf, 1); | ||
82 | free (buf); | ||
83 | } | ||
84 | } | ||
85 | |||
83 | if (debug_level > 1) | 86 | if (debug_level > 1) |
84 | { | 87 | { |
85 | mu_debug_t debug; | 88 | mu_debug_t debug; |
@@ -365,6 +368,10 @@ do_notify (struct file_triplet *trp, enum notification_event ev, | |||
365 | const char *errp; | 368 | const char *errp; |
366 | switch (ntf->tgt) | 369 | switch (ntf->tgt) |
367 | { | 370 | { |
371 | case notify_read: | ||
372 | rcpt = NULL; | ||
373 | break; | ||
374 | |||
368 | case notify_admin: | 375 | case notify_admin: |
369 | rcpt = mu_address_dup (admin_address); | 376 | rcpt = mu_address_dup (admin_address); |
370 | break; | 377 | break; |
@@ -378,7 +385,7 @@ do_notify (struct file_triplet *trp, enum notification_event ev, | |||
378 | trp, &errp); | 385 | trp, &errp); |
379 | } | 386 | } |
380 | 387 | ||
381 | if (!rcpt) | 388 | if (!rcpt && ntf->tgt != notify_read) |
382 | { | 389 | { |
383 | logmsg (LOG_ERR, _("not notifying %s (project %s) about %s: %s"), | 390 | logmsg (LOG_ERR, _("not notifying %s (project %s) about %s: %s"), |
384 | notification_target_str (ntf->tgt), | 391 | notification_target_str (ntf->tgt), |
@@ -389,16 +396,22 @@ do_notify (struct file_triplet *trp, enum notification_event ev, | |||
389 | 396 | ||
390 | if (debug_level) | 397 | if (debug_level) |
391 | { | 398 | { |
392 | size_t size; | 399 | if (rcpt) |
393 | char *buf; | 400 | { |
394 | mu_address_to_string (rcpt, NULL, 0, &size); | 401 | size_t size; |
395 | buf = xmalloc (size + 1); | 402 | char *buf; |
396 | mu_address_to_string (rcpt, buf, size + 1, NULL); | 403 | mu_address_to_string (rcpt, NULL, 0, &size); |
397 | logmsg (LOG_DEBUG, _("notifying %s (project %s) about %s"), | 404 | buf = xmalloc (size + 1); |
398 | buf, trp->project, notification_event_str (ev)); | 405 | mu_address_to_string (rcpt, buf, size + 1, NULL); |
399 | free (buf); | 406 | logmsg (LOG_DEBUG, _("notifying %s (project %s) about %s"), |
407 | buf, trp->project, notification_event_str (ev)); | ||
408 | free (buf); | ||
409 | } | ||
410 | else | ||
411 | logmsg (LOG_DEBUG, _("notifying message recipients (project %s) about %s"), | ||
412 | trp->project, notification_event_str (ev)); | ||
400 | } | 413 | } |
401 | 414 | ||
402 | if (!dry_run_mode) | 415 | if (!dry_run_mode) |
403 | { | 416 | { |
404 | const char *msg = resolve_message_template (ntf->msg); | 417 | const char *msg = resolve_message_template (ntf->msg); |