From e7e026b94da8c0ca9a17eced937acb5dc6d5e7b2 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 26 Nov 2007 17:43:42 +0000 Subject: [PATCH] little mailer rework. git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6397 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_utils.h | 2 +- src/switch_utils.c | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h index 6949d1d3ae..0bb187b09b 100644 --- a/src/include/switch_utils.h +++ b/src/include/switch_utils.h @@ -336,7 +336,7 @@ SWITCH_DECLARE(switch_status_t) switch_string_match(const char *string, size_t s #define SWITCH_READ_ACCEPTABLE(status) (status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_BREAK) SWITCH_DECLARE(size_t) switch_url_encode(const char *url, char *buf, size_t len); SWITCH_DECLARE(char *) switch_url_decode(char *s); -SWITCH_DECLARE(switch_bool_t) switch_simple_email(char *to, char *from, char *headers, char *body, char *file); +SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to, const char *from, const char *headers, const char *body, const char *file); /* malloc or DIE macros */ #ifdef NDEBUG diff --git a/src/switch_utils.c b/src/switch_utils.c index 5e495c1b2e..521e65664b 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -70,7 +70,7 @@ SWITCH_DECLARE(switch_status_t) switch_b64_encode(unsigned char *in, switch_size -static int write_buf(int fd, char *buf) +static int write_buf(int fd, const char *buf) { int len = (int) strlen(buf); @@ -82,23 +82,22 @@ static int write_buf(int fd, char *buf) return 1; } -SWITCH_DECLARE(switch_bool_t) switch_simple_email(char *to, char *from, char *headers, char *body, char *file) +SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to, const char *from, const char *headers, const char *body, const char *file) { char *bound = "XXXX_boundary_XXXX"; + char *mime_type = "audio/x-WAV"; char filename[80], buf[B64BUFFLEN]; int fd = 0, ifd = 0; int x = 0, y = 0, bytes = 0, ilen = 0; unsigned int b = 0, l = 0; unsigned char in[B64BUFFLEN]; unsigned char out[B64BUFFLEN + 512]; - char *path = NULL; snprintf(filename, 80, "%smail.%d%04x", SWITCH_GLOBAL_dirs.temp_dir, (int)time(NULL), rand() & 0xffff); if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644))) { if (file) { - path = file; - if ((ifd = open(path, O_RDONLY)) < 1) { + if ((ifd = open(file, O_RDONLY)) < 1) { return SWITCH_FALSE; } @@ -127,9 +126,13 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(char *to, char *from, char *he } if (file) { - snprintf(buf, B64BUFFLEN, "\n\n--%s\nContent-Type: audio/x-WAV; name=\"%s\"\n" - "Content-Transfer-Encoding: base64\n" - "Content-Description: Sound attachment.\n" "Content-Disposition: attachment; filename=\"%s\"\n\n", bound, switch_cut_path(file), switch_cut_path(file)); + const char *filename = switch_cut_path(file); + snprintf(buf, B64BUFFLEN, + "\n\n--%s\nContent-Type: %s; name=\"%s\"\n" + "Content-Transfer-Encoding: base64\n" + "Content-Description: Sound attachment.\n" + "Content-Disposition: attachment; filename=\"%s\"\n\n", + bound, mime_type, filename, filename); if (!write_buf(fd, buf)) return SWITCH_FALSE;