/* Message envelope */ static int message_envelope_date (mu_envelope_t envelope, char *buf, size_t len, size_t *pnwrite) { mu_message_t msg = mu_envelope_get_owner (envelope); time_t t; size_t n; if (msg == NULL) return EINVAL; /* FIXME: extract the time from "Date:". */ if (buf == NULL || len == 0) { n = MU_DATETIME_FROM_LENGTH; } else { char tmpbuf[MU_DATETIME_FROM_LENGTH+1]; t = time (NULL); n = mu_strftime (tmpbuf, sizeof tmpbuf, MU_DATETIME_FROM, gmtime (&t)); n = mu_cpystr (buf, tmpbuf, len); } if (pnwrite) *pnwrite = n; return 0; }
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; }
static int mbox_envelope_sender (mu_envelope_t envelope, char *buf, size_t len, size_t *pnwrite) { mu_message_t msg = mu_envelope_get_owner (envelope); mbox_message_t mum = mu_message_get_owner (msg); size_t n = 0; int status; char buffer[512]; char *s; if (mum == NULL) return EINVAL; status = mu_stream_readline (mum->mud->mailbox->stream, buffer, sizeof(buffer), mum->header_from, &n); if (status != 0) { if (pnwrite) *pnwrite = 0; return status; } /* Format: "From [sender] [date]" */ /* strlen ("From ") == 5 */ if (n > 5 && (s = strchr (buffer + 5, ' ')) != NULL) { /* Put a NULL to isolate the sender string, make a C string. */ *s = '\0'; if (buf && len > 0) { len--; /* leave space for the null */ strncpy (buf, buffer + 5, len)[len] = '\0'; len = strlen (buf); } else len = strlen (buffer + 5); } else len = 0; if (pnwrite) *pnwrite = len; return 0; }