Voicemail2 fixes for attachment and timezone stuff (bug #384/#385)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1631 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Spencer
2003-10-14 10:03:42 +00:00
parent 2bf8b38383
commit aada3ee156

View File

@@ -25,6 +25,7 @@
#include <asterisk/app.h> #include <asterisk/app.h>
#include <asterisk/manager.h> #include <asterisk/manager.h>
#include <asterisk/dsp.h> #include <asterisk/dsp.h>
#include <asterisk/localtime.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
@@ -631,7 +632,7 @@ static int base_encode(char *filename, FILE *so)
return 1; return 1;
} }
static int sendmail(char *srcemail, char *email, char *name, int msgnum, char *mailbox, char *callerid, char *attach, char *format, long duration, int attach_user_voicemail) static int sendmail(char *srcemail, struct ast_vm_user *vmu, int msgnum, char *mailbox, char *callerid, char *attach, char *format, long duration, int attach_user_voicemail)
{ {
FILE *p; FILE *p;
char date[256]; char date[256];
@@ -642,6 +643,8 @@ static int sendmail(char *srcemail, char *email, char *name, int msgnum, char *m
char dur[256]; char dur[256];
time_t t; time_t t;
struct tm tm; struct tm tm;
struct vm_zone *the_zone = NULL;
if (!strcmp(format, "wav49")) if (!strcmp(format, "wav49"))
format = "WAV"; format = "WAV";
ast_log(LOG_DEBUG, "Attaching file '%s', format '%s', uservm is '%d', global is %d\n", attach, format, attach_user_voicemail, attach_voicemail); ast_log(LOG_DEBUG, "Attaching file '%s', format '%s', uservm is '%d', global is %d\n", attach, format, attach_user_voicemail, attach_voicemail);
@@ -655,7 +658,25 @@ static int sendmail(char *srcemail, char *email, char *name, int msgnum, char *m
} }
snprintf(dur, sizeof(dur), "%ld:%02ld", duration / 60, duration % 60); snprintf(dur, sizeof(dur), "%ld:%02ld", duration / 60, duration % 60);
time(&t); time(&t);
localtime_r(&t,&tm);
/* Does this user have a timezone specified? */
if (strlen(vmu->zonetag)) {
/* Find the zone in the list */
struct vm_zone *z;
z = zones;
while (z) {
if (!strcmp(z->name, vmu->zonetag)) {
the_zone = z;
break;
}
z = z->next;
}
}
if (the_zone)
ast_localtime(&t,&tm,the_zone->timezone);
else
ast_localtime(&t,&tm,NULL);
strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", &tm); strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", &tm);
fprintf(p, "Date: %s\n", date); fprintf(p, "Date: %s\n", date);
@@ -663,7 +684,7 @@ static int sendmail(char *srcemail, char *email, char *name, int msgnum, char *m
fprintf(p, "From: %s <%s>\n", fromstring, who); fprintf(p, "From: %s <%s>\n", fromstring, who);
else else
fprintf(p, "From: Asterisk PBX <%s>\n", who); fprintf(p, "From: Asterisk PBX <%s>\n", who);
fprintf(p, "To: %s <%s>\n", name, email); fprintf(p, "To: %s <%s>\n", vmu->fullname, vmu->email);
if( *emailtitle) if( *emailtitle)
{ {
@@ -691,27 +712,26 @@ static int sendmail(char *srcemail, char *email, char *name, int msgnum, char *m
struct ast_channel *ast = ast_channel_alloc(0); struct ast_channel *ast = ast_channel_alloc(0);
if (ast) { if (ast) {
char *passdata; char *passdata;
int vmlen = strlen(emailbody)*2; int vmlen = strlen(emailbody)*3 + 200;
if (vmlen < 20) if ((passdata = alloca(vmlen))) {
vmlen = 100; memset(passdata, 0, vmlen);
passdata = alloca(vmlen); pbx_builtin_setvar_helper(ast, "VM_NAME", vmu->fullname);
bzero( passdata, vmlen ); pbx_builtin_setvar_helper(ast, "VM_DUR", dur);
pbx_builtin_setvar_helper(ast, "VM_NAME", name); sprintf(passdata,"%d",msgnum);
pbx_builtin_setvar_helper(ast, "VM_DUR", dur); pbx_builtin_setvar_helper(ast, "VM_MSGNUM", passdata);
sprintf(passdata,"%d",msgnum); pbx_builtin_setvar_helper(ast, "VM_MAILBOX", mailbox);
pbx_builtin_setvar_helper(ast, "VM_MSGNUM", passdata); pbx_builtin_setvar_helper(ast, "VM_CALLERID", (callerid ? callerid : "an unknown caller"));
pbx_builtin_setvar_helper(ast, "VM_MAILBOX", mailbox); pbx_builtin_setvar_helper(ast, "VM_DATE", date);
pbx_builtin_setvar_helper(ast, "VM_CALLERID", (callerid ? callerid : "an unknown caller")); pbx_substitute_variables_helper(ast,emailbody,passdata,vmlen);
pbx_builtin_setvar_helper(ast, "VM_DATE", date); fprintf(p, "%s\n",passdata);
pbx_substitute_variables_helper(ast,emailbody,passdata,vmlen); } else ast_log(LOG_WARNING, "Cannot allocate workspace for variable substitution\n");
fprintf(p, "%s\n",passdata);
ast_channel_free(ast); ast_channel_free(ast);
} else ast_log(LOG_WARNING, "Cannot allocate the channel for variables substitution\n"); } else ast_log(LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
} else { } else {
fprintf(p, "Dear %s:\n\n\tJust wanted to let you know you were just left a %s long message (number %d)\n" fprintf(p, "Dear %s:\n\n\tJust wanted to let you know you were just left a %s long message (number %d)\n"
"in mailbox %s from %s, on %s so you might\n" "in mailbox %s from %s, on %s so you might\n"
"want to check it when you get a chance. Thanks!\n\n\t\t\t\t--Asterisk\n\n", name, "want to check it when you get a chance. Thanks!\n\n\t\t\t\t--Asterisk\n\n", vmu->fullname,
dur, msgnum + 1, mailbox, (callerid ? callerid : "an unknown caller"), date); dur, msgnum + 1, mailbox, (callerid ? callerid : "an unknown caller"), date);
} }
if (attach_user_voicemail) { if (attach_user_voicemail) {
@@ -733,7 +753,7 @@ static int sendmail(char *srcemail, char *email, char *name, int msgnum, char *m
return 0; return 0;
} }
static int sendpage(char *srcemail, char *pager, int msgnum, char *mailbox, char *callerid, long duration) static int sendpage(char *srcemail, char *pager, int msgnum, char *mailbox, char *callerid, long duration, struct ast_vm_user *vmu)
{ {
FILE *p; FILE *p;
char date[256]; char date[256];
@@ -742,6 +762,7 @@ static int sendpage(char *srcemail, char *pager, int msgnum, char *mailbox, char
char dur[256]; char dur[256];
time_t t; time_t t;
struct tm tm; struct tm tm;
struct vm_zone *the_zone = NULL;
p = popen(SENDMAIL, "w"); p = popen(SENDMAIL, "w");
if (p) { if (p) {
@@ -753,7 +774,26 @@ static int sendpage(char *srcemail, char *pager, int msgnum, char *mailbox, char
} }
snprintf(dur, sizeof(dur), "%ld:%02ld", duration / 60, duration % 60); snprintf(dur, sizeof(dur), "%ld:%02ld", duration / 60, duration % 60);
time(&t); time(&t);
localtime_r(&t,&tm);
/* Does this user have a timezone specified? */
if (strlen(vmu->zonetag)) {
/* Find the zone in the list */
struct vm_zone *z;
z = zones;
while (z) {
if (!strcmp(z->name, vmu->zonetag)) {
the_zone = z;
break;
}
z = z->next;
}
}
if (the_zone)
ast_localtime(&t,&tm,the_zone->timezone);
else
ast_localtime(&t,&tm,NULL);
strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", &tm); strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", &tm);
fprintf(p, "Date: %s\n", date); fprintf(p, "Date: %s\n", date);
fprintf(p, "From: Asterisk PBX <%s>\n", who); fprintf(p, "From: Asterisk PBX <%s>\n", who);
@@ -1176,13 +1216,13 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, int silent, int
attach_user_voicemail = vmu->attach; attach_user_voicemail = vmu->attach;
if (strlen(vmu->serveremail)) if (strlen(vmu->serveremail))
myserveremail = vmu->serveremail; myserveremail = vmu->serveremail;
sendmail(myserveremail, vmu->email, vmu->fullname, msgnum, ext, chan->callerid, fn, fmt, end - start, attach_user_voicemail); sendmail(myserveremail, vmu, msgnum, ext, chan->callerid, fn, fmt, end - start, attach_user_voicemail);
} }
if (strlen(vmu->pager)) { if (strlen(vmu->pager)) {
char *myserveremail = serveremail; char *myserveremail = serveremail;
if (strlen(vmu->serveremail)) if (strlen(vmu->serveremail))
myserveremail = vmu->serveremail; myserveremail = vmu->serveremail;
sendpage(myserveremail, vmu->pager, msgnum, ext, chan->callerid, end - start); sendpage(myserveremail, vmu->pager, msgnum, ext, chan->callerid, end - start, vmu);
} }
} else } else
ast_log(LOG_WARNING, "No more messages possible\n"); ast_log(LOG_WARNING, "No more messages possible\n");
@@ -1889,14 +1929,14 @@ forward_message(struct ast_channel *chan, char *context, char *dir, int curmsg,
attach_user_voicemail = receiver->attach; attach_user_voicemail = receiver->attach;
if (strlen(receiver->serveremail)) if (strlen(receiver->serveremail))
myserveremail = receiver->serveremail; myserveremail = receiver->serveremail;
sendmail(myserveremail, receiver->email, receiver->fullname, todircount, username, callerid, fn, tmp, atol(ast_variable_retrieve(mif, NULL, "duration")), attach_user_voicemail); sendmail(myserveremail, receiver, todircount, username, callerid, fn, tmp, atol(ast_variable_retrieve(mif, NULL, "duration")), attach_user_voicemail);
} }
if (strlen(receiver->pager)) { if (strlen(receiver->pager)) {
char *myserveremail = serveremail; char *myserveremail = serveremail;
if (strlen(receiver->serveremail)) if (strlen(receiver->serveremail))
myserveremail = receiver->serveremail; myserveremail = receiver->serveremail;
sendpage(myserveremail, receiver->pager, todircount, username, callerid, duration); sendpage(myserveremail, receiver->pager, todircount, username, callerid, duration, receiver);
} }
ast_destroy(mif); /* or here */ ast_destroy(mif); /* or here */