From d5ab27fd20523145658a5594b47c9cf2da689266 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Fri, 13 Jun 2008 03:29:40 +0300 Subject: [PATCH] mbox_from_parse() now returns also the parsed timezone. --HG-- branch : HEAD --- src/deliver/deliver.c | 4 ++-- src/lib-mail/mbox-from.c | 5 ++++- src/lib-mail/mbox-from.h | 2 +- src/lib-storage/index/mbox/istream-raw-mbox.c | 11 ++++++----- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/deliver/deliver.c b/src/deliver/deliver.c index e88fe471d5..40ece31438 100644 --- a/src/deliver/deliver.c +++ b/src/deliver/deliver.c @@ -563,7 +563,7 @@ static struct istream *create_raw_stream(int fd, time_t *mtime_r) const unsigned char *data; char *sender = NULL; size_t i, size; - int ret; + int ret, tz; *mtime_r = (time_t)-1; fd_set_nonblock(fd, FALSE); @@ -581,7 +581,7 @@ static struct istream *create_raw_stream(int fd, time_t *mtime_r) break; } if (i != size) { - (void)mbox_from_parse(data, i, mtime_r, + (void)mbox_from_parse(data, i, mtime_r, &tz, &sender); i_stream_skip(input, i + 1); break; diff --git a/src/lib-mail/mbox-from.c b/src/lib-mail/mbox-from.c index 8c0d874f2c..3b6f268e05 100644 --- a/src/lib-mail/mbox-from.c +++ b/src/lib-mail/mbox-from.c @@ -1,6 +1,7 @@ /* Copyright (c) 2002-2008 Dovecot authors, see the included COPYING file */ #include "lib.h" +#include "ioloop.h" #include "str.h" #include "utc-mktime.h" #include "mbox-from.h" @@ -50,7 +51,7 @@ static int mbox_parse_year(const unsigned char *msg, struct tm *tm) } int mbox_from_parse(const unsigned char *msg, size_t size, - time_t *time_r, char **sender_r) + time_t *time_r, int *tz_offset_r, char **sender_r) { const unsigned char *msg_start, *sender_end, *msg_end; struct tm tm; @@ -229,9 +230,11 @@ int mbox_from_parse(const unsigned char *msg, size_t size, t -= timezone_secs; *time_r = t; + *tz_offset_r = timezone_secs/60; } else { /* assume local timezone */ *time_r = mktime(&tm); + *tz_offset_r = -ioloop_timezone.tz_minuteswest; } *sender_r = i_strdup_until(msg_start, sender_end); diff --git a/src/lib-mail/mbox-from.h b/src/lib-mail/mbox-from.h index e4557bb302..fbca06643d 100644 --- a/src/lib-mail/mbox-from.h +++ b/src/lib-mail/mbox-from.h @@ -4,7 +4,7 @@ /* Parse time and sender from mbox-compatible From_-line. msg points to the data after "From ". */ int mbox_from_parse(const unsigned char *msg, size_t size, - time_t *time_r, char **sender_r); + time_t *time_r, int *tz_offset_r, char **sender_r); /* Return a mbox-compatible From_-line using given sender and time. The returned string begins with "From ". */ const char *mbox_from_create(const char *sender, time_t timestamp); diff --git a/src/lib-storage/index/mbox/istream-raw-mbox.c b/src/lib-storage/index/mbox/istream-raw-mbox.c index 97094e02c3..ebbf1ce249 100644 --- a/src/lib-storage/index/mbox/istream-raw-mbox.c +++ b/src/lib-storage/index/mbox/istream-raw-mbox.c @@ -48,7 +48,7 @@ static int mbox_read_from_line(struct raw_mbox_istream *rstream) char *sender; time_t received_time; size_t pos, line_pos; - int skip; + int skip, tz; buf = i_stream_get_data(rstream->istream.parent, &pos); i_assert(pos > 0); @@ -76,7 +76,7 @@ static int mbox_read_from_line(struct raw_mbox_istream *rstream) /* beginning of mbox */ if (memcmp(buf, "From ", 5) != 0 || - mbox_from_parse(buf+5, pos-5, &received_time, &sender) < 0) { + mbox_from_parse(buf+5, pos-5, &received_time, &tz, &sender) < 0) { /* broken From - should happen only at beginning of file if this isn't a mbox.. */ return -1; @@ -129,7 +129,7 @@ static ssize_t i_stream_raw_mbox_read(struct istream_private *stream) time_t received_time; size_t i, pos, new_pos, from_start_pos, from_after_pos; ssize_t ret = 0; - int eoh_char; + int eoh_char, tz; bool crlf_ending = FALSE; i_assert(stream->istream.v_offset >= rstream->from_offset); @@ -258,7 +258,7 @@ static ssize_t i_stream_raw_mbox_read(struct istream_private *stream) See if it's a valid one. */ if (mbox_from_parse(buf + from_after_pos, pos - from_after_pos, - &received_time, + &received_time, &tz, &sender) == 0) { /* yep, we stop here. */ rstream->next_received_time = @@ -392,6 +392,7 @@ static int istream_raw_mbox_is_valid_from(struct raw_mbox_istream *rstream) size_t size; time_t received_time; char *sender; + int tz; /* minimal: "From x Thu Nov 29 22:33:52 2001" = 31 chars */ (void)i_stream_read_data(rstream->istream.parent, &data, &size, 30); @@ -418,7 +419,7 @@ static int istream_raw_mbox_is_valid_from(struct raw_mbox_istream *rstream) break; } - if (mbox_from_parse(data, size, &received_time, &sender) < 0) + if (mbox_from_parse(data, size, &received_time, &tz, &sender) < 0) return 0; rstream->next_received_time = received_time; -- 2.47.3