diff --git a/apps/app_voicemail2.c b/apps/app_voicemail2.c index 911763e1dfce4d83f2002f9c3c782485c1e60ee8..06ba301c5ebbe3ca26193987a0d2f6acf4f9ecd2 100755 --- a/apps/app_voicemail2.c +++ b/apps/app_voicemail2.c @@ -83,6 +83,7 @@ struct ast_vm_user { char fullname[80]; char email[80]; char pager[80]; + char options[160]; int alloced; struct ast_vm_user *next; }; @@ -187,6 +188,7 @@ static struct ast_vm_user *find_user(struct ast_vm_user *ivm, char *context, cha *retval->fullname='\0'; *retval->email='\0'; *retval->pager='\0'; + *retval->options='\0'; retval->alloced=1; retval->next=NULL; if (mailbox) { @@ -197,9 +199,9 @@ static struct ast_vm_user *find_user(struct ast_vm_user *ivm, char *context, cha } if (*retval->context) { - sprintf(query, "SELECT password,fullname,email,pager FROM users WHERE context='%s' AND mailbox='%s'", context, mailbox); + sprintf(query, "SELECT password,fullname,email,pager,options FROM users WHERE context='%s' AND mailbox='%s'", context, mailbox); } else { - sprintf(query, "SELECT password,fullname,email,pager FROM users WHERE mailbox='%s'", mailbox); + sprintf(query, "SELECT password,fullname,email,pager,options FROM users WHERE mailbox='%s'", mailbox); } pthread_mutex_lock(&mysqllock); mysql_query(dbhandler, query); @@ -217,6 +219,8 @@ static struct ast_vm_user *find_user(struct ast_vm_user *ivm, char *context, cha strcpy(retval->email, rowval[i]); } else if (!strcmp(fields[i].name, "pager")) { strcpy(retval->pager, rowval[i]); + } else if (!strcmp(fields[i].name, "options")) { + strcpy(retval->options, rowval[i]); } } } @@ -528,7 +532,31 @@ static int base_encode(char *filename, FILE *so) return 1; } -static int sendmail(char *srcemail, char *email, char *name, int msgnum, char *mailbox, char *callerid, char *attach, char *format, long duration) +static int getoptionvalue(char *options, char *optionname, char *value) +{ + char *c, *d; + + if (!(c=strstr(options, optionname))) { + return 0; + } + if (c!=options && *(c-1)!='|') { + return 0; + } + if (*(c+strlen(optionname))!='=') { + return 0; + } + + c+=strlen(optionname)+1; + if ((d=strchr(c, '|'))) { + strncpy(value, c, d-c); + *(value+(d-c))='\0'; + } else { + strcpy(value, c); + } + 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) { FILE *p; char date[256]; @@ -559,7 +587,7 @@ static int sendmail(char *srcemail, char *email, char *name, int msgnum, char *m fprintf(p, "Subject: [PBX]: New message %d in mailbox %s\n", msgnum, mailbox); fprintf(p, "Message-ID: <Asterisk-%d-%s-%d@%s>\n", msgnum, mailbox, getpid(), host); fprintf(p, "MIME-Version: 1.0\n"); - if (attach_voicemail) { + if ((attach_user_voicemail==-1 && attach_voicemail) || attach_user_voicemail==1) { // Something unique. snprintf(bound, sizeof(bound), "Boundary=%d%s%d", msgnum, mailbox, getpid()); @@ -574,7 +602,7 @@ static int sendmail(char *srcemail, char *email, char *name, int msgnum, char *m "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, dur, msgnum, mailbox, (callerid ? callerid : "an unknown caller"), date); - if (attach_voicemail) { + if ((attach_user_voicemail==-1 && attach_voicemail) || attach_user_voicemail==1) { fprintf(p, "--%s\n", bound); fprintf(p, "Content-Type: audio/x-wav; name=\"msg%04d.%s\"\n", msgnum, format); fprintf(p, "Content-Transfer-Encoding: BASE64\n"); @@ -1021,8 +1049,14 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, int silent, int stringp = fmt; strsep(&stringp, "|"); /* Send e-mail if applicable */ - if (strlen(vmu->email)) - sendmail(serveremail, vmu->email, vmu->fullname, msgnum, ext, chan->callerid, fn, fmt, end - start); + if (strlen(vmu->email)) { + int attach_user_voicemail=-1; + char tmpvalue[160]; + if (getoptionvalue(vmu->options, "attach", tmpvalue)) { + attach_user_voicemail=ast_true(tmpvalue); + } + sendmail(serveremail, vmu->email, vmu->fullname, msgnum, ext, chan->callerid, fn, fmt, end - start, attach_user_voicemail); + } if (strlen(vmu->pager)) sendpage(serveremail, vmu->pager, msgnum, ext, chan->callerid, end - start); } else @@ -1706,9 +1740,15 @@ forward_message(struct ast_channel *chan, char *context, char *dir, int curmsg, snprintf(callerid, sizeof(callerid), "FWD from: %s from %s", sender->fullname, ast_variable_retrieve(mif, NULL, "callerid")); duration = atol(ast_variable_retrieve(mif, NULL, "duration")); - if (strlen(receiver->email)) - sendmail(serveremail, receiver->email, receiver->fullname, todircount, username, callerid, fn, tmp, atol(ast_variable_retrieve(mif, NULL, "duration"))); - + if (strlen(receiver->email)) { + int attach_user_voicemail=-1; + char tmpvalue[160]; + if (getoptionvalue(receiver->options, "attach", tmpvalue)) { + attach_user_voicemail=ast_true(tmpvalue); + } + sendmail(serveremail, receiver->email, receiver->fullname, todircount, username, callerid, fn, tmp, atol(ast_variable_retrieve(mif, NULL, "duration")), attach_user_voicemail); + } + if (strlen(receiver->pager)) sendpage(serveremail, receiver->pager, todircount, username, callerid, duration); @@ -2353,6 +2393,8 @@ static int append_mailbox(char *context, char *mbox, char *data) strncpy(vmu->email, s, sizeof(vmu->email)); if ((s = strsep(&stringp, ","))) strncpy(vmu->pager, s, sizeof(vmu->pager)); + if ((s = strsep(&stringp, ","))) + strncpy(vmu->options, s, sizeof(vmu->options)); vmu->next = NULL; if (usersl) usersl->next = vmu; diff --git a/contrib/scripts/vmdb.sql b/contrib/scripts/vmdb.sql index be70f323d2b5fa010e89299fc04e8adb1d661132..dbef173160116985788338761cf49f193e35998a 100755 --- a/contrib/scripts/vmdb.sql +++ b/contrib/scripts/vmdb.sql @@ -1 +1,2 @@ -create table users (mailbox VARCHAR(80) NOT NULL PRIMARY KEY, context VARCHAR(80), password VARCHAR(80), fullname VARCHAR(80), email VARCHAR(80), pager VARCHAR(80)); +drop table if exists users; +create table users (mailbox VARCHAR(80) NOT NULL PRIMARY KEY, context VARCHAR(80), password VARCHAR(80), fullname VARCHAR(80), email VARCHAR(80), pager VARCHAR(80), options VARCHAR(160)); diff --git a/vmdb.sql b/vmdb.sql index be70f323d2b5fa010e89299fc04e8adb1d661132..dbef173160116985788338761cf49f193e35998a 100755 --- a/vmdb.sql +++ b/vmdb.sql @@ -1 +1,2 @@ -create table users (mailbox VARCHAR(80) NOT NULL PRIMARY KEY, context VARCHAR(80), password VARCHAR(80), fullname VARCHAR(80), email VARCHAR(80), pager VARCHAR(80)); +drop table if exists users; +create table users (mailbox VARCHAR(80) NOT NULL PRIMARY KEY, context VARCHAR(80), password VARCHAR(80), fullname VARCHAR(80), email VARCHAR(80), pager VARCHAR(80), options VARCHAR(160));