aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--driver.c27
-rw-r--r--env.c34
-rw-r--r--fetchmail.c14
-rw-r--r--fetchmail.h1
4 files changed, 39 insertions, 37 deletions
diff --git a/driver.c b/driver.c
index 6016de51..33c3b48b 100644
--- a/driver.c
+++ b/driver.c
@@ -31,11 +31,6 @@
#include <sys/time.h>
#include <signal.h>
-#ifndef HAVE_STRFTIME /* For ctime prototype */
-#include <sys/types.h>
-#include <time.h>
-#endif
-
#ifdef HAVE_RES_SEARCH
#include <netdb.h>
#include "mx.h"
@@ -866,8 +861,6 @@ static int readheaders(int sock, long fetchlen, long reallen, struct query *ctl,
n = stuffline(ctl, buf);
if (n != -1)
{
- time_t now;
-
buf[0] = '\t';
if (good_addresses == 0)
{
@@ -890,24 +883,8 @@ static int readheaders(int sock, long fetchlen, long reallen, struct query *ctl,
else
buf[1] = '\0';
- time(&now);
-#ifdef HAVE_STRFTIME
- /*
- * Conform to RFC822. This is typically going to emit
- * a three-letter timezone for %Z, which is going to
- * be marked "obsolete syntax" in 822bis. Note that we
- * generate a 4-digit year here.
- */
- strftime(buf + strlen(buf), sizeof(buf) - strlen(buf),
- "%a, %d %b %Y %H:%M:%S %Z\r\n", localtime(&now));
-#else
- /*
- * This is really just a portability fallback, as the
- * date format ctime(3) emits is not RFC822
- * conformant.
- */
- strcat(buf, ctime(&now));
-#endif /* HAVE_STRFTIME */
+ strcat(buf, rfc822timestamp());
+ strcat(buf, "\r\n");
n = stuffline(ctl, buf);
}
}
diff --git a/env.c b/env.c
index 7fe36040..da8168d6 100644
--- a/env.c
+++ b/env.c
@@ -19,6 +19,10 @@
#ifdef HAVE_GETHOSTBYNAME
#include <netdb.h>
#endif /* HAVE_GETHOSTBYNAME */
+#ifndef HAVE_STRFTIME /* For ctime prototype */
+#include <sys/types.h>
+#include <time.h>
+#endif
#include "fetchmail.h"
extern char *getenv(); /* needed on sysV68 R3V7.1. */
@@ -99,6 +103,36 @@ char *host_fqdn(void)
return(xstrdup(tmpbuf));
}
+char *rfc822timestamp(void)
+/* return a timestamp in RFC822 form */
+{
+ time_t now;
+ static char buf[40];
+
+ time(&now);
+#ifdef HAVE_STRFTIME
+ /*
+ * Conform to RFC822. This is typically going to emit
+ * a three-letter timezone for %Z, which is going to
+ * be marked "obsolete syntax" in 822bis. Note that we
+ * generate a 4-digit year here, avoiding Y2K hassles.
+ * Note: max length of this timestamp in an English locale
+ * should be 29 chars, assuming a 3-character timezone.
+ */
+ strftime(buf, sizeof(buf)-1,
+ "%a, %d %b %Y %H:%M:%S %Z", localtime(&now));
+#else
+ /*
+ * This is really just a portability fallback, as the
+ * date format ctime(3) emits is not RFC822
+ * conformant.
+ */
+ strcpy(buf, ctime(&now));
+ buf[strlen(buf)-1] = '\0'; /* remove trailing \n */
+#endif /* HAVE_STRFTIME */
+
+ return(buf);
+}
const char *showproto(int proto)
/* protocol index to protocol name mapping */
diff --git a/fetchmail.c b/fetchmail.c
index 4923ecea..9a05dc82 100644
--- a/fetchmail.c
+++ b/fetchmail.c
@@ -600,12 +600,7 @@ int main (int argc, char **argv)
}
if (outlevel >= O_VERBOSE)
- {
- time_t now;
-
- time(&now);
- error(0, -1, "fetchmail: sleeping at %s", ctime(&now));
- }
+ error(0, -1, "fetchmail: sleeping at %s", rfc822timestamp());
/*
* With this simple hack, we make it possible for a foreground
@@ -712,12 +707,7 @@ int main (int argc, char **argv)
signal(SIGHUP, SIG_IGN);
if (outlevel >= O_VERBOSE)
- {
- time_t now;
-
- time(&now);
- error(0, -1, "awakened at %s", ctime(&now));
- }
+ error(0, -1, "awakened at %s", rfc822timestamp());
}
} while
(run.poll_interval);
diff --git a/fetchmail.h b/fetchmail.h
index 73e0b8ec..65780434 100644
--- a/fetchmail.h
+++ b/fetchmail.h
@@ -447,6 +447,7 @@ const char *showproto(int);
void dump_config(struct runctl *runp, struct query *querylist);
int is_host_alias(const char *, struct query *);
char *host_fqdn(void);
+char *rfc822timestamp(void);
#ifdef SDPS_ENABLE
char *sdps_envto;
#endif /* SDPS_ENABLE */