]> Pileus Git - ~andy/fetchmail/blobdiff - env.c
Version bump -- SpryNet support.
[~andy/fetchmail] / env.c
diff --git a/env.c b/env.c
index cfd39f4999e9b11b97c9fab025f85bf3ab022238..ad915263e9f6551329328e2d28ad148e04148e83 100644 (file)
--- a/env.c
+++ b/env.c
 #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"
 
 #include "i18n.h"
@@ -106,25 +104,52 @@ char *host_fqdn(void)
        return(xstrdup(tmpbuf));
 }
 
+static char *tzoffset(time_t *now)
+/* calculate timezone offset */
+{
+    static char offset_string[6];
+    struct tm gmt, *lt;
+    int off;
+    char sign = '+';
+
+    gmt = *gmtime(now);
+    lt = localtime(now);
+    off = (lt->tm_hour - gmt.tm_hour) * 60 + lt->tm_min - gmt.tm_min;
+    if (lt->tm_year < gmt.tm_year)
+       off -= 24 * 60;
+    else if (lt->tm_year > gmt.tm_year)
+       off += 24 * 60;
+    else if (lt->tm_yday < gmt.tm_yday)
+       off -= 24 * 60;
+    else if (lt->tm_yday > gmt.tm_yday)
+       off += 24 * 60;
+    if (off < 0) {
+       sign = '-';
+       off = -off;
+    }
+    if (off >= 24 * 60)                        /* should be impossible */
+       off = 23 * 60 + 59;             /* if not, insert silly value */
+    sprintf(offset_string, "%c%02d%02d", sign, off / 60, off % 60);
+    return (offset_string);
+}
+
 char *rfc822timestamp(void)
 /* return a timestamp in RFC822 form */
 {
     time_t     now;
-    static char buf[40];
+    static char buf[50];
 
     time(&now);
 #ifdef HAVE_STRFTIME
     /*
-     * Conform to RFC822. UTC rather than local time because of the
-     * mess that %Z generates obsolete 822 syntax but %z is not
-     * guaranteed portable. We generate a 4-digit year here, avoiding
+     * Conform to RFC822.  We generate a 4-digit year here, avoiding
      * Y2K hassles.  Max length of this timestamp in an English locale
      * should be 29 chars.  The only things that should vary by locale
      * are the day and month abbreviations.
      */
     strftime(buf, sizeof(buf)-1, 
-            "%a, %d %b %Y %H:%M:%S +0000 (UTC)",
-            gmtime(&now));
+            "%a, %d %b %Y %H:%M:%S XXXXX (%Z)", localtime(&now));
+    strncpy(strstr(buf, "XXXXX"), tzoffset(&now), 5);
 #else
     /*
      * This is really just a portability fallback, as the
@@ -143,20 +168,20 @@ const char *showproto(int proto)
 {
     switch (proto)
     {
-    case P_AUTO: return("auto"); break;
+    case P_AUTO: return("auto");
 #ifdef POP2_ENABLE
-    case P_POP2: return("POP2"); break;
+    case P_POP2: return("POP2");
 #endif /* POP2_ENABLE */
-    case P_POP3: return("POP3"); break;
-    case P_IMAP: return("IMAP"); break;
-    case P_IMAP_K4: return("IMAP-K4"); break;
+    case P_POP3: return("POP3");
+    case P_IMAP: return("IMAP");
+    case P_IMAP_K4: return("IMAP-K4");
 #ifdef GSSAPI
-    case P_IMAP_GSS: return("IMAP-GSS"); break;
+    case P_IMAP_GSS: return("IMAP-GSS");
 #endif /* GSSAPI */
-    case P_APOP: return("APOP"); break;
-    case P_RPOP: return("RPOP"); break;
-    case P_ETRN: return("ETRN"); break;
-    default: return("unknown?!?"); break;
+    case P_APOP: return("APOP");
+    case P_RPOP: return("RPOP");
+    case P_ETRN: return("ETRN");
+    default: return("unknown?!?");
     }
 }