diff f-demime/msgstate.c @ 4:612c4d0df768

f-demime: rework for unboundedly long lines
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 06 May 2023 09:02:12 +0000
parents 7e0d08176f32
children
line wrap: on
line diff
--- a/f-demime/msgstate.c	Sat May 06 06:41:20 2023 +0000
+++ b/f-demime/msgstate.c	Sat May 06 09:02:12 2023 +0000
@@ -47,7 +47,7 @@
 }
 
 static int
-check_mp_terminator(line)
+check_mp_terminator(line, unterm)
 	char *line;
 {
 	unsigned lev, bndlen;
@@ -61,15 +61,19 @@
 		if (strncmp(line+2, bnd, bndlen))
 			continue;
 		finish_msg_body();
-		puts(line);
+		fputs(line, stdout);
 		cp = line + 2 + bndlen;
 		if (!*cp || isspace(*cp)) {
 			mp_nest_level = lev + 1;
 			start_entity_hdr();
+			if (unterm)
+				msg_state = MSG_STATE_DELIM_UNTERM;
 			return(1);
 		}
-		if (cp[0] != '-' || cp[1] != '-')
-			puts("X-Fdemime-Error: invalid delimiter line");
+		if (cp[0] != '-' || cp[1] != '-') {
+			if (!unterm)
+				puts("X-Fdemime-Error: invalid delimiter line");
+		}
 		mp_nest_level = lev;
 		msg_state = MSG_STATE_BODY_PASS;
 		return(1);
@@ -78,21 +82,26 @@
 }
 
 void
-message_input_line(line)
+message_input_line(line, unterm, prev_unterm)
 	char *line;
 {
-	if (check_mp_terminator(line))
+	if (!prev_unterm && check_mp_terminator(line, unterm))
 		return;
 	switch (msg_state) {
 	case MSG_STATE_UNDEF:
 		emit_prefrom_warning();
-		puts(line);
+		fputs(line, stdout);
+		return;
+	case MSG_STATE_DELIM_UNTERM:
+		fputs(line, stdout);
+		if (!unterm)
+			msg_state = MSG_STATE_HEADER;
 		return;
 	case MSG_STATE_HEADER:
-		header_input_line(line);
+		header_input_line(line, unterm, prev_unterm);
 		return;
 	case MSG_STATE_BODY_PASS:
-		puts(line);
+		fputs(line, stdout);
 		return;
 	case MSG_STATE_PTEXT_B64:
 	case MSG_STATE_BLOB_B64:
@@ -100,7 +109,7 @@
 		base64_input_line(line);
 		return;
 	case MSG_STATE_PTEXT_QP:
-		qpdec_input_line(line);
+		qpdec_input_line(line, unterm);
 		return;
 	default:
 		fprintf(stderr,