Commit 86c4ae8d 86c4ae8dc8d2e25b100a835d9a53a280f96889f9 by Sergey Poznyakoff

Use mu_strftime

1 parent e3fc8d4b
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2001, 2005 Free Software Foundation, Inc.
Copyright (C) 1999, 2001, 2005, 2006 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -67,7 +67,7 @@ _append_date (mu_envelope_t envelope, char *buf, size_t len, size_t *pnwrite)
mu_message_t msg = mu_envelope_get_owner (envelope);
struct tm **tm = mu_message_get_owner (msg);
strftime (buf, len, "%a %b %d %H:%M:%S %Y", *tm);
mu_strftime (buf, len, "%a %b %d %H:%M:%S %Y", *tm);
return 0;
}
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2001, 2005 Free Software Foundation, Inc.
Copyright (C) 1999, 2001, 2005, 2006 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -367,7 +367,7 @@ fetch_internaldate (struct fetch_command *command, char **arg ARG_UNUSED)
time_t t = time(NULL);
tmp = localtime(&t);
}
strftime (date, sizeof (date), "%d-%b-%Y %H:%M:%S", tmp);
mu_strftime (date, sizeof (date), "%d-%b-%Y %H:%M:%S", tmp);
util_send ("%s", command->name);
util_send (" \"%s +0000\"", date);
return RESP_OK;
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2003, 2004,
2005 Free Software Foundation, Inc.
2005, 2006 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -1560,31 +1560,20 @@ imap_envelope_date (mu_envelope_t envelope, char *buffer, size_t buflen,
parsed, use the calendar time. */
if (now == (time_t)-1)
{
struct tm* gmt;
struct tm *gmt;
time(&now);
gmt = gmtime(&now);
time (&now);
gmt = gmtime (&now);
tm = *gmt;
}
{
int len = strftime (buffer, buflen, " %a %b %d %H:%M:%S %Y", &tm);
/* FIXME: I don't know what strftime does if the buflen is too
short, or it fails. Assuming that it won't fail, this is my guess
as to the right thing.
I think if the buffer is too short, it will fill it as much
as it can, and nul terminate it. But I'll terminate it anyhow.
*/
if(len == 0)
{
len = buflen - 1;
buffer[len] = 0;
}
if(plen)
*plen = len;
char tmpbuf[MU_ENVELOPE_DATE_LENGTH+1];
size_t n = mu_strftime (tmpbuf, sizeof tmpbuf,
MU_ENVELOPE_DATE_FORMAT, localtime (&tm));
n = mu_cpystr (buffer, tmpbuf, buflen);
if (plen)
*plen = n;
}
return 0;
}
......
......@@ -1373,11 +1373,10 @@ restore_date (mu_message_t msg, mbox_data_t mud)
if (date && mu_parse_date (date, &t, NULL))
{
char datebuf[25];
char datebuf[MU_ENVELOPE_DATE_LENGTH+1];
/* FIXME: 1. Preserve TZ info */
/* FIXME: 2. Do not depend on LC */
strftime (datebuf, sizeof datebuf, "%a %b %d %H:%M:%S %Y",
mu_strftime (datebuf, sizeof datebuf, MU_ENVELOPE_DATE_FORMAT,
localtime (&t));
free (date);
date = strdup (datebuf);
......
......@@ -155,7 +155,7 @@ mime_create_reason (mu_mime_t mime, mu_message_t msg, const char *text)
time (&t);
tm = localtime (&t);
strftime (datestr, sizeof datestr, "%a, %b %d %H:%M:%S %Y %Z", tm);
mu_strftime (datestr, sizeof datestr, "%a, %b %d %H:%M:%S %Y %Z", tm);
mu_sieve_get_message_sender (msg, &sender);
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2002, 2004,
2005 Free Software Foundation, Inc.
2005, 2006 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -948,20 +948,18 @@ message_date (mu_envelope_t envelope, char *buf, size_t len, size_t *pnwrite)
/* FIXME: extract the time from "Date:". */
/* Catch all. */
/* FIXME: ctime() is not thread safe use strftime(). */
t = time (NULL);
n = strlen (ctime (&t));
if (buf == NULL || len == 0)
{
if (pnwrite)
*pnwrite = n;
return 0;
n = MU_ENVELOPE_DATE_LENGTH;
}
else
{
char tmpbuf[MU_ENVELOPE_DATE_LENGTH+1];
t = time (NULL);
n = mu_strftime (tmpbuf, sizeof tmpbuf,
MU_ENVELOPE_DATE_FORMAT, localtime (&t));
n = mu_cpystr (buf, tmpbuf, len);
}
n = (n > len) ? len : n;
strncpy (buf, ctime (&t), n);
buf [n] = '\0';
if (pnwrite)
*pnwrite = n;
return 0;
......
......@@ -261,11 +261,11 @@ restore_envelope (mu_stream_t str, struct _mu_rfc822_message **pmenv)
{
struct tm *tm;
time_t t;
char date[80];
char date[80]; /* FIXME: This size is way too big */
time(&t);
tm = gmtime(&t);
strftime (date, sizeof (date), "%a %b %e %H:%M:%S %Y", tm);
mu_strftime (date, sizeof (date), "%a %b %e %H:%M:%S %Y", tm);
env_date = strdup (date);
}
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2002, 2003,
2005 Free Software Foundation, Inc.
2005, 2006 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -357,7 +357,7 @@ mh_audit_open (char *name, mu_mailbox_t mbox)
time (&t);
tm = localtime (&t);
strftime (date, sizeof date, "%a, %d %b %Y %H:%M:%S %Z", tm);
mu_strftime (date, sizeof date, "%a, %d %b %Y %H:%M:%S %Z", tm);
mu_mailbox_get_url (mbox, &url);
fprintf (fp, "<<%s>> %s %s\n",
......@@ -758,7 +758,7 @@ mh_annotate (mu_message_t msg, char *field, char *text, int date)
char datebuf[80];
t = time (NULL);
tm = localtime (&t);
strftime (datebuf, sizeof datebuf, "%a, %d %b %Y %H:%M:%S %Z", tm);
mu_strftime (datebuf, sizeof datebuf, "%a, %d %b %Y %H:%M:%S %Z", tm);
mu_header_set_value (hdr, field, datebuf, 0);
}
......@@ -786,7 +786,7 @@ mh_create_message_id (int subpart)
char *host;
char *p;
strftime (date, sizeof date, "%Y%m%d%H%M%S", tm);
mu_strftime (date, sizeof date, "%Y%m%d%H%M%S", tm);
mu_get_host_name (&host);
if (subpart)
......
......@@ -456,7 +456,7 @@ _action_send (void *item, void *data)
time_t t = time (NULL);
struct tm *tm = localtime (&t);
strftime (date, sizeof date, "%a, %d %b %Y %H:%M:%S %Z", tm);
mu_strftime (date, sizeof date, "%a, %d %b %Y %H:%M:%S %Z", tm);
mu_header_set_value (hdr, MU_HEADER_DATE, date, 1);
if (mu_header_get_value (hdr, MU_HEADER_FROM, NULL, 0, &n))
......