summaryrefslogtreecommitdiff
path: root/sfeed_mbox.c
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2020-03-15 23:13:31 +0100
committerHiltjo Posthuma <hiltjo@codemadness.org>2020-03-15 23:13:31 +0100
commit785a50c37c11c8e92387f8409d91bd77c41297b2 (patch)
treea32b2034505639f635b28d3ccf8c60c8772924e2 /sfeed_mbox.c
parenta335239b1f9803298e42e16535d759856be831b0 (diff)
sfeed_mbox: time parsing and consistency fixes
- make converting time error out as the other format tools do also. - remove wrong comment. - make code-style consistent.
Diffstat (limited to 'sfeed_mbox.c')
-rw-r--r--sfeed_mbox.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/sfeed_mbox.c b/sfeed_mbox.c
index a10bd45..1aab49b 100644
--- a/sfeed_mbox.c
+++ b/sfeed_mbox.c
@@ -24,8 +24,8 @@ djb2(unsigned char *s, unsigned long hash)
static void
printfeed(FILE *fp, const char *feedname)
{
- struct tm tm;
char *fields[FieldLast], timebuf[32];
+ struct tm *tm;
time_t parsedtime;
unsigned long hash;
ssize_t linelen;
@@ -36,20 +36,18 @@ printfeed(FILE *fp, const char *feedname)
hash = djb2((unsigned char *)line, 5381UL);
if (!parseline(line, fields))
break;
+
parsedtime = 0;
if (strtotime(fields[FieldUnixTimestamp], &parsedtime))
continue;
+ if (!(tm = gmtime(&parsedtime)))
+ err(1, "gmtime");
+ if (!strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S +0000", tm))
+ errx(1, "strftime");
/* mbox + mail header */
printf("From MAILER-DAEMON %s\n", mtimebuf);
- /* can't convert: default to formatted time for time_t 0. */
- if (gmtime_r(&parsedtime, &tm) &&
- strftime(timebuf, sizeof(timebuf),
- "%a, %d %b %Y %H:%M:%S +0000", &tm))
- printf("Date: %s\n", timebuf);
- else
- printf("Date: Thu, 01 Jan 1970 00:00:00 +0000\n");
-
+ printf("Date: %s\n", timebuf);
printf("From: %s <sfeed@>\n", fields[FieldAuthor][0] ? fields[FieldAuthor] : "unknown");
printf("To: %s <%s@%s>\n", user, user, host);
if (feedname[0])