From 73f91fcc44e2c38e93a35c60d35745745b9afe28 Mon Sep 17 00:00:00 2001
From: Mark Spencer <markster@digium.com>
Date: Sun, 18 Jul 2004 20:50:37 +0000
Subject: [PATCH] Grab the Message-ID too

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3473 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 apps/app_voicemail.c |  2 +-
 channels/chan_zap.c  | 29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index 2cd9968556..7f22806ad3 100755
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -923,7 +923,7 @@ static int sendmail(char *srcemail, struct ast_vm_user *vmu, int msgnum, char *m
 			fprintf(p, "Subject: New message %d in mailbox %s\n", msgnum + 1, mailbox);
 		else
 			fprintf(p, "Subject: [PBX]: New message %d in mailbox %s\n", msgnum + 1, mailbox);
-		fprintf(p, "Message-ID: <Asterisk-%d-%s-%d@%s>\n", msgnum, mailbox, getpid(), host);
+		fprintf(p, "Message-ID: <Asterisk-%d-%d-%s-%d@%s>\n", msgnum, (unsigned int)rand(), mailbox, getpid(), host);
 		fprintf(p, "MIME-Version: 1.0\n");
 		if (attach_user_voicemail) {
 			/* Something unique. */
diff --git a/channels/chan_zap.c b/channels/chan_zap.c
index d5d17f4006..4cdc98b2cc 100755
--- a/channels/chan_zap.c
+++ b/channels/chan_zap.c
@@ -4972,6 +4972,35 @@ static void *ss_thread(void *data)
 	case SIG_FXSLS:
 	case SIG_FXSGS:
 	case SIG_FXSKS:
+		if (p->pri) {
+			/* This is a GR-303 trunk actually.  Wait for the first ring... */
+			struct ast_frame *f;
+			int res;
+			time_t start;
+
+			time(&start);
+			ast_setstate(chan, AST_STATE_RING);
+			while(time(NULL) < start + 3) {
+				res = ast_waitfor(chan, 1000);
+				if (res) {
+					f = ast_read(chan);
+					if (!f) {
+						ast_log(LOG_WARNING, "Whoa, hangup while waiting for first ring!\n");
+						ast_hangup(chan);
+						return NULL;
+					} else if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_RING)) {
+						res = 1;
+					} else
+						res = 0;
+					ast_frfree(f);
+					if (res) {
+						ast_log(LOG_DEBUG, "Got ring!\n");
+						res = 0;
+						break;
+					}
+				}
+			}
+		}
 		if (p->use_callerid) {
 			cs = callerid_new();
 			if (cs) {
-- 
GitLab