From - Sun May 18 09:25:17 2003
X-UIDL: 3ec4cbb0000000df
X-Mozilla-Status: 0011
X-Mozilla-Status2: 10000000
Return-Path: <asterisk-dev-admin@lists.digium.com>
Received: from lists.digium.com (rattler.digium.com [216.207.245.21])
	by quark.dynx.net (8.11.6/8.11.6) with ESMTP id h4GHeqD16132
	for <pchammer@dynx.net>; Fri, 16 May 2003 13:40:53 -0400
Received: from rattler.digium.com (localhost [127.0.0.1])
	by lists.digium.com (Postfix) with ESMTP
	id 0EC16243354; Fri, 16 May 2003 18:43:03 -0400 (EDT)
Delivered-To: asterisk-dev@lists.digium.com
Received: from smtp-out.comcast.net (smtp-out.comcast.net [24.153.64.116])
	by lists.digium.com (Postfix) with ESMTP id D9599243352
	for <asterisk-dev@lists.digium.com>; Fri, 16 May 2003 18:42:15 -0400 (EDT)
Received: from jeff.jeffandtilghman.com
 (pcp01812660pcs.nash01.tn.comcast.net [68.52.249.170])
 by mtaout01.icomcast.net
 (iPlanet Messaging Server 5.2 HotFix 1.12 (built Feb 13 2003))
 with ESMTP id <0HF0004XA3VHG2@mtaout01.icomcast.net> for
 asterisk-dev@lists.digium.com; Fri, 16 May 2003 18:30:54 -0400 (EDT)
Received: from vcch16.vcch.int (vcch16.vcch.int [192.168.98.16])
	by jeff.jeffandtilghman.com (8.12.9/8.12.8) with ESMTP id h4GMUxEO097817	for
 <asterisk-dev@lists.digium.com>; Fri, 16 May 2003 17:30:59 -0500 (CDT)
From: Tilghman Lesher <tilghman@mail.jeffandtilghman.com>
Subject: Re: [Asterisk-Dev] Patch for voicemail date/time
In-reply-to: <200305161728.16665.tilghman@mail.jeffandtilghman.com>
To: asterisk-dev@lists.digium.com
Message-id: <200305161730.52196.tilghman@mail.jeffandtilghman.com>
MIME-version: 1.0
Content-type: multipart/mixed; boundary="Boundary_(ID_4PAMqUpSzSzK7NtuOhv7Hg)"
User-Agent: KMail/1.4.2
X-Message: Open Source Rocks!
References: <200305141644.37628.tilghman@mail.jeffandtilghman.com>
 <200305160050.25980.tilghman@mail.jeffandtilghman.com>
 <200305161728.16665.tilghman@mail.jeffandtilghman.com>
Sender: asterisk-dev-admin@lists.digium.com
Errors-To: asterisk-dev-admin@lists.digium.com
X-BeenThere: asterisk-dev@lists.digium.com
X-Mailman-Version: 2.0.13
Precedence: bulk
Reply-To: asterisk-dev@lists.digium.com
List-Unsubscribe: <http://lists.digium.com/mailman/listinfo/asterisk-dev>,
	<mailto:asterisk-dev-request@lists.digium.com?subject=unsubscribe>
List-Id: Asterisk Developers Mailing List <asterisk-dev.lists.digium.com>
List-Post: <mailto:asterisk-dev@lists.digium.com>
List-Help: <mailto:asterisk-dev-request@lists.digium.com?subject=help>
List-Subscribe: <http://lists.digium.com/mailman/listinfo/asterisk-dev>,
	<mailto:asterisk-dev-request@lists.digium.com?subject=subscribe>
List-Archive: <http://lists.digium.com/pipermail/asterisk-dev/>
Date: Fri, 16 May 2003 17:30:52 -0500
Status:  O


--Boundary_(ID_4PAMqUpSzSzK7NtuOhv7Hg)
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 7BIT

On Friday 16 May 2003 05:28 pm, Tilghman Lesher wrote:
> On Friday 16 May 2003 12:50 am, Tilghman Lesher wrote:
> > On Thursday 15 May 2003 10:49, Jim Gottlieb wrote:
> > > On 2003-05-15 at 02:53, Brian Capouch (brianc@palaver.net)
> >
> > wrote:
> > > > If that could be done, then the timestamp should prolly be
> > > > played backwards, time-of-day first.  If I'm getting
> > > > messages very often, that's all I'd need to know of any use;
> > > > then beep right along.
> > >
> > > What's usually done in voicemail systems is to just say
> > > "Today" or "Yesterday" as appropriate.  Only if the message is
> > > older is, perhaps, the day of the week given, or the full
> > > date.
> >
> > Here's the latest bit of code.  This patch is currently UNTESTED,
> > but I'll test it tomorrow during the day.  It will allow a new
> > variable in voicemail.conf called "datetime" which is a format
> > string.  The string currently accepts the following specifiers:
> > 	'any/soundfile'	quoted, in single ticks, the name of a sound
> > 	A			weekday
> > 	B			monthname
> > 	d			day of month
> > 	Y			year
> > 	I (capital i)		hour, in 12-hour format
> > 	M			minute
> > 	p			am or pm
> > 	Q			"digits/today", "digits/yesterday", or
> > 				"ABdY" if neither.
> > Spaces and tabs are ignored within the string.  The default
> > string is:
> > 	'vm-received' Q 'digits/at' IMp
> >
> > The format specifiers, with the exception of Q, are in keeping
> > with strftime(3), in case you're interested.
>
> Okay, this patch has been tested (original voicemail).  I'll
> attempt to get the patch ported over to voicemail2 this weekend.

Ooops, let's try that again, with the non-inhouse patch.

-Tilghman

--Boundary_(ID_4PAMqUpSzSzK7NtuOhv7Hg)
Content-type: text/x-diff; charset=iso-8859-1; name=vm1__msg_datetime__3.diff
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename=vm1__msg_datetime__3.diff

Index: apps/app_voicemail.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_voicemail.c,v
retrieving revision 1.13
diff -u -r1.13 app_voicemail.c
--- apps/app_voicemail.c	3 May 2003 20:46:19 -0000	1.13
+++ apps/app_voicemail.c	16 May 2003 22:40:18 -0000
@@ -114,6 +114,7 @@
 STANDARD_LOCAL_USER;
 
 LOCAL_USER_DECL;
+static int play_message_datetime(struct ast_channel *chan, char *filename);
 
 static int make_dir(char *dest, int len, char *ext, char *mailbox)
 {
@@ -1573,6 +1574,12 @@
 		goto cmd; \
 } while(0)
 
+#define WAITFILE3(file) do { \
+	if (ast_streamfile(chan, file, chan->language)) \
+		ast_log(LOG_WARNING, "Unable to play message %s\n", file); \
+	d = ast_waitstream(chan, AST_DIGIT_ANY); \
+} while(0)
+
 #define WAITFILE2(file) do { \
 	if (ast_streamfile(chan, file, chan->language)) \
 		ast_log(LOG_WARNING, "Unable to play message %s\n", file); \
@@ -1614,6 +1621,7 @@
 	} \
 	make_file(fn, sizeof(fn), curdir, a); \
 	heard[a] = 1; \
+	play_message_datetime(chan, fn); \
 	WAITFILE(fn); \
 } while(0)
 
@@ -2301,3 +2309,190 @@
 {
 	return ASTERISK_GPL_KEY;
 }
+
+static int play_message_datetime(struct ast_channel *chan, char *file)
+{
+	char filename[256], *astdtformat, *origtime;
+	struct ast_config *cfg, *msg_cfg;
+	time_t t;
+
+	cfg = ast_load(VOICEMAIL_CONFIG);
+	if (!cfg) {
+		ast_log(LOG_WARNING, "No voicemail.conf?!!\n");
+		return 0;
+	}
+
+	if (!(astdtformat = ast_variable_retrieve(cfg, "general", "datetime"))) 
+		astdtformat = "'vm-received' Q 'digits/at' IMp";
+	snprintf(filename,sizeof(filename), "%s.txt", file);
+
+	msg_cfg = ast_load(filename);
+	if (!msg_cfg) {
+		ast_log(LOG_WARNING, "No message attribute file?!! (%s)\n", filename);
+		return 0;
+	}
+	if (!(origtime = ast_variable_retrieve(msg_cfg, "message", "origtime")))
+		return 0;
+	if (sscanf(origtime,"%i",&t) < 1) {
+		ast_log(LOG_WARNING, "Couldn't find origtime in %s\n", filename);
+		return 0;
+	}
+
+	return play_datetime_format(chan, t, astdtformat);
+}
+
+static int play_datetime_format(struct ast_channel *chan, time_t time, const char *dateformat)
+{
+	int d = 0, offset = 0, sndoffset = 0;
+	char sndfile[256], nextmsg[256];
+	struct tm tm;
+
+	localtime_r(&time, &tm);
+
+	for (offset=0 ; dateformat[offset] != '\0' ; offset++) {
+		ast_log(LOG_NOTICE, "Parsing %c in %s\n", dateformat[offset], dateformat);
+		switch (dateformat[offset]) {
+			/* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
+			case '\'':
+				/* Literal name of a sound file */
+				sndoffset=0;
+				for (sndoffset=0 ; dateformat[++offset] != '\'' ; sndoffset++)
+					sndfile[sndoffset] = dateformat[offset];
+				sndfile[sndoffset] = '\0';
+				snprintf(nextmsg,sizeof(nextmsg),"%s/%s", AST_SOUNDS, sndfile);
+				WAITFILE3(nextmsg);
+				break;
+			case 'A':
+			case 'a':
+				/* Sunday - Saturday */
+				snprintf(nextmsg,sizeof(nextmsg),"%s/digits/day-%d", AST_SOUNDS, tm.tm_wday);
+				WAITFILE3(nextmsg);
+				break;
+			case 'B':
+			case 'b':
+				/* January - December */
+				snprintf(nextmsg,sizeof(nextmsg),"%s/digits/mon-%d", AST_SOUNDS, tm.tm_mon);
+				WAITFILE3(nextmsg);
+				break;
+			case 'd':
+				/* First - Thirtyfirst */
+				if ((tm.tm_mday < 21) || (tm.tm_mday == 30)) {
+					snprintf(nextmsg,sizeof(nextmsg),"%s/digits/h-%d", AST_SOUNDS, tm.tm_mday);
+					WAITFILE3(nextmsg);
+				} else if (tm.tm_mday == 31) {
+					/* "Thirty" and "first" */
+					snprintf(nextmsg,sizeof(nextmsg),"%s/digits/30", AST_SOUNDS);
+					WAITFILE3(nextmsg);
+					if (!d) {
+						snprintf(nextmsg,sizeof(nextmsg),"%s/digits/h-1", AST_SOUNDS);
+						WAITFILE3(nextmsg);
+					}
+				} else {
+					/* Between 21 and 29 - two sounds */
+					snprintf(nextmsg,sizeof(nextmsg),"%s/digits/20", AST_SOUNDS);
+					WAITFILE3(nextmsg);
+					if (!d) {
+						snprintf(nextmsg,sizeof(nextmsg),"%s/digits/h-%d", AST_SOUNDS, tm.tm_mday - 20);
+						WAITFILE3(nextmsg);
+					}
+				}
+				break;
+			case 'Y':
+				/* Year */
+				snprintf(nextmsg,sizeof(nextmsg),"%s/digits/2", AST_SOUNDS);
+				WAITFILE3(nextmsg);
+				if (!d) {
+					snprintf(nextmsg,sizeof(nextmsg),"%s/digits/thousand", AST_SOUNDS);
+					WAITFILE3(nextmsg);
+				}
+				if (!d) {
+					/* This works until the end of 2020 */
+					snprintf(nextmsg,sizeof(nextmsg),"%s/digits/%d", AST_SOUNDS, tm.tm_year - 100);
+					WAITFILE3(nextmsg);
+				}
+				break;
+			case 'I':
+				/* 12-Hour */
+				if (tm.tm_hour == 0)
+					snprintf(nextmsg,sizeof(nextmsg),"%s/digits/12", AST_SOUNDS);
+				else if (tm.tm_hour > 12)
+					snprintf(nextmsg,sizeof(nextmsg),"%s/digits/%d", AST_SOUNDS, tm.tm_hour - 12);
+				else
+					snprintf(nextmsg,sizeof(nextmsg),"%s/digits/%d", AST_SOUNDS, tm.tm_hour);
+				WAITFILE3(nextmsg);
+				break;
+			case 'M':
+				/* Minute */
+				if (tm.tm_min == 0) {
+					snprintf(nextmsg,sizeof(nextmsg),"%s/digits/oclock", AST_SOUNDS);
+					WAITFILE3(nextmsg);
+				} else if (tm.tm_min < 10) {
+					snprintf(nextmsg,sizeof(nextmsg),"%s/digits/oh", AST_SOUNDS);
+					WAITFILE3(nextmsg);
+					if (!d) {
+						snprintf(nextmsg,sizeof(nextmsg),"%s/digits/%d", AST_SOUNDS, tm.tm_min);
+						WAITFILE3(nextmsg);
+					}
+				} else if ((tm.tm_min < 21) || (tm.tm_min % 10 == 0)) {
+					snprintf(nextmsg,sizeof(nextmsg),"%s/digits/%d", AST_SOUNDS, tm.tm_min);
+					WAITFILE3(nextmsg);
+				} else {
+					int ten, one;
+					ten = (tm.tm_min / 10) * 10;
+					one = (tm.tm_min % 10);
+					snprintf(nextmsg,sizeof(nextmsg),"%s/digits/%d", AST_SOUNDS, ten);
+					WAITFILE3(nextmsg);
+					if (!d) {
+						snprintf(nextmsg,sizeof(nextmsg),"%s/digits/%d", AST_SOUNDS, one);
+						WAITFILE3(nextmsg);
+					}
+				}
+				break;
+			case 'p':
+				/* AM/PM */
+				if ((tm.tm_hour == 0) || (tm.tm_hour > 12))
+					snprintf(nextmsg,sizeof(nextmsg),"%s/digits/p-m", AST_SOUNDS);
+				else
+					snprintf(nextmsg,sizeof(nextmsg),"%s/digits/a-m", AST_SOUNDS);
+				WAITFILE3(nextmsg);
+				break;
+			case 'Q':
+				/* Shorthand for "Today", "Yesterday", or ABdY */
+				{
+					struct timeval now;
+					struct tm tmnow;
+					time_t beg_today;
+
+					gettimeofday(&now,NULL);
+					localtime_r(&now.tv_sec,&tmnow);
+					tmnow.tm_hour = 0;
+					tmnow.tm_min = 0;
+					tmnow.tm_sec = 0;
+					beg_today = mktime(&tmnow);
+					if (beg_today < time) {
+						/* Today */
+						WAITFILE3(AST_SOUNDS "/digits/today");
+					} else if (beg_today - 86400 < time) {
+						/* Yesterday */
+						WAITFILE3(AST_SOUNDS "/digits/yesterday");
+					} else {
+						d = play_datetime_format(chan, time, "ABdY");
+					}
+				}
+				break;
+			case ' ':
+			case '	':
+				/* Just ignore spaces and tabs */
+				break;
+			default:
+				/* Unknown character */
+				ast_log(LOG_WARNING, "Unknown character in datetime format: %c\n", dateformat[offset]);
+		}
+		/* Jump out on DTMF */
+		if (d) {
+			break;
+		}
+	}
+	return d;
+}
+

--Boundary_(ID_4PAMqUpSzSzK7NtuOhv7Hg)--
_______________________________________________
Asterisk-Dev mailing list
Asterisk-Dev@lists.digium.com
http://lists.digium.com/mailman/listinfo/asterisk-dev


