Commit c8bb4b94 c8bb4b9413f72f2e9c5f81b5f1674c9341ed369f by Sergey Poznyakoff

Rewrite using new envelope accessors

......@@ -37,16 +37,18 @@ util_get_sender (int msgno)
mu_header_t header = NULL;
mu_address_t addr = NULL;
mu_message_t msg = NULL;
char buffer[512];
const char *buffer;
char *email;
mu_mailbox_get_message (mbox, msgno, &msg);
mu_message_get_header (msg, &header);
if (mu_header_get_value (header, MU_HEADER_FROM, buffer, sizeof (buffer), NULL)
if (mu_header_sget_value (header, MU_HEADER_FROM, &buffer)
|| mu_address_create (&addr, buffer))
{
mu_envelope_t env = NULL;
mu_message_get_envelope (msg, &env);
if (mu_envelope_sender (env, buffer, sizeof (buffer), NULL)
if (mu_envelope_sget_sender (env, &buffer)
|| mu_address_create (&addr, buffer))
{
util_error (_("Cannot determine sender name (msg %d)"), msgno);
......@@ -54,7 +56,7 @@ util_get_sender (int msgno)
}
}
if (mu_address_get_email (addr, 1, buffer, sizeof (buffer), NULL))
if (mu_address_aget_email (addr, 1, &email))
{
util_error (_("Cannot determine sender name (msg %d)"), msgno);
mu_address_destroy (&addr);
......@@ -62,6 +64,6 @@ util_get_sender (int msgno)
}
mu_address_destroy (&addr);
return strdup (buffer);
return email;
}
......
......@@ -65,16 +65,25 @@ static int
_append_date (mu_envelope_t envelope, char *buf, size_t len, size_t *pnwrite)
{
mu_message_t msg = mu_envelope_get_owner (envelope);
size_t size;
if (!buf)
size = MU_ENVELOPE_DATE_LENGTH;
else
{
struct tm **tm = mu_message_get_owner (msg);
mu_strftime (buf, len, "%a %b %d %H:%M:%S %Y", *tm);
size = mu_strftime (buf, len, "%a %b %d %H:%M:%S %Y", *tm);
}
if (pnwrite)
*pnwrite = size;
return 0;
}
static int
_append_sender (mu_envelope_t envelope, char *buf, size_t len, size_t *pnwrite)
{
strncpy (buf, "GNU-imap4d", len);
size_t n = mu_cpystr (buf, "GNU-imap4d", len);
if (pnwrite)
*pnwrite = n;
return 0;
}
......@@ -139,4 +148,3 @@ imap4d_append0 (mu_mailbox_t mbox, int flags, char *text)
}
......
......@@ -349,27 +349,24 @@ fetch_flags (struct fetch_command *command, char **arg)
static int
fetch_internaldate (struct fetch_command *command, char **arg MU_ARG_UNUSED)
{
char date[128];
const char *date;
mu_envelope_t env = NULL;
struct tm tm, *tmp = NULL;
mu_timezone tz;
char datebuf[sizeof ("13-Jul-2002 00:00:00")];
mu_message_get_envelope (command->msg, &env);
date[0] = '\0';
if (mu_envelope_date (env, date, sizeof (date), NULL) == 0)
{
char *p = date;
if (mu_parse_ctime_date_time ((const char **) &p, &tm, &tz) == 0)
if (mu_envelope_sget_date (env, &date) == 0
&& mu_parse_ctime_date_time (&date, &tm, &tz) == 0)
tmp = &tm;
}
if (!tmp)
else
{
time_t t = time(NULL);
tmp = localtime(&t);
time_t t = time (NULL);
tmp = localtime (&t);
}
mu_strftime (date, sizeof (date), "%d-%b-%Y %H:%M:%S", tmp);
mu_strftime (datebuf, sizeof (datebuf), "%d-%b-%Y %H:%M:%S", tmp);
util_send ("%s", command->name);
util_send (" \"%s +0000\"", date);
util_send (" \"%s +0000\"", datebuf);
return RESP_OK;
}
......
......@@ -790,12 +790,13 @@ cond_before (struct parsebuf *pb)
{
time_t t = (time_t)_search_arg (pb);
time_t mesg_time;
char buffer[512];
const char *date;
mu_envelope_t env;
mu_message_get_envelope (pb->msg, &env);
mu_envelope_date (env, buffer, sizeof (buffer), NULL);
util_parse_ctime_date (buffer, &mesg_time);
if (mu_envelope_sget_date (env, &date))
return 0;
util_parse_ctime_date (date, &mesg_time);
_search_push (pb, mesg_time < t);
}
......@@ -816,12 +817,12 @@ cond_from (struct parsebuf *pb)
{
char *s = _search_arg (pb);
mu_envelope_t env;
char buffer[512];
const char *from;
int rc = 0;
mu_message_get_envelope (pb->msg, &env);
if (mu_envelope_sender (env, buffer, sizeof (buffer), NULL) == 0)
rc = util_strcasestr (buffer, s) != NULL;
if (mu_envelope_sget_sender (env, &from) == 0)
rc = util_strcasestr (from, s) != NULL;
_search_push (pb, _scan_header (pb, "from", s));
}
......@@ -859,12 +860,13 @@ cond_on (struct parsebuf *pb)
{
time_t t = (time_t)_search_arg (pb);
time_t mesg_time;
char buffer[512];
const char *date;
mu_envelope_t env;
mu_message_get_envelope (pb->msg, &env);
mu_envelope_date (env, buffer, sizeof (buffer), NULL);
util_parse_ctime_date (buffer, &mesg_time);
if (mu_envelope_sget_date (env, &date))
return 0;
util_parse_ctime_date (date, &mesg_time);
_search_push (pb, t <= mesg_time && mesg_time <= t + 86400);
}
......@@ -903,12 +905,13 @@ cond_since (struct parsebuf *pb)
{
time_t t = (time_t)_search_arg (pb);
time_t mesg_time;
char buffer[512];
const char *date;
mu_envelope_t env;
mu_message_get_envelope (pb->msg, &env);
mu_envelope_date (env, buffer, sizeof (buffer), NULL);
util_parse_ctime_date (buffer, &mesg_time);
if (mu_envelope_sget_date (env, &date))
return 0;
util_parse_ctime_date (date, &mesg_time);
_search_push (pb, mesg_time >= t);
}
......
......@@ -53,10 +53,10 @@ static char *
_get_envelope_sender (mu_envelope_t env)
{
mu_address_t addr;
char buffer[128];
const char *buffer;
char *ptr;
if (mu_envelope_sender (env, buffer, sizeof (buffer), NULL)
if (mu_envelope_sget_sender (env, &buffer)
|| mu_address_create (&addr, buffer))
return NULL;
......@@ -75,11 +75,12 @@ mu_scm_message_print (SCM message_smob, SCM port, scm_print_state * pstate)
{
struct mu_message *mum = (struct mu_message *) SCM_CDR (message_smob);
mu_envelope_t env = NULL;
char buffer[128];
const char *buffer;
const char *p;
size_t m_size = 0, m_lines = 0;
struct tm tm;
mu_timezone tz;
char datebuf[sizeof ("Mon Jan 01 00:00")]; /* Warning: length must be > 9 */
mu_message_get_envelope (mum->msg, &env);
......@@ -102,12 +103,14 @@ mu_scm_message_print (SCM message_smob, SCM port, scm_print_state * pstate)
else
scm_puts ("UNKNOWN", port);
mu_envelope_date (env, buffer, sizeof (buffer), NULL);
p = buffer;
if (mu_parse_ctime_date_time (&p, &tm, &tz) == 0)
strftime (buffer, sizeof (buffer), "%a %b %e %H:%M", &tm);
if (mu_envelope_sget_date (env, &buffer) == 0
&& mu_parse_ctime_date_time (&p, &tm, &tz) == 0)
{
strftime (datebuf, sizeof (datebuf), "%a %b %e %H:%M", &tm);
buffer = datebuf;
}
else
strcpy (buffer, "UNKNOWN");
buffer = "UNKNOWN";
scm_puts ("\" \"", port);
scm_puts (buffer, port);
scm_puts ("\" ", port);
......@@ -115,9 +118,9 @@ mu_scm_message_print (SCM message_smob, SCM port, scm_print_state * pstate)
mu_message_size (mum->msg, &m_size);
mu_message_lines (mum->msg, &m_lines);
snprintf (buffer, sizeof (buffer), "%3lu %-5lu",
snprintf (datebuf, sizeof (datebuf), "%3lu %-5lu",
(unsigned long) m_lines, (unsigned long) m_size);
scm_puts (buffer, port);
scm_puts (datebuf, port);
}
scm_puts (">", port);
return 1;
......
......@@ -107,30 +107,19 @@ mu_sieve_get_message_sender (mu_message_t msg, char **ptext)
{
int rc;
mu_envelope_t envelope;
char *text;
size_t size;
rc = mu_message_get_envelope (msg, &envelope);
if (rc)
return rc;
rc = mu_envelope_sender (envelope, NULL, 0, &size);
if (rc == 0)
{
if (!(text = malloc (size + 1)))
return ENOMEM;
mu_envelope_sender (envelope, text, size + 1, NULL);
}
else
rc = mu_envelope_aget_sender (envelope, ptext);
if (rc)
{
mu_header_t hdr = NULL;
mu_message_get_header (msg, &hdr);
if ((rc = mu_header_aget_value (hdr, MU_HEADER_SENDER, &text)))
rc = mu_header_aget_value (hdr, MU_HEADER_FROM, &text);
if ((rc = mu_header_aget_value (hdr, MU_HEADER_SENDER, ptext)))
rc = mu_header_aget_value (hdr, MU_HEADER_FROM, ptext);
}
if (rc == 0)
*ptext = text;
return rc;
}
......@@ -431,7 +420,6 @@ sieve_action_redirect (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
if (rc)
{
mu_sieve_error (mach,
"redirect",
_("%d: cannot create sender address <%s>: %s"),
mu_sieve_get_message_num (mach),
fromaddr, mu_strerror (rc));
......
......@@ -243,13 +243,12 @@ retrieve_envelope (void *item, void *data, int idx, char **pval)
if (!ap->addr)
{
char buf[512];
size_t n;
const char *buf;
if (strcasecmp ((char*)item, "from") != 0)
return 1;
if (mu_envelope_sender ((mu_envelope_t)ap->data, buf, sizeof(buf), &n))
if (mu_envelope_sget_sender ((mu_envelope_t)ap->data, &buf))
return 1;
rc = mu_address_create (&ap->addr, buf);
......@@ -291,7 +290,8 @@ sieve_test_envelope (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
mu_sieve_abort (mach);
}
mu_message_get_envelope (mu_sieve_get_message (mach), (mu_envelope_t*)&clos.data);
mu_message_get_envelope (mu_sieve_get_message (mach),
(mu_envelope_t*)&clos.data);
clos.aget = sieve_get_address_part (tags);
clos.addr = NULL;
rc = mu_sieve_vlist_compare (h, v, comp, test, retrieve_envelope, &clos,
......
......@@ -121,9 +121,8 @@ mail_from0 (msgset_t *mspec, mu_message_t msg, void *data)
mu_timezone tz;
mu_message_get_envelope (msg, &env);
mu_envelope_date (env, date, sizeof (date), NULL);
p = date;
if (mu_parse_ctime_date_time (&p, &tm, &tz) == 0)
if (mu_envelope_sget_date (env, &p) == 0
&& mu_parse_ctime_date_time (&p, &tm, &tz) == 0)
strftime (date, sizeof(date), "%a %b %e %H:%M", &tm);
}
......
......@@ -554,7 +554,7 @@ _amd_message_save (struct _amd_data *amd, struct _amd_message *mhm, int expunge)
int status;
mu_attribute_t attr;
mu_body_t body;
char buffer[512];
const char *sbuf;
mu_envelope_t env = NULL;
status = mu_message_size (msg, &bsize);
......@@ -608,23 +608,22 @@ _amd_message_save (struct _amd_data *amd, struct _amd_message *mhm, int expunge)
}
mu_message_get_envelope (msg, &env);
if (mu_envelope_date (env, buffer, sizeof buffer, &n) == 0 && n > 0)
if (mu_envelope_sget_date (env, &sbuf) == 0)
{
/* NOTE: buffer is terminated with \n */
char *p = buffer;
while (isspace (*p))
p++;
nbytes += fprintf (fp, "%s: %s", MU_HEADER_ENV_DATE, p);
/* NOTE: buffer might be terminated with \n */
while (*sbuf && isspace (*sbuf))
sbuf++;
nbytes += fprintf (fp, "%s: %s", MU_HEADER_ENV_DATE, sbuf);
if (*p && p[strlen (p) - 1] != '\n')
if (*sbuf && sbuf[strlen (sbuf) - 1] != '\n')
nbytes += fprintf (fp, "\n");
nlines++;
}
if (mu_envelope_sender (env, buffer, sizeof buffer, &n) == 0 && n > 0)
if (mu_envelope_sget_sender (env, &sbuf) == 0)
{
fprintf (fp, "%s: %s\n", MU_HEADER_ENV_SENDER, buffer);
fprintf (fp, "%s: %s\n", MU_HEADER_ENV_SENDER, sbuf);
nlines++;
}
......
......@@ -1067,7 +1067,8 @@ mu_rfc2822_msg_id (int subpart, char **pval)
int
mu_rfc2822_in_reply_to (mu_message_t msg, char **pstr)
{
char *value, *s1 = NULL, *s2 = NULL;
const char *value = NULL;
char *s1 = NULL, *s2 = NULL;
mu_header_t hdr;
int rc;
......@@ -1075,39 +1076,30 @@ mu_rfc2822_in_reply_to (mu_message_t msg, char **pstr)
if (rc)
return rc;
if (mu_header_aget_value (hdr, MU_HEADER_DATE, &value))
if (mu_header_sget_value (hdr, MU_HEADER_DATE, &value))
{
mu_envelope_t envelope = NULL;
value = malloc (DATEBUFSIZE);
if (value)
{
mu_message_get_envelope (msg, &envelope);
mu_envelope_date (envelope, value, DATEBUFSIZE, NULL);
}
mu_envelope_sget_date (envelope, &value);
}
if (value)
{
s1 = malloc (sizeof (COMMENT) + strlen (value));
if (s1)
strcat (strcpy (s1, COMMENT), value);
free (value);
if (!s1)
return ENOMEM;
strcat (strcpy (s1, COMMENT), value);
}
if (mu_header_aget_value (hdr, MU_HEADER_MESSAGE_ID, &value) == 0)
if (mu_header_sget_value (hdr, MU_HEADER_MESSAGE_ID, &value) == 0)
{
s2 = malloc (strlen (value) + 3);
if (s2)
strcat (strcpy (s2, "\n\t"), value);
free (value);
if (!s2)
{
free (s1);
return ENOMEM;
}
strcat (strcpy (s2, "\n\t"), value);
}
if (s1 || s2)
......