]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/tools/bsmtp.c
kes Make bat have 'make install' target.
[bacula/bacula] / bacula / src / tools / bsmtp.c
index 9cccc49c29051eb2f0ffe15492d97b72c1e9bab1..05851b869fb1b5cfd58926febadcdc8517d4a184 100644 (file)
@@ -1,17 +1,30 @@
 /*
-  Copyright (C) 2001-2006 Kern Sibbald
-
-   This program is free software; you can redistribute it and/or
-   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 
-   the file LICENSE for additional details.
-
- */
+   Bacula® - The Network Backup Solution
+
+   Copyright (C) 2001-2007 Free Software Foundation Europe e.V.
+
+   The main author of Bacula is Kern Sibbald, with contributions from
+   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.
+
+   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., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+   Bacula® is a registered trademark of John Walker.
+   The licensor of Bacula is the Free Software Foundation Europe
+   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+   Switzerland, email:ftf@fsfeurope.org.
+*/
 /*
    Derived from a SMTPclient:
 
@@ -27,6 +40,7 @@
 
  */
 
+
 #include "bacula.h"
 #include "jcr.h"
 #define MY_NAME "bsmtp"
@@ -54,6 +68,7 @@ static const char *mailhost = NULL;
 static char *reply_addr = NULL;
 static int mailport = 25;
 static char my_hostname[MAXSTRING];
+static bool content_utf8 = false;
 
 
 /*
@@ -116,6 +131,7 @@ static void usage()
    fprintf(stderr,
 _("\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"
 "       -f          set the From: field\n"
@@ -158,8 +174,11 @@ int main (int argc, char *argv[])
    my_name_is(argc, argv, "bsmtp");
    maxlines = 0;
 
-   while ((ch = getopt(argc, argv, "c:d:f:h:r:s:l:?")) != -1) {
+   while ((ch = getopt(argc, argv, "8c:d:f:h:r:s:l:?")) != -1) {
       switch (ch) {
+      case '8':
+         content_utf8 = true;
+         break;
       case 'c':
          Dmsg1(20, "cc=%s\n", optarg);
          cc_addr = optarg;
@@ -350,19 +369,33 @@ hp:
 #endif
 
    /*
-    *  Send SMTP headers
+    *  Send SMTP headers.  Note, if any of the strings have a <
+    *   in them already, we do not enclose the string in < >, otherwise
+    *   we do.
     */
    get_response(); /* banner */
    chat("helo %s\r\n", my_hostname);
-   chat("mail from:<%s>\r\n", from_addr);
+   if (strchr(from_addr, '<') == NULL) {
+      chat("mail from:<%s>\r\n", from_addr);
+   } else {
+      chat("mail from:%s\r\n", from_addr);
+   }
 
    for (i = 0; i < argc; i++) {
       Dmsg1(20, "rcpt to: %s\n", argv[i]);
-      chat("rcpt to:<%s>\r\n", argv[i]);
+      if (strchr(from_addr, '<') == NULL) {
+         chat("rcpt to:<%s>\r\n", argv[i]);
+      } else {
+         chat("rcpt to:%s\r\n", argv[i]);
+      }
    }
 
    if (cc_addr) {
-      chat("rcpt to:<%s>\r\n", cc_addr);
+      if (strchr(from_addr, '<') == NULL) {
+         chat("rcpt to:<%s>\r\n", cc_addr);
+      } else {
+         chat("rcpt to:%s\r\n", cc_addr);
+      }
    }
    Dmsg0(20, "Data\n");
    chat("data\r\n");
@@ -420,11 +453,16 @@ hp:
       Dmsg1(10, "Cc: %s\r\n", cc_addr);
    }
 
+   if (content_utf8) {
+      fprintf(sfp, "Content-Type: text/plain; charset=UTF-8\r\n");
+      Dmsg0(10, "Content-Type: text/plain; charset=UTF-8\r\n");
+   }
+
    /* Add RFC822 date */
    (void)localtime_r(&now, &tm);
 #if defined(HAVE_WIN32)
 #if defined(HAVE_MINGW)
-__MINGW_IMPORT long    _dstbias;
+__MINGW_IMPORT long     _dstbias;
 #endif
    long tzoffset = 0;