Use mu_strftime
Showing
9 changed files
with
35 additions
and
49 deletions
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2001, 2005 Free Software Foundation, Inc. | 2 | Copyright (C) 1999, 2001, 2005, 2006 Free Software Foundation, Inc. |
3 | 3 | ||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | 4 | GNU Mailutils is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 5 | 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) | ... | @@ -67,7 +67,7 @@ _append_date (mu_envelope_t envelope, char *buf, size_t len, size_t *pnwrite) |
67 | mu_message_t msg = mu_envelope_get_owner (envelope); | 67 | mu_message_t msg = mu_envelope_get_owner (envelope); |
68 | struct tm **tm = mu_message_get_owner (msg); | 68 | struct tm **tm = mu_message_get_owner (msg); |
69 | 69 | ||
70 | strftime (buf, len, "%a %b %d %H:%M:%S %Y", *tm); | 70 | mu_strftime (buf, len, "%a %b %d %H:%M:%S %Y", *tm); |
71 | return 0; | 71 | return 0; |
72 | } | 72 | } |
73 | 73 | ... | ... |
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2001, 2005 Free Software Foundation, Inc. | 2 | Copyright (C) 1999, 2001, 2005, 2006 Free Software Foundation, Inc. |
3 | 3 | ||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | 4 | GNU Mailutils is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 5 | 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) | ... | @@ -367,7 +367,7 @@ fetch_internaldate (struct fetch_command *command, char **arg ARG_UNUSED) |
367 | time_t t = time(NULL); | 367 | time_t t = time(NULL); |
368 | tmp = localtime(&t); | 368 | tmp = localtime(&t); |
369 | } | 369 | } |
370 | strftime (date, sizeof (date), "%d-%b-%Y %H:%M:%S", tmp); | 370 | mu_strftime (date, sizeof (date), "%d-%b-%Y %H:%M:%S", tmp); |
371 | util_send ("%s", command->name); | 371 | util_send ("%s", command->name); |
372 | util_send (" \"%s +0000\"", date); | 372 | util_send (" \"%s +0000\"", date); |
373 | return RESP_OK; | 373 | return RESP_OK; | ... | ... |
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2000, 2001, 2003, 2004, | 2 | Copyright (C) 1999, 2000, 2001, 2003, 2004, |
3 | 2005 Free Software Foundation, Inc. | 3 | 2005, 2006 Free Software Foundation, Inc. |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public | 6 | 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, | ... | @@ -1560,31 +1560,20 @@ imap_envelope_date (mu_envelope_t envelope, char *buffer, size_t buflen, |
1560 | parsed, use the calendar time. */ | 1560 | parsed, use the calendar time. */ |
1561 | if (now == (time_t)-1) | 1561 | if (now == (time_t)-1) |
1562 | { | 1562 | { |
1563 | struct tm* gmt; | 1563 | struct tm *gmt; |
1564 | 1564 | ||
1565 | time(&now); | 1565 | time (&now); |
1566 | gmt = gmtime(&now); | 1566 | gmt = gmtime (&now); |
1567 | tm = *gmt; | 1567 | tm = *gmt; |
1568 | } | 1568 | } |
1569 | 1569 | ||
1570 | { | 1570 | { |
1571 | int len = strftime (buffer, buflen, " %a %b %d %H:%M:%S %Y", &tm); | 1571 | char tmpbuf[MU_ENVELOPE_DATE_LENGTH+1]; |
1572 | 1572 | size_t n = mu_strftime (tmpbuf, sizeof tmpbuf, | |
1573 | /* FIXME: I don't know what strftime does if the buflen is too | 1573 | MU_ENVELOPE_DATE_FORMAT, localtime (&tm)); |
1574 | short, or it fails. Assuming that it won't fail, this is my guess | 1574 | n = mu_cpystr (buffer, tmpbuf, buflen); |
1575 | as to the right thing. | 1575 | if (plen) |
1576 | 1576 | *plen = n; | |
1577 | I think if the buffer is too short, it will fill it as much | ||
1578 | as it can, and nul terminate it. But I'll terminate it anyhow. | ||
1579 | */ | ||
1580 | if(len == 0) | ||
1581 | { | ||
1582 | len = buflen - 1; | ||
1583 | buffer[len] = 0; | ||
1584 | } | ||
1585 | |||
1586 | if(plen) | ||
1587 | *plen = len; | ||
1588 | } | 1577 | } |
1589 | return 0; | 1578 | return 0; |
1590 | } | 1579 | } | ... | ... |
... | @@ -1373,12 +1373,11 @@ restore_date (mu_message_t msg, mbox_data_t mud) | ... | @@ -1373,12 +1373,11 @@ restore_date (mu_message_t msg, mbox_data_t mud) |
1373 | 1373 | ||
1374 | if (date && mu_parse_date (date, &t, NULL)) | 1374 | if (date && mu_parse_date (date, &t, NULL)) |
1375 | { | 1375 | { |
1376 | char datebuf[25]; | 1376 | char datebuf[MU_ENVELOPE_DATE_LENGTH+1]; |
1377 | 1377 | ||
1378 | /* FIXME: 1. Preserve TZ info */ | 1378 | /* FIXME: 1. Preserve TZ info */ |
1379 | /* FIXME: 2. Do not depend on LC */ | 1379 | mu_strftime (datebuf, sizeof datebuf, MU_ENVELOPE_DATE_FORMAT, |
1380 | strftime (datebuf, sizeof datebuf, "%a %b %d %H:%M:%S %Y", | 1380 | localtime (&t)); |
1381 | localtime (&t)); | ||
1382 | free (date); | 1381 | free (date); |
1383 | date = strdup (datebuf); | 1382 | date = strdup (datebuf); |
1384 | } | 1383 | } | ... | ... |
... | @@ -155,7 +155,7 @@ mime_create_reason (mu_mime_t mime, mu_message_t msg, const char *text) | ... | @@ -155,7 +155,7 @@ mime_create_reason (mu_mime_t mime, mu_message_t msg, const char *text) |
155 | 155 | ||
156 | time (&t); | 156 | time (&t); |
157 | tm = localtime (&t); | 157 | tm = localtime (&t); |
158 | strftime (datestr, sizeof datestr, "%a, %b %d %H:%M:%S %Y %Z", tm); | 158 | mu_strftime (datestr, sizeof datestr, "%a, %b %d %H:%M:%S %Y %Z", tm); |
159 | 159 | ||
160 | mu_sieve_get_message_sender (msg, &sender); | 160 | mu_sieve_get_message_sender (msg, &sender); |
161 | 161 | ... | ... |
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2000, 2001, 2002, 2004, | 2 | Copyright (C) 1999, 2000, 2001, 2002, 2004, |
3 | 2005 Free Software Foundation, Inc. | 3 | 2005, 2006 Free Software Foundation, Inc. |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public | 6 | 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) | ... | @@ -948,20 +948,18 @@ message_date (mu_envelope_t envelope, char *buf, size_t len, size_t *pnwrite) |
948 | 948 | ||
949 | /* FIXME: extract the time from "Date:". */ | 949 | /* FIXME: extract the time from "Date:". */ |
950 | 950 | ||
951 | /* Catch all. */ | ||
952 | /* FIXME: ctime() is not thread safe use strftime(). */ | ||
953 | t = time (NULL); | ||
954 | n = strlen (ctime (&t)); | ||
955 | |||
956 | if (buf == NULL || len == 0) | 951 | if (buf == NULL || len == 0) |
957 | { | 952 | { |
958 | if (pnwrite) | 953 | n = MU_ENVELOPE_DATE_LENGTH; |
959 | *pnwrite = n; | 954 | } |
960 | return 0; | 955 | else |
956 | { | ||
957 | char tmpbuf[MU_ENVELOPE_DATE_LENGTH+1]; | ||
958 | t = time (NULL); | ||
959 | n = mu_strftime (tmpbuf, sizeof tmpbuf, | ||
960 | MU_ENVELOPE_DATE_FORMAT, localtime (&t)); | ||
961 | n = mu_cpystr (buf, tmpbuf, len); | ||
961 | } | 962 | } |
962 | n = (n > len) ? len : n; | ||
963 | strncpy (buf, ctime (&t), n); | ||
964 | buf [n] = '\0'; | ||
965 | if (pnwrite) | 963 | if (pnwrite) |
966 | *pnwrite = n; | 964 | *pnwrite = n; |
967 | return 0; | 965 | return 0; | ... | ... |
... | @@ -261,11 +261,11 @@ restore_envelope (mu_stream_t str, struct _mu_rfc822_message **pmenv) | ... | @@ -261,11 +261,11 @@ restore_envelope (mu_stream_t str, struct _mu_rfc822_message **pmenv) |
261 | { | 261 | { |
262 | struct tm *tm; | 262 | struct tm *tm; |
263 | time_t t; | 263 | time_t t; |
264 | char date[80]; | 264 | char date[80]; /* FIXME: This size is way too big */ |
265 | 265 | ||
266 | time(&t); | 266 | time(&t); |
267 | tm = gmtime(&t); | 267 | tm = gmtime(&t); |
268 | strftime (date, sizeof (date), "%a %b %e %H:%M:%S %Y", tm); | 268 | mu_strftime (date, sizeof (date), "%a %b %e %H:%M:%S %Y", tm); |
269 | env_date = strdup (date); | 269 | env_date = strdup (date); |
270 | } | 270 | } |
271 | 271 | ... | ... |
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2000, 2001, 2002, 2003, | 2 | Copyright (C) 1999, 2000, 2001, 2002, 2003, |
3 | 2005 Free Software Foundation, Inc. | 3 | 2005, 2006 Free Software Foundation, Inc. |
4 | 4 | ||
5 | GNU Mailutils is free software; you can redistribute it and/or modify | 5 | GNU Mailutils is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | 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) | ... | @@ -357,7 +357,7 @@ mh_audit_open (char *name, mu_mailbox_t mbox) |
357 | 357 | ||
358 | time (&t); | 358 | time (&t); |
359 | tm = localtime (&t); | 359 | tm = localtime (&t); |
360 | strftime (date, sizeof date, "%a, %d %b %Y %H:%M:%S %Z", tm); | 360 | mu_strftime (date, sizeof date, "%a, %d %b %Y %H:%M:%S %Z", tm); |
361 | mu_mailbox_get_url (mbox, &url); | 361 | mu_mailbox_get_url (mbox, &url); |
362 | 362 | ||
363 | fprintf (fp, "<<%s>> %s %s\n", | 363 | fprintf (fp, "<<%s>> %s %s\n", |
... | @@ -758,7 +758,7 @@ mh_annotate (mu_message_t msg, char *field, char *text, int date) | ... | @@ -758,7 +758,7 @@ mh_annotate (mu_message_t msg, char *field, char *text, int date) |
758 | char datebuf[80]; | 758 | char datebuf[80]; |
759 | t = time (NULL); | 759 | t = time (NULL); |
760 | tm = localtime (&t); | 760 | tm = localtime (&t); |
761 | strftime (datebuf, sizeof datebuf, "%a, %d %b %Y %H:%M:%S %Z", tm); | 761 | mu_strftime (datebuf, sizeof datebuf, "%a, %d %b %Y %H:%M:%S %Z", tm); |
762 | 762 | ||
763 | mu_header_set_value (hdr, field, datebuf, 0); | 763 | mu_header_set_value (hdr, field, datebuf, 0); |
764 | } | 764 | } |
... | @@ -786,7 +786,7 @@ mh_create_message_id (int subpart) | ... | @@ -786,7 +786,7 @@ mh_create_message_id (int subpart) |
786 | char *host; | 786 | char *host; |
787 | char *p; | 787 | char *p; |
788 | 788 | ||
789 | strftime (date, sizeof date, "%Y%m%d%H%M%S", tm); | 789 | mu_strftime (date, sizeof date, "%Y%m%d%H%M%S", tm); |
790 | mu_get_host_name (&host); | 790 | mu_get_host_name (&host); |
791 | 791 | ||
792 | if (subpart) | 792 | if (subpart) | ... | ... |
... | @@ -456,7 +456,7 @@ _action_send (void *item, void *data) | ... | @@ -456,7 +456,7 @@ _action_send (void *item, void *data) |
456 | time_t t = time (NULL); | 456 | time_t t = time (NULL); |
457 | struct tm *tm = localtime (&t); | 457 | struct tm *tm = localtime (&t); |
458 | 458 | ||
459 | strftime (date, sizeof date, "%a, %d %b %Y %H:%M:%S %Z", tm); | 459 | mu_strftime (date, sizeof date, "%a, %d %b %Y %H:%M:%S %Z", tm); |
460 | mu_header_set_value (hdr, MU_HEADER_DATE, date, 1); | 460 | mu_header_set_value (hdr, MU_HEADER_DATE, date, 1); |
461 | 461 | ||
462 | if (mu_header_get_value (hdr, MU_HEADER_FROM, NULL, 0, &n)) | 462 | if (mu_header_get_value (hdr, MU_HEADER_FROM, NULL, 0, &n)) | ... | ... |
-
Please register or sign in to post a comment