[asterisk-commits] oej: branch oej/minivoicemail r56836 - in
/team/oej/minivoicemail: apps/ conf...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Mon Feb 26 11:48:28 MST 2007
Author: oej
Date: Mon Feb 26 12:48:27 2007
New Revision: 56836
URL: http://svn.digium.com/view/asterisk?view=rev&rev=56836
Log:
- Read templates from files (still buggy)
- Update documentation (doxygen + configuration example)
Modified:
team/oej/minivoicemail/apps/app_minivm.c
team/oej/minivoicemail/configs/minivm.conf.sample
team/oej/minivoicemail/include/asterisk/doxyref.h
Modified: team/oej/minivoicemail/apps/app_minivm.c
URL: http://svn.digium.com/view/asterisk/team/oej/minivoicemail/apps/app_minivm.c?view=diff&rev=56836&r1=56835&r2=56836
==============================================================================
--- team/oej/minivoicemail/apps/app_minivm.c (original)
+++ team/oej/minivoicemail/apps/app_minivm.c Mon Feb 26 12:48:27 2007
@@ -4,8 +4,8 @@
* Copyright (C) 1999 - 2005, Digium, Inc.
* and Edvina AB, Sollentuna, Sweden
*
- * Mark Spencer <markster at digium.com>
- * and Olle E. Johansson, Edvina.net
+ * Mark Spencer <markster at digium.com> (Comedian Mail)
+ * and Olle E. Johansson, Edvina.net <oej at edvina.net> (Mini-Voicemail changes)
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
@@ -23,12 +23,14 @@
* \brief MiniVoiceMail - A Minimal Voicemail System
*
* A voicemail system in small building blocks, working together
- *
* based on the Comedian Mail voicemail system (app_voicemail.c).
*
* \par See also
- * \arg \ref Config_vm
+ * \arg \ref Config_minivm
+ * \arg \ref App_minivm
+ *
* \ingroup applications
+ *
* \page App_minivm Markodian Mail - A minimal voicemail system
*
* This is a minimal voicemail system, building blocks for something
@@ -44,8 +46,13 @@
* by userid and domain
*
* Language codes are like setlocale - langcode_countrycode
+ * \note Don't use language codes like the rest of Asterisk, two letter countrycode
+ *
+ * \par See also
+ * \arg \ref Config_minivm
+ * \arg \ref app_minivm.c
+ * \arg Comedian mail: app_voicemail.c
*
- *
*/
/*! \page App_minivm_todo Markodian Minimail - todo
@@ -57,6 +64,7 @@
* - test, test, test, test
* - fix "vm-theextensionis.gsm" voiceprompt from Allison in various formats
* "The extension you are calling"
+ * - Maybe split recording from actual forwarding in e-mail into two applications
*/
#include <stdlib.h>
@@ -112,38 +120,39 @@
#define MVM_PBXSKIP (1 << 9)
#define MVM_ALLOCED (1 << 13)
-/* Default mail command to mail voicemail. Change it with the
+/*! \brief Default mail command to mail voicemail. Change it with the
mailcmd= command in voicemail.conf */
#define SENDMAIL "/usr/sbin/sendmail -t"
-#define SOUND_INTRO "vm-intro"
-#define B64_BASEMAXINLINE 256 /*!< Buffer size for Base 64 attachment encoding */
-#define B64_BASELINELEN 72 /*!< Line length for Base 64 endoded messages */
-#define EOL "\r\n"
+#define SOUND_INTRO "vm-intro"
+#define B64_BASEMAXINLINE 256 /*!< Buffer size for Base 64 attachment encoding */
+#define B64_BASELINELEN 72 /*!< Line length for Base 64 endoded messages */
+#define EOL "\r\n"
#define MAX_DATETIME_FORMAT 512
-#define MAX_NUM_CID_CONTEXTS 10
+#define MAX_NUM_CID_CONTEXTS 10
#define ERROR_LOCK_PATH -100
#define VOICEMAIL_DIR_MODE 0700
-#define VOICEMAIL_FILE_MODE 0600
#define VOICEMAIL_CONFIG "minivm.conf"
-#define ASTERISK_USERNAME "asterisk" /*!< Default username for sending mail is asterisk at localhost */
+#define ASTERISK_USERNAME "asterisk" /*!< Default username for sending mail is asterisk\@localhost */
/*! \brief Message types for notification */
enum mvm_messagetype {
MVM_MESSAGE_EMAIL,
MVM_MESSAGE_PAGE
+ /* For trunk: MVM_MESSAGE_JABBER, */
};
static char MVM_SPOOL_DIR[AST_CONFIG_MAX_PATH];
+/* Module declarations */
static char *tdesc = "Mini VoiceMail (A minimal Voicemail e-mail System)";
static char *app = "MiniVM"; /* Leave a message */
static char *app_greet = "MiniVMgreet"; /* Play voicemail prompts */
-static char *synopsis_vm = "Receive voicemail and forward via e-mail";
+static char *synopsis_vm = "Receive Mini-Voicemail and forward via e-mail";
static char *descrip_vm =
"Syntax: minivm(username at domain[,options])\n"
"This application is part of the Mini-Voicemail system, configured in minivm.conf.\n"
@@ -162,7 +171,7 @@
" message. The units are whole-number decibels (dB).\n"
"\n";
-static char *synopsis_vm_greet = "Play voicemail prompts";
+static char *synopsis_vm_greet = "Play Mini-Voicemail prompts";
static char *descrip_vm_greet =
"Syntax: minivm_greet(username at domain[,options])\n"
"This application is part of the Mini-Voicemail system, configured in minivm.conf.\n"
@@ -201,8 +210,7 @@
-/*! Structure for linked list of users
-*/
+/*! \brief Structure for linked list of Mini-Voicemail users */
struct minivm_user {
char username[AST_MAX_CONTEXT]; /*!< Mailbox username */
char domain[AST_MAX_CONTEXT]; /*!< Voicemail domain */
@@ -256,9 +264,7 @@
unsigned char iobuf[B64_BASEMAXINLINE];
};
-
-
-/*! Voicemail time zones */
+/*! \brief Voicemail time zones */
struct minivm_zone {
char name[80]; /* Name of this time zone */
char timezone[80];
@@ -279,9 +285,10 @@
time_t lastvoicemail; /*!< Time for last voicemail sent */
};
+/*! \brief Statistics for voicemail */
static struct minivm_stats global_stats;
-AST_MUTEX_DEFINE_STATIC(minivmlock);
+AST_MUTEX_DEFINE_STATIC(minivmlock); /*!< Lock to protect voicemail system */
static int global_vmminmessage; /*!< Minimum duration of messages */
static int global_vmmaxmessage; /*!< Maximum duration of message */
@@ -291,32 +298,27 @@
static char global_externnotify[160]; /*!< External notification application */
static char default_vmformat[80];
-static int maxgreet;
-
-static struct ast_flags globalflags = {0};
-
+
+static struct ast_flags globalflags = {0}; /*!< Global voicemail flags */
static int global_saydurationminfo;
-/* XXX These will be replaced by the template structure */
-struct minivm_message *default_mailtemplate;
-struct minivm_message *default_pagertemplate;
-static char *emailbody = NULL;
-static char *pagerbody = NULL;
-static char *pagersubject = NULL;
-
-static char global_fromstring[100];
-static char global_pagerfromstring[100];
-static char global_charset[32];
-
-static double global_volgain; /* Volume gain for voicmemail via e-mail */
+static char global_fromstring[100]; /*!< Global fromstring in voicemail */
+static char global_pagerfromstring[100]; /*!< Global fromstring in pager */
+static char global_charset[32]; /*!< Global charset in messages */
+
+static double global_volgain; /*!< Volume gain for voicmemail via e-mail */
#define DEFAULT_DATEFORMAT "%A, %B %d, %Y at %r"
#define DEFAULT_CHARSET "ISO-8859-1"
STANDARD_LOCAL_USER;
-
LOCAL_USER_DECL;
+/* Forward declarations */
+static char *message_template_parse_filebody(char *filename);
+static char *message_template_parse_emailbody(char *body);
+static int create_vmaccount(char *name, struct ast_variable *var, int realtime);
+static struct minivm_user *find_user_realtime(const char *domain, const char *username);
/*! \brief Create message template */
static struct minivm_message *message_template_create(char *name)
@@ -350,8 +352,13 @@
static int message_template_build(char *name, struct ast_variable *var)
{
struct minivm_message *template;
+ int error = 0;
+
template = message_template_create(name);
- int error = 0;
+ if (!template) {
+ ast_log(LOG_ERROR, "Out of memory, can't allocate message template object %s.\n", name);
+ return -1;
+ }
while (var) {
if (option_debug > 2)
@@ -367,13 +374,29 @@
} else if (!strcasecmp(var->name, "charset")) {
ast_copy_string(template->charset, var->value, sizeof(template->charset));
} else if (!strcasecmp(var->name, "templatefile")) {
- /* NO op */
+ if (template->body)
+ free(template->body);
+ template->body = message_template_parse_filebody(var->value);
+ if (!template->body) {
+ ast_log(LOG_ERROR, "Error reading message body definition file %s\n", var->value);
+ error++;
+ }
+ } else if (!strcasecmp(var->name, "messagebody")) {
+ if (template->body)
+ free(template->body);
+ template->body = message_template_parse_emailbody(var->value);
+ if (!template->body) {
+ ast_log(LOG_ERROR, "Error parsing message body definition:\n %s\n", var->value);
+ error++;
+ }
} else {
ast_log(LOG_ERROR, "Unknown message template configuration option \"%s=%s\"\n", var->name, var->value);
error++;
}
var = var->next;
- }
+ }
+ if (error)
+ ast_log(LOG_ERROR, "-- %d errors found parsing message template definition %s\n", error, name);
AST_LIST_LOCK(&message_templates);
AST_LIST_INSERT_TAIL(&message_templates, template, list);
@@ -576,6 +599,7 @@
pbx_builtin_setvar_helper(ast, "MVM_DATE", date);
}
+/*! \brief Set default values for Mini-Voicemail users */
static void populate_defaults(struct minivm_user *vmu)
{
ast_copy_flags(vmu, (&globalflags), AST_FLAGS_ALL);
@@ -617,8 +641,6 @@
return new;
}
-static int create_vmaccount(char *name, struct ast_variable *var, int realtime);
-static struct minivm_user *find_user_realtime(const char *domain, const char *username);
/*! \brief Clear list of users */
static void vmaccounts_destroy_list(void)
@@ -907,19 +929,34 @@
return 0;
}
-static int make_dir(char *dest, int len, const char *context, const char *ext, const char *folder)
-{
- return snprintf(dest, len, "%s%s/%s/%s", MVM_SPOOL_DIR, context, ext, folder);
-}
-
-/*! \brief basically mkdir -p $dest/$domain/$ext/$$username
+/*! \brief Create directory based on components */
+static int make_dir(char *dest, int len, const char *domain, const char *username, const char *folder)
+{
+ return snprintf(dest, len, "%s%s/%s%s%s", MVM_SPOOL_DIR, domain, username, ast_strlen_zero(folder) ? "" : "/", folder);
+}
+
+/*! \brief Checks if directory exists. Does not create directory, but builds string in dest
* \param dest String. base directory.
* \param domain String. Ignored if is null or empty string.
+ * \param username String. Ignored if is null or empty string.
+ * \param folder String. Ignored if is null or empty string.
+ * \return 0 on failure, 1 on success.
+ */
+static int check_dirpath(char *dest, int len, char *domain, char *username, char *folder)
+{
+ make_dir(dest, len, domain, username, folder);
+ return ast_fileexists(dest, NULL, NULL);
+}
+
+/*! \brief basically mkdir -p $dest/$domain/$username/$folder
+ * \param dest String. base directory.
+ * \param len Length of directory string
+ * \param domain String. Ignored if is null or empty string.
+ * \param folder String. Ignored if is null or empty string.
* \param ext String. Ignored if is null or empty string.
- * \param username String. Ignored if is null or empty string.
- * \param returns 0 on failure, 1 on success.
+ * \return 0 on failure, 1 on success.
*/
-static int create_dirpath(char *dest, int len, char *domain, char *ext, char *username)
+static int create_dirpath(char *dest, int len, char *domain, char *username, char *folder)
{
mode_t mode = VOICEMAIL_DIR_MODE;
@@ -930,45 +967,37 @@
return 0;
}
}
- if(!ast_strlen_zero(ext)) {
- make_dir(dest, len, domain, ext, "");
+ if(!ast_strlen_zero(username)) {
+ make_dir(dest, len, domain, username, "");
if(mkdir(dest, mode) && errno != EEXIST) {
ast_log(LOG_WARNING, "mkdir '%s' failed: %s\n", dest, strerror(errno));
return 0;
}
}
- if(!ast_strlen_zero(username)) {
- make_dir(dest, len, domain, ext, username);
+ if(!ast_strlen_zero(folder)) {
+ make_dir(dest, len, domain, username, folder);
if(mkdir(dest, mode) && errno != EEXIST) {
ast_log(LOG_WARNING, "mkdir '%s' failed: %s\n", dest, strerror(errno));
return 0;
}
}
if (option_debug > 1)
- ast_log(LOG_DEBUG, "Creating directory for %s@%s ext %s : %s\n", username, domain, ext, dest);
+ ast_log(LOG_DEBUG, "Creating directory for %s@%s folder %s : %s\n", username, domain, folder, dest);
return 1;
}
/*! \brief Play intro message before recording voicemail
- \note maybe this should be done in the dialplan, not
- in the application
*/
static int invent_message(struct ast_channel *chan, char *domain, char *username, int busy, char *ecodes)
{
int res;
char fn[PATH_MAX];
- char dest[PATH_MAX];
if (option_debug > 1)
ast_log(LOG_DEBUG, "-_-_- Still preparing to play message ...\n");
snprintf(fn, sizeof(fn), "%s%s/%s/greet", MVM_SPOOL_DIR, domain, username);
-
- if (!(res = create_dirpath(dest, sizeof(dest), domain, username, "greet"))) {
- ast_log(LOG_WARNING, "Failed to make directory(%s)\n", fn);
- return -1;
- }
if (ast_fileexists(fn, NULL, NULL) > 0) {
res = ast_streamfile(chan, fn, chan->language);
@@ -1267,6 +1296,7 @@
char *domain;
char tmp[256] = "";
struct minivm_user *vmu;
+ int userdir;
ast_copy_string(tmp, username, sizeof(tmp));
username = tmp;
@@ -1305,10 +1335,15 @@
}
msgnum = 0;
- /* It's easier just to try to make it than to check for its existence */
- create_dirpath(tmpdir, sizeof(tmpdir), vmu->domain, "tmp", username);
+ userdir = check_dirpath(tmpdir, sizeof(tmpdir), vmu->domain, username, "tmp");
+
+ /* If we have no user directory, use generic temporary directory */
+ if (!userdir)
+ create_dirpath(tmpdir, sizeof(tmpdir), "0000_minivm_temp", "mediafiles", "");
+
snprintf(tmptxtfile, sizeof(tmptxtfile), "%s/XXXXXX", tmpdir);
+
/* XXX This file needs to be in temp directory */
txtdes = mkstemp(tmptxtfile);
if (txtdes < 0) {
@@ -1333,8 +1368,12 @@
if (option_debug)
ast_log(LOG_DEBUG, "Open file for metadata: %s\n", tmptxtfile);
+ res = play_record_review(chan, NULL, tmptxtfile, global_vmmaxmessage, fmt, 1, vmu, &duration, NULL, options->record_gain);
+
txt = fdopen(txtdes, "w+");
- if (txt) {
+ if (!txt) {
+ ast_log(LOG_WARNING, "Error opening text file for output\n");
+ } else {
struct tm tm;
time_t now;
char timebuf[30];
@@ -1345,8 +1384,8 @@
strftime(timebuf, sizeof(timebuf), "%H:%M:%S", &tm);
fprintf(txt,
- /* "Mailbox:domain:macrocontext:exten:priority:callerchan:callerid:origdate:origtime:duration" */
- "%s:%s:%s:%s:%d:%s:%s:%s:%s:%s\n",
+ /* "Mailbox:domain:macrocontext:exten:priority:callerchan:callerid:origdate:origtime:duration:durationstatus" */
+ "%s:%s:%s:%s:%d:%s:%s:%s:%s:%d:%s\n",
username,
chan->context,
chan->macrocontext,
@@ -1356,17 +1395,11 @@
ast_callerid_merge(callerid, sizeof(callerid), chan->cid.cid_name, chan->cid.cid_num, "Unknown"),
date,
timebuf,
- "durationholder");
- } else
- ast_log(LOG_WARNING, "Error opening text file for output\n");
-
- res = play_record_review(chan, NULL, tmptxtfile, global_vmmaxmessage, fmt, 1, vmu, &duration, NULL, options->record_gain);
-
-// static int play_record_review(struct ast_channel *chan, char *playfile, char *recordfile, int maxtime, char *fmt,
-// int outsidecaller, struct minivm_user *vmu, int *duration, const char *unlockdir,
-// signed char record_gain)
-
- if (txt) {
+ duration,
+ duration < global_vmminmessage ? "IGNORED" : "OK"
+ );
+
+
if (duration < global_vmminmessage) {
if (option_verbose > 2)
ast_verbose( VERBOSE_PREFIX_3 "Recording was %d seconds long but needs to be at least %d - abandoning\n", duration, global_vmminmessage);
@@ -1377,8 +1410,7 @@
free_user(vmu);
return 0;
}
- fprintf(txt, "duration=%d\n", duration);
- fclose(txt);
+ fclose(txt); /* Close log file */
if (vm_lock_path(dir)) {
ast_log(LOG_ERROR, "Couldn't lock directory %s. Voicemail will be lost.\n", dir);
/* Delete files */
@@ -1400,11 +1432,17 @@
/* assign a variable with the name of the voicemail file */
pbx_builtin_setvar_helper(chan, "MVM_MESSAGEFILE", tmptxtfile);
-
ast_unlock_path(dir);
-
- if (ast_fileexists(tmptxtfile, NULL, NULL) > 0)
- notify_new_message(chan, vmu, tmptxtfile, duration, fmt, chan->cid.cid_num, chan->cid.cid_name);
+ /* Notify of new message to e-mail and pager */
+ notify_new_message(chan, vmu, tmptxtfile, duration, fmt, chan->cid.cid_num, chan->cid.cid_name);
+ }
+ /* Go ahead and delete audio files from system, they're not needed any more */
+ if (ast_fileexists(tmptxtfile, NULL, NULL) <= 0) {
+ vm_lock_path(dir);
+ ast_filedelete(tmptxtfile, NULL);
+ ast_unlock_path(dir);
+ if (option_debug > 1)
+ ast_log(LOG_DEBUG, "-_-_- Deleted audio file after notification :: %s \n", tmptxtfile);
}
if (res > 0)
@@ -1431,7 +1469,6 @@
int ousemacro = 0;
int ouseexten = 0;
char tmp[PATH_MAX];
- char tmpdir[PATH_MAX];
char dest[PATH_MAX];
char prefile[PATH_MAX] = "";
char tempfile[PATH_MAX] = "";
@@ -1499,26 +1536,23 @@
ast_copy_string(ext_context, vmu->domain, sizeof(ext_context));
if (ast_test_flag(&leave_options, OPT_BUSY_GREETING)) {
- res = create_dirpath(dest, sizeof(dest), vmu->domain, username, "busy");
- snprintf(prefile, sizeof(prefile), "%s%s/%s/busy", MVM_SPOOL_DIR, vmu->domain, username);
+ res = check_dirpath(dest, sizeof(dest), vmu->domain, username, "busy");
+ if (res)
+ snprintf(prefile, sizeof(prefile), "%s%s/%s/busy", MVM_SPOOL_DIR, vmu->domain, username);
} else if (ast_test_flag(&leave_options, OPT_UNAVAIL_GREETING)) {
- res = create_dirpath(dest, sizeof(dest), vmu->domain, username, "unavail");
- snprintf(prefile, sizeof(prefile), "%s%s/%s/unavail", MVM_SPOOL_DIR, vmu->domain, username);
- }
+ res = check_dirpath(dest, sizeof(dest), vmu->domain, username, "unavail");
+ if (res)
+ snprintf(prefile, sizeof(prefile), "%s%s/%s/unavail", MVM_SPOOL_DIR, vmu->domain, username);
+ }
+ /* Check for temporary greeting - it overrides busy and unavail */
snprintf(tempfile, sizeof(tempfile), "%s%s/%s/temp", MVM_SPOOL_DIR, vmu->domain, username);
- if (!(res = create_dirpath(dest, sizeof(dest), vmu->domain, username, "temp"))) {
- ast_log(LOG_WARNING, "Failed to make directory (%s)\n", tempfile);
- return -1;
+ if (!(res = check_dirpath(dest, sizeof(dest), vmu->domain, username, "temp"))) {
+ if (option_debug > 1)
+ ast_log(LOG_DEBUG, "Temporary message directory does not exist, using default (%s)\n", tempfile);
+ ast_copy_string(prefile, tempfile, sizeof(prefile));
}
if (option_debug > 1)
ast_log(LOG_DEBUG, "-_-_- Preparing to play message ...\n");
-
- /* Play the message */
- if (ast_fileexists(tempfile, NULL, NULL) > 0)
- ast_copy_string(prefile, tempfile, sizeof(prefile));
-
- /* It's easier just to try to make it than to check for its existence */
- create_dirpath(tmpdir, sizeof(tmpdir), vmu->domain, username, "tmp");
/* Check current or macro-calling context for special extensions */
if (ast_test_flag(vmu, MVM_OPERATOR)) {
@@ -1547,23 +1581,22 @@
ausemacro = 1;
}
+ res = 0; /* Reset */
/* Play the beginning intro if desired */
if (!ast_strlen_zero(prefile)) {
- if (ast_fileexists(prefile, NULL, NULL) > 0) {
- if (ast_streamfile(chan, prefile, chan->language) > -1)
- res = ast_waitstream(chan, ecodes);
- } else {
- if (option_debug > 1)
- ast_log(LOG_DEBUG, "%s doesn't exist, doing what we can\n", prefile);
- res = invent_message(chan, vmu->domain, username, ast_test_flag(&leave_options, OPT_BUSY_GREETING), ecodes);
- }
- if (res < 0) {
- if (option_debug > 1)
- ast_log(LOG_DEBUG, "Hang up during prefile playback\n");
- free_user(vmu);
- pbx_builtin_setvar_helper(chan, "MINIVMGREETSTATUS", "FAILED");
- return -1;
- }
+ if (ast_streamfile(chan, prefile, chan->language) > -1)
+ res = ast_waitstream(chan, ecodes);
+ } else {
+ if (option_debug > 1)
+ ast_log(LOG_DEBUG, "%s doesn't exist, doing what we can\n", prefile);
+ res = invent_message(chan, vmu->domain, username, ast_test_flag(&leave_options, OPT_BUSY_GREETING), ecodes);
+ }
+ if (res < 0) {
+ if (option_debug > 1)
+ ast_log(LOG_DEBUG, "Hang up during prefile playback\n");
+ free_user(vmu);
+ pbx_builtin_setvar_helper(chan, "MINIVMGREETSTATUS", "FAILED");
+ return -1;
}
if (res == '#') {
/* On a '#' we skip the instructions */
@@ -1698,6 +1731,7 @@
return res;
}
+/*! \brief Free Mini Voicemail timezone */
static void free_zone(struct minivm_zone *z)
{
free(z);
@@ -1712,7 +1746,7 @@
char accbuf[BUFSIZ];
if (option_debug > 2)
- ast_log(LOG_DEBUG, "Creating static account for [%s]\n", name);
+ ast_log(LOG_DEBUG, "Creating %s account for [%s]\n", realtime ? "realtime" : "static", name);
ast_copy_string(accbuf, name, sizeof(accbuf));
username = accbuf;
@@ -1833,8 +1867,53 @@
return 0;
}
+/*! \brief Read message template from file */
+static char *message_template_parse_filebody(char *filename) {
+ char buf[BUFSIZ * 6];
+ char readbuf[BUFSIZ];
+ char filenamebuf[BUFSIZ];
+ char *writepos;
+ char *messagebody;
+ FILE *fi;
+ int lines = 0;
+
+ if (ast_strlen_zero(filename))
+ return NULL;
+ if (*filename == '/')
+ ast_copy_string(filenamebuf, filename, sizeof(filenamebuf));
+ else
+ snprintf(filenamebuf, sizeof(filenamebuf), "%s/%s", ast_config_AST_CONFIG_DIR, filename);
+
+ if (!(fi = fopen(filenamebuf, "r"))) {
+ ast_log(LOG_ERROR, "Can't read message template from file: %s\n", filenamebuf);
+ return NULL;
+ }
+ writepos = buf;
+ while (fgets(readbuf, sizeof(readbuf), fi)) {
+ lines ++;
+ if (writepos != buf) {
+ *writepos = '\n'; /* Replace EOL with new line */
+ writepos++;
+ }
+ ast_copy_string(writepos, readbuf, sizeof(buf) - (writepos - buf));
+ ast_log(LOG_DEBUG, "---> Message body now: %s\n", buf);
+ writepos += strlen(readbuf) - 1;
+ if (option_debug > 3) {
+ ast_log(LOG_DEBUG, "---> Reading message template : Line %d: %s\n", lines, readbuf);
+ ast_log(LOG_DEBUG, "---> Strlen readbuf %d Writepos %d Left %d\n", strlen(readbuf), writepos - buf, sizeof(buf) - (writepos - buf));
+ }
+ }
+ fclose(fi);
+ messagebody = calloc(1, strlen(buf + 1));
+ ast_copy_string(messagebody, buf, sizeof(messagebody));
+ if (option_debug > 3)
+ ast_log(LOG_DEBUG, "---> Reading message template : \n%s\n---- END message template--- \n", messagebody);
+
+ return messagebody;
+}
+
/*! \brief Parse emailbody template from configuration file */
-static char *parse_emailbody(char *configuration)
+static char *message_template_parse_emailbody(char *configuration)
{
char *tmpread, *tmpwrite;
char *emailbody = strdup(configuration);
@@ -1900,14 +1979,6 @@
}
} else if (!strcmp(var->name, "format")) {
ast_copy_string(default_vmformat, var->value, sizeof(default_vmformat));
- } else if (!strcmp(var->name, "maxgreet")) {
- int x;
- if (sscanf(var->value, "%d", &x) == 1)
- maxgreet = x;
- else {
- ast_log(LOG_WARNING, "Invalid max message greeting length\n");
- error ++;
- }
} else if (!strcmp(var->name, "review")) {
ast_set2_flag((&globalflags), ast_true(var->value), MVM_REVIEW);
} else if (!strcmp(var->name, "operator")) {
@@ -1963,19 +2034,6 @@
memset(&global_stats, 0, sizeof(struct minivm_stats));
global_stats.reset = time(NULL);
- if (emailbody) {
- free(emailbody);
- emailbody = NULL;
- }
- if (pagerbody) {
- free(pagerbody);
- pagerbody = NULL;
- }
- if (pagersubject) {
- free(pagersubject);
- pagersubject = NULL;
- }
-
/* Make sure we could load configuration file */
if (!cfg) {
ast_log(LOG_WARNING, "Failed to load configuration file. Module activated with default settings.\n");
@@ -2038,7 +2096,7 @@
if ((s = ast_variable_retrieve(cfg, "general", "emailsubject")))
ast_copy_string(template->subject,s,sizeof(template->subject));
if ((s = ast_variable_retrieve(cfg, "general", "emailbody")))
- template->body = parse_emailbody(s);
+ template->body = message_template_parse_emailbody(s);
template->attachment = TRUE;
message_template_build("pager-default", NULL);
@@ -2050,7 +2108,7 @@
if ((s = ast_variable_retrieve(cfg, "general", "pagersubject")))
ast_copy_string(template->subject,s,sizeof(template->subject));
if ((s = ast_variable_retrieve(cfg, "general", "pagerbody")))
- template->body = parse_emailbody(s);
+ template->body = message_template_parse_emailbody(s);
template->attachment = FALSE;
if (error)
Modified: team/oej/minivoicemail/configs/minivm.conf.sample
URL: http://svn.digium.com/view/asterisk/team/oej/minivoicemail/configs/minivm.conf.sample?view=diff&rev=56836&r1=56835&r2=56836
==============================================================================
--- team/oej/minivoicemail/configs/minivm.conf.sample (original)
+++ team/oej/minivoicemail/configs/minivm.conf.sample Mon Feb 26 12:48:27 2007
@@ -7,7 +7,7 @@
; Default format for storing and sending voicemail
; (only one format. Can also be set on a per-mailbox level)
format=wav49
-format=gsm
+;format=gsm
;
; Who the e-mail notification should appear to come from
serveremail=asterisk
@@ -15,8 +15,6 @@
; Minimum length of a voicemail message in seconds for the message to be kept
; The default is no minimum.
;minmessage=3
-; Maximum length of greetings in seconds
-;maxgreet=60
; How many seconds of silence before we end the recording
maxsilence=10
; Silence threshold (what we consider silence: the lower, the more sensitive)
@@ -30,6 +28,12 @@
; Skip the "[PBX]:" string from the message title
;pbxskip=yes
; Change the From: string
+
+; You can override the default program to send e-mail if you wish, too
+; This is used both for e-mail and pager messages
+;mailcmd=/usr/sbin/sendmail -t
+
+;--------------Default e-mail message template (used if no templates are used) ------
;fromstring=The Asterisk PBX
;
; Change the from, body and/or subject, variables:
@@ -44,12 +48,6 @@
; caller", if they are both null.
;emailbody=Dear ${VM_NAME}:\n\n\tjust wanted to let you know you were just left a ${VM_DUR} long message (number ${VM_MSGNUM})\nin mailbox ${VM_MAILBOX} from ${VM_CALLERID}, on ${VM_DATE}, so you might\nwant to check it when you get a chance. Thanks!\n\n\t\t\t\t--Asterisk\n
;
-; You can also change the Pager From: string, the pager body and/or subject.
-; The above defined variables also can be used here
-;pagerfromstring=The Asterisk PBX
-;pagersubject=New VM
-;pagerbody=New ${VM_DUR} long msg in box ${VM_MAILBOX}\nfrom ${VM_CALLERID}, on ${VM_DATE}
-;
; Set the date format on outgoing mails. Valid arguments can be found on the
; strftime(3) man page
;
@@ -57,11 +55,16 @@
emaildateformat=%A, %B %d, %Y at %r
; 24h date format
;emaildateformat=%A, %d %B %Y at %H:%M:%S
+;--------------Default pager message template (used if no templates are used) ------
+; You can also change the Pager From: string, the pager body and/or subject.
+; The above defined variables also can be used here
+;pagerfromstring=The Asterisk PBX
+;pagersubject=New VM
+;pagerbody=New ${VM_DUR} long msg in box ${VM_MAILBOX}\nfrom ${VM_CALLERID}, on ${VM_DATE}
;
-; You can override the default program to send e-mail if you wish, too
+;
+;--------------Timezone definitions (used in voicemail accounts) -------------------
;
-;mailcmd=/usr/sbin/sendmail -t
-;
; Users may be located in different timezones, or may have different
; message announcements for their introductory message when they enter
; the voicemail system. Set the message and the timezone each user
@@ -94,23 +97,8 @@
; (*note: not standard strftime value)
; R 24 hour time, including minute
;
-;
-
-;
-; Each mailbox is listed in the form <mailbox>=<password>,<name>,<email>,<pager_email>,<options>
-; if the e-mail is specified, a message will be sent when a message is
-; received, to the given mailbox. If pager is specified, a message will be
-; sent there as well. If the password is prefixed by '-', then it is
-; considered to be unchangeable.
-;
-; Advanced options example is extension 4069
-; NOTE: All options can be expressed globally in the general section, and
-; overridden in the per-mailbox settings, unless listed otherwise.
-;
-; tz=central ; Timezone from zonemessages above. Irrelevant if envelope=no.
-; review=yes ; Allow sender to review/rerecord their message before saving it [OFF by default
-; operator=yes ; Allow sender to hit 0 before/after/during leaving a voicemail to
- ; reach an operator [OFF by default]
+; The message here is not used in mini-voicemail, but stays for
+; backwards compatibility
[zonemessages]
eastern=America/New_York|'vm-received' Q 'digits/at' IMp
@@ -118,9 +106,53 @@
central24=America/Chicago|'vm-received' q 'digits/at' H N 'hours'
military=Zulu|'vm-received' q 'digits/at' H N 'hours' 'phonetic/z_p'
-[templates]
+;----------------------- Message body templates---------------------
+; [template-name] ; "template-" is a verbatim marker
+; fromaddress = asteriskvm at digium.com
+; subject = <string>
+; attachmedia = yes | no ; Add media file as attachment?
+; dateformat = <formatstring> ; See above
+; charset = <charset> ; Mime charset definition
+; templatefile = <filename> ; File name (relative to Asterisk configuration directory,
+ ; or absolute
+; messagebody = Format ; Message body definition with variables
+;
+[template-sv_se_email]
+messagebody=Hej ${VM_NAME}:\n\n\tDu har fått ett röstbrevlåde-meddelande från ${VM_CALLERID}.\nLängd: ${VM_DUR}\nMailbox ${VM_MAILBOX}\nDatum: ${VM_DATE}. \nMeddelandet bifogas det här brevet. Om du inte kan läsa det, kontakta intern support. \nHälsningar\n\n\t\t\t\t--Asterisk\n
+subject = Du har fått röstmeddelande (se bilaga)
+charset=iso-8859-1
+attachmedia=yes
+dateformat=%A, %d %B %Y at %H:%M:%S
+[template-en_us_email]
+messagebody=Dear ${VM_NAME}:\n\n\tjust wanted to let you know you were just left a ${VM_DUR} long message (number ${VM_MSGNUM})\nin mailbox ${VM_MAILBOX} from ${VM_CALLERID}, on ${VM_DATE}, so you might\nwant to check it when you get a chance. Thanks!\n\n\t\t\t\t--Asterisk\n
+subject = New voicemail
+charset=ascii
+attachmedia=yes
+dateformat=%A, %B %d, %Y at %r
+;[template-sv_se_pager]
+;templatefile = templates/pager_sv_se.txt
+;subject = Du har fått voicemail
+;charset=iso-8859-1
+;attachmedia=no
+
+;[template-no_no_email]
+;templatefile = templates/email_no_no.txt
+;subject = Du har fått voicemail
+;charset=iso-8859-1
+
+;[template-en_us_email_southern]
+;templatefile = templates/email_en_us.txt
+;subject = Y'all got voicemail, honey!
+;charset=ascii
+
+;[template-en_uk_email]
+;templatefile = templates/email_en_us.txt
+;subject = Dear old chap, you've got an electronic communique
+;charset=ascii
+
+;----------------------- Mailbox accounts --------------------------
;Template for mailbox definition - all options
;
; [username at domain] ; Has to be unique within domain
Modified: team/oej/minivoicemail/include/asterisk/doxyref.h
URL: http://svn.digium.com/view/asterisk/team/oej/minivoicemail/include/asterisk/doxyref.h?view=diff&rev=56836&r1=56835&r2=56836
==============================================================================
--- team/oej/minivoicemail/include/asterisk/doxyref.h (original)
+++ team/oej/minivoicemail/include/asterisk/doxyref.h Mon Feb 26 12:48:27 2007
@@ -152,6 +152,7 @@
* \arg \link Config_mm Meetme (conference bridge) configuration \endlink
* \arg \link Config_qu Queue system configuration \endlink
* \arg \link Config_vm Voicemail configuration \endlink
+ * \arg \link Config_minivm Mini-Voicemail configuration \endlink
* \section cdrconf CDR configuration files
* \arg \link Config_cdr CDR configuration \endlink
* \arg \link cdr_custom Custom CDR driver configuration \endlink
@@ -168,7 +169,6 @@
* \arg \link Config_dun DUNDi configuration \endlink
* \arg \link Config_enum ENUM configuration \endlink
* \arg \link Config_moh Music on Hold configuration \endlink
- * \arg \link Config_vm Voicemail configuration \endlink
*/
/*! \page Config_ast Asterisk.conf
@@ -238,6 +238,12 @@
* \section vmconf voicemail.conf
* \arg Implemented in \ref app_voicemail.c
* \verbinclude voicemail.conf.sample
+ */
+
+/*! \page Config_minivm Mini-VoiceMail configuration
+ * \section minivmconf minivm.conf
+ * \arg Implemented in \ref app_minivm.c
+ * \verbinclude minivm.conf.sample
*/
/*! \page Config_zap Zaptel configuration
More information about the asterisk-commits
mailing list