]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/tools/bsmtp.c
- Move Python variables from Job to Bacula. They are
[bacula/bacula] / bacula / src / tools / bsmtp.c
index d51c57b37b37aec5a641d701e2df44930e94b791..bc83bd4f59ab46a4dee2bc336618c49eb9671239 100644 (file)
@@ -1,23 +1,17 @@
 /*
-   Copyright (C) 2000-2004 Kern Sibbald and John Walker
+   Copyright (C) 2001-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as amended with additional clauses defined in the
+   file LICENSE in the main source directory.
 
    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.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
-
 /*
    Derived from a SMTPclient:
 
@@ -28,9 +22,9 @@
        www.engelschall.com
 
    Kern Sibbald, July 2001
-  
+
    Version $Id$
-    
+
  */
 
 #ifdef APCUPSD
@@ -51,6 +45,9 @@ UPSINFO *core_ups = &myUPS;
 
 #endif
 
+/* Dummy functions */
+int generate_daemon_event(JCR *jcr, const char *event) 
+   { return 1; }
 
 #ifndef MAXSTRING
 #define MAXSTRING 254
@@ -70,7 +67,7 @@ static char my_hostname[MAXSTRING];
 
 
 /*
- *  examine message from server 
+ *  examine message from server
  */
 static void get_response(void)
 {
@@ -79,18 +76,18 @@ static void get_response(void)
     Dmsg0(50, "Calling fgets on read socket rfp.\n");
     buf[3] = 0;
     while (fgets(buf, sizeof(buf), rfp)) {
-       int len = strlen(buf);
-       if (len > 0) {
-          buf[len-1] = 0;
-       }
+        int len = strlen(buf);
+        if (len > 0) {
+           buf[len-1] = 0;
+        }
         Dmsg2(10, "%s --> %s\n", mailhost, buf);
         if (!isdigit((int)buf[0]) || buf[0] > '3') {
             Pmsg2(0, "Fatal malformed reply from %s: %s\n", mailhost, buf);
-           exit(1);
-       }
+            exit(1);
+        }
         if (buf[3] != '-') {
-           break;
-       }
+            break;
+        }
     }
     return;
 }
@@ -105,11 +102,11 @@ static void chat(const char *fmt, ...)
     va_start(ap, fmt);
     vfprintf(sfp, fmt, ap);
     if (debug_level >= 10) {
-       fprintf(stdout, "%s --> ", my_hostname); 
+       fprintf(stdout, "%s --> ", my_hostname);
        vfprintf(stdout, fmt, ap);
     }
     va_end(ap);
-  
+
     fflush(sfp);
     if (debug_level >= 10) {
        fflush(stdout);
@@ -122,13 +119,13 @@ static void usage()
 {
    fprintf(stderr,
 "\n"
-"Usage: %s [-f from] [-h mailhost] [-s subject] [-c copy] [recepient ...]\n"
+"Usage: %s [-f from] [-h mailhost] [-s subject] [-c copy] [recipient ...]\n"
 "       -c          set the Cc: field\n"
 "       -dnn        set debug level to nn\n"
 "       -f          set the From: field\n"
 "       -h          use mailhost:port as the SMTP server\n"
 "       -s          set the Subject: field\n"
-"       -?          print this message.\n"  
+"       -?          print this message.\n"
 "\n", MY_NAME);
 
    exit(1);
@@ -154,47 +151,47 @@ int main (int argc, char *argv[])
 
    while ((ch = getopt(argc, argv, "c:d:f:h:r:s:?")) != -1) {
       switch (ch) {
-      case 'c':                    
+      case 'c':
          Dmsg1(20, "cc=%s\n", optarg);
-        cc_addr = optarg;
-        break;
+         cc_addr = optarg;
+         break;
 
       case 'd':                    /* set debug level */
-        debug_level = atoi(optarg);
-        if (debug_level <= 0) {
-           debug_level = 1; 
-        }
+         debug_level = atoi(optarg);
+         if (debug_level <= 0) {
+            debug_level = 1;
+         }
          Dmsg1(20, "Debug level = %d\n", debug_level);
-        break;
+         break;
 
       case 'f':                    /* from */
-        from_addr = optarg;
-        break;
+         from_addr = optarg;
+         break;
 
       case 'h':                    /* smtp host */
          Dmsg1(20, "host=%s\n", optarg);
          p = strchr(optarg, ':');
-        if (p) {
-           *p++ = 0;
-           mailport = atoi(p);
-        }
-        mailhost = optarg;
-        break;
+         if (p) {
+            *p++ = 0;
+            mailport = atoi(p);
+         }
+         mailhost = optarg;
+         break;
 
       case 's':                    /* subject */
          Dmsg1(20, "subject=%s\n", optarg);
-        subject = optarg;
-        break;
+         subject = optarg;
+         break;
 
       case 'r':                    /* reply address */
-        reply_addr = optarg;
-        break;
+         reply_addr = optarg;
+         break;
 
       case '?':
       default:
-        usage();
+         usage();
 
-      }  
+      }
    }
    argc -= optind;
    argv += optind;
@@ -210,14 +207,14 @@ int main (int argc, char *argv[])
     */
    if (mailhost == NULL) {
       if ((cp = getenv("SMTPSERVER")) != NULL) {
-        mailhost = cp;
+         mailhost = cp;
       } else {
          mailhost = "localhost";
       }
    }
 
    /*
-    *  Find out my own host name for HELO; 
+    *  Find out my own host name for HELO;
     *  if possible, get the fully qualified domain name
     */
    if (gethostname(my_hostname, sizeof(my_hostname) - 1) < 0) {
@@ -226,7 +223,7 @@ int main (int argc, char *argv[])
    }
    if ((hp = gethostbyname(my_hostname)) == NULL) {
       Pmsg2(0, "Fatal gethostbyname for myself failed \"%s\": ERR=%s\n", my_hostname,
-        strerror(errno));
+         strerror(errno));
       exit(1);
    }
    strcpy(my_hostname, hp->h_name);
@@ -251,11 +248,11 @@ int main (int argc, char *argv[])
 hp:
    if ((hp = gethostbyname(mailhost)) == NULL) {
       Pmsg2(0, "Error unknown mail host \"%s\": ERR=%s\n", mailhost,
-        strerror(errno));
+         strerror(errno));
       if (strcasecmp(mailhost, "localhost") != 0) {
          Pmsg0(0, "Retrying connection using \"localhost\".\n");
          mailhost = "localhost";
-        goto hp;
+         goto hp;
       }
       exit(1);
    }
@@ -290,7 +287,7 @@ hp:
       exit(1);
    }
 
-   /* 
+   /*
     *  Send SMTP headers
     */
    get_response(); /* banner */
@@ -308,7 +305,7 @@ hp:
    Dmsg0(20, "Data\n");
    chat("data\r\n");
 
-   /* 
+   /*
     *  Send message header
     */
    fprintf(sfp, "From: %s\r\n", from_addr);
@@ -344,25 +341,25 @@ hp:
 
    fprintf(sfp, "\r\n");
 
-   /* 
-    *  Send message body 
+   /*
+    *  Send message body
     */
    while (fgets(buf, sizeof(buf), stdin)) {
       buf[strlen(buf)-1] = 0;
       if (strcmp(buf, ".") == 0) { /* quote lone dots */
          fprintf(sfp, "..\r\n");
-      } else {                    /* pass body through unchanged */
+      } else {                     /* pass body through unchanged */
          fprintf(sfp, "%s\r\n", buf);
       }
    }
 
-   /* 
+   /*
     *  Send SMTP quit command
     */
    chat(".\r\n");
    chat("quit\r\n");
 
-   /* 
+   /*
     *  Go away gracefully ...
     */
    exit(0);