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; }
void _dealloc4 (PyObject *self) { PyAuthData *py_ad = (PyAuthData *)self; if (py_ad->auth_data) mu_auth_data_free (py_ad->auth_data); self->ob_type->tp_free (self); }
int mail_tmp_add_line (struct mail_tmp *mtmp, char *buf, size_t buflen) { int status = 0; mtmp->line++; if (mtmp->line == 1) { const char *from = mtmp->from; if (buflen >= 5 && memcmp (buf, "From ", 5)) { struct mu_auth_data *auth = NULL; if (!from) { auth = mu_get_auth_by_uid (getuid ()); if (auth) from = auth->name; } if (from) { time_t t; char *envs; time (&t); asprintf (&envs, "From %s %s", from, ctime (&t)); status = mu_stream_sequential_write (mtmp->stream, envs, strlen (envs)); free (envs); } else { maidag_error (_("cannot determine sender address")); return EINVAL; } if (auth) mu_auth_data_free (auth); } } else if (buflen >= 5 && !memcmp (buf, "From ", 5)) { static char *escape = ">"; status = mu_stream_sequential_write (mtmp->stream, escape, 1); } if (!status) status = mu_stream_sequential_write (mtmp->stream, buf, buflen); if (status) { maidag_error (_("error writing temporary file: %s"), mu_strerror (status)); mu_stream_destroy (&mtmp->stream, mu_stream_get_owner (mtmp->stream)); } mtmp->had_nl = buf[buflen-1] == '\n'; return status; }
/* Note: allocates memory */ char * mu_get_user_email (const char *name) { int status = 0; char *localpart = NULL; const char *domainpart = NULL; char *email = NULL; char *tmpname = NULL; if (!name && mu_user_email) { email = strdup (mu_user_email); if (!email) errno = ENOMEM; return email; } if (!name) { struct mu_auth_data *auth = mu_get_auth_by_uid (geteuid ()); if (!auth) { errno = EINVAL; return NULL; } name = tmpname = strdup(auth->name); if (auth) mu_auth_data_free (auth); if (!name) { errno = ENOMEM; return NULL; } } status = mu_get_user_email_domain (&domainpart); if (status) { free(tmpname); errno = status; return NULL; } if ((status = mu_parse822_quote_local_part (&localpart, name))) { free(tmpname); errno = status; return NULL; } email = malloc (strlen (localpart) + 1 + strlen (domainpart) + 1); if (!email) errno = ENOMEM; else sprintf (email, "%s@%s", localpart, domainpart); free(tmpname); free (localpart); return email; }