Commit 76cc3308 76cc330864a9680365123c86f8d5a394f952dcc5 by Sergey Poznyakoff

New function mu_datetime_tz_local.

The function initializes mu_timezone structure to the local timezone.

* include/mailutils/datetime.h (mu_utc_offset): Change return type.
(mu_datetime_tz_local): New proto.
* libmailutils/datetime/tzlocal.c: New file.
* libmailutils/datetime/Makefile.am: Add new file.
* libmailutils/datetime/scantime.c (mu_scan_datetime): Use
mu_datetime_tz_local to initialize local TZ.
* mh/mh_format.c (_parse_date): Likewise.
* libmailutils/datetime/utcoff.c (mu_utc_offset): Returns int.
* libmu_sieve/actions.c (mime_create_ds): Use mu_c_streamftime
to format time directly to stream.
1 parent 912224f8
......@@ -58,7 +58,8 @@ struct mu_timezone
int mu_parse_date (const char *p, time_t *rettime, const time_t *now);
time_t mu_utc_offset (void);
int mu_utc_offset (void);
void mu_datetime_tz_local (struct mu_timezone *tz);
time_t mu_datetime_to_utc (struct tm *timeptr, struct mu_timezone *tz);
size_t mu_strftime (char *s, size_t max, const char *format, struct tm *tm);
......
......@@ -25,6 +25,7 @@ libdatetime_la_SOURCES = \
streamftime.c\
strftime.c\
tab.c\
tzlocal.c\
unixtime.c\
utcoff.c\
yd.c
......
......@@ -325,10 +325,7 @@ mu_scan_datetime (const char *input, const char *fmt,
#endif
/* provide default timezone, in case it is not supplied in input */
if (tz)
{
memset (tz, 0, sizeof *tz);
tz->utc_offset = mu_utc_offset ();
}
mu_datetime_tz_local (tz);
/* Skip leading whitespace */
input = mu_str_skip_class (input, MU_CTYPE_BLANK);
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2011 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
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Mailutils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <mailutils/datetime.h>
void
mu_datetime_tz_local (struct mu_timezone *tz)
{
tz->utc_offset = mu_utc_offset ();
tz->tz_name = NULL;
}
......@@ -22,7 +22,7 @@
/* Convert time 0 at UTC to our localtime, that tells us the offset
of our current timezone from UTC. */
time_t
int
mu_utc_offset (void)
{
time_t t = 0;
......
......@@ -185,12 +185,11 @@ mime_create_ds (mu_mime_t mime, mu_message_t orig)
mu_header_t hdr;
mu_body_t body;
char *email;
char datestr[80];
time_t t = time (NULL);
struct tm tm, *tmp;
struct mu_timezone tz;
mu_envelope_t env;
const char *p;
time_t t = time (NULL);
mu_message_create (&newmsg, NULL);
mu_message_get_header (newmsg, &hdr);
......@@ -202,15 +201,17 @@ mime_create_ds (mu_mime_t mime, mu_message_t orig)
mu_message_get_envelope (orig, &env);
if (mu_envelope_sget_date (env, &p) == 0
&& mu_scan_datetime (p, MU_DATETIME_FROM, &tm, &tz, NULL) == 0)
t = mu_datetime_to_utc (&tm, &tz);
{
tmp = &tm;
}
else
/* Use local time instead */
t = time (NULL);
tmp = localtime (&t);
{
tmp = localtime (&t);
mu_datetime_tz_local (&tz);
}
/* FIXME: timezone info is lost */
mu_strftime (datestr, sizeof datestr, "%a, %b %d %H:%M:%S %Y %Z", tmp);
mu_stream_printf (stream, "Arrival-Date: %s\n", datestr);
mu_c_streamftime (stream, "Arrival-Date: %a, %b %d %H:%M:%S %Y %Z%n",
tmp, &tz);
email = mu_get_user_email (NULL);
mu_stream_printf (stream, "Final-Recipient: RFC822; %s\n",
......@@ -220,10 +221,10 @@ mime_create_ds (mu_mime_t mime, mu_message_t orig)
mu_stream_printf (stream,
"Disposition: automatic-action/MDN-sent-automatically;deleted\n");
t = time (NULL);
tmp = localtime (&t);
mu_strftime (datestr, sizeof datestr, "%a, %b %d %H:%M:%S %Y %Z", tmp);
mu_stream_printf (stream, "Last-Attempt-Date: %s\n", datestr);
mu_datetime_tz_local (&tz);
mu_c_streamftime (stream, "Last-Attempt-Date: %a, %b %d %H:%M:%S %Y %Z%n",
tmp, &tz);
mu_stream_close (stream);
mu_stream_destroy (&stream);
......
......@@ -1172,7 +1172,7 @@ _parse_date (struct mh_machine *mach, struct tm *tm, struct mu_timezone *tz)
/*mu_error ("can't parse date: [%s]", date);*/
time (&t);
*tm = *localtime (&t);
tz->utc_offset = mu_utc_offset ();
mu_datetime_tz_local (tz);
}
return 0;
......