]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/tools/bsmtp.c
ebl Update SQLite for Long term statistics
[bacula/bacula] / bacula / src / tools / bsmtp.c
index d0b6066e686b67261f22ee65e0032938bebf9a0d..0188cedab3e7c14fe45138b9096510c81ddb9478 100644 (file)
@@ -7,8 +7,8 @@
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
    modify it under the terms of version two of the GNU General Public
-   License as published by the Free Software Foundation plus additions
-   that are listed in the file LICENSE.
+   License as published by the Free Software Foundation and included
+   in the file LICENSE.
 
    This program is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
 /*
    Derived from a SMTPclient:
 
+  ======== Original copyrights ==========  
+
        SMTPclient -- simple SMTP client
 
-       Copyright (C) 1997 Ralf S. Engelschall, All Rights Reserved.
-       rse@engelschall.com
-       www.engelschall.com
+       Copyright (c) 1997 Ralf S. Engelschall, All rights reserved.
+
+       This program is free software; it may be redistributed and/or modified
+       only under the terms of either the Artistic License or the GNU General
+       Public License, which may be found in the SMTP source distribution.
+       Look at the file COPYING.
+
+       This program 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.
+
+       ======================================================================
+
+       smtpclient_main.c -- program source
+
+       Based on smtp.c as of August 11, 1995 from
+           W.Z. Venema,
+           Eindhoven University of Technology,
+           Department of Mathematics and Computer Science,
+           Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands.
+
+   =========
+
 
    Kern Sibbald, July 2001
 
+     Note, the original W.Z. Venema smtp.c had no license and no
+     copyright.  See:
+        http://archives.neohapsis.com/archives/postfix/2000-05/1520.html
+
    Version $Id$
 
  */
@@ -79,7 +107,7 @@ static char *cleanup_addr(char *addr, char *buf, int buf_len)
 {
    char *p, *q;
 
-   if ((p = strchr(from_addr, '<')) == NULL) {
+   if ((p = strchr(addr, '<')) == NULL) {
       snprintf(buf, buf_len, "<%s>", addr);
    } else {
       /* Copy <addr> */
@@ -136,11 +164,13 @@ static void chat(const char *fmt, ...)
 
     va_start(ap, fmt);
     vfprintf(sfp, fmt, ap);
+    va_end(ap);
     if (debug_level >= 10) {
        fprintf(stdout, "%s --> ", my_hostname);
+       va_start(ap, fmt);
        vfprintf(stdout, fmt, ap);
+       va_end(ap);
     }
-    va_end(ap);
 
     fflush(sfp);
     if (debug_level >= 10) {
@@ -157,7 +187,8 @@ _("\n"
 "Usage: %s [-f from] [-h mailhost] [-s subject] [-c copy] [recipient ...]\n"
 "       -8          set charset utf-8\n"
 "       -c          set the Cc: field\n"
-"       -dnn        set debug level to nn\n"
+"       -d <nn>     set debug level to <nn>\n"
+"       -dt         print timestamp in debug output\n"
 "       -f          set the From: field\n"
 "       -h          use mailhost:port as the SMTP server\n"
 "       -s          set the Subject: field\n"
@@ -169,31 +200,50 @@ _("\n"
    exit(1);
 }
 
+/*
+ * Return the offset west from localtime to UTC in minutes
+  * Same as timezone.tz_minuteswest
+  *   Unix tz_offset coded by:  Attila Fülöp
+  */
+
+static long tz_offset(time_t lnow, struct tm &tm)
+{
+#if defined(HAVE_WIN32)
+#if defined(HAVE_MINGW)
+__MINGW_IMPORT long     _dstbias;
+#endif
+
+   /* Win32 code */
+   long offset;
+   _tzset();
+   offset = _timezone;
+   if (tm.tm_isdst) {
+      offset += _dstbias;
+   }
+   return offset /= 60;
+#else
+
+   /* Unix/Linux code */
+   struct tm tm_utc;
+   time_t now = lnow;
+
+   (void)gmtime_r(&now, &tm_utc);
+   tm_utc.tm_isdst = tm.tm_isdst;
+   return (long)difftime(mktime(&tm_utc), now) / 60;
+#endif
+}
+
 static void get_date_string(char *buf, int buf_len)
 {
    time_t now = time(NULL);
    struct tm tm;
    char tzbuf[MAXSTRING];
    long my_timezone;
-   struct timeval tv;
-   struct timezone tz;
 
    /* Add RFC822 date */
    (void)localtime_r(&now, &tm);
 
-#if defined(HAVE_WIN32)
-#if defined(HAVE_MINGW)
-__MINGW_IMPORT long     _dstbias;
-#endif
-   _tzset();
-   my_timezone = _timezone;
-   my_timezone += _dstbias;
-   my_timezone /= 60;
-
-#else
-   gettimeofday(&tv, &tz);
-   my_timezone = tz.tz_minuteswest; /* timezone offset in mins */
-#endif
+   my_timezone = tz_offset(now, tm);
    strftime(buf, buf_len, "%a, %d %b %Y %H:%M:%S", &tm);
    sprintf(tzbuf, " %+2.2ld%2.2u", -my_timezone / 60, abs(my_timezone) % 60);
    strcat(buf, tzbuf);              /* add +0100 */
@@ -239,9 +289,13 @@ int main (int argc, char *argv[])
          break;
 
       case 'd':                    /* set debug level */
-         debug_level = atoi(optarg);
-         if (debug_level <= 0) {
-            debug_level = 1;
+         if (*optarg == 't') {
+            dbg_timestamp = true;
+         } else {
+            debug_level = atoi(optarg);
+            if (debug_level <= 0) {
+               debug_level = 1;
+            }
          }
          Dmsg1(20, "Debug level = %d\n", debug_level);
          break;
@@ -289,9 +343,6 @@ int main (int argc, char *argv[])
       exit(1);
    }
 
-#if defined(HAVE_WIN32)
-   _setmode(0, _O_BINARY);
-#endif
 
    /*
     *  Determine SMTP server
@@ -307,6 +358,7 @@ int main (int argc, char *argv[])
 #if defined(HAVE_WIN32)
    WSADATA  wsaData;
 
+   _setmode(0, _O_BINARY);
    WSAStartup(MAKEWORD(2,2), &wsaData);
 #endif