--- app_queue.c	2007-10-05 01:57:03.000000000 +0400
+++ app_queue.c.new	2007-10-16 10:19:34.000000000 +0400
@@ -341,6 +341,11 @@
 #define ANNOUNCEHOLDTIME_ONCE 2
 #define QUEUE_EVENT_VARIABLES 3
 
+#define ANNOUNCEPOSITION_YES 1 /*!< We announce position */
+#define ANNOUNCEPOSITION_NO 2 /*!< We not announce position */
+#define ANNOUNCEPOSITION_MORE_THAN 3 /*!< We say "There are currently more than <limit>" */
+#define ANNOUNCEPOSITION_LIMIT 4 /*!< We not announce position more than <limit> */
+
 struct call_queue {
 	ast_mutex_t lock;	
 	char name[80];                      /*!< Name */
@@ -358,11 +363,13 @@
 	unsigned int wrapped:1;
 	unsigned int timeoutrestart:1;
 	unsigned int announceholdtime:2;
+	unsigned int announceposition:3;
 	unsigned int strategy:3;
 	unsigned int maskmemberstatus:1;
 	unsigned int realtime:1;
 	unsigned int found:1;
 	int announcefrequency;              /*!< How often to announce their position */
+	int announcepositionlimit;          /*!< How many positions we announce? */
 	int periodicannouncefrequency;      /*!< How often to play periodic announcement */
 	int roundingseconds;                /*!< How many seconds do we round to? */
 	int holdtime;                       /*!< Current avg holdtime, based on recursive boxcar filter */
@@ -374,6 +381,7 @@
 	int montype;                        /*!< Monitor type  Monitor vs. MixMonitor */
 	char sound_next[80];                /*!< Sound file: "Your call is now first in line" (def. queue-youarenext) */
 	char sound_thereare[80];            /*!< Sound file: "There are currently" (def. queue-thereare) */
+	char sound_morethan[80];            /*!< Sound file: "more than" (def. queue-morethan) */
 	char sound_calls[80];               /*!< Sound file: "calls waiting to speak to a representative." (def. queue-callswaiting)*/
 	char sound_holdtime[80];            /*!< Sound file: "The current estimated total holdtime is" (def. queue-holdtime) */
 	char sound_minutes[80];             /*!< Sound file: "minutes." (def. queue-minutes) */
@@ -711,6 +719,8 @@
 	q->maxlen = 0;
 	q->announcefrequency = 0;
 	q->announceholdtime = 0;
+	q->announceposition = ANNOUNCEPOSITION_YES; /* Default yes */
+	q->announcepositionlimit = 10; /* Default 10 positions */
 	q->roundingseconds = 0; /* Default - don't announce seconds */
 	q->servicelevel = 0;
 	q->ringinuse = 1;
@@ -728,6 +738,7 @@
 	q->found = 1;
 	ast_copy_string(q->sound_next, "queue-youarenext", sizeof(q->sound_next));
 	ast_copy_string(q->sound_thereare, "queue-thereare", sizeof(q->sound_thereare));
+	ast_copy_string(q->sound_morethan, "queue-morethan", sizeof(q->sound_morethan));
 	ast_copy_string(q->sound_calls, "queue-callswaiting", sizeof(q->sound_calls));
 	ast_copy_string(q->sound_holdtime, "queue-holdtime", sizeof(q->sound_holdtime));
 	ast_copy_string(q->sound_minutes, "queue-minutes", sizeof(q->sound_minutes));
@@ -865,6 +876,8 @@
 		ast_copy_string(q->sound_next, val, sizeof(q->sound_next));
 	} else if (!strcasecmp(param, "queue-thereare")) {
 		ast_copy_string(q->sound_thereare, val, sizeof(q->sound_thereare));
+	} else if (!strcasecmp(param, "queue-morethan")) {
+		ast_copy_string(q->sound_morethan, val, sizeof(q->sound_morethan));
 	} else if (!strcasecmp(param, "queue-callswaiting")) {
 		ast_copy_string(q->sound_calls, val, sizeof(q->sound_calls));
 	} else if (!strcasecmp(param, "queue-holdtime")) {
@@ -901,6 +914,17 @@
 			q->announceholdtime = ANNOUNCEHOLDTIME_ALWAYS;
 		else
 			q->announceholdtime = 0;
+	} else if (!strcasecmp(param, "announce-position")) {
+		if (!strcasecmp(val, "limit"))
+			q->announceposition = ANNOUNCEPOSITION_LIMIT; 
+		else if (!strcasecmp(val, "more"))
+			q->announceposition = ANNOUNCEPOSITION_MORE_THAN; 
+		else if (ast_true(val))
+			q->announceposition = ANNOUNCEPOSITION_YES;
+		else
+			q->announceposition = ANNOUNCEPOSITION_NO;
+	} else if (!strcasecmp(param, "announce-position-limit")) {
+		q->announcepositionlimit = atoi(val);
 	} else if (!strcasecmp(param, "periodic-announce")) {
 		if (strchr(val, '|')) {
 			char *s, *buf = ast_strdupa(val);
@@ -1402,7 +1426,7 @@
 
 static int say_position(struct queue_ent *qe)
 {
-	int res = 0, avgholdmins, avgholdsecs;
+	int res = 0, avgholdmins, avgholdsecs, announceposition = 0;
 	time_t now;
 
 	/* Check to see if this is ludicrous -- if we just announced position, don't do it again*/
@@ -1415,24 +1439,40 @@
 		return 0;
 
 	ast_moh_stop(qe->chan);
-	/* Say we're next, if we are */
-	if (qe->pos == 1) {
-		res = play_file(qe->chan, qe->parent->sound_next);
-		if (res)
-			goto playout;
-		else
-			goto posout;
-	} else {
-		res = play_file(qe->chan, qe->parent->sound_thereare);
-		if (res)
-			goto playout;
-		res = ast_say_number(qe->chan, qe->pos, AST_DIGIT_ANY, qe->chan->language, (char *) NULL); /* Needs gender */
-		if (res)
-			goto playout;
-		res = play_file(qe->chan, qe->parent->sound_calls);
-		if (res)
-			goto playout;
+	if (qe->parent->announceposition == ANNOUNCEPOSITION_YES || 
+		qe->parent->announceposition == ANNOUNCEPOSITION_MORE_THAN || 
+		(qe->parent->announceposition == ANNOUNCEPOSITION_LIMIT && 
+		qe->pos <= qe->parent->announcepositionlimit)) 
+			announceposition = 1;
+		
+	if (announceposition == 1){
+		/* Say we're next, if we are */
+		if (qe->pos == 1) {
+			res = play_file(qe->chan, qe->parent->sound_next);
+			if (res)
+				goto playout;
+			else
+				goto posout;
+		} else {
+			res = play_file(qe->chan, qe->parent->sound_thereare);
+			if (res)
+				goto playout;
+			if (qe->parent->announceposition == ANNOUNCEPOSITION_MORE_THAN && qe->pos > qe->parent->announcepositionlimit){
+				res = play_file(qe->chan, qe->parent->sound_morethan);
+				if (res)
+					goto playout;
+				res = ast_say_number(qe->chan, qe->parent->announcepositionlimit, AST_DIGIT_ANY, qe->chan->language, (char *) NULL); /* Needs gender */
+			} else
+				res = ast_say_number(qe->chan, qe->pos, AST_DIGIT_ANY, qe->chan->language, (char *) NULL); /* Needs gender */
+			
+			if (res)
+				goto playout;
+			res = play_file(qe->chan, qe->parent->sound_calls);
+			if (res)
+				goto playout;
+		}
 	}
+
 	/* Round hold time to nearest minute */
 	avgholdmins = abs(((qe->parent->holdtime + 30) - (now - qe->start)) / 60);
 
@@ -1487,10 +1527,12 @@
 	}
 
 posout:
-	if (option_verbose > 2)
-		ast_verbose(VERBOSE_PREFIX_3 "Told %s in %s their queue position (which was %d)\n",
-			qe->chan->name, qe->parent->name, qe->pos);
-	res = play_file(qe->chan, qe->parent->sound_thanks);
+	if (announceposition == 1){
+		if (option_verbose > 2)
+			ast_verbose(VERBOSE_PREFIX_3 "Told %s in %s their queue position (which was %d)\n",
+				qe->chan->name, qe->parent->name, qe->pos);
+		res = play_file(qe->chan, qe->parent->sound_thanks);
+	}
 
 playout:
 	if (res > 0 && !valid_exit(qe, res))
