]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/tools/bsmtp.c
Change to inner joins. The outer joins don't get us any more resulting records
[bacula/bacula] / bacula / src / tools / bsmtp.c
index 2701f7ba4e6f6e636b888891d32b041080c62f16..93eae1ba38f2352f8ac4088206d4ce78c4167828 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
@@ -70,13 +70,37 @@ static int mailport = 25;
 static char my_hostname[MAXSTRING];
 static bool content_utf8 = false;
 
+/* 
+ * Take input that may have names and other stuff and strip
+ *  it down to the mail box address ... i.e. what is enclosed
+ *  in < >.  Otherwise add < >.
+ */
+static char *cleanup_addr(char *addr, char *buf, int buf_len)
+{
+   char *p, *q;
+
+   if ((p = strchr(from_addr, '<')) == NULL) {
+      snprintf(buf, buf_len, "<%s>", addr);
+   } else {
+      /* Copy <addr> */
+      for (q=buf; *p && *p!='>'; ) {
+         *q++ = *p++;
+      }
+      if (*p) {
+         *q++ = *p;
+      }
+      *q = 0;
+  }
+  Dmsg2(100, "cleanup in=%s out=%s\n", addr, buf);
+  return buf;    
+}
 
 /*
  *  examine message from server
  */
 static void get_response(void)
 {
-    char buf[MAXSTRING];
+    char buf[1000];
 
     Dmsg0(50, "Calling fgets on read socket rfp.\n");
     buf[3] = 0;
@@ -150,6 +174,7 @@ static void get_date_string(char *buf, int buf_len)
    time_t now = time(NULL);
    struct tm tm;
    char tzbuf[MAXSTRING];
+   long my_timezone;
 
    /* Add RFC822 date */
    (void)localtime_r(&now, &tm);
@@ -158,28 +183,22 @@ static void get_date_string(char *buf, int buf_len)
 #if defined(HAVE_MINGW)
 __MINGW_IMPORT long     _dstbias;
 #endif
-   long tzoffset = 0;
-
    _tzset();
+   my_timezone = _timezone;
+   my_timezone += _dstbias;
+   my_timezone /= 60;
 
-   tzoffset = _timezone;
-   tzoffset += _dstbias;
-   tzoffset /= 60;
-
-   size_t length = strftime(buf, buf_len, "%a, %d %b %Y %H:%M:%S", &tm);
-   sprintf(&buf[length], " %+2.2ld%2.2u", -tzoffset / 60, abs(tzoffset) % 60);
 #else
+   struct timeval tv;
+   struct timezone tz;
+   gettimeofday(&tv, &tz);
+   my_timezone = tz.tz_minuteswest; /* timezone offset in mins */
+#endif
    strftime(buf, buf_len, "%a, %d %b %Y %H:%M:%S", &tm);
-   tzset();
-   timezone /= 60;                  /* timezone offset in mins */
-   if (tm.tm_isdst == 1) {
-      timezone -= 60;              /* adjust for daylight savings */
-   }
-   sprintf(tzbuf, " %+2.2ld%2.2u", -timezone / 60, abs(timezone) % 60);
+   sprintf(tzbuf, " %+2.2ld%2.2u", -my_timezone / 60, abs(my_timezone) % 60);
    strcat(buf, tzbuf);              /* add +0100 */
    strftime(tzbuf, sizeof(tzbuf), " (%Z)", &tm);
    strcat(buf, tzbuf);              /* add (CEST) */
-#endif
 }
 
 
@@ -189,7 +208,7 @@ __MINGW_IMPORT long     _dstbias;
  */
 int main (int argc, char *argv[])
 {
-    char buf[MAXSTRING];
+    char buf[1000];
     struct sockaddr_in sin;
     struct hostent *hp;
     int i, ch;
@@ -270,9 +289,6 @@ int main (int argc, char *argv[])
       exit(1);
    }
 
-#if defined(HAVE_WIN32)
-   _setmode(0, _O_BINARY);
-#endif
 
    /*
     *  Determine SMTP server
@@ -288,6 +304,7 @@ int main (int argc, char *argv[])
 #if defined(HAVE_WIN32)
    WSADATA  wsaData;
 
+   _setmode(0, _O_BINARY);
    WSAStartup(MAKEWORD(2,2), &wsaData);
 #endif
 
@@ -410,27 +427,15 @@ hp:
     */
    get_response(); /* banner */
    chat("helo %s\r\n", my_hostname);
-   if (strchr(from_addr, '<') == NULL) {
-      chat("mail from:<%s>\r\n", from_addr);
-   } else {
-      chat("mail from:%s\r\n", from_addr);
-   }
-
+   chat("mail from:%s\r\n", cleanup_addr(from_addr, buf, sizeof(buf)));
+   
    for (i = 0; i < argc; i++) {
       Dmsg1(20, "rcpt to: %s\n", argv[i]);
-      if (strchr(argv[i], '<') == NULL) {
-         chat("rcpt to:<%s>\r\n", argv[i]);
-      } else {
-         chat("rcpt to:%s\r\n", argv[i]);
-      }
+      chat("rcpt to:%s\r\n", cleanup_addr(argv[i], buf, sizeof(buf)));
    }
 
    if (cc_addr) {
-      if (strchr(cc_addr, '<') == NULL) {
-         chat("rcpt to:<%s>\r\n", cc_addr);
-      } else {
-         chat("rcpt to:%s\r\n", cc_addr);
-      }
+      chat("rcpt to:%s\r\n", cleanup_addr(cc_addr, buf, sizeof(buf)));
    }
    Dmsg0(20, "Data\n");
    chat("data\r\n");