little mailer rework.
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6397 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
bd6ff49d05
commit
e7e026b94d
|
@ -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)
|
#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(size_t) switch_url_encode(const char *url, char *buf, size_t len);
|
||||||
SWITCH_DECLARE(char *) switch_url_decode(char *s);
|
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 */
|
/* malloc or DIE macros */
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
|
|
|
@ -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);
|
int len = (int) strlen(buf);
|
||||||
|
@ -82,23 +82,22 @@ static int write_buf(int fd, char *buf)
|
||||||
return 1;
|
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 *bound = "XXXX_boundary_XXXX";
|
||||||
|
char *mime_type = "audio/x-WAV";
|
||||||
char filename[80], buf[B64BUFFLEN];
|
char filename[80], buf[B64BUFFLEN];
|
||||||
int fd = 0, ifd = 0;
|
int fd = 0, ifd = 0;
|
||||||
int x = 0, y = 0, bytes = 0, ilen = 0;
|
int x = 0, y = 0, bytes = 0, ilen = 0;
|
||||||
unsigned int b = 0, l = 0;
|
unsigned int b = 0, l = 0;
|
||||||
unsigned char in[B64BUFFLEN];
|
unsigned char in[B64BUFFLEN];
|
||||||
unsigned char out[B64BUFFLEN + 512];
|
unsigned char out[B64BUFFLEN + 512];
|
||||||
char *path = NULL;
|
|
||||||
|
|
||||||
snprintf(filename, 80, "%smail.%d%04x", SWITCH_GLOBAL_dirs.temp_dir, (int)time(NULL), rand() & 0xffff);
|
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 ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644))) {
|
||||||
if (file) {
|
if (file) {
|
||||||
path = file;
|
if ((ifd = open(file, O_RDONLY)) < 1) {
|
||||||
if ((ifd = open(path, O_RDONLY)) < 1) {
|
|
||||||
return SWITCH_FALSE;
|
return SWITCH_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,9 +126,13 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(char *to, char *from, char *he
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
snprintf(buf, B64BUFFLEN, "\n\n--%s\nContent-Type: audio/x-WAV; name=\"%s\"\n"
|
const char *filename = switch_cut_path(file);
|
||||||
"Content-Transfer-Encoding: base64\n"
|
snprintf(buf, B64BUFFLEN,
|
||||||
"Content-Description: Sound attachment.\n" "Content-Disposition: attachment; filename=\"%s\"\n\n", bound, switch_cut_path(file), switch_cut_path(file));
|
"\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))
|
if (!write_buf(fd, buf))
|
||||||
return SWITCH_FALSE;
|
return SWITCH_FALSE;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue