Modified: freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c (15036 => 15037)
--- freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c 2009-10-01 22:22:33 UTC (rev 15036)
+++ freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c 2009-10-01 22:43:44 UTC (rev 15037)
@@ -130,6 +130,8 @@
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 @@
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 @@
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 @@
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 @@
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 @@
&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 @@
}
} 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 @@
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 @@
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 @@
}
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 @@
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);
Modified: freeswitch/trunk/src/switch_utils.c (15036 => 15037)
--- freeswitch/trunk/src/switch_utils.c 2009-10-01 22:22:33 UTC (rev 15036)
+++ freeswitch/trunk/src/switch_utils.c 2009-10-01 22:43:44 UTC (rev 15037)
@@ -429,7 +429,13 @@
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 @@
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_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 @@
"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 @@
}
}
if (write(fd, &out, bytes) != bytes) {
- return -1;
+ rval = -1;
} else
bytes = 0;
@@ -521,14 +549,14 @@
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_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)