Move date/time declarations into a separate header: mailutils/datetime.h
Additionally, do not typedef mu_timezone, leave it in struct namespace.
Showing
32 changed files
with
133 additions
and
102 deletions
... | @@ -29,6 +29,7 @@ | ... | @@ -29,6 +29,7 @@ |
29 | #include <sys/socket.h> | 29 | #include <sys/socket.h> |
30 | #include <netinet/in.h> | 30 | #include <netinet/in.h> |
31 | #include <arpa/inet.h> | 31 | #include <arpa/inet.h> |
32 | #include <time.h> | ||
32 | #include <signal.h> | 33 | #include <signal.h> |
33 | #include <errno.h> | 34 | #include <errno.h> |
34 | #include <termios.h> | 35 | #include <termios.h> | ... | ... |
... | @@ -959,7 +959,7 @@ _frt_internaldate (struct fetch_function_closure *ffc, | ... | @@ -959,7 +959,7 @@ _frt_internaldate (struct fetch_function_closure *ffc, |
959 | const char *date; | 959 | const char *date; |
960 | mu_envelope_t env = NULL; | 960 | mu_envelope_t env = NULL; |
961 | struct tm tm, *tmp = NULL; | 961 | struct tm tm, *tmp = NULL; |
962 | mu_timezone tz; | 962 | struct mu_timezone tz; |
963 | 963 | ||
964 | mu_message_get_envelope (frt->msg, &env); | 964 | mu_message_get_envelope (frt->msg, &env); |
965 | if (mu_envelope_sget_date (env, &date) == 0 | 965 | if (mu_envelope_sget_date (env, &date) == 0 | ... | ... |
... | @@ -336,7 +336,7 @@ add2set (size_t ** set, int *n, unsigned long val) | ... | @@ -336,7 +336,7 @@ add2set (size_t ** set, int *n, unsigned long val) |
336 | } | 336 | } |
337 | 337 | ||
338 | static void | 338 | static void |
339 | adjust_tm (struct tm *tm, mu_timezone *tz, enum datetime_parse_mode flag) | 339 | adjust_tm (struct tm *tm, struct mu_timezone *tz, enum datetime_parse_mode flag) |
340 | { | 340 | { |
341 | switch (flag) | 341 | switch (flag) |
342 | { | 342 | { |
... | @@ -371,7 +371,7 @@ util_parse_internal_date (char *date, time_t *timep, | ... | @@ -371,7 +371,7 @@ util_parse_internal_date (char *date, time_t *timep, |
371 | enum datetime_parse_mode flag) | 371 | enum datetime_parse_mode flag) |
372 | { | 372 | { |
373 | struct tm tm; | 373 | struct tm tm; |
374 | mu_timezone tz; | 374 | struct mu_timezone tz; |
375 | time_t time; | 375 | time_t time; |
376 | 376 | ||
377 | if (mu_scan_datetime (date, MU_DATETIME_INTERNALDATE, &tm, &tz, NULL)) | 377 | if (mu_scan_datetime (date, MU_DATETIME_INTERNALDATE, &tm, &tz, NULL)) |
... | @@ -392,7 +392,7 @@ util_parse_822_date (const char *date, time_t *timep, | ... | @@ -392,7 +392,7 @@ util_parse_822_date (const char *date, time_t *timep, |
392 | enum datetime_parse_mode flag) | 392 | enum datetime_parse_mode flag) |
393 | { | 393 | { |
394 | struct tm tm; | 394 | struct tm tm; |
395 | mu_timezone tz; | 395 | struct mu_timezone tz; |
396 | const char *p = date; | 396 | const char *p = date; |
397 | 397 | ||
398 | if (mu_parse822_date_time (&p, date + strlen (date), &tm, &tz) == 0) | 398 | if (mu_parse822_date_time (&p, date + strlen (date), &tm, &tz) == 0) |
... | @@ -409,7 +409,7 @@ util_parse_ctime_date (const char *date, time_t *timep, | ... | @@ -409,7 +409,7 @@ util_parse_ctime_date (const char *date, time_t *timep, |
409 | enum datetime_parse_mode flag) | 409 | enum datetime_parse_mode flag) |
410 | { | 410 | { |
411 | struct tm tm; | 411 | struct tm tm; |
412 | mu_timezone tz; | 412 | struct mu_timezone tz; |
413 | 413 | ||
414 | if (mu_scan_datetime (date, MU_DATETIME_FROM, &tm, &tz, NULL) == 0) | 414 | if (mu_scan_datetime (date, MU_DATETIME_FROM, &tm, &tz, NULL) == 0) |
415 | { | 415 | { | ... | ... |
include/mailutils/datetime.h
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2011 Free Software Foundation, Inc. | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Lesser General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 3 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Lesser General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Lesser General | ||
15 | Public License along with this library. If not, see | ||
16 | <http://www.gnu.org/licenses/>. */ | ||
17 | |||
18 | #ifndef _MAILUTILS_DATETIME_H | ||
19 | #define _MAILUTILS_DATETIME_H | ||
20 | |||
21 | #include <time.h> | ||
22 | #include <mailutils/types.h> | ||
23 | |||
24 | /* ----------------------- */ | ||
25 | /* Date & time functions */ | ||
26 | /* ----------------------- */ | ||
27 | struct mu_timezone | ||
28 | { | ||
29 | int utc_offset; /* Seconds east of UTC. */ | ||
30 | |||
31 | const char *tz_name; | ||
32 | /* Nickname for this timezone, if known. It is always considered | ||
33 | to be a pointer to static string, so will never be freed. */ | ||
34 | }; | ||
35 | |||
36 | int mu_parse_date (const char *p, time_t *rettime, const time_t *now); | ||
37 | |||
38 | time_t mu_utc_offset (void); | ||
39 | time_t mu_tm2time (struct tm *timeptr, struct mu_timezone *tz); | ||
40 | size_t mu_strftime (char *s, size_t max, const char *format, struct tm *tm); | ||
41 | |||
42 | int mu_c_streamftime (mu_stream_t str, const char *fmt, struct tm *tm, | ||
43 | struct mu_timezone *tz); | ||
44 | int mu_scan_datetime (const char *input, const char *fmt, struct tm *tm, | ||
45 | struct mu_timezone *tz, char **endp); | ||
46 | |||
47 | /* Common datetime formats: */ | ||
48 | #define MU_DATETIME_FROM "%a %b %e %H:%M:%S %Y" | ||
49 | /* Length of an envelope date in C locale, | ||
50 | not counting the terminating nul character */ | ||
51 | #define MU_DATETIME_FROM_LENGTH 24 | ||
52 | |||
53 | #define MU_DATETIME_IMAP "%d-%b-%Y %H:%M:%S %z" | ||
54 | #define MU_DATETIME_INTERNALDATE "%d-%b-%Y%$ %H:%M:%S %z" | ||
55 | |||
56 | /* RFC2822 date. Scan format contains considerable allowances which would | ||
57 | stun formatting functions, therefore two distinct formats are provided: | ||
58 | one for outputting and one for scanning: */ | ||
59 | #define MU_DATETIME_FORM_RFC822 "%a, %e %b %Y %H:%M:%S %z" | ||
60 | #define MU_DATETIME_SCAN_RFC822 "%[%a, %]%e %b %Y %H:%M%[:%S%] %z" | ||
61 | |||
62 | #endif |
... | @@ -51,12 +51,6 @@ int mu_envelope_set_destroy (mu_envelope_t envelope, | ... | @@ -51,12 +51,6 @@ int mu_envelope_set_destroy (mu_envelope_t envelope, |
51 | int (*_destroy) (mu_envelope_t), | 51 | int (*_destroy) (mu_envelope_t), |
52 | void *owner); | 52 | void *owner); |
53 | 53 | ||
54 | /* mu_strftime format for envelope dates */ | ||
55 | #define MU_ENVELOPE_DATE_FORMAT "%a %b %d %H:%M:%S %Y" | ||
56 | /* Length of an envelope date in C locale, | ||
57 | not counting the terminating nul character */ | ||
58 | #define MU_ENVELOPE_DATE_LENGTH 24 | ||
59 | |||
60 | #ifdef __cplusplus | 54 | #ifdef __cplusplus |
61 | } | 55 | } |
62 | #endif | 56 | #endif | ... | ... |
... | @@ -21,7 +21,7 @@ | ... | @@ -21,7 +21,7 @@ |
21 | #include <mailutils/iterator.h> | 21 | #include <mailutils/iterator.h> |
22 | #include <mailutils/debug.h> | 22 | #include <mailutils/debug.h> |
23 | #include <mailutils/stream.h> | 23 | #include <mailutils/stream.h> |
24 | #include <mailutils/util.h> | 24 | #include <mailutils/datetime.h> |
25 | #include <mailutils/kwd.h> | 25 | #include <mailutils/kwd.h> |
26 | 26 | ||
27 | #ifdef __cplusplus | 27 | #ifdef __cplusplus | ... | ... |
... | @@ -22,7 +22,7 @@ extern "C" { | ... | @@ -22,7 +22,7 @@ extern "C" { |
22 | #endif | 22 | #endif |
23 | 23 | ||
24 | # include <mailutils/types.h> | 24 | # include <mailutils/types.h> |
25 | # include <mailutils/util.h> | 25 | # include <mailutils/datetime.h> |
26 | # include <time.h> | 26 | # include <time.h> |
27 | 27 | ||
28 | #define MU_IMAPIO_CLIENT 0 | 28 | #define MU_IMAPIO_CLIENT 0 | ... | ... |
... | @@ -25,6 +25,7 @@ | ... | @@ -25,6 +25,7 @@ |
25 | #include <mailutils/attribute.h> | 25 | #include <mailutils/attribute.h> |
26 | #include <mailutils/auth.h> | 26 | #include <mailutils/auth.h> |
27 | #include <mailutils/body.h> | 27 | #include <mailutils/body.h> |
28 | #include <mailutils/datetime.h> | ||
28 | #include <mailutils/debug.h> | 29 | #include <mailutils/debug.h> |
29 | #include <mailutils/envelope.h> | 30 | #include <mailutils/envelope.h> |
30 | #include <mailutils/errno.h> | 31 | #include <mailutils/errno.h> | ... | ... |
... | @@ -24,7 +24,7 @@ | ... | @@ -24,7 +24,7 @@ |
24 | #define _MAILUTILS_PARSE822_H | 24 | #define _MAILUTILS_PARSE822_H |
25 | 25 | ||
26 | #include <mailutils/types.h> | 26 | #include <mailutils/types.h> |
27 | #include <mailutils/util.h> | 27 | #include <mailutils/datetime.h> |
28 | 28 | ||
29 | #ifdef __cplusplus | 29 | #ifdef __cplusplus |
30 | extern "C" { | 30 | extern "C" { |
... | @@ -131,7 +131,7 @@ extern int mu_parse822_date (const char **p, const char *e, int *day, | ... | @@ -131,7 +131,7 @@ extern int mu_parse822_date (const char **p, const char *e, int *day, |
131 | extern int mu_parse822_time (const char **p, const char *e, int *h, | 131 | extern int mu_parse822_time (const char **p, const char *e, int *h, |
132 | int *m, int *s, int *tz, const char **tz_name); | 132 | int *m, int *s, int *tz, const char **tz_name); |
133 | extern int mu_parse822_date_time (const char **p, const char *e, | 133 | extern int mu_parse822_date_time (const char **p, const char *e, |
134 | struct tm *tm, mu_timezone *tz); | 134 | struct tm *tm, struct mu_timezone *tz); |
135 | 135 | ||
136 | 136 | ||
137 | #ifdef __cplusplus | 137 | #ifdef __cplusplus | ... | ... |
... | @@ -21,8 +21,6 @@ | ... | @@ -21,8 +21,6 @@ |
21 | 21 | ||
22 | /* A collection of utility routines that don't belong somewhere else. */ | 22 | /* A collection of utility routines that don't belong somewhere else. */ |
23 | 23 | ||
24 | #include <time.h> | ||
25 | |||
26 | #include <mailutils/list.h> | 24 | #include <mailutils/list.h> |
27 | #include <mailutils/types.h> | 25 | #include <mailutils/types.h> |
28 | 26 | ||
... | @@ -47,42 +45,6 @@ void mu_str_url_decode_inline (char *str); | ... | @@ -47,42 +45,6 @@ void mu_str_url_decode_inline (char *str); |
47 | int mu_str_url_decode (char **ptr, const char *s); | 45 | int mu_str_url_decode (char **ptr, const char *s); |
48 | 46 | ||
49 | /* ----------------------- */ | 47 | /* ----------------------- */ |
50 | /* Date & time functions */ | ||
51 | /* ----------------------- */ | ||
52 | struct mu_timezone | ||
53 | { | ||
54 | int utc_offset; /* Seconds east of UTC. */ | ||
55 | |||
56 | const char *tz_name; | ||
57 | /* Nickname for this timezone, if known. It is always considered | ||
58 | to be a pointer to static string, so will never be freed. */ | ||
59 | }; | ||
60 | |||
61 | typedef struct mu_timezone mu_timezone; | ||
62 | |||
63 | int mu_parse_date (const char *p, time_t *rettime, const time_t *now); | ||
64 | |||
65 | time_t mu_utc_offset (void); | ||
66 | time_t mu_tm2time (struct tm *timeptr, mu_timezone *tz); | ||
67 | size_t mu_strftime (char *s, size_t max, const char *format, struct tm *tm); | ||
68 | |||
69 | int mu_c_streamftime (mu_stream_t str, const char *fmt, struct tm *tm, | ||
70 | struct mu_timezone *tz); | ||
71 | int mu_scan_datetime (const char *input, const char *fmt, struct tm *tm, | ||
72 | struct mu_timezone *tz, char **endp); | ||
73 | |||
74 | /* Common datetime formats: */ | ||
75 | #define MU_DATETIME_FROM "%a %b %e %H:%M:%S %Y" | ||
76 | #define MU_DATETIME_IMAP "%d-%b-%Y %H:%M:%S %z" | ||
77 | #define MU_DATETIME_INTERNALDATE "%d-%b-%Y%$ %H:%M:%S %z" | ||
78 | |||
79 | /* RFC2822 date. Scan format contains considerable allowances which would | ||
80 | stun formatting functions, therefore two distinct formats are provided: | ||
81 | one for outputting and one for scanning: */ | ||
82 | #define MU_DATETIME_FORM_RFC822 "%a, %e %b %Y %H:%M:%S %z" | ||
83 | #define MU_DATETIME_SCAN_RFC822 "%[%a, %]%e %b %Y %H:%M%[:%S%] %z" | ||
84 | |||
85 | /* ----------------------- */ | ||
86 | /* File & path names. */ | 48 | /* File & path names. */ |
87 | /* ----------------------- */ | 49 | /* ----------------------- */ |
88 | char *mu_get_homedir (void); | 50 | char *mu_get_homedir (void); | ... | ... |
... | @@ -63,6 +63,7 @@ | ... | @@ -63,6 +63,7 @@ |
63 | #include <mailutils/locker.h> | 63 | #include <mailutils/locker.h> |
64 | #include <mailutils/message.h> | 64 | #include <mailutils/message.h> |
65 | #include <mailutils/util.h> | 65 | #include <mailutils/util.h> |
66 | #include <mailutils/datetime.h> | ||
66 | #include <mailutils/property.h> | 67 | #include <mailutils/property.h> |
67 | #include <mailutils/stream.h> | 68 | #include <mailutils/stream.h> |
68 | #include <mailutils/url.h> | 69 | #include <mailutils/url.h> | ... | ... |
... | @@ -23,6 +23,7 @@ | ... | @@ -23,6 +23,7 @@ |
23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
24 | #include <string.h> | 24 | #include <string.h> |
25 | #include <mailutils/diag.h> | 25 | #include <mailutils/diag.h> |
26 | #include <mailutils/datetime.h> | ||
26 | #include <mailutils/util.h> | 27 | #include <mailutils/util.h> |
27 | #include <mailutils/stream.h> | 28 | #include <mailutils/stream.h> |
28 | #include <mailutils/errno.h> | 29 | #include <mailutils/errno.h> |
... | @@ -123,7 +124,7 @@ ISO_8601_weekdays (int yday, int wday) | ... | @@ -123,7 +124,7 @@ ISO_8601_weekdays (int yday, int wday) |
123 | /* Convert struct tm into time_t, taking into account timezone offset. */ | 124 | /* Convert struct tm into time_t, taking into account timezone offset. */ |
124 | /* FIXME: It does not take DST into account */ | 125 | /* FIXME: It does not take DST into account */ |
125 | time_t | 126 | time_t |
126 | mu_tm2time (struct tm *tm, mu_timezone *tz) | 127 | mu_tm2time (struct tm *tm, struct mu_timezone *tz) |
127 | { | 128 | { |
128 | time_t t; | 129 | time_t t; |
129 | int day; | 130 | int day; | ... | ... |
... | @@ -28,6 +28,7 @@ | ... | @@ -28,6 +28,7 @@ |
28 | #include <mailutils/cctype.h> | 28 | #include <mailutils/cctype.h> |
29 | #include <mailutils/message.h> | 29 | #include <mailutils/message.h> |
30 | #include <mailutils/header.h> | 30 | #include <mailutils/header.h> |
31 | #include <mailutils/datetime.h> | ||
31 | #include <mailutils/util.h> | 32 | #include <mailutils/util.h> |
32 | #include <mailutils/io.h> | 33 | #include <mailutils/io.h> |
33 | #include <mailutils/envelope.h> | 34 | #include <mailutils/envelope.h> | ... | ... |
... | @@ -18,7 +18,7 @@ | ... | @@ -18,7 +18,7 @@ |
18 | #ifdef HAVE_CONFIG_H | 18 | #ifdef HAVE_CONFIG_H |
19 | # include <config.h> | 19 | # include <config.h> |
20 | #endif | 20 | #endif |
21 | #include <mailutils/util.h> | 21 | #include <mailutils/datetime.h> |
22 | #include <mailutils/stream.h> | 22 | #include <mailutils/stream.h> |
23 | #include <mailutils/errno.h> | 23 | #include <mailutils/errno.h> |
24 | #include <mailutils/cstr.h> | 24 | #include <mailutils/cstr.h> | ... | ... |
... | @@ -19,7 +19,7 @@ | ... | @@ -19,7 +19,7 @@ |
19 | #include <mailutils/stream.h> | 19 | #include <mailutils/stream.h> |
20 | #include <mailutils/errno.h> | 20 | #include <mailutils/errno.h> |
21 | #include <mailutils/sys/imapio.h> | 21 | #include <mailutils/sys/imapio.h> |
22 | #include <mailutils/util.h> | 22 | #include <mailutils/datetime.h> |
23 | 23 | ||
24 | int | 24 | int |
25 | mu_imapio_send_time (struct _mu_imapio *io, struct tm *tm, | 25 | mu_imapio_send_time (struct _mu_imapio *io, struct tm *tm, | ... | ... |
... | @@ -28,6 +28,7 @@ | ... | @@ -28,6 +28,7 @@ |
28 | #include <mailutils/errno.h> | 28 | #include <mailutils/errno.h> |
29 | #include <mailutils/envelope.h> | 29 | #include <mailutils/envelope.h> |
30 | #include <mailutils/util.h> | 30 | #include <mailutils/util.h> |
31 | #include <mailutils/datetime.h> | ||
31 | #include <mailutils/header.h> | 32 | #include <mailutils/header.h> |
32 | #include <mailutils/mu_auth.h> | 33 | #include <mailutils/mu_auth.h> |
33 | #include <mailutils/address.h> | 34 | #include <mailutils/address.h> |
... | @@ -49,14 +50,14 @@ message_envelope_date (mu_envelope_t envelope, char *buf, size_t len, | ... | @@ -49,14 +50,14 @@ message_envelope_date (mu_envelope_t envelope, char *buf, size_t len, |
49 | 50 | ||
50 | if (buf == NULL || len == 0) | 51 | if (buf == NULL || len == 0) |
51 | { | 52 | { |
52 | n = MU_ENVELOPE_DATE_LENGTH; | 53 | n = MU_DATETIME_FROM_LENGTH; |
53 | } | 54 | } |
54 | else | 55 | else |
55 | { | 56 | { |
56 | char tmpbuf[MU_ENVELOPE_DATE_LENGTH+1]; | 57 | char tmpbuf[MU_DATETIME_FROM_LENGTH+1]; |
57 | t = time (NULL); | 58 | t = time (NULL); |
58 | n = mu_strftime (tmpbuf, sizeof tmpbuf, | 59 | n = mu_strftime (tmpbuf, sizeof tmpbuf, |
59 | MU_ENVELOPE_DATE_FORMAT, localtime (&t)); | 60 | MU_DATETIME_FROM, localtime (&t)); |
60 | n = mu_cpystr (buf, tmpbuf, len); | 61 | n = mu_cpystr (buf, tmpbuf, len); |
61 | } | 62 | } |
62 | if (pnwrite) | 63 | if (pnwrite) | ... | ... |
... | @@ -36,6 +36,7 @@ | ... | @@ -36,6 +36,7 @@ |
36 | #include <mailutils/body.h> | 36 | #include <mailutils/body.h> |
37 | #include <mailutils/stream.h> | 37 | #include <mailutils/stream.h> |
38 | #include <mailutils/util.h> | 38 | #include <mailutils/util.h> |
39 | #include <mailutils/datetime.h> | ||
39 | #include <mailutils/errno.h> | 40 | #include <mailutils/errno.h> |
40 | #include <mailutils/error.h> | 41 | #include <mailutils/error.h> |
41 | #include <mailutils/cctype.h> | 42 | #include <mailutils/cctype.h> |
... | @@ -291,11 +292,11 @@ _message_open (mu_stream_t stream) | ... | @@ -291,11 +292,11 @@ _message_open (mu_stream_t stream) |
291 | { | 292 | { |
292 | struct tm *tm; | 293 | struct tm *tm; |
293 | time_t t; | 294 | time_t t; |
294 | char date[80]; /* FIXME: This size is way too big */ | 295 | char date[MU_DATETIME_FROM_LENGTH+1]; |
295 | 296 | ||
296 | time(&t); | 297 | time (&t); |
297 | tm = gmtime(&t); | 298 | tm = gmtime (&t); |
298 | mu_strftime (date, sizeof (date), "%a %b %e %H:%M:%S %Y", tm); | 299 | mu_strftime (date, sizeof (date), MU_DATETIME_FROM, tm); |
299 | env_date = strdup (date); | 300 | env_date = strdup (date); |
300 | } | 301 | } |
301 | 302 | ... | ... |
... | @@ -23,7 +23,7 @@ | ... | @@ -23,7 +23,7 @@ |
23 | #include <string.h> | 23 | #include <string.h> |
24 | #include <mailutils/error.h> | 24 | #include <mailutils/error.h> |
25 | #include <mailutils/errno.h> | 25 | #include <mailutils/errno.h> |
26 | #include <mailutils/util.h> | 26 | #include <mailutils/datetime.h> |
27 | #include <mailutils/stream.h> | 27 | #include <mailutils/stream.h> |
28 | #include <mailutils/cctype.h> | 28 | #include <mailutils/cctype.h> |
29 | #include <mailutils/cstr.h> | 29 | #include <mailutils/cstr.h> | ... | ... |
... | @@ -23,7 +23,7 @@ | ... | @@ -23,7 +23,7 @@ |
23 | #include <string.h> | 23 | #include <string.h> |
24 | #include <mailutils/error.h> | 24 | #include <mailutils/error.h> |
25 | #include <mailutils/errno.h> | 25 | #include <mailutils/errno.h> |
26 | #include <mailutils/util.h> | 26 | #include <mailutils/datetime.h> |
27 | #include <mailutils/stream.h> | 27 | #include <mailutils/stream.h> |
28 | #include <mailutils/cctype.h> | 28 | #include <mailutils/cctype.h> |
29 | #include <mailutils/cstr.h> | 29 | #include <mailutils/cstr.h> | ... | ... |
... | @@ -79,7 +79,7 @@ mu_scm_message_print (SCM message_smob, SCM port, scm_print_state * pstate) | ... | @@ -79,7 +79,7 @@ mu_scm_message_print (SCM message_smob, SCM port, scm_print_state * pstate) |
79 | const char *p; | 79 | const char *p; |
80 | size_t m_size = 0, m_lines = 0; | 80 | size_t m_size = 0, m_lines = 0; |
81 | struct tm tm; | 81 | struct tm tm; |
82 | mu_timezone tz; | 82 | struct mu_timezone tz; |
83 | char datebuf[sizeof ("Mon Jan 01 00:00")]; /* Warning: length must be > 9 */ | 83 | char datebuf[sizeof ("Mon Jan 01 00:00")]; /* Warning: length must be > 9 */ |
84 | 84 | ||
85 | mu_message_get_envelope (mum->msg, &env); | 85 | mu_message_get_envelope (mum->msg, &env); |
... | @@ -404,7 +404,7 @@ SCM_DEFINE_PUBLIC (scm_mu_message_get_envelope_date, "mu-message-get-envelope-da | ... | @@ -404,7 +404,7 @@ SCM_DEFINE_PUBLIC (scm_mu_message_get_envelope_date, "mu-message-get-envelope-da |
404 | int status; | 404 | int status; |
405 | const char *sdate; | 405 | const char *sdate; |
406 | struct tm tm; | 406 | struct tm tm; |
407 | mu_timezone tz; | 407 | struct mu_timezone tz; |
408 | 408 | ||
409 | SCM_ASSERT (mu_scm_is_message (mesg), mesg, SCM_ARG1, FUNC_NAME); | 409 | SCM_ASSERT (mu_scm_is_message (mesg), mesg, SCM_ARG1, FUNC_NAME); |
410 | msg = mu_scm_message_get (mesg); | 410 | msg = mu_scm_message_get (mesg); | ... | ... |
... | @@ -38,6 +38,7 @@ | ... | @@ -38,6 +38,7 @@ |
38 | #include <mailutils/address.h> | 38 | #include <mailutils/address.h> |
39 | #include <mailutils/registrar.h> | 39 | #include <mailutils/registrar.h> |
40 | #include <mailutils/util.h> | 40 | #include <mailutils/util.h> |
41 | #include <mailutils/datetime.h> | ||
41 | #include <mailutils/stream.h> | 42 | #include <mailutils/stream.h> |
42 | #include <mailutils/debug.h> | 43 | #include <mailutils/debug.h> |
43 | #include <mailutils/attribute.h> | 44 | #include <mailutils/attribute.h> | ... | ... |
... | @@ -188,7 +188,7 @@ mime_create_ds (mu_mime_t mime, mu_message_t orig) | ... | @@ -188,7 +188,7 @@ mime_create_ds (mu_mime_t mime, mu_message_t orig) |
188 | char datestr[80]; | 188 | char datestr[80]; |
189 | time_t t = time (NULL); | 189 | time_t t = time (NULL); |
190 | struct tm tm, *tmp; | 190 | struct tm tm, *tmp; |
191 | mu_timezone tz; | 191 | struct mu_timezone tz; |
192 | mu_envelope_t env; | 192 | mu_envelope_t env; |
193 | const char *p; | 193 | const char *p; |
194 | 194 | ... | ... |
... | @@ -29,6 +29,7 @@ | ... | @@ -29,6 +29,7 @@ |
29 | #include <mailutils/io.h> | 29 | #include <mailutils/io.h> |
30 | #include <mailutils/filter.h> | 30 | #include <mailutils/filter.h> |
31 | #include <mailutils/cctype.h> | 31 | #include <mailutils/cctype.h> |
32 | #include <mailutils/datetime.h> | ||
32 | 33 | ||
33 | #define ATTRIBUTE_IS_DELETED(flag) (flag & MU_ATTRIBUTE_DELETED) | 34 | #define ATTRIBUTE_IS_DELETED(flag) (flag & MU_ATTRIBUTE_DELETED) |
34 | #define ATTRIBUTE_IS_EQUAL(flag1, flag2) (flag1 == flag2) | 35 | #define ATTRIBUTE_IS_EQUAL(flag1, flag2) (flag1 == flag2) |
... | @@ -859,22 +860,23 @@ restore_date (mu_message_t msg, char **pret) | ... | @@ -859,22 +860,23 @@ restore_date (mu_message_t msg, char **pret) |
859 | mu_header_t hdr; | 860 | mu_header_t hdr; |
860 | const char *s; | 861 | const char *s; |
861 | char *date = NULL; | 862 | char *date = NULL; |
862 | time_t t; | 863 | struct tm tm; |
864 | struct mu_timezone tz; | ||
863 | 865 | ||
864 | if (mu_message_get_header (msg, &hdr) == 0) | 866 | if (mu_message_get_header (msg, &hdr) == 0) |
865 | mu_header_sget_value (hdr, MU_HEADER_DATE, &s); | 867 | mu_header_sget_value (hdr, MU_HEADER_DATE, &s); |
866 | 868 | ||
867 | if (s && mu_parse_date (s, &t, NULL)) | 869 | if (s && mu_scan_datetime (s, MU_DATETIME_SCAN_RFC822, &tm, &tz, NULL) == 0) |
868 | { | 870 | { |
869 | char datebuf[MU_ENVELOPE_DATE_LENGTH+1]; | 871 | char datebuf[MU_DATETIME_FROM_LENGTH+1]; |
870 | 872 | ||
871 | /* FIXME: 1. Preserve TZ info */ | 873 | /* FIXME: Compensate for TZ differences. */ |
872 | mu_strftime (datebuf, sizeof datebuf, MU_ENVELOPE_DATE_FORMAT, | 874 | mu_strftime (datebuf, sizeof datebuf, MU_DATETIME_FROM, &tm); |
873 | localtime (&t)); | ||
874 | date = strdup (datebuf); | 875 | date = strdup (datebuf); |
875 | } | 876 | } |
876 | else | 877 | else |
877 | { | 878 | { |
879 | time_t t; | ||
878 | time (&t); | 880 | time (&t); |
879 | date = strdup (ctime (&t)); | 881 | date = strdup (ctime (&t)); |
880 | } | 882 | } | ... | ... |
... | @@ -208,7 +208,7 @@ hdr_date (struct header_call_args *args, void *data) | ... | @@ -208,7 +208,7 @@ hdr_date (struct header_call_args *args, void *data) |
208 | { | 208 | { |
209 | const char *p; | 209 | const char *p; |
210 | struct tm tm; | 210 | struct tm tm; |
211 | mu_timezone tz; | 211 | struct mu_timezone tz; |
212 | mu_envelope_t env; | 212 | mu_envelope_t env; |
213 | 213 | ||
214 | mu_message_get_envelope (args->msg, &env); | 214 | mu_message_get_envelope (args->msg, &env); | ... | ... |
... | @@ -71,6 +71,7 @@ | ... | @@ -71,6 +71,7 @@ |
71 | #include <mailutils/mailer.h> | 71 | #include <mailutils/mailer.h> |
72 | #include <mailutils/message.h> | 72 | #include <mailutils/message.h> |
73 | #include <mailutils/util.h> | 73 | #include <mailutils/util.h> |
74 | #include <mailutils/datetime.h> | ||
74 | #include <mailutils/registrar.h> | 75 | #include <mailutils/registrar.h> |
75 | #include <mailutils/stream.h> | 76 | #include <mailutils/stream.h> |
76 | #include <mailutils/url.h> | 77 | #include <mailutils/url.h> | ... | ... |
... | @@ -59,6 +59,7 @@ | ... | @@ -59,6 +59,7 @@ |
59 | #include <mailutils/prog.h> | 59 | #include <mailutils/prog.h> |
60 | #include <mailutils/mh.h> | 60 | #include <mailutils/mh.h> |
61 | #include <mailutils/stdstream.h> | 61 | #include <mailutils/stdstream.h> |
62 | #include <mailutils/datetime.h> | ||
62 | 63 | ||
63 | #include <mu_umaxtostr.h> | 64 | #include <mu_umaxtostr.h> |
64 | 65 | ... | ... |
... | @@ -1160,7 +1160,7 @@ builtin_putnumf (struct mh_machine *mach) | ... | @@ -1160,7 +1160,7 @@ builtin_putnumf (struct mh_machine *mach) |
1160 | } | 1160 | } |
1161 | 1161 | ||
1162 | static int | 1162 | static int |
1163 | _parse_date (struct mh_machine *mach, struct tm *tm, mu_timezone *tz) | 1163 | _parse_date (struct mh_machine *mach, struct tm *tm, struct mu_timezone *tz) |
1164 | { | 1164 | { |
1165 | char *date = strobj_ptr (&mach->arg_str); | 1165 | char *date = strobj_ptr (&mach->arg_str); |
1166 | const char *p = date; | 1166 | const char *p = date; |
... | @@ -1183,7 +1183,7 @@ static void | ... | @@ -1183,7 +1183,7 @@ static void |
1183 | builtin_sec (struct mh_machine *mach) | 1183 | builtin_sec (struct mh_machine *mach) |
1184 | { | 1184 | { |
1185 | struct tm tm; | 1185 | struct tm tm; |
1186 | mu_timezone tz; | 1186 | struct mu_timezone tz; |
1187 | 1187 | ||
1188 | if (_parse_date (mach, &tm, &tz)) | 1188 | if (_parse_date (mach, &tm, &tz)) |
1189 | return; | 1189 | return; |
... | @@ -1196,7 +1196,7 @@ static void | ... | @@ -1196,7 +1196,7 @@ static void |
1196 | builtin_min (struct mh_machine *mach) | 1196 | builtin_min (struct mh_machine *mach) |
1197 | { | 1197 | { |
1198 | struct tm tm; | 1198 | struct tm tm; |
1199 | mu_timezone tz; | 1199 | struct mu_timezone tz; |
1200 | 1200 | ||
1201 | if (_parse_date (mach, &tm, &tz)) | 1201 | if (_parse_date (mach, &tm, &tz)) |
1202 | return; | 1202 | return; |
... | @@ -1209,7 +1209,7 @@ static void | ... | @@ -1209,7 +1209,7 @@ static void |
1209 | builtin_hour (struct mh_machine *mach) | 1209 | builtin_hour (struct mh_machine *mach) |
1210 | { | 1210 | { |
1211 | struct tm tm; | 1211 | struct tm tm; |
1212 | mu_timezone tz; | 1212 | struct mu_timezone tz; |
1213 | 1213 | ||
1214 | if (_parse_date (mach, &tm, &tz)) | 1214 | if (_parse_date (mach, &tm, &tz)) |
1215 | return; | 1215 | return; |
... | @@ -1222,7 +1222,7 @@ static void | ... | @@ -1222,7 +1222,7 @@ static void |
1222 | builtin_wday (struct mh_machine *mach) | 1222 | builtin_wday (struct mh_machine *mach) |
1223 | { | 1223 | { |
1224 | struct tm tm; | 1224 | struct tm tm; |
1225 | mu_timezone tz; | 1225 | struct mu_timezone tz; |
1226 | 1226 | ||
1227 | if (_parse_date (mach, &tm, &tz)) | 1227 | if (_parse_date (mach, &tm, &tz)) |
1228 | return; | 1228 | return; |
... | @@ -1235,7 +1235,7 @@ static void | ... | @@ -1235,7 +1235,7 @@ static void |
1235 | builtin_day (struct mh_machine *mach) | 1235 | builtin_day (struct mh_machine *mach) |
1236 | { | 1236 | { |
1237 | struct tm tm; | 1237 | struct tm tm; |
1238 | mu_timezone tz; | 1238 | struct mu_timezone tz; |
1239 | char buf[80]; | 1239 | char buf[80]; |
1240 | 1240 | ||
1241 | if (_parse_date (mach, &tm, &tz)) | 1241 | if (_parse_date (mach, &tm, &tz)) |
... | @@ -1251,7 +1251,7 @@ static void | ... | @@ -1251,7 +1251,7 @@ static void |
1251 | builtin_weekday (struct mh_machine *mach) | 1251 | builtin_weekday (struct mh_machine *mach) |
1252 | { | 1252 | { |
1253 | struct tm tm; | 1253 | struct tm tm; |
1254 | mu_timezone tz; | 1254 | struct mu_timezone tz; |
1255 | char buf[80]; | 1255 | char buf[80]; |
1256 | 1256 | ||
1257 | if (_parse_date (mach, &tm, &tz)) | 1257 | if (_parse_date (mach, &tm, &tz)) |
... | @@ -1268,7 +1268,7 @@ static void | ... | @@ -1268,7 +1268,7 @@ static void |
1268 | builtin_sday (struct mh_machine *mach) | 1268 | builtin_sday (struct mh_machine *mach) |
1269 | { | 1269 | { |
1270 | struct tm tm; | 1270 | struct tm tm; |
1271 | mu_timezone tz; | 1271 | struct mu_timezone tz; |
1272 | 1272 | ||
1273 | /*FIXME: more elaborate check needed */ | 1273 | /*FIXME: more elaborate check needed */ |
1274 | if (_parse_date (mach, &tm, &tz)) | 1274 | if (_parse_date (mach, &tm, &tz)) |
... | @@ -1282,7 +1282,7 @@ static void | ... | @@ -1282,7 +1282,7 @@ static void |
1282 | builtin_mday (struct mh_machine *mach) | 1282 | builtin_mday (struct mh_machine *mach) |
1283 | { | 1283 | { |
1284 | struct tm tm; | 1284 | struct tm tm; |
1285 | mu_timezone tz; | 1285 | struct mu_timezone tz; |
1286 | 1286 | ||
1287 | if (_parse_date (mach, &tm, &tz)) | 1287 | if (_parse_date (mach, &tm, &tz)) |
1288 | return; | 1288 | return; |
... | @@ -1295,7 +1295,7 @@ static void | ... | @@ -1295,7 +1295,7 @@ static void |
1295 | builtin_yday (struct mh_machine *mach) | 1295 | builtin_yday (struct mh_machine *mach) |
1296 | { | 1296 | { |
1297 | struct tm tm; | 1297 | struct tm tm; |
1298 | mu_timezone tz; | 1298 | struct mu_timezone tz; |
1299 | 1299 | ||
1300 | if (_parse_date (mach, &tm, &tz)) | 1300 | if (_parse_date (mach, &tm, &tz)) |
1301 | return; | 1301 | return; |
... | @@ -1308,7 +1308,7 @@ static void | ... | @@ -1308,7 +1308,7 @@ static void |
1308 | builtin_mon (struct mh_machine *mach) | 1308 | builtin_mon (struct mh_machine *mach) |
1309 | { | 1309 | { |
1310 | struct tm tm; | 1310 | struct tm tm; |
1311 | mu_timezone tz; | 1311 | struct mu_timezone tz; |
1312 | 1312 | ||
1313 | if (_parse_date (mach, &tm, &tz)) | 1313 | if (_parse_date (mach, &tm, &tz)) |
1314 | return; | 1314 | return; |
... | @@ -1321,7 +1321,7 @@ static void | ... | @@ -1321,7 +1321,7 @@ static void |
1321 | builtin_month (struct mh_machine *mach) | 1321 | builtin_month (struct mh_machine *mach) |
1322 | { | 1322 | { |
1323 | struct tm tm; | 1323 | struct tm tm; |
1324 | mu_timezone tz; | 1324 | struct mu_timezone tz; |
1325 | char buf[80]; | 1325 | char buf[80]; |
1326 | 1326 | ||
1327 | if (_parse_date (mach, &tm, &tz)) | 1327 | if (_parse_date (mach, &tm, &tz)) |
... | @@ -1337,7 +1337,7 @@ static void | ... | @@ -1337,7 +1337,7 @@ static void |
1337 | builtin_lmonth (struct mh_machine *mach) | 1337 | builtin_lmonth (struct mh_machine *mach) |
1338 | { | 1338 | { |
1339 | struct tm tm; | 1339 | struct tm tm; |
1340 | mu_timezone tz; | 1340 | struct mu_timezone tz; |
1341 | char buf[80]; | 1341 | char buf[80]; |
1342 | 1342 | ||
1343 | if (_parse_date (mach, &tm, &tz)) | 1343 | if (_parse_date (mach, &tm, &tz)) |
... | @@ -1353,7 +1353,7 @@ static void | ... | @@ -1353,7 +1353,7 @@ static void |
1353 | builtin_year (struct mh_machine *mach) | 1353 | builtin_year (struct mh_machine *mach) |
1354 | { | 1354 | { |
1355 | struct tm tm; | 1355 | struct tm tm; |
1356 | mu_timezone tz; | 1356 | struct mu_timezone tz; |
1357 | 1357 | ||
1358 | if (_parse_date (mach, &tm, &tz)) | 1358 | if (_parse_date (mach, &tm, &tz)) |
1359 | return; | 1359 | return; |
... | @@ -1366,7 +1366,7 @@ static void | ... | @@ -1366,7 +1366,7 @@ static void |
1366 | builtin_zone (struct mh_machine *mach) | 1366 | builtin_zone (struct mh_machine *mach) |
1367 | { | 1367 | { |
1368 | struct tm tm; | 1368 | struct tm tm; |
1369 | mu_timezone tz; | 1369 | struct mu_timezone tz; |
1370 | 1370 | ||
1371 | if (_parse_date (mach, &tm, &tz)) | 1371 | if (_parse_date (mach, &tm, &tz)) |
1372 | return; | 1372 | return; |
... | @@ -1379,7 +1379,7 @@ static void | ... | @@ -1379,7 +1379,7 @@ static void |
1379 | builtin_tzone (struct mh_machine *mach) | 1379 | builtin_tzone (struct mh_machine *mach) |
1380 | { | 1380 | { |
1381 | struct tm tm; | 1381 | struct tm tm; |
1382 | mu_timezone tz; | 1382 | struct mu_timezone tz; |
1383 | 1383 | ||
1384 | if (_parse_date (mach, &tm, &tz)) | 1384 | if (_parse_date (mach, &tm, &tz)) |
1385 | return; | 1385 | return; |
... | @@ -1410,7 +1410,7 @@ static void | ... | @@ -1410,7 +1410,7 @@ static void |
1410 | builtin_szone (struct mh_machine *mach) | 1410 | builtin_szone (struct mh_machine *mach) |
1411 | { | 1411 | { |
1412 | struct tm tm; | 1412 | struct tm tm; |
1413 | mu_timezone tz; | 1413 | struct mu_timezone tz; |
1414 | 1414 | ||
1415 | /*FIXME: more elaborate check needed */ | 1415 | /*FIXME: more elaborate check needed */ |
1416 | if (_parse_date (mach, &tm, &tz)) | 1416 | if (_parse_date (mach, &tm, &tz)) |
... | @@ -1438,7 +1438,7 @@ static void | ... | @@ -1438,7 +1438,7 @@ static void |
1438 | builtin_dst (struct mh_machine *mach) | 1438 | builtin_dst (struct mh_machine *mach) |
1439 | { | 1439 | { |
1440 | struct tm tm; | 1440 | struct tm tm; |
1441 | mu_timezone tz; | 1441 | struct mu_timezone tz; |
1442 | 1442 | ||
1443 | if (_parse_date (mach, &tm, &tz)) | 1443 | if (_parse_date (mach, &tm, &tz)) |
1444 | return; | 1444 | return; |
... | @@ -1454,7 +1454,7 @@ static void | ... | @@ -1454,7 +1454,7 @@ static void |
1454 | builtin_clock (struct mh_machine *mach) | 1454 | builtin_clock (struct mh_machine *mach) |
1455 | { | 1455 | { |
1456 | struct tm tm; | 1456 | struct tm tm; |
1457 | mu_timezone tz; | 1457 | struct mu_timezone tz; |
1458 | 1458 | ||
1459 | if (_parse_date (mach, &tm, &tz)) | 1459 | if (_parse_date (mach, &tm, &tz)) |
1460 | return; | 1460 | return; |
... | @@ -1466,7 +1466,7 @@ void | ... | @@ -1466,7 +1466,7 @@ void |
1466 | builtin_rclock (struct mh_machine *mach) | 1466 | builtin_rclock (struct mh_machine *mach) |
1467 | { | 1467 | { |
1468 | struct tm tm; | 1468 | struct tm tm; |
1469 | mu_timezone tz; | 1469 | struct mu_timezone tz; |
1470 | time_t now = time (NULL); | 1470 | time_t now = time (NULL); |
1471 | 1471 | ||
1472 | if (_parse_date (mach, &tm, &tz)) | 1472 | if (_parse_date (mach, &tm, &tz)) |
... | @@ -1493,7 +1493,7 @@ static void | ... | @@ -1493,7 +1493,7 @@ static void |
1493 | date_cvt (struct mh_machine *mach, int pretty) | 1493 | date_cvt (struct mh_machine *mach, int pretty) |
1494 | { | 1494 | { |
1495 | struct tm tm; | 1495 | struct tm tm; |
1496 | mu_timezone tz; | 1496 | struct mu_timezone tz; |
1497 | char buf[80]; | 1497 | char buf[80]; |
1498 | int i, len; | 1498 | int i, len; |
1499 | const char *tzname = NULL; | 1499 | const char *tzname = NULL; |
... | @@ -1567,7 +1567,7 @@ static void | ... | @@ -1567,7 +1567,7 @@ static void |
1567 | builtin_nodate (struct mh_machine *mach) | 1567 | builtin_nodate (struct mh_machine *mach) |
1568 | { | 1568 | { |
1569 | struct tm tm; | 1569 | struct tm tm; |
1570 | mu_timezone tz; | 1570 | struct mu_timezone tz; |
1571 | 1571 | ||
1572 | mach->arg_num = _parse_date (mach, &tm, &tz); | 1572 | mach->arg_num = _parse_date (mach, &tm, &tz); |
1573 | } | 1573 | } | ... | ... |
... | @@ -336,7 +336,7 @@ static int | ... | @@ -336,7 +336,7 @@ static int |
336 | _parse_822_date (char *date, time_t * timep) | 336 | _parse_822_date (char *date, time_t * timep) |
337 | { | 337 | { |
338 | struct tm tm; | 338 | struct tm tm; |
339 | mu_timezone tz; | 339 | struct mu_timezone tz; |
340 | const char *p = date; | 340 | const char *p = date; |
341 | 341 | ||
342 | if (mu_parse822_date_time (&p, date + strlen (date), &tm, &tz) == 0) | 342 | if (mu_parse822_date_time (&p, date + strlen (date), &tm, &tz) == 0) | ... | ... |
... | @@ -179,13 +179,13 @@ print_unix_header (mu_message_t message) | ... | @@ -179,13 +179,13 @@ print_unix_header (mu_message_t message) |
179 | 179 | ||
180 | if (mu_envelope_sget_date (envelope, &buf)) | 180 | if (mu_envelope_sget_date (envelope, &buf)) |
181 | { | 181 | { |
182 | char datebuf[MU_ENVELOPE_DATE_LENGTH+1]; | 182 | char datebuf[MU_DATETIME_FROM_LENGTH+1]; |
183 | time_t t; | 183 | time_t t; |
184 | struct tm *tm; | 184 | struct tm *tm; |
185 | 185 | ||
186 | t = time (NULL); | 186 | t = time (NULL); |
187 | tm = localtime (&t); | 187 | tm = localtime (&t); |
188 | mu_strftime (datebuf, sizeof datebuf, "%a %b %d %H:%M:%S %Y", tm); | 188 | mu_strftime (datebuf, sizeof datebuf, MU_DATETIME_FROM, tm); |
189 | buf = datebuf; | 189 | buf = datebuf; |
190 | } | 190 | } |
191 | 191 | ... | ... |
... | @@ -50,7 +50,7 @@ | ... | @@ -50,7 +50,7 @@ |
50 | #include <mailutils/error.h> | 50 | #include <mailutils/error.h> |
51 | #include <mailutils/envelope.h> | 51 | #include <mailutils/envelope.h> |
52 | #include <mailutils/wordsplit.h> | 52 | #include <mailutils/wordsplit.h> |
53 | #include <mailutils/util.h> | 53 | #include <mailutils/datetime.h> |
54 | 54 | ||
55 | int msglist (mu_mailbox_t mbox, int show_all, int argc, char **argv, int **set, int *n); | 55 | int msglist (mu_mailbox_t mbox, int show_all, int argc, char **argv, int **set, int *n); |
56 | 56 | ... | ... |
-
Please register or sign in to post a comment