diff options
Diffstat (limited to 'modules/mailutils/mod_mailutils.c')
-rw-r--r-- | modules/mailutils/mod_mailutils.c | 64 |
1 files changed, 39 insertions, 25 deletions
diff --git a/modules/mailutils/mod_mailutils.c b/modules/mailutils/mod_mailutils.c index bbd34f0..577723a 100644 --- a/modules/mailutils/mod_mailutils.c +++ b/modules/mailutils/mod_mailutils.c @@ -22,6 +22,7 @@ #include <wydawca/wydawca.h> #include <wydawca/cfg.h> #include <mailutils/mailutils.h> +#include <wydawca/wordsplit.h> #define WY_MODULE mod_mailutils @@ -617,7 +618,7 @@ wy_flush() } static mu_address_t -get_uploader_email(wy_triplet_t trp, const char **errp) +get_uploader_email(wy_triplet_t *trp, const char **errp) { struct wy_user const *info = wy_triplet_get_uploader(trp); mu_address_t addr; @@ -643,7 +644,7 @@ get_uploader_email(wy_triplet_t trp, const char **errp) } static mu_address_t -get_owner_address(wy_triplet_t trp) +get_owner_address(wy_triplet_t *trp) { struct wy_user *wp; mu_address_t rcpt = NULL; @@ -662,47 +663,60 @@ get_owner_address(wy_triplet_t trp) return rcpt; } -static const char * -expand_email_admin(struct wy_metadef *def, void *data) +static int +expand_email_admin(char **ret, struct wy_triplet *trp) { - if (mu_address_aget_printable(admin_address, &def->storage) == 0) - def->value = def->storage; - else - def->value = ""; - return def->value; + int rc; + size_t size = 0; + + rc = mu_address_aget_printable(admin_address, ret); + if (rc == 0) + return WRDSE_OK; + *ret = NULL; + if (grecs_asprintf(ret, &size, "mu_address_aget_printable: %s", + mu_strerror(rc))) + return WRDSE_NOSPACE; + return WRDSE_USERERR; } -static const char * -expand_email_owner(struct wy_metadef *def, void *data) +static int +expand_email_owner(char **ret, struct wy_triplet *trp) { - wy_triplet_t trp = data; mu_address_t addr; - + int rc; + addr = get_owner_address(trp); if (!addr) { wy_log(LOG_ERR, _("cannot get email of the %s's owner"), wy_triplet_project(trp)); - def->value = ""; + return WRDSE_UNDEF; } else { - if (mu_address_aget_printable(addr, &def->storage) == 0) - def->value = def->storage; - else - def->value = ""; + rc = mu_address_aget_printable(addr, ret); mu_address_destroy(&addr); + if (rc) { + size_t size = 0; + *ret = NULL; + if (grecs_asprintf(ret, + &size, + "mu_address_aget_printable: %s", + mu_strerror(rc))) + return WRDSE_NOSPACE; + return WRDSE_USERERR; + } } - return def->value; + return WRDSE_OK; } static void -t_notify(struct mailevt *evt, int ev, wy_triplet_t trp) +t_notify(struct mailevt *evt, int ev, wy_triplet_t *trp) { mu_address_t rcpt = NULL; const char *errp; char *text; const char *msg; - static struct wy_metadef email_meta[] = { - { "email:admin", NULL, expand_email_admin, NULL }, - { "email:owner", NULL, expand_email_owner, NULL }, + static struct wy_vardef email_def[] = { + { "email:admin", expand_email_admin }, + { "email:owner", expand_email_owner }, { NULL } }; @@ -762,7 +776,7 @@ t_notify(struct mailevt *evt, int ev, wy_triplet_t trp) wy_log(LOG_ERR, _("undefined message reference: %s"), evt->msg); else { - text = wy_triplet_expand_param(msg, trp, email_meta); + text = wy_triplet_expand_param(msg, trp, email_def); mail_send_message(rcpt, text, evt->sign_keys); free(text); } @@ -807,7 +821,7 @@ mail_stats(struct mailevt *evt) } void -wy_notify(void *data, int ev, wy_triplet_t trp) +wy_notify(void *data, int ev, wy_triplet_t *trp) { struct mailevt *evt = data; |