git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@15037 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Brian West 2009-10-01 22:43:44 +00:00
parent cf23296c9a
commit 169195f3ce
3 changed files with 87 additions and 20 deletions

View File

@ -555,7 +555,13 @@ SWITCH_DECLARE(char *) switch_util_quote_shell_arg(const char *string);
#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(const char *to, const char *from, const char *headers, const char *body, const 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,
const char *convert_cmd,
const char *convert_ext);
SWITCH_DECLARE(char *) switch_find_end_paren(const char *s, char open, char close);

View File

@ -130,6 +130,8 @@ struct vm_profile {
char *web_tail;
char *email_from;
char *date_fmt;
char *convert_cmd;
char *convert_ext;
date_location_t play_date_announcement;
uint32_t digit_timeout;
uint32_t max_login_attempts;
@ -553,7 +555,13 @@ vm_profile_t *profile_set_config(vm_profile_t *profile)
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "play-date-announcement", SWITCH_CONFIG_ENUM, CONFIG_RELOADABLE,
&profile->play_date_announcement, VM_DATE_FIRST, &config_play_date_announcement, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "convert-cmd", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->convert_cmd, NULL, &profile->config_str_pool, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "convert-ext", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->convert_ext, NULL, &profile->config_str_pool, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "digit-timeout", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
&profile->digit_timeout, 10000, &config_int_digit_timeout, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "max-login-attempts", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
@ -1232,6 +1240,8 @@ struct listen_callback {
int want;
msg_type_t type;
msg_move_t move;
char *convert_cmd;
char *convert_ext;
};
typedef struct listen_callback listen_callback_t;
@ -1659,7 +1669,7 @@ static switch_status_t listen_file(switch_core_session_t *session, vm_profile_t
body = switch_mprintf("%u second Voicemail from %s %s", message_len, cbt->cid_name, cbt->cid_number);
}
switch_simple_email(cbt->email, from, header_string, body, cbt->file_path);
switch_simple_email(cbt->email, from, header_string, body, cbt->file_path, cbt->convert_cmd, cbt->convert_ext);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Sending message to %s\n", cbt->email);
switch_safe_free(body);
TRY_CODE(switch_ivr_phrase_macro(session, VM_ACK_MACRO, "emailed", NULL, NULL));
@ -1735,6 +1745,8 @@ static void voicemail_check_main(switch_core_session_t *session, vm_profile_t *p
int total_saved_urgent_messages = 0;
int heard_auto_saved = 0, heard_auto_new = 0;
char *vm_email = NULL;
char *convert_cmd = profile->convert_cmd;
char *convert_ext = profile->convert_ext;
char *vm_storage_dir = NULL;
char global_buf[2] = "";
switch_input_args_t args = { 0 };
@ -1849,6 +1861,8 @@ static void voicemail_check_main(switch_core_session_t *session, vm_profile_t *p
&total_new_urgent_messages, &total_saved_urgent_messages);
memset(&cbt, 0, sizeof(cbt));
cbt.email = vm_email;
cbt.convert_cmd = convert_cmd;
cbt.convert_ext = convert_ext;
cbt.move = VM_MOVE_NEXT;
switch (play_msg_type) {
case MSG_NEW:
@ -2154,9 +2168,13 @@ static void voicemail_check_main(switch_core_session_t *session, vm_profile_t *p
}
} else if (!strcasecmp(var, "vm-mailto")) {
vm_email = switch_core_session_strdup(session, val);
} else if (!strcasecmp(var, "vm-convert-cmd")) {
convert_cmd = switch_core_session_strdup(session, val);
} else if (!strcasecmp(var, "vm-convert-ext")) {
convert_ext = switch_core_session_strdup(session, val);
} else if (!strcasecmp(var, "storage-dir")) {
vm_storage_dir = switch_core_session_strdup(session, val);
} else if (!strcasecmp(var, "timezone")) {
switch_channel_set_variable(channel, var, val);
}
@ -2304,7 +2322,9 @@ static switch_status_t deliver_vm(vm_profile_t *profile,
const char *tmp;
switch_event_t *local_event = NULL;
switch_status_t ret = SWITCH_STATUS_SUCCESS;
char *convert_cmd = profile->convert_cmd;
char *convert_ext = profile->convert_ext;
if (!params) {
switch_event_create(&local_event, SWITCH_EVENT_REQUEST_PARAMS);
params = local_event;
@ -2357,6 +2377,10 @@ static switch_status_t deliver_vm(vm_profile_t *profile,
insert_db = switch_true(val);
} else if (!strcasecmp(var, "vm-attach-file")) {
email_attach = switch_true(val);
} else if (!strcasecmp(var, "vm-convert-cmd")) {
convert_cmd = switch_core_strdup(pool, val);
} else if (!strcasecmp(var, "vm-convert-ext")) {
convert_ext = switch_core_strdup(pool, val);
} else if (!strcasecmp(var, "timezone")) {
vm_timezone = switch_core_strdup(pool, val);
}
@ -2528,9 +2552,9 @@ static switch_status_t deliver_vm(vm_profile_t *profile,
}
if (email_attach) {
switch_simple_email(vm_email, from, header_string, body, file_path);
switch_simple_email(vm_email, from, header_string, body, file_path, convert_cmd, convert_ext);
} else {
switch_simple_email(vm_email, from, header_string, body, NULL);
switch_simple_email(vm_email, from, header_string, body, NULL, NULL, NULL);
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending message to %s\n", vm_email);
@ -2579,7 +2603,7 @@ static switch_status_t deliver_vm(vm_profile_t *profile,
body = switch_mprintf("%u second Voicemail from %s %s", message_len, caller_id_name, caller_id_number);
}
switch_simple_email(vm_notify_email, from, header_string, body, NULL);
switch_simple_email(vm_notify_email, from, header_string, body, NULL, NULL, NULL);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending notify message to %s\n", vm_notify_email);

View File

@ -429,7 +429,13 @@ static int write_buf(int fd, const char *buf)
return 1;
}
SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to, const char *from, const char *headers, const char *body, const 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,
const char *convert_cmd,
const char *convert_ext)
{
char *bound = "XXXX_boundary_XXXX";
const char *mime_type = "audio/inline";
@ -439,25 +445,47 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to, const char *fr
unsigned int b = 0, l = 0;
unsigned char in[B64BUFFLEN];
unsigned char out[B64BUFFLEN + 512];
char *dupfile = NULL, *ext = NULL;
char *newfile = NULL;
switch_bool_t rval = SWITCH_FALSE;
if (!switch_strlen_zero(file) && !switch_strlen_zero(convert_cmd) && !switch_strlen_zero(convert_ext)) {
if ((ext = strrchr(file, '.'))) {
dupfile = strdup(file);
if ((ext = strrchr(dupfile, '.'))) {
*ext++ = '\0';
newfile = switch_mprintf("%s.%s", dupfile, convert_ext);
}
}
if (newfile) {
char cmd[1024] = "";
switch_snprintf(cmd, sizeof(cmd), "%s %s %s", convert_cmd, file, newfile);
switch_system(cmd, SWITCH_TRUE);
file = newfile;
}
switch_safe_free(dupfile);
}
switch_snprintf(filename, 80, "%smail.%d%04x", SWITCH_GLOBAL_dirs.temp_dir, (int) switch_epoch_time_now(NULL), rand() & 0xffff);
if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644))) {
if (file) {
if ((ifd = open(file, O_RDONLY | O_BINARY)) < 1) {
return SWITCH_FALSE;
rval = SWITCH_FALSE; goto end;
}
}
switch_snprintf(buf, B64BUFFLEN, "MIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"%s\"\n", bound);
if (!write_buf(fd, buf)) {
return SWITCH_FALSE;
rval = SWITCH_FALSE; goto end;
}
if (headers && !write_buf(fd, headers))
return SWITCH_FALSE;
rval = SWITCH_FALSE; goto end;
if (!write_buf(fd, "\n\n"))
return SWITCH_FALSE;
rval = SWITCH_FALSE; goto end;
if (body && switch_stristr("content-type", body)) {
switch_snprintf(buf, B64BUFFLEN, "--%s\n", bound);
@ -465,11 +493,11 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to, const char *fr
switch_snprintf(buf, B64BUFFLEN, "--%s\nContent-Type: text/plain\n\n", bound);
}
if (!write_buf(fd, buf))
return SWITCH_FALSE;
rval = SWITCH_FALSE; goto end;
if (body) {
if (!write_buf(fd, body)) {
return SWITCH_FALSE;
rval = SWITCH_FALSE; goto end;
}
}
@ -492,7 +520,7 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to, const char *fr
"Content-Description: Sound attachment.\n"
"Content-Disposition: attachment; filename=\"%s\"\n\n", bound, mime_type, stipped_file, stipped_file);
if (!write_buf(fd, buf))
return SWITCH_FALSE;
rval = SWITCH_FALSE; goto end;
while ((ilen = read(ifd, in, B64BUFFLEN))) {
for (x = 0; x < ilen; x++) {
@ -507,7 +535,7 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to, const char *fr
}
}
if (write(fd, &out, bytes) != bytes) {
return -1;
rval = -1;
} else
bytes = 0;
@ -521,14 +549,14 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to, const char *fr
out[bytes++] = '=', l += 2;
}
if (write(fd, &out, bytes) != bytes) {
return -1;
rval = -1;
}
}
switch_snprintf(buf, B64BUFFLEN, "\n\n--%s--\n.\n", bound);
if (!write_buf(fd, buf))
return SWITCH_FALSE;
rval = SWITCH_FALSE; goto end;
}
if (fd) {
@ -556,7 +584,16 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to, const char *fr
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Emailed data to [%s]\n", to);
}
return SWITCH_TRUE;
rval = SWITCH_TRUE;
end:
if (newfile) {
unlink(newfile);
free(newfile);
}
return rval;
}
SWITCH_DECLARE(switch_bool_t) switch_is_lan_addr(const char *ip)