diff f-demime/ptext_out.c @ 0:7e0d08176f32

f-demime starting code
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 06 May 2023 06:14:03 +0000
parents
children a92d0d59b669
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/f-demime/ptext_out.c	Sat May 06 06:14:03 2023 +0000
@@ -0,0 +1,62 @@
+/*
+ * This module implements transformations that are specific to text/plain.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "defs.h"
+
+extern FILE *tempfile;
+extern int ptext_has_backslash, ptext_has_linesplit;
+extern unsigned mp_nest_level;
+extern char mp_boundaries[MAX_MP_NESTING][MAX_MP_BOUNDARY+1];
+
+void
+ptext_mark_transform(base_xform)
+	char *base_xform;
+{
+	printf("X-Fdemime-Transform: %s", base_xform);
+	if (ptext_has_backslash)
+		fputs(", double-backslash", stdout);
+	if (ptext_has_linesplit)
+		fputs(", line-split", stdout);
+	putchar('\n');
+}
+
+static int
+boundary_hit(line)
+	char *line;
+{
+	unsigned lev, bndlen;
+	char *bnd;
+
+	if (line[0] != '-' || line[1] != '-')
+		return(0);
+	for (lev = 0; lev < mp_nest_level; lev++) {
+		bnd = mp_boundaries[lev];
+		bndlen = strlen(bnd);
+		if (strncmp(line+2, bnd, bndlen))
+			continue;
+		return(1);
+	}
+	return(0);
+}
+
+void
+ptext_emit_output()
+{
+	char line[LINE_BUF_SIZE];
+
+	rewind(tempfile);
+	while (fgets(line, sizeof line, tempfile)) {
+		if (!strncmp(line, "From ", 5) || boundary_hit(line) ||
+		    !strcmp(line, ".\n")) {
+			putchar('\\');
+			putchar('&');
+		}
+		fputs(line, stdout);
+	}
+	fclose(tempfile);
+}