int mu_set_user_email (const char *candidate) { int err = 0; mu_address_t addr = NULL; size_t emailno = 0; char *email = NULL; const char *domain = NULL; if (!candidate) { free (mu_user_email); mu_user_email = NULL; return 0; } if ((err = mu_address_create (&addr, candidate)) != 0) return err; if ((err = mu_address_get_email_count (addr, &emailno)) != 0) goto cleanup; if (emailno != 1) { errno = EINVAL; goto cleanup; } if ((err = mu_address_aget_email (addr, 1, &email)) != 0) goto cleanup; free (mu_user_email); mu_user_email = email; if ((err = mu_address_sget_domain (addr, 1, &domain)) == 0) mu_set_user_email_domain (domain); cleanup: mu_address_destroy (&addr); return err; }
int restore_sender (mu_message_t msg, mbox_data_t mud) { mu_header_t hdr; char *from = NULL; int rc = 0; if (mu_message_get_header (msg, &hdr) == 0) mu_header_aget_value (hdr, MU_HEADER_FROM, &from); if (from) { int status; mu_address_t addr; status = mu_address_create (&addr, from); free (from); from = NULL; if (status == 0) mu_address_aget_email (addr, 1, &from); mu_address_destroy (&addr); } if (!from) { from = strdup (PACKAGE); if (!from) return ENOMEM; } mud->sender = strdup (from); if (!mud->sender) rc = ENOMEM; free (from); return rc; }
/* %f */ static char * hdr_from (struct header_call_args *args, void *data) { char *from = NULL; if (mailvar_get (NULL, "fromfield", mailvar_type_boolean, 0) == 0) { mu_header_t hdr; mu_message_get_header (args->msg, &hdr); if (mu_header_aget_value_unfold (hdr, MU_HEADER_FROM, &from) == 0) { mu_address_t address = NULL; if (mu_address_create (&address, from) == 0) { char *name; const char *email; if (mu_address_sget_email (address, 1, &email) == 0) { if (mailvar_get (NULL, "showto", mailvar_type_boolean, 0) == 0 && mail_is_my_name (email)) { char *tmp; if (mu_header_aget_value_unfold (hdr, MU_HEADER_TO, &tmp) == 0) { mu_address_t addr_to; if (mu_address_create (&addr_to, tmp) == 0) { mu_address_destroy (&address); address = addr_to; } free (tmp); } } } if ((mu_address_aget_personal (address, 1, &name) == 0 && name) || (mu_address_aget_email (address, 1, &name) == 0 && name)) { free (from); from = name; } mu_address_destroy (&address); } } util_rfc2047_decode (&from); } else { mu_envelope_t env = NULL; const char *sender = ""; if (mu_message_get_envelope (args->msg, &env) == 0) mu_envelope_sget_sender (env, &sender); from = strdup (sender); } header_buf_string (args, from); free (from); return args->buf; }