--- apps/app_dial.c.org	2007-09-23 13:56:40.000000000 -0700
+++ apps/app_dial.c	2007-09-23 16:26:10.000000000 -0700
@@ -66,7 +66,7 @@
 static char *synopsis = "Place a call and connect to the current channel";
 
 static char *descrip =
-"  Dial(Technology/resource[&Tech2/resource2...][,timeout][,options][,URL]):\n"
+"  Dial(Technology/resource[&Tech2/resource2...][,timeout][,options][,URL],[TEXT]):\n"
 "This application will place calls to one or more specified channels. As soon\n"
 "as one of the requested channels answers, the originating channel will be\n"
 "answered, if it has not already been answered. These two channels will then\n"
@@ -91,6 +91,7 @@
 "hangs up, or if the call is bridged and either of the parties in the bridge\n"
 "ends the call.\n"
 "  The optional URL will be sent to the called party if the channel supports it.\n"
+"  The optional TEXT will be sent to the called party if the channel supports it.\n"
 "  If the OUTBOUND_GROUP variable is set, all peer channels created by this\n"
 "application will be put into that group (as in Set(GROUP()=...).\n"
 "  If the OUTBOUND_GROUP_ONCE variable is set, all peer channels created by this\n"
@@ -262,6 +263,7 @@
 
 #define DIAL_STILLGOING			(1 << 31)
 #define DIAL_NOFORWARDHTML		((uint64_t)1 << 32) /* flags are now 64 bits, so keep it up! */
+#define DIAL_NOFORWARDTEXT		((uint64_t)1 << 33) /* flags are now 64 bits, so keep it up! */
 
 enum {
 	OPT_ARG_ANNOUNCE = 0,
@@ -623,7 +625,7 @@
 						       OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
 						       OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
 						       OPT_CALLEE_PARK | OPT_CALLER_PARK |
-						       DIAL_NOFORWARDHTML);
+						       DIAL_NOFORWARDHTML | DIAL_NOFORWARDTEXT);
 					ast_copy_string(c->dialcontext, "", sizeof(c->dialcontext));
 					ast_copy_string(c->exten, "", sizeof(c->exten));
 				}
@@ -657,7 +659,7 @@
 							       OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
 							       OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
 							       OPT_CALLEE_PARK | OPT_CALLER_PARK |
-							       DIAL_NOFORWARDHTML);
+							       DIAL_NOFORWARDHTML | DIAL_NOFORWARDTEXT);
 						ast_copy_string(c->dialcontext, "", sizeof(c->dialcontext));
 						ast_copy_string(c->exten, "", sizeof(c->exten));
 						/* Setup early bridge if appropriate */
@@ -742,7 +744,7 @@
 				} else if (f->frametype == AST_FRAME_IMAGE && !ast_test_flag64(outgoing, OPT_RINGBACK|OPT_MUSICBACK)) {
 					if (ast_write(in, f))
 						ast_log(LOG_WARNING, "Unable to forward image\n");
-				} else if (f->frametype == AST_FRAME_TEXT && !ast_test_flag64(outgoing, OPT_RINGBACK|OPT_MUSICBACK)) {
+				} else if (f->frametype == AST_FRAME_TEXT && !ast_test_flag64(outgoing, DIAL_NOFORWARDTEXT)) {
 					if (ast_write(in, f))
 						ast_log(LOG_WARNING, "Unable to send text\n");
 				} else if (f->frametype == AST_FRAME_HTML && !ast_test_flag64(outgoing, DIAL_NOFORWARDHTML)) {
@@ -800,7 +802,10 @@
 			if (single && (f->frametype == AST_FRAME_HTML) && !ast_test_flag64(outgoing, DIAL_NOFORWARDHTML)) 
 				if(ast_channel_sendhtml(outgoing->chan, f->subclass, f->data, f->datalen) == -1)
 					ast_log(LOG_WARNING, "Unable to send URL\n");
-			
+			/* Forward TEXT stuff */
+			if (single && (f->frametype == AST_FRAME_TEXT) && !ast_test_flag64(outgoing, DIAL_NOFORWARDTEXT)) 
+				if(ast_sendtext(outgoing->chan, f))
+					ast_log(LOG_WARNING, "Unable to send TEXT\n");			
 
 			if (single && ((f->frametype == AST_FRAME_VOICE) || (f->frametype == AST_FRAME_DTMF_BEGIN) || (f->frametype == AST_FRAME_DTMF_END)))  {
 				if (ast_write(outgoing->chan, f))
@@ -1216,6 +1221,7 @@
 			     AST_APP_ARG(timeout);
 			     AST_APP_ARG(options);
 			     AST_APP_ARG(url);
+			     AST_APP_ARG(text);
 	);
 	struct ast_flags64 opts = { 0, };
 	char *opt_args[OPT_ARG_ARRAY_SIZE];
@@ -1316,6 +1322,7 @@
 				       OPT_CALLEE_PARK | OPT_CALLER_PARK |
 				       OPT_RINGBACK | OPT_MUSICBACK | OPT_FORCECLID);
 			ast_set2_flag64(tmp, args.url, DIAL_NOFORWARDHTML);	
+			ast_set2_flag64(tmp, args.text, DIAL_NOFORWARDTEXT);	
 		}
 		ast_copy_string(numsubst, number, sizeof(numsubst));
 		/* Request the peer */
@@ -1520,6 +1527,10 @@
  			ast_debug(1, "app_dial: sendurl=%s.\n", args.url);
  			ast_channel_sendurl( peer, args.url );
  		}
+ 		if (!ast_strlen_zero(args.text)) {
+ 			ast_debug(1, "app_dial: sendtext=%s.\n", args.text);
+ 			ast_sendtext( peer, args.text );
+ 		}
 		if ( (ast_test_flag64(&opts, OPT_PRIVACY) || ast_test_flag64(&opts, OPT_SCREENING)) && pa.privdb_val == AST_PRIVACY_UNKNOWN) {
 			if (do_privacy(chan, peer, &opts, opt_args, &pa)) {
 				res = 0;
