comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:7e0d08176f32
1 /*
2 * This module implements transformations that are specific to text/plain.
3 */
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <strings.h>
9 #include "defs.h"
10
11 extern FILE *tempfile;
12 extern int ptext_has_backslash, ptext_has_linesplit;
13 extern unsigned mp_nest_level;
14 extern char mp_boundaries[MAX_MP_NESTING][MAX_MP_BOUNDARY+1];
15
16 void
17 ptext_mark_transform(base_xform)
18 char *base_xform;
19 {
20 printf("X-Fdemime-Transform: %s", base_xform);
21 if (ptext_has_backslash)
22 fputs(", double-backslash", stdout);
23 if (ptext_has_linesplit)
24 fputs(", line-split", stdout);
25 putchar('\n');
26 }
27
28 static int
29 boundary_hit(line)
30 char *line;
31 {
32 unsigned lev, bndlen;
33 char *bnd;
34
35 if (line[0] != '-' || line[1] != '-')
36 return(0);
37 for (lev = 0; lev < mp_nest_level; lev++) {
38 bnd = mp_boundaries[lev];
39 bndlen = strlen(bnd);
40 if (strncmp(line+2, bnd, bndlen))
41 continue;
42 return(1);
43 }
44 return(0);
45 }
46
47 void
48 ptext_emit_output()
49 {
50 char line[LINE_BUF_SIZE];
51
52 rewind(tempfile);
53 while (fgets(line, sizeof line, tempfile)) {
54 if (!strncmp(line, "From ", 5) || boundary_hit(line) ||
55 !strcmp(line, ".\n")) {
56 putchar('\\');
57 putchar('&');
58 }
59 fputs(line, stdout);
60 }
61 fclose(tempfile);
62 }