/*
- 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:
*/
+
#include "bacula.h"
#include "jcr.h"
#define MY_NAME "bsmtp"
static char *reply_addr = NULL;
static int mailport = 25;
static char my_hostname[MAXSTRING];
+static bool content_utf8 = false;
/*
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"
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;
exit(1);
}
+#if defined(HAVE_WIN32)
+ _setmode(0, _O_BINARY);
+#endif
+
/*
* Determine SMTP server
*/
Dmsg0(20, "Connected\n");
#if defined(HAVE_WIN32)
- int fdSocket = _open_osfhandle(s, _O_RDWR);
+ int fdSocket = _open_osfhandle(s, _O_RDWR | _O_BINARY);
if (fdSocket == -1) {
Pmsg1(0, _("Fatal _open_osfhandle error: ERR=%s\n"), strerror(errno));
exit(1);
#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");
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;
Dmsg1(20, "skip line because of maxlines limit: %lu\n", maxlines);
break;
}
- buf[strlen(buf)-1] = 0;
- if (strcmp(buf, ".") == 0) { /* quote lone dots */
- fprintf(sfp, "..\r\n");
+ buf[sizeof(buf)-1] = '\0';
+ buf[strlen(buf)-1] = '\0';
+ if (buf[0] == '.' && buf[1] == '\0') { /* quote lone dots */
+ fputs("..\r\n", sfp);
} else { /* pass body through unchanged */
- fprintf(sfp, "%s\r\n", buf);
+ fputs(buf, sfp);
+ fputs("\r\n", sfp);
}
}