[asterisk-commits] oej: branch oej/minivoicemail r58472 - in /team/oej/minivoicemail: apps/ conf...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Mar 8 13:21:34 MST 2007


Author: oej
Date: Thu Mar  8 14:21:33 2007
New Revision: 58472

URL: http://svn.digium.com/view/asterisk?view=rev&rev=58472
Log:
Adding support for locale's to get weekdays right in e-mail 

Modified:
    team/oej/minivoicemail/apps/app_minivm.c
    team/oej/minivoicemail/configs/minivm.conf.sample

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=58472&r1=58471&r2=58472
==============================================================================
--- team/oej/minivoicemail/apps/app_minivm.c (original)
+++ team/oej/minivoicemail/apps/app_minivm.c Thu Mar  8 14:21:33 2007
@@ -143,6 +143,7 @@
 #include <sys/mman.h>
 #include <time.h>
 #include <dirent.h>
+#include <locale.h>
 
 #include "asterisk.h"
 
@@ -371,6 +372,7 @@
 	char	serveremail[80];	/*!< From: Mail address */
 	char	subject[100];		/*!< Subject line */
 	char	charset[32];		/*!< Default character set for this template */
+	char	locale[20];		/*!< Locale for setlocale() */
 	char	dateformat[80];		/*!< Date format to use in this attachment */
 	int	attachment;		/*!< Attachment of media yes/no - no for pager messages */
 	AST_LIST_ENTRY(minivm_template) list;	/*!< List mechanics */
@@ -500,6 +502,8 @@
 			ast_copy_string(template->serveremail, var->value, sizeof(template->serveremail));
 		} else if (!strcasecmp(var->name, "subject")) {
 			ast_copy_string(template->subject, var->value, sizeof(template->subject));
+		} else if (!strcasecmp(var->name, "locale")) {
+			ast_copy_string(template->locale, var->value, sizeof(template->locale));
 		} else if (!strcasecmp(var->name, "attachmedia")) {
 			template->attachment = ast_true(var->value);
 		} else if (!strcasecmp(var->name, "dateformat")) {
@@ -1433,6 +1437,7 @@
 	struct minivm_template *etemplate;
 	char *messageformat;
 	int res = 0;
+	char oldlocale[100];
 
 	snprintf(ext_context, sizeof(ext_context), "%s@%s", vmu->username, vmu->domain);
 
@@ -1451,6 +1456,18 @@
 	stringp = messageformat = ast_strdupa(format);
 	strsep(&stringp, "|");
 
+	if (etemplate->locale) {
+		char *newlocale;
+		ast_copy_string(oldlocale, setlocale(LC_TIME, NULL), sizeof(oldlocale));
+		if (option_debug > 1)
+			ast_log(LOG_DEBUG, "-_-_- Changing locale from %s to %s\n", oldlocale, etemplate->locale);
+		newlocale = setlocale(LC_TIME, etemplate->locale);
+		if (newlocale == NULL) {
+			ast_log(LOG_WARNING, "-_-_- Changing to new locale did not work. Locale: %s\n", etemplate->locale);
+		}
+	}
+
+
 
 	res = sendmail(etemplate, vmu, cidnum, cidname, filename, messageformat, duration, etemplate->attachment, MVM_MESSAGE_EMAIL);
 
@@ -1459,6 +1476,10 @@
 		etemplate = message_template_find(vmu->ptemplate);
 		if (!etemplate)
 			etemplate = message_template_find("pager-default");
+		if (etemplate->locale) {
+			ast_copy_string(oldlocale, setlocale(LC_TIME, ""), sizeof(oldlocale));
+			setlocale(LC_TIME, etemplate->locale);
+		}
 
 		res = sendmail(etemplate, vmu, cidnum, cidname, filename, messageformat, duration, etemplate->attachment, MVM_MESSAGE_PAGE);
 	}
@@ -1466,6 +1487,9 @@
 	manager_event(EVENT_FLAG_CALL, "MiniVoiceMail", "Action: SentNotification\rn\nMailbox: %s@%s\r\n", vmu->username, vmu->domain);
 
 	run_externnotify(chan, vmu);		/* Run external notification */
+
+	if (etemplate->locale) 
+		setlocale(LC_TIME, oldlocale); /* Rest to old locale */
 	return res;
 }
 

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=58472&r1=58471&r2=58472
==============================================================================
--- team/oej/minivoicemail/configs/minivm.conf.sample (original)
+++ team/oej/minivoicemail/configs/minivm.conf.sample Thu Mar  8 14:21:33 2007
@@ -74,7 +74,7 @@
 ; 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}
+;pagerbody=New ${MVM_DUR} long msg in box ${MVM_MAILBOX}\nfrom ${MVM_CALLERID}, on ${MVM_DATE}
 ;
 ; 
 ;--------------Timezone definitions (used in voicemail accounts) -------------------
@@ -127,42 +127,44 @@
 ; subject = <string>
 ; attachmedia = yes | no	; Add media file as attachment?
 ; dateformat = <formatstring>   ; See above
-; charset = <charset>		; Mime charset definition
+; charset = <charset>		; Mime charset definition for e-mail messages
+; locale = <locale>		; Locale for LC_TIME - to get weekdays in local language 
+;				; See your O/S documentation for proper settings for setlocale()
 ; templatefile = <filename>	; File name (relative to Asterisk configuration directory,
 				; or absolute
 ; messagebody = Format		; Message body definition with variables
 ;
-[template-sv_se_email] 
+[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] 
+[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]
+;[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
+;[template-nb_NO_email]
+;templatefile = templates/email_nb_NO.txt
 ;subject = Du har fått voicemail
 ;charset=iso-8859-1
 
-;[template-en_us_email_southern]
-;templatefile = templates/email_en_us.txt
+;[template-en_US_email_southern]
+;templatefile = templates/email_en_US.txt
 ;subject = Y'all got voicemail, honey!
 ;charset=ascii  
 
-;[template-en_uk_email]
+;[template-en_UK_email]
 ;templatefile = templates/email_en_us.txt
 ;subject = Dear old chap, you've got an electronic communique
 ;charset=ascii  
@@ -171,8 +173,8 @@
 ;Template for mailbox definition - all options
 ;
 ;	[username at domain]		; Has to be unique within domain (MWM_USERNAME, MWM_DOMAIN)
-;	etemplate = sv_se		; Email template from [templates]
-;	ptemplate = en_us		; Pager template from [templates]
+;	etemplate = sv_SE		; Email template from [templates]
+;	ptemplate = en_US		; Pager template from [templates]
 ;	email = userpart at domain		; Extra e-mail address (overrides mailbox name)
 ;	pager = pageremail at domain	; E-mail address for pager messages
 ;	fullname = Mark Spencer		; Full name  (MWM_NAME)



More information about the asterisk-commits mailing list