CTRACE(tfp,"GridText - post_data: %s\n",doc->post_data);
FREE(doc->post_content_type); doc->post_content_type = content_type_out;  CTRACE((tfp,"GridText - post_data: %s\n",doc->post_data));
PUBLIC void HText_SubmitForm ARGS4(	FormInfo *,	submit_item,	document *,	doc,	char *,		link_name,	char *,		link_value){    TextAnchor *anchor_ptr;    int form_number = submit_item->number;    FormInfo *form_ptr;    PerFormInfo *thisform;    char *query = NULL;    char *escaped1 = NULL, *escaped2 = NULL;    int first_one = 1;    char *last_textarea_name = NULL;    int textarea_lineno = 0;    char *previous_blanks = NULL;    BOOLEAN PlainText = FALSE;    BOOLEAN SemiColon = FALSE;    char *Boundary = NULL;    char *MultipartContentType = NULL;    int target_cs = -1;    CONST char *out_csname;    CONST char *target_csname = NULL;    char *name_used = "";    BOOL form_has_8bit = NO, form_has_special = NO;    BOOL field_has_8bit = NO, field_has_special = NO;    BOOL name_has_8bit = NO, name_has_special = NO;    BOOL have_accept_cs = NO;    BOOL success;    BOOL had_chartrans_warning = NO;    char *val_used = "";    char *copied_val_used = NULL;    char *copied_name_used = NULL;    CTRACE(tfp, "FIXME:SubmitForm\n");    if (!HTMainText)	return;    thisform = HTList_objectAt(HTMainText->forms, form_number - 1);    /*  Sanity check */    if (!thisform) {	CTRACE(tfp, "SubmitForm: form %d not in HTMainText's list!\n",		    form_number);    } else if (thisform->number != form_number) {	CTRACE(tfp, "SubmitForm: failed sanity check, %d!=%d !\n",		    thisform->number, form_number);	thisform = NULL;    }    if (submit_item->submit_action) {	/*	 *  If we're mailing, make sure it's a mailto ACTION. - FM	 */	if ((submit_item->submit_method == URL_MAIL_METHOD) &&	    strncmp(submit_item->submit_action, "mailto:", 7)) {	    HTAlert(BAD_FORM_MAILTO);	    return;	}    } else {	return;    }    /*     *  Check the ENCTYPE and set up the appropriate variables. - FM     */    if (submit_item->submit_enctype &&	!strncasecomp(submit_item->submit_enctype, "text/plain", 10)) {	/*	 *  Do not hex escape, and use physical newlines	 *  to separate name=value pairs. - FM	 */	PlainText = TRUE;    } else if (submit_item->submit_enctype &&	       !strncasecomp(submit_item->submit_enctype,			     "application/sgml-form-urlencoded", 32)) {	/*	 *  Use semicolons instead of ampersands as the	 *  separators for name=value pairs. - FM	 */	SemiColon = TRUE;    } else if (submit_item->submit_enctype &&	       !strncasecomp(submit_item->submit_enctype,			     "multipart/form-data", 19)) {	/*	 *  Use the multipart MIME format.  We should generate	 *  a boundary string which we are sure doesn't occur	 *  in the content, but for now we'll just assume that	 *  this string doesn't. - FM	 */	Boundary = "xnyLAaB03X";    }    /*     *  Determine in what character encoding (aka. charset) we should     *  submit.  We call this target_cs and the MIME name for it     *  target_csname.     *  TODO:   - actually use ACCEPT-CHARSET stuff from FORM     *  TODO:   - deal with list in ACCEPT-CHARSET, find a "best"     *		  charset to submit     */    /* Look at ACCEPT-CHARSET on the submitting field if we have one. */    if (thisform && submit_item->accept_cs &&	strcasecomp(submit_item->accept_cs, "UNKNOWN")) {	have_accept_cs = YES;	target_cs = find_best_target_cs(&thisform->thisacceptcs,					current_char_set,					submit_item->accept_cs);    }    /* Look at ACCEPT-CHARSET on form as a whole if submitting field     * didn't have one. */    if (thisform && !have_accept_cs && thisform->accept_cs &&	strcasecomp(thisform->accept_cs, "UNKNOWN")) {	have_accept_cs = YES;	target_cs = find_best_target_cs(&thisform->thisacceptcs,					current_char_set,					thisform->accept_cs);    }    if (have_accept_cs && (target_cs >= 0) && thisform->thisacceptcs) {	target_csname = thisform->thisacceptcs;    }    if (target_cs < 0 &&	HTMainText->node_anchor->charset &&	*HTMainText->node_anchor->charset) {	target_cs = UCGetLYhndl_byMIME(HTMainText->node_anchor->charset);	if (target_cs >= 0) {	    target_csname = HTMainText->node_anchor->charset;	} else {	    target_cs = UCLYhndl_for_unspec; /* always >= 0 */	    target_csname = LYCharSet_UC[target_cs].MIMEname;	}    }    if (target_cs < 0) {	target_cs = UCLYhndl_for_unspec;  /* always >= 0 */    }    /*     *  Go through list of anchors and get size first.     */    /*     *  also get a "max." charset parameter - kw     */    anchor_ptr = HTMainText->first_anchor;    while (anchor_ptr) {	if (anchor_ptr->link_type == INPUT_ANCHOR) {	    if (anchor_ptr->input_field->number == form_number) {		char *p;		char * val;		form_ptr = anchor_ptr->input_field;		val = form_ptr->cp_submit_value != NULL ?				    form_ptr->cp_submit_value : form_ptr->value;		field_has_8bit = NO;		field_has_special = NO;		for (p = val;		     p && *p && !(field_has_8bit && field_has_special);		     p++)		    if ((*p == HT_NON_BREAK_SPACE) ||		       (*p == HT_EN_SPACE) ||			(*p == LY_SOFT_HYPHEN)) {			field_has_special = YES;		    } else if ((*p & 0x80) != 0) {			field_has_8bit = YES;		    }		for (p = form_ptr->name;		     p && *p && !(name_has_8bit && name_has_special);		     p++)		    if ((*p == HT_NON_BREAK_SPACE) ||			(*p == HT_EN_SPACE) ||			(*p == LY_SOFT_HYPHEN)) {			name_has_special = YES;		    } else if ((*p & 0x80) != 0) {			name_has_8bit = YES;		    }		if (field_has_8bit || name_has_8bit)		    form_has_8bit = YES;		if (field_has_special || name_has_special)		    form_has_special = YES;		if (!field_has_8bit && !field_has_special) {		    /* already ok */		} else if (target_cs < 0) {		    /* already confused */		} else if (!field_has_8bit &&		    (LYCharSet_UC[target_cs].enc == UCT_ENC_8859 ||		     (LYCharSet_UC[target_cs].like8859 & UCT_R_8859SPECL))) {		    /* those specials will be trivial */		} else if (UCNeedNotTranslate(form_ptr->value_cs, target_cs)) {		    /* already ok */		} else if (UCCanTranslateFromTo(form_ptr->value_cs, target_cs)) {		    /* also ok */		} else if (UCCanTranslateFromTo(target_cs, form_ptr->value_cs)) {		    target_cs = form_ptr->value_cs;	/* try this */		    target_csname = NULL; /* will be set after loop */		} else {		    target_cs = -1; /* don't know what to do */		}		/*  Same for name */		if (!name_has_8bit && !name_has_special) {		    /* already ok */		} else if (target_cs < 0) {		    /* already confused */		} else if (!name_has_8bit &&		    (LYCharSet_UC[target_cs].enc == UCT_ENC_8859 ||		     (LYCharSet_UC[target_cs].like8859 & UCT_R_8859SPECL))) {		    /* those specials will be trivial */		} else if (UCNeedNotTranslate(form_ptr->name_cs, target_cs)) {		    /* already ok */		} else if (UCCanTranslateFromTo(form_ptr->name_cs, target_cs)) {		    /* also ok */		} else if (UCCanTranslateFromTo(target_cs, form_ptr->name_cs)) {		    target_cs = form_ptr->value_cs;	/* try this */		    target_csname = NULL; /* will be set after loop */		} else {		    target_cs = -1; /* don't know what to do */		}	    } else if (anchor_ptr->input_field->number > form_number) {		break;	    }	}	if (anchor_ptr == HTMainText->last_anchor)	    break;	anchor_ptr = anchor_ptr->next;    }    if (target_csname == NULL && target_cs >= 0) {	if (form_has_8bit) {	    target_csname = LYCharSet_UC[target_cs].MIMEname;	} else if (form_has_special) {	    target_csname = LYCharSet_UC[target_cs].MIMEname;	} else {	    target_csname = "us-ascii";	}    }    if (submit_item->submit_method == URL_GET_METHOD && Boundary == NULL) {	StrAllocCopy(query, submit_item->submit_action);	/*	 *  Method is GET.  Clip out any anchor in the current URL.	 */	strtok (query, "#");	/*	 *  Clip out any old query in the current URL.	 */	strtok (query, "?");	/*	 *  Add the lead question mark for the new URL.	 */	StrAllocCat(query,"?");    } else {	/*	 *  We are submitting POST content to a server,	 *  so load the post_content_type element. - FM	 */	if (SemiColon == TRUE) {	    StrAllocCopy(doc->post_content_type,			 "application/sgml-form-urlencoded");	} else if (PlainText == TRUE) {	    StrAllocCopy(doc->post_content_type,			 "text/plain");	} else if (Boundary != NULL) {	    StrAllocCopy(doc->post_content_type,			 "multipart/form-data; boundary=");	    StrAllocCat(doc->post_content_type, Boundary);	} else {	    StrAllocCopy(doc->post_content_type,			 "application/x-www-form-urlencoded");	}	/*	 *  If the ENCTYPE is not multipart/form-data, append the	 *  charset we'll be sending to the post_content_type, IF	 *  (1) there was an explicit accept-charset attribute, OR	 *  (2) we have 8-bit or special chars, AND the document had	 *      an explicit (recognized and accepted) charset parameter,	 *	AND it or target_csname is different from iso-8859-1,	 *      OR	 *  (3) we have 8-bit or special chars, AND the document had	 *      no explicit (recognized and accepted) charset parameter,	 *	AND target_cs is different from the currently effective	 *	assumed charset (which should have been set by the user	 *	so that it reflects what the server is sending, if the	 *	document is rendered correctly).	 *  For multipart/form-data the equivalent will be done later,	 *  separately for each form field. - kw	 */	if (have_accept_cs ||	    (form_has_8bit || form_has_special)) {	    if (target_cs >= 0 && target_csname) {		if (Boundary == NULL) {		    if ((HTMainText->node_anchor->charset &&			 (strcmp(HTMainText->node_anchor->charset,				 "iso-8859-1") ||			  strcmp(target_csname, "iso-8859-1"))) ||			(!HTMainText->node_anchor->charset &&			 target_cs != UCLYhndl_for_unspec)) {			StrAllocCat(doc->post_content_type, "; charset=");			StrAllocCat(doc->post_content_type, target_csname);		    }		}	    } else {		had_chartrans_warning = YES;		_user_message(		    CANNOT_TRANSCODE_FORM,		    target_csname ? target_csname : "UNKNOWN");		sleep(AlertSecs);	    }	}    }    out_csname = target_csname;    /*     *  Reset anchor->ptr.     */    anchor_ptr = HTMainText->first_anchor;    /*     *  Go through list of anchors and assemble URL query.     */    while (anchor_ptr) {	if (anchor_ptr->link_type == INPUT_ANCHOR) {	    if (anchor_ptr->input_field->number == form_number) {		char *p;		int out_cs;		form_ptr = anchor_ptr->input_field;		if (form_ptr->type != F_TEXTAREA_TYPE)		    textarea_lineno = 0;		switch(form_ptr->type) {		case F_RESET_TYPE:		    break;		case F_SUBMIT_TYPE:		case F_TEXT_SUBMIT_TYPE:		case F_IMAGE_SUBMIT_TYPE:		    if (!(form_ptr->name && *form_ptr->name != '\0' &&			  !strcmp(form_ptr->name, link_name))) {			CTRACE(tfp,				    "SubmitForm: skipping submit field with ");			CTRACE(tfp, "name \"%s\" for link_name \"%s\", %s.\n",				    form_ptr->name ? form_ptr->name : "???",				    link_name ? link_name : "???",				    (form_ptr->name && *form_ptr->name) ?				    "not current link" : "no field name");			break;		    }		    if (!(form_ptr->type == F_TEXT_SUBMIT_TYPE ||			(form_ptr->value && *form_ptr->value != '\0' &&			 !strcmp(form_ptr->value, link_value)))) {			if (TRACE) {			    fprintf(tfp,				    "SubmitForm: skipping submit field with ");			    fprintf(tfp,				    "name \"%s\" for link_name \"%s\", %s!\n",				    form_ptr->name ? form_ptr->name : "???",				    link_name ? link_name : "???",				    "values are different");			}			break;		    }		    /*  fall through  */		case F_RADIO_TYPE:		case F_CHECKBOX_TYPE:		case F_TEXTAREA_TYPE:		case F_PASSWORD_TYPE:		case F_TEXT_TYPE:		case F_OPTION_LIST_TYPE:		case F_HIDDEN_TYPE:		    /*		     *	Be sure to actually look at the option submit value.		     */		    if (form_ptr->cp_submit_value != NULL) {			val_used = form_ptr->cp_submit_value;		    } else {			val_used = form_ptr->value;		    }		    /*		     *  Charset-translate value now, because we need		     *  to know the charset parameter for multipart		     *  bodyparts. - kw		     */		    field_has_8bit = NO;		    field_has_special = NO;		    for (p = val_used;			 p && *p && !(field_has_8bit && field_has_special);			 p++) {			if ((*p == HT_NON_BREAK_SPACE) ||			    (*p == HT_EN_SPACE) ||			    (*p == LY_SOFT_HYPHEN)) {			    field_has_special = YES;			} else if ((*p & 0x80) != 0) {			    field_has_8bit = YES;			}		    }		    if (field_has_8bit || field_has_special) {			/*  We should translate back. */			StrAllocCopy(copied_val_used, val_used);			success = LYUCTranslateBackFormData(&copied_val_used,							form_ptr->value_cs,							target_cs, PlainText);			CTRACE(tfp, "SubmitForm: field \"%s\" %d %s -> %d %s %s\n",				    form_ptr->name ? form_ptr->name : "",				    form_ptr->value_cs,				    form_ptr->value_cs >= 0 ?				    LYCharSet_UC[form_ptr->value_cs].MIMEname :									  "???",				    target_cs,				    target_csname ? target_csname : "???",				    success ? "OK" : "FAILED");			if (success) {			    val_used = copied_val_used;			}		    } else {  /* We can use the value directly. */			CTRACE(tfp, "SubmitForm: field \"%s\" %d %s OK\n",				    form_ptr->name ? form_ptr->name : "",				    target_cs,				    target_csname ? target_csname : "???");			success = YES;		    }		    if (!success) {			if (!had_chartrans_warning) {			    had_chartrans_warning = YES;			    _user_message(				CANNOT_TRANSCODE_FORM,				target_csname ? target_csname : "UNKNOWN");			    sleep(AlertSecs);			}			out_cs = form_ptr->value_cs;		    } else {			out_cs = target_cs;		    }		    if (out_cs >= 0)			out_csname = LYCharSet_UC[out_cs].MIMEname;		    if (Boundary) {			if (!success && form_ptr->value_cs < 0) {			    /*  This is weird. */			    StrAllocCopy(MultipartContentType,					 "\r\nContent-Type: text/plain; charset=");			    StrAllocCat(MultipartContentType, "UNKNOWN-8BIT");			} else if (!success) {			    StrAllocCopy(MultipartContentType,					 "\r\nContent-Type: text/plain; charset=");			    StrAllocCat(MultipartContentType, out_csname);			    target_csname = NULL;			} else {			    if (!target_csname) {				target_csname = LYCharSet_UC[target_cs].MIMEname;			    }			    StrAllocCopy(MultipartContentType,					 "\r\nContent-Type: text/plain; charset=");			    StrAllocCat(MultipartContentType, out_csname);			}		    }		    /*		     *  Charset-translate name now, because we need		     *  to know the charset parameter for multipart		     *  bodyparts. - kw		     */		    if (form_ptr->type == F_TEXTAREA_TYPE) {			textarea_lineno++;			if (textarea_lineno > 1 &&			    last_textarea_name && form_ptr->name &&			    !strcmp(last_textarea_name, form_ptr->name)) {			    break;			}		    }		    name_used = (form_ptr->name ?				 form_ptr->name : "");		    name_has_8bit = NO;		    name_has_special = NO;		    for (p = name_used;			 p && *p && !(name_has_8bit && name_has_special);			 p++) {			if ((*p == HT_NON_BREAK_SPACE) ||			    (*p == HT_EN_SPACE) ||			    (*p == LY_SOFT_HYPHEN)) {			    name_has_special = YES;			} else if ((*p & 0x80) != 0) {			    name_has_8bit = YES;			}		    }		    if (name_has_8bit || name_has_special) {			/*  We should translate back. */			StrAllocCopy(copied_name_used, name_used);			success = LYUCTranslateBackFormData(&copied_name_used,							form_ptr->name_cs,							target_cs, PlainText);			CTRACE(tfp, "SubmitForm: name \"%s\" %d %s -> %d %s %s\n",				    form_ptr->name ? form_ptr->name : "",				    form_ptr->name_cs,				    form_ptr->name_cs >= 0 ?				    LYCharSet_UC[form_ptr->name_cs].MIMEname :									  "???",				    target_cs,				    target_csname ? target_csname : "???",				    success ? "OK" : "FAILED");			if (success) {			    name_used = copied_name_used;			}			if (Boundary) {			    if (!success) {				StrAllocCopy(MultipartContentType, "");				target_csname = NULL;			    } else {				if (!target_csname)				    target_csname = LYCharSet_UC[target_cs].MIMEname;			    }			}		    } else {  /* We can use the name directly. */			CTRACE(tfp, "SubmitForm: name \"%s\" %d %s OK\n",				    form_ptr->name ? form_ptr->name : "",				    target_cs,				    target_csname ? target_csname : "???");			success = YES;			if (Boundary) {			    StrAllocCopy(copied_name_used, name_used);			}		    }		    if (!success) {			if (!had_chartrans_warning) {			    had_chartrans_warning = YES;			    _user_message(				CANNOT_TRANSCODE_FORM,				target_csname ? target_csname : "UNKNOWN");			    sleep(AlertSecs);			}		    }		    if (Boundary) {			/*			 *  According to RFC 1867, Non-ASCII field names			 *  "should be encoded according to the prescriptions			 *  of RFC 1522 [...].  I don't think RFC 1522 actually			 *  is meant to apply to parameters like this, and it			 *  is unknown whether any server would make sense of			 *  it, so for now just use some quoting/escaping and			 *  otherwise leave 8-bit values as they are.			 *  Non-ASCII characters in form field names submitted			 *  as multipart/form-data can only occur if the form			 *  provider specifically asked for it anyway. - kw			 */			HTMake822Word(&copied_name_used);			name_used = copied_name_used;		    }		    break;		default:		    CTRACE(tfp, "SubmitForm: What type is %d?\n",				form_ptr->type);		}		switch(form_ptr->type) {		case F_RESET_TYPE:		    break;		case F_SUBMIT_TYPE:		case F_TEXT_SUBMIT_TYPE:		case F_IMAGE_SUBMIT_TYPE:		    /*		     *  If it has a non-zero length name (e.g., because		     *  it's IMAGE_SUBMIT_TYPE to be handled homologously		     *  to an image map, or a SUBMIT_TYPE in a set of		     *  multiple submit buttons, or a single type="text"		     *  that's been converted to a TEXT_SUBMIT_TYPE),		     *  include the name=value pair, or fake name.x=0 and		     *  name.y=0 pairs for IMAGE_SUBMIT_TYPE. - FM		     */		    if ((form_ptr->name && *form_ptr->name != '\0' &&			!strcmp(form_ptr->name, link_name)) &&		       (form_ptr->type == F_TEXT_SUBMIT_TYPE ||			(form_ptr->value && *form_ptr->value != '\0' &&			 !strcmp(form_ptr->value, link_value)))) {			int cdisp_name_startpos = 0;			if (first_one) {			    if (Boundary) {				HTSprintf(&query, "--%s\r\n", Boundary);			    }			    first_one=FALSE;			} else {			    if (PlainText) {				StrAllocCat(query, "\n");			    } else if (SemiColon) {				StrAllocCat(query, ";");			    } else if (Boundary) {				HTSprintf(&query, "\r\n--%s\r\n", Boundary);			    } else {				StrAllocCat(query, "&");			    }			}			if (PlainText) {			    StrAllocCopy(escaped1, name_used);			} else if (Boundary) {			    StrAllocCopy(escaped1,				    "Content-Disposition: form-data; name=");			    cdisp_name_startpos = strlen(escaped1);			    StrAllocCat(escaped1, name_used);			    if (MultipartContentType)				StrAllocCat(escaped1, MultipartContentType);			    StrAllocCat(escaped1, "\r\n\r\n");			} else {			    escaped1 = HTEscapeSP(name_used, URL_XALPHAS);			}			if (PlainText || Boundary) {			    StrAllocCopy(escaped2,					 (val_used ?					  val_used : ""));			} else {			    escaped2 = HTEscapeSP(val_used, URL_XALPHAS);			}			if (form_ptr->type == F_IMAGE_SUBMIT_TYPE) {			    /*			     *  It's a clickable image submit button.			     *  Fake a 0,0 coordinate pair, which			     *  typically returns the image's default. - FM			     */			    if (Boundary) {				escaped1[cdisp_name_startpos] = '\0';				HTSprintf(&query,					"%s.x\r\n\r\n0\r\n--%s\r\n%s.y\r\n\r\n0",					escaped1,					Boundary,					escaped1);			    } else {				HTSprintf(&query,					"%s.x=0%s%s.y=0%s",					escaped1,					(PlainText ?					      "\n" : (SemiColon ?							    ";" : "&")),					escaped1,					((PlainText && *escaped1) ?							     "\n" : ""));			    }			} else {			    /*			     *  It's a standard submit button.			     *  Use the name=value pair. = FM			     */			    HTSprintf(&query,				    "%s%s%s%s%s",				    escaped1,				    (Boundary ?					   "" : "="),				    (PlainText ?					  "\n" : ""),				    escaped2,				    ((PlainText && *escaped2) ?							 "\n" : ""));			}			FREE(escaped1);			FREE(escaped2);		    }		    FREE(copied_name_used);		    FREE(copied_val_used);		    break;		case F_RADIO_TYPE:		case F_CHECKBOX_TYPE:		    /*		     *  Only add if selected.		     */		    if (form_ptr->num_value) {			if (first_one) {			    if (Boundary) {				HTSprintf(&query,					"--%s\r\n", Boundary);			    }			    first_one=FALSE;			} else {			    if (PlainText) {				StrAllocCat(query, "\n");			    } else if (SemiColon) {				StrAllocCat(query, ";");			    } else if (Boundary) {				HTSprintf(&query, "\r\n--%s\r\n", Boundary);			    } else {				StrAllocCat(query, "&");			    }			}			if (PlainText) {			    StrAllocCopy(escaped1, name_used);			} else if (Boundary) {			    StrAllocCopy(escaped1,				     "Content-Disposition: form-data; name=");			    StrAllocCat(escaped1,					name_used);			    if (MultipartContentType)				StrAllocCat(escaped1, MultipartContentType);			    StrAllocCat(escaped1, "\r\n\r\n");			} else {			    escaped1 = HTEscapeSP(name_used, URL_XALPHAS);			}			if (PlainText || Boundary) {			    StrAllocCopy(escaped2,					 (val_used ?					  val_used : ""));			} else {			    escaped2 = HTEscapeSP(val_used, URL_XALPHAS);			}			HTSprintf(&query,				"%s%s%s%s%s",				escaped1,				(Boundary ?				       "" : "="),				(PlainText ?				      "\n" : ""),				escaped2,				((PlainText && *escaped2) ?						     "\n" : ""));			FREE(escaped1);			FREE(escaped2);		    }		    FREE(copied_name_used);		    FREE(copied_val_used);		    break;		case F_TEXTAREA_TYPE:		    if (PlainText || Boundary) {			StrAllocCopy(escaped2,				     (val_used ?				      val_used : ""));		    } else {			escaped2 = HTEscapeSP(val_used, URL_XALPHAS);		    }		    if (!last_textarea_name ||			strcmp(last_textarea_name, form_ptr->name)) {			textarea_lineno = 1;			/*			 *  Names are different so this is the first			 *  textarea or a different one from any before			 *  it.			 */			if (Boundary) {			    StrAllocCopy(previous_blanks, "\r\n");			} else {			    FREE(previous_blanks);			}			if (first_one) {			    if (Boundary) {				HTSprintf(&query, "--%s\r\n", Boundary);			    }			    first_one=FALSE;			} else {			    if (PlainText) {				StrAllocCat(query, "\n");			    } else if (SemiColon) {				StrAllocCat(query, ";");			    } else if (Boundary) {				HTSprintf(&query, "\r\n--%s\r\n", Boundary);			    } else {				StrAllocCat(query, "&");			    }			}			if (PlainText) {			    StrAllocCopy(escaped1, name_used);			} else if (Boundary) {			    StrAllocCopy(escaped1,				    "Content-Disposition: form-data; name=");			    StrAllocCat(escaped1, name_used);			    if (MultipartContentType)				StrAllocCat(escaped1, MultipartContentType);			    StrAllocCat(escaped1, "\r\n\r\n");			} else {			    escaped1 = HTEscapeSP(name_used, URL_XALPHAS);			}			HTSprintf(&query,				"%s%s%s%s%s",				escaped1,				(Boundary ?				       "" : "="),				(PlainText ?				      "\n" : ""),				escaped2,				((PlainText && *escaped2) ?						     "\n" : ""));			FREE(escaped1);			last_textarea_name = form_ptr->name;		    } else {			/*			 *  This is a continuation of a previous textarea			 *  add %0a (\n) and the escaped string.			 */			if (escaped2[0] != '\0') {			    if (previous_blanks) {				StrAllocCat(query, previous_blanks);				FREE(previous_blanks);			    }			    if (PlainText) {				HTSprintf(&query, "%s\n", escaped2);			    } else if (Boundary) {				HTSprintf(&query, "%s\r\n", escaped2);			    } else {				HTSprintf(&query, "%%0a%s", escaped2);			    }			} else {			    if (PlainText) {				StrAllocCat(previous_blanks, "\n");			    } else if (Boundary) {				StrAllocCat(previous_blanks, "\r\n");			    } else {				StrAllocCat(previous_blanks, "%0a");			    }			}		    }		    FREE(escaped2);		    FREE(copied_val_used);		    break;		case F_PASSWORD_TYPE:		case F_TEXT_TYPE:		case F_OPTION_LIST_TYPE:		case F_HIDDEN_TYPE:		    if (first_one) {			if (Boundary) {			    HTSprintf(&query, "--%s\r\n", Boundary);			}			first_one=FALSE;		    } else {			if (PlainText) {			    StrAllocCat(query, "\n");			} else if (SemiColon) {			    StrAllocCat(query, ";");			} else if (Boundary) {			    HTSprintf(&query, "\r\n--%s\r\n", Boundary);			} else {			    StrAllocCat(query, "&");			}		    }		    if (PlainText) {		       StrAllocCopy(escaped1, name_used);		    } else if (Boundary) {			StrAllocCopy(escaped1,				    "Content-Disposition: form-data; name=");			StrAllocCat(escaped1, name_used);			if (MultipartContentType)			    StrAllocCat(escaped1, MultipartContentType);			StrAllocCat(escaped1, "\r\n\r\n");		    } else {			escaped1 = HTEscapeSP(name_used, URL_XALPHAS);		    }		    if (PlainText || Boundary) {			StrAllocCopy(escaped2,				     (val_used ?				      val_used : ""));		    } else {			escaped2 = HTEscapeSP(val_used, URL_XALPHAS);		    }		    HTSprintf(&query,			    "%s%s%s%s%s",			    escaped1,			    (Boundary ?				   "" : "="),			    (PlainText ?				  "\n" : ""),			    escaped2,			    ((PlainText && *escaped2) ?						 "\n" : ""));		    FREE(escaped1);		    FREE(escaped2);		    FREE(copied_name_used);		    FREE(copied_val_used);		    break;		}	    } else if (anchor_ptr->input_field->number > form_number) {		break;	    }	}	if (anchor_ptr == HTMainText->last_anchor)	    break;	anchor_ptr = anchor_ptr->next;    }    FREE(copied_name_used);    if (Boundary) {	FREE(MultipartContentType);	HTSprintf(&query, "\r\n--%s--\r\n", Boundary);    } else if (!query) {	StrAllocCopy(query, "");    }    FREE(previous_blanks);    if (submit_item->submit_method == URL_MAIL_METHOD) {	HTUserMsg2(gettext("Submitting %s"), submit_item->submit_action);	CTRACE(tfp, "\nGridText - mailto_address: %s\n",			    (submit_item->submit_action+7));	CTRACE(tfp, "GridText - mailto_subject: %s\n",			    ((submit_item->submit_title &&			      *submit_item->submit_title) ?			      (submit_item->submit_title) :					(HText_getTitle() ?					 HText_getTitle() : "")));	CTRACE(tfp,"GridText - mailto_content: %s\n",query);	mailform((submit_item->submit_action+7),		 ((submit_item->submit_title &&		   *submit_item->submit_title) ?		   (submit_item->submit_title) :			     (HText_getTitle() ?			      HText_getTitle() : "")),		 query,		 doc->post_content_type);	FREE(query);	FREE(doc->post_content_type);	return;    } else {	_statusline(SUBMITTING_FORM);    }    if (submit_item->submit_method == URL_POST_METHOD || Boundary) {	StrAllocCopy(doc->post_data, query);	CTRACE(tfp,"GridText - post_data: %s\n",doc->post_data);	StrAllocCopy(doc->address, submit_item->submit_action);	FREE(query);	return;    } else { /* GET_METHOD */	StrAllocCopy(doc->address, query);	FREE(doc->post_data);	FREE(doc->post_content_type);	FREE(query);	return;    }}