--- app_voicemail2.c.original	Mon Sep 22 22:14:16 2003
+++ app_voicemail2.c	Tue Sep 23 11:44:57 2003
@@ -62,7 +62,6 @@
 #define eol "\r\n"
 
 #define MAX_DATETIME_FORMAT	512
-#define DIGITS_DIR	AST_SOUNDS "/digits/"
 struct baseio {
 	int iocp;
 	int iolen;
@@ -1741,13 +1740,24 @@
 		d = play_and_wait(chan, "vm-for");
 		if (d)
 			return d;
-		snprintf(fn, sizeof(fn), "vm-%s", mbox(x));
-		d = play_and_wait(chan, fn);
-		if (d)
+                if (!strcasecmp(chan->language, "pt")) {        // PORTUGUESE
+                    d = play_and_wait(chan, "vm-messages");
+                    if (d)
+                        return d;
+                    snprintf(fn, sizeof(fn), "vm-%s", mbox(x));
+                    d = play_and_wait(chan, fn);
+                    if (d)
+                        return d;
+                }
+                else {          // Default to ENGLISH
+                    snprintf(fn, sizeof(fn), "vm-%s", mbox(x));
+                    d = play_and_wait(chan, fn);
+                    if (d)
 			return d;
-		d = play_and_wait(chan, "vm-messages");
-		if (d)
+                    d = play_and_wait(chan, "vm-messages");
+                    if (d)
 			return d;
+                }
 		d = ast_waitfordigit(chan, 500);
 		if (d)
 			return d;
@@ -1957,7 +1967,7 @@
 	if (the_zone)
 		res = ast_say_date_with_format(chan, t, AST_DIGIT_ANY, chan->language, the_zone->msg_format, &(the_zone->timezone));
 	else
-		res = ast_say_date_with_format(chan, t, AST_DIGIT_ANY, chan->language, "'vm-received' q 'digits/at' IMp", NULL);
+		res = ast_say_date_with_format(chan, t, AST_DIGIT_ANY, chan->language, "'vm-received' qIMp", NULL);
 #if 0
 	pbx_builtin_setvar_helper(chan, "DIFF_DAY", NULL);
 #endif
@@ -2044,10 +2054,54 @@
 static int vm_intro(struct ast_channel *chan,struct vm_state *vms)
 {
 	/* Introduce messages they have */
-	int res;
-	res = play_and_wait(chan, "vm-youhave");
-	if (!res) {
-		if (vms->newmessages) {
+         int res = 0;
+         if (!strcasecmp(chan->language, "pt")) {        // PORTUGUESE
+                if (vms->newmessages || vms->oldmessages)
+            	    res = play_and_wait(chan, "vm-youhave");
+                if (!res) {
+                    if (vms->newmessages) {
+                        res = ast_say_number(chan, -(vms->newmessages), AST_DIGIT_ANY, chan->language);
+                        if (!res) {
+                                if ((vms->newmessages == 1)) {
+                                        res = play_and_wait(chan, "vm-message");
+                                        if (!res)
+                                            res = play_and_wait(chan, "vm-INBOXs");
+                                }
+                                else {
+                                        res = play_and_wait(chan, "vm-messages");
+                                        if (!res) 
+                                            res = play_and_wait(chan, "vm-INBOX");
+                                }
+                        }
+                        if (vms->oldmessages && !res)
+                                res = play_and_wait(chan, "vm-and");
+                    }
+                    if (!res && vms->oldmessages) {
+                        res = ast_say_number(chan, -(vms->oldmessages), AST_DIGIT_ANY, chan->language);
+                        if (!res) {
+                                if (vms->oldmessages == 1) {
+                                        res = play_and_wait(chan, "vm-message");
+                                        if (!res)
+                                            res = play_and_wait(chan, "vm-Olds");
+                                }
+                                else {
+                                        res = play_and_wait(chan, "vm-messages");
+                                        if (!res)
+                                            res = play_and_wait(chan, "vm-Old");
+                                }
+                        }
+                    }
+                    if (!res) {
+                        if (!vms->oldmessages && !vms->newmessages) {
+                                res = play_and_wait(chan, "vm-no");
+                        }
+                    }
+                }
+        }
+        else {          // Default to ENGLISH
+                res = play_and_wait(chan, "vm-youhave");
+                if (!res) {
+                    if (vms->newmessages) { 
 			res = say_and_wait(chan, vms->newmessages);
 			if (!res)
 				res = play_and_wait(chan, "vm-INBOX");
@@ -2060,10 +2114,9 @@
 					res = play_and_wait(chan, "vm-messages");
 			}
 				
-		}
-		if (!res && vms->oldmessages) {
-			res = say_and_wait(chan, vms->oldmessages);
-			if (!res)
+                    }
+                    if (!res && vms->oldmessages) {
+                        res = ast_say_number(chan, -(vms->oldmessages), AST_DIGIT_ANY, chan->language);			if (!res)
 				res = play_and_wait(chan, "vm-Old");
 			if (!res) {
 				if (vms->oldmessages == 1)
@@ -2071,13 +2124,14 @@
 				else
 					res = play_and_wait(chan, "vm-messages");
 			}
-		}
-		if (!res) {
+		    }
+		    if (!res) {
 			if (!vms->oldmessages && !vms->newmessages) {
 				res = play_and_wait(chan, "vm-no");
 				if (!res)
 					res = play_and_wait(chan, "vm-messages");
 			}
+		    }
 		}
 	}
 	return res;
@@ -2091,10 +2145,18 @@
 		if (vms->starting) {
 			if (vms->lastmsg > -1) {
 				res = play_and_wait(chan, "vm-onefor");
-				if (!res)
+                                if (!strcasecmp(chan->language, "pt")) {        // PORTUGUESE
+                                    if (!res)
+                                        res = play_and_wait(chan, "vm-messages");
+                                    if (!res)
+                                        res = play_and_wait(chan, vms->vmbox);
+                                }
+                                else {          // Default to ENGLISH
+                                    if (!res)
 					res = play_and_wait(chan, vms->vmbox);
-				if (!res)
+				    if (!res)
 					res = play_and_wait(chan, "vm-messages");
+				}
 			}
 			if (!res)
 				res = play_and_wait(chan, "vm-opts");
@@ -2372,15 +2434,22 @@
 				if (vms.lastmsg > -1) {
 					cmd = play_message(chan, vmu, &vms, vms.curmsg);
 				} else {
-					cmd = play_and_wait(chan, "vm-youhave");
-					if (!cmd) 
+                                        if (!strcasecmp(chan->language, "pt")) {        // PORTUGUESE
+                                            cmd = play_and_wait(chan, "vm-no");
+                                            if (!cmd) {
+                                                snprintf(vms.fn, sizeof(vms.fn), "vm-%s", vms.curbox);
+                                                cmd = play_and_wait(chan, vms.fn);
+                                            }
+                                        }
+                                        else {  // Default to ENGLISH
+                                    	    cmd = play_and_wait(chan, "vm-youhave");
+                                            if (!cmd)
 						cmd = play_and_wait(chan, "vm-no");
-					if (!cmd) {
+					    if (!cmd) {
 						snprintf(vms.fn, sizeof(vms.fn), "vm-%s", vms.curbox);
 						cmd = play_and_wait(chan, vms.fn);
+					    }
 					}
-					if (!cmd)
-						cmd = play_and_wait(chan, "vm-messages");
 				}
 				break;
 			case '2': /* Change folders */
@@ -2397,10 +2466,18 @@
 				}
 				if (useadsi)
 					adsi_status2(chan, vms.curbox, vms.lastmsg + 1);
-				if (!cmd)
+                                if (!strcasecmp(chan->language, "pt")) {        // PORTUGUESE
+                                    if (!cmd)
+                                        cmd = play_and_wait(chan, "vm-messages");
+                                    if (!cmd)
+                                        cmd = play_and_wait(chan, vms.vmbox);
+                               }
+                                else {          // Default to ENGLISH
+                                    if (!cmd)
 					cmd = play_and_wait(chan, vms.vmbox);
-				if (!cmd)
+				    if (!cmd)
 					cmd = play_and_wait(chan, "vm-messages");
+				}
 				vms.starting = 1;
 				break;
 			case '4':
@@ -2454,12 +2531,22 @@
 					cmd = say_and_wait(chan, vms.curmsg + 1);
 				if (!cmd)
 					cmd = play_and_wait(chan, "vm-savedto");
-				if (!cmd) {
+                                if (!strcasecmp(chan->language, "pt")) {        // PORTUGUESE
+                                    if (!cmd)
+                                        cmd = play_and_wait(chan, "vm-messages");
+                                    if (!cmd) {
 					snprintf(vms.fn, sizeof(vms.fn), "vm-%s", mbox(box));
 					cmd = play_and_wait(chan, vms.fn);
+				    }
 				}
-				if (!cmd)
+                                else {          // Default to ENGLISH
+                                    if (!cmd) {
+                                        snprintf(vms.fn, sizeof(vms.fn), "vm-%s", mbox(box));
+                                        cmd = play_and_wait(chan, vms.fn);
+                                    }
+                                    if (!cmd)
 					cmd = play_and_wait(chan, "vm-messages");
+				}
 				break;
 			case '*':
 				if (!vms.starting) {
