]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-5142 don't multipart/mixed if body has content-type present
authorBrian West <brian@freeswitch.org>
Thu, 11 Sep 2014 19:18:37 +0000 (14:18 -0500)
committerBrian West <brian@freeswitch.org>
Thu, 11 Sep 2014 19:18:42 +0000 (14:18 -0500)
src/switch_utils.c

index 399442be7192c122a35ce644521b1f6ccaba96a0..f57ea00c4e9d06dc9122468af46235adbe19478b 100644 (file)
@@ -808,11 +808,18 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to,
                                goto end;
                        }
                }
-               switch_snprintf(buf, B64BUFFLEN, "MIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"%s\"\n", bound);
-               if (!write_buf(fd, buf)) {
-                       rval = SWITCH_FALSE;
-                       err = "write error.";
-                       goto end;
+
+               if (!file && (!body || !switch_stristr("content-type", body))) {
+                       bound = NULL;
+               }
+
+               if (bound) {
+                       switch_snprintf(buf, B64BUFFLEN, "MIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"%s\"\n", bound);
+                       if (!write_buf(fd, buf)) {
+                               rval = SWITCH_FALSE;
+                               err = "write error.";
+                               goto end;
+                       }
                }
 
                if (headers && !write_buf(fd, headers)) {
@@ -827,15 +834,17 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to,
                        goto end;
                }
 
-               if (body && switch_stristr("content-type", body)) {
-                       switch_snprintf(buf, B64BUFFLEN, "--%s\n", bound);
-               } else {
-                       switch_snprintf(buf, B64BUFFLEN, "--%s\nContent-Type: text/plain\n\n", bound);
-               }
-               if (!write_buf(fd, buf)) {
-                       rval = SWITCH_FALSE;
-                       err = "write error.";
-                       goto end;
+               if (bound) {
+                       if (body && switch_stristr("content-type", body)) {
+                               switch_snprintf(buf, B64BUFFLEN, "--%s\n", bound);
+                       } else {
+                               switch_snprintf(buf, B64BUFFLEN, "--%s\nContent-Type: text/plain\n\n", bound);
+                       }
+                       if (!write_buf(fd, buf)) {
+                               rval = SWITCH_FALSE;
+                               err = "write error.";
+                               goto end;
+                       }
                }
 
                if (body) {
@@ -846,7 +855,7 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to,
                        }
                }
 
-               if (file) {
+               if (file && bound) {
                        const char *stipped_file = switch_cut_path(file);
                        const char *new_type;
                        char *ext;
@@ -904,12 +913,14 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to,
 
                }
 
-               switch_snprintf(buf, B64BUFFLEN, "\n\n--%s--\n.\n", bound);
+               if (bound) {
+                       switch_snprintf(buf, B64BUFFLEN, "\n\n--%s--\n.\n", bound);
 
-               if (!write_buf(fd, buf)) {
-                       rval = SWITCH_FALSE;
-                       err = "write error.";
-                       goto end;
+                       if (!write_buf(fd, buf)) {
+                               rval = SWITCH_FALSE;
+                               err = "write error.";
+                               goto end;
+                       }
                }
        }