/* Convert addr to a comma-separated list of email addresses, suitable as an argument to RCPT TO command */ char * address_email_string (mu_address_t addr) { size_t count, i, n, length; char *value, *p; mu_address_get_email_count (addr, &count); length = 0; for (i = 1; i <= count; i++) { const char *str; mu_address_sget_email (recipients, i, &str); length += strlen (str) + 3; } value = malloc (length + 1); if (!value) { mu_error ("%s: not enough memory", progname); return NULL; } p = value; for (i = 1; i <= count; i++) { *p++ = '<'; mu_address_get_email (recipients, i, p, length - (p - value), &n); p += n; *p++ = '>'; if (i + 1 <= count) *p++ = ','; } *p = 0; return value; }
static int message_envelope_sender (mu_envelope_t envelope, char *buf, size_t len, size_t *pnwrite) { mu_message_t msg = mu_envelope_get_owner (envelope); mu_header_t header; int status; const char *sender; struct mu_auth_data *auth = NULL; static char *hdrnames[] = { "X-Envelope-Sender", "X-Envelope-From", "X-Original-Sender", "From", NULL }; mu_address_t address = NULL; if (msg == NULL) return EINVAL; /* First, try the header */ status = mu_message_get_header (msg, &header); if (status) return status; status = mu_header_sget_firstof (header, hdrnames, &sender, NULL); if (status) { auth = mu_get_auth_by_uid (getuid ()); if (!auth) return MU_ERR_NOENT; sender = auth->name; } status = mu_address_create (&address, sender); if (status == 0) { status = mu_address_sget_email (address, 1, &sender); if (status == 0) { size_t n = strlen (sender); if (buf && len > 0) { len--; /* One for the null. */ n = (n < len) ? n : len; memcpy (buf, sender, n); buf[n] = '\0'; } if (pnwrite) *pnwrite = n; } mu_address_destroy (&address); } if (auth) mu_auth_data_free (auth); return status; }
int reply0 (msgset_t *mspec, mu_message_t msg, void *data) { mu_header_t hdr; compose_env_t env; int status; char *str; set_cursor (mspec->msg_part[0]); compose_init (&env); mu_message_get_header (msg, &hdr); compose_header_set (&env, MU_HEADER_TO, util_get_sender (mspec->msg_part[0], 0), COMPOSE_SINGLE_LINE); if (*(int*) data) /* reply starts with a lowercase */ { /* Add all recepients of the originate letter */ mu_address_t addr = NULL; size_t i, count = 0; if (mu_header_aget_value (hdr, MU_HEADER_TO, &str) == 0) { mu_address_create (&addr, str); free (str); mu_address_get_count (addr, &count); } /* Make sure we do not include our alternate names */ for (i = 1; i <= count; i++) { const char *email; if (mu_address_sget_email (addr, i, &email) || email == NULL) continue; if ((mailvar_get (NULL, "metoo", mailvar_type_boolean, 0) == 0) || !mail_is_my_name (email)) compose_header_set (&env, MU_HEADER_TO, email, COMPOSE_SINGLE_LINE); } mu_address_destroy (&addr); /* Finally, add any Ccs */ if (mu_header_aget_value (hdr, MU_HEADER_CC, &str) == 0) compose_header_set (&env, MU_HEADER_TO, str, COMPOSE_SINGLE_LINE); } if (mu_header_aget_value (hdr, MU_HEADER_SUBJECT, &str) == 0) { char *p = NULL; if (mu_unre_subject (str, NULL)) util_strcat (&p, util_reply_prefix ()); util_strcat (&p, str); free (str); compose_header_set (&env, MU_HEADER_SUBJECT, p, COMPOSE_REPLACE); free (p); } else compose_header_set (&env, MU_HEADER_SUBJECT, "", COMPOSE_REPLACE); mu_printf ("To: %s\n", compose_header_get (&env, MU_HEADER_TO, "")); str = compose_header_get (&env, MU_HEADER_CC, NULL); if (str) mu_printf ("Cc: %s\n", str); mu_printf ("Subject: %s\n\n", compose_header_get (&env, MU_HEADER_SUBJECT, "")); make_in_reply_to (&env, msg); make_references (&env, msg); status = mail_send0 (&env, mailvar_get (NULL, "byname", mailvar_type_boolean, 0) == 0); compose_destroy (&env); return status; }
/* %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; }