On Monday 13 October 2003 22:18, Martin Pycko wrote:
> > However, the timezone is still not straight in the message body.
> > ${VM_DATE} doesn't seem to use the timezone matching routines
> > defined by the user's tz= setting.
>
> Well it's the task for those who add features to have a global-system
> thinking. The emailbody was added way before the timezones ...
You could have just said it was a bug, instead of insulting a
contributing developer. Patch attached.
> > Also, there seems to be a character limit for the length of
> > "emailbody=" that is a bit short - I get the last part of my
> > messages chopped off at a predictable point (seems to be around the
> > 500th character of the emailbody= line that it gets snipped.)
>
> That can be easily changes since the static array is used.
Actually, no, a static array is not used. The code assumes that a
minimum of twice the length of the email body (or 100 minimum) is of
sufficient length. But it's easily changed.
int vmlen = strlen(emailbody)*2;
if (vmlen < 20)
vmlen = 100;
passdata = alloca(vmlen);
bzero( passdata, vmlen );
-Tilghman
Index: apps/app_voicemail2.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_voicemail2.c,v
retrieving revision 1.56
diff -u -r1.56 app_voicemail2.c
--- apps/app_voicemail2.c 4 Oct 2003 22:08:02 -0000 1.56
+++ apps/app_voicemail2.c 14 Oct 2003 04:42:47 -0000
@@ -25,6 +25,7 @@
#include <asterisk/app.h>
#include <asterisk/manager.h>
#include <asterisk/dsp.h>
+#include <asterisk/localtime.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
@@ -631,7 +632,7 @@
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;
char date[256];
@@ -642,6 +643,8 @@
char dur[256];
time_t t;
struct tm tm;
+ struct vm_zone *the_zone = NULL;
+
if (!strcmp(format, "wav49"))
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);
@@ -655,7 +658,25 @@
}
snprintf(dur, sizeof(dur), "%ld:%02ld", duration / 60, duration % 60);
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);
fprintf(p, "Date: %s\n", date);
@@ -663,7 +684,7 @@
fprintf(p, "From: %s <%s>\n", fromstring, who);
else
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)
{
@@ -696,7 +717,7 @@
vmlen = 100;
passdata = alloca(vmlen);
bzero( passdata, vmlen );
- pbx_builtin_setvar_helper(ast, "VM_NAME", name);
+ pbx_builtin_setvar_helper(ast, "VM_NAME", vmu->fullname);
pbx_builtin_setvar_helper(ast, "VM_DUR", dur);
sprintf(passdata,"%d",msgnum);
pbx_builtin_setvar_helper(ast, "VM_MSGNUM", passdata);
@@ -711,7 +732,7 @@
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"
- "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);
}
if (attach_user_voicemail) {
@@ -733,7 +754,7 @@
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;
char date[256];
@@ -742,6 +763,7 @@
char dur[256];
time_t t;
struct tm tm;
+ struct vm_zone *the_zone = NULL;
p = popen(SENDMAIL, "w");
if (p) {
@@ -753,7 +775,26 @@
}
snprintf(dur, sizeof(dur), "%ld:%02ld", duration / 60, duration % 60);
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);
fprintf(p, "Date: %s\n", date);
fprintf(p, "From: Asterisk PBX <%s>\n", who);
@@ -1176,13 +1217,13 @@
attach_user_voicemail = vmu->attach;
if (strlen(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)) {
char *myserveremail = serveremail;
if (strlen(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
ast_log(LOG_WARNING, "No more messages possible\n");
@@ -1889,14 +1930,14 @@
attach_user_voicemail = receiver->attach;
if (strlen(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)) {
char *myserveremail = serveremail;
if (strlen(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 */