diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index 88f43b75e2ba76bf70b1ac0b6b753cacafbc7ca1..50427e3a6991743f6cc13308ad4185c660e27530 100755 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -391,6 +391,45 @@ static int sendmail(char *srcemail, char *email, char *name, int msgnum, char *m return 0; } +static int sendpage(char *srcemail, char *pager, int msgnum, char *mailbox, char *callerid, long duration) +{ + FILE *p; + char date[256]; + char host[256]; + char who[256]; + char dur[256]; + time_t t; + struct tm tm; + struct ast_config *cfg; + p = popen(SENDMAIL, "w"); + cfg = ast_load(VOICEMAIL_CONFIG); + + if (p) { + gethostname(host, sizeof(host)); + if (strchr(srcemail, '@')) + strncpy(who, srcemail, sizeof(who)-1); + else { + snprintf(who, sizeof(who), "%s@%s", srcemail, host); + } + snprintf(dur, sizeof(dur), "%ld:%02ld", duration / 60, duration % 60); + time(&t); + localtime_r(&t,&tm); + 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); + fprintf(p, "To: %s\n", pager); + fprintf(p, "Subject: New voicemail\n\n"); + strftime(date, sizeof(date), "%A, %B %d, %Y at %r", &tm); + fprintf(p, "New %s long message in mailbox %s\n" + "from %s, on %s", dur, mailbox, (callerid ? callerid : "unknown"), date); + pclose(p); + } else { + ast_log(LOG_WARNING, "Unable to launch '%s'\n", SENDMAIL); + return -1; + } + return 0; +} + static int get_date(char *s, int len) { struct tm tm; @@ -436,7 +475,7 @@ static int invent_message(struct ast_channel *chan, char *ext, int busy, char *e static int leave_voicemail(struct ast_channel *chan, char *ext, int silent, int busy, int unavail) { struct ast_config *cfg; - char *copy, *name, *passwd, *email, *fmt, *fmts; + char *copy, *name, *passwd, *email, *pager, *fmt, *fmts; char comment[256]; struct ast_filestream *writer=NULL, *others[MAX_OTHER_FORMATS]; char *sfmt[MAX_OTHER_FORMATS]; @@ -485,6 +524,7 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, int silent, int passwd = strsep(&stringp, ","); name = strsep(&stringp, ","); email = strsep(&stringp, ","); + pager = strsep(&stringp, ","); make_dir(dir, sizeof(dir), ext, ""); /* It's easier just to try to make it than to check for its existence */ if (mkdir(dir, 0700) && (errno != EEXIST)) @@ -712,6 +752,8 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, int silent, int /* Send e-mail if applicable */ if (email) sendmail(astemail, email, name, msgnum, ext, chan->callerid, fn, wavother ? "wav" : fmts, end - start); + if (pager) + sendpage(astemail, pager, msgnum, ext, chan->callerid, end - start); } } else { if (msgnum < MAXMSG) diff --git a/configs/voicemail.conf.sample b/configs/voicemail.conf.sample index 1b76e1916fd7aa4ef7f79b472d7406d4980a4579..f88887ccc2be591a9db0cc31e1ea809bb86c6e3d 100755 --- a/configs/voicemail.conf.sample +++ b/configs/voicemail.conf.sample @@ -18,9 +18,9 @@ attach=yes skipms=3000 ; -; Each mailbox is listed in the form <mailbox>=<password>,<name>,<email> +; Each mailbox is listed in the form <mailbox>=<password>,<name>,<email>,<pager_email> ; if the e-mail is specified, a message will be sent when a message is -; received, to the given mailbox. +; received, to the given mailbox. If pager is specified, a message will be sent there as well. ; [default] 1234 => 4242,Example Mailbox,root@localhost