annotate f-demime/finish.c @ 8:a92d0d59b669 default tip

f-demime: indicate X-backslash-escapes encoding in output
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 06 May 2023 17:00:23 +0000
parents 612c4d0df768
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements the handling at the end of entity body input.
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <stdio.h>
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdlib.h>
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <string.h>
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <strings.h>
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include "defs.h"
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 extern enum msg_state msg_state;
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 extern char cont_type_buf[HDR_BUF_SIZE], cont_te_buf[HDR_BUF_SIZE];
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 extern int got_cont_type, got_cont_te;
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 extern int b64_err_flag, b64_nonempty, qpdec_err_flag;
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 static void
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 check_b64_err()
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 {
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 if (b64_err_flag)
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 puts("X-Fdemime-Error: bad base64 data");
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 }
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 static void
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 check_qpdec_err()
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 {
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (qpdec_err_flag)
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 puts("X-Fdemime-Error: bad quoted-printable data");
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 }
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 void
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 finish_msg_body()
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 {
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 switch (msg_state) {
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 case MSG_STATE_HEADER:
4
612c4d0df768 f-demime: rework for unboundedly long lines
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
35 if (got_cont_type) {
0
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 fputs(cont_type_buf, stdout);
4
612c4d0df768 f-demime: rework for unboundedly long lines
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
37 if (cont_type_buf[strlen(cont_type_buf)-1] != '\n')
612c4d0df768 f-demime: rework for unboundedly long lines
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
38 putchar('\n');
612c4d0df768 f-demime: rework for unboundedly long lines
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
39 }
612c4d0df768 f-demime: rework for unboundedly long lines
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
40 if (got_cont_te) {
0
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 fputs(cont_te_buf, stdout);
4
612c4d0df768 f-demime: rework for unboundedly long lines
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
42 if (cont_te_buf[strlen(cont_te_buf)-1] != '\n')
612c4d0df768 f-demime: rework for unboundedly long lines
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
43 putchar('\n');
612c4d0df768 f-demime: rework for unboundedly long lines
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
44 }
0
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 return;
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 case MSG_STATE_PTEXT_B64:
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 base64_dec_finish();
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 check_b64_err();
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 ptext_conv_finish();
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 ptext_mark_transform("decode-base64");
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 putchar('\n');
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 ptext_emit_output();
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 return;
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 case MSG_STATE_PTEXT_QP:
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 check_qpdec_err();
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 ptext_conv_finish();
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 ptext_mark_transform("decode-qp");
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 putchar('\n');
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 ptext_emit_output();
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return;
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 case MSG_STATE_BLOB_B64:
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 base64_dec_finish();
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 check_b64_err();
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 putchar('\n');
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 attach_out_finish();
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 if (b64_nonempty)
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 puts("[base64 blob stripped]");
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 putchar('\n');
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 return;
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 case MSG_STATE_B64_TO_QP:
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 base64_dec_finish();
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 check_b64_err();
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 b2q_conv_finish();
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 puts("X-Fdemime-Transform: base64-to-qp");
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 puts("Content-Transfer-Encoding: quoted-printable");
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 putchar('\n');
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 b2q_emit_output();
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 return;
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 }
7e0d08176f32 f-demime starting code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 }