FreeCalypso > hg > falcon-mail-tools
comparison 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 |
comparison
equal
deleted
inserted
replaced
3:7a6cd16689f5 | 4:612c4d0df768 |
---|---|
45 "f-demime warning: data present before the first From\n"); | 45 "f-demime warning: data present before the first From\n"); |
46 done = 1; | 46 done = 1; |
47 } | 47 } |
48 | 48 |
49 static int | 49 static int |
50 check_mp_terminator(line) | 50 check_mp_terminator(line, unterm) |
51 char *line; | 51 char *line; |
52 { | 52 { |
53 unsigned lev, bndlen; | 53 unsigned lev, bndlen; |
54 char *bnd, *cp; | 54 char *bnd, *cp; |
55 | 55 |
59 bnd = mp_boundaries[lev]; | 59 bnd = mp_boundaries[lev]; |
60 bndlen = strlen(bnd); | 60 bndlen = strlen(bnd); |
61 if (strncmp(line+2, bnd, bndlen)) | 61 if (strncmp(line+2, bnd, bndlen)) |
62 continue; | 62 continue; |
63 finish_msg_body(); | 63 finish_msg_body(); |
64 puts(line); | 64 fputs(line, stdout); |
65 cp = line + 2 + bndlen; | 65 cp = line + 2 + bndlen; |
66 if (!*cp || isspace(*cp)) { | 66 if (!*cp || isspace(*cp)) { |
67 mp_nest_level = lev + 1; | 67 mp_nest_level = lev + 1; |
68 start_entity_hdr(); | 68 start_entity_hdr(); |
69 if (unterm) | |
70 msg_state = MSG_STATE_DELIM_UNTERM; | |
69 return(1); | 71 return(1); |
70 } | 72 } |
71 if (cp[0] != '-' || cp[1] != '-') | 73 if (cp[0] != '-' || cp[1] != '-') { |
72 puts("X-Fdemime-Error: invalid delimiter line"); | 74 if (!unterm) |
75 puts("X-Fdemime-Error: invalid delimiter line"); | |
76 } | |
73 mp_nest_level = lev; | 77 mp_nest_level = lev; |
74 msg_state = MSG_STATE_BODY_PASS; | 78 msg_state = MSG_STATE_BODY_PASS; |
75 return(1); | 79 return(1); |
76 } | 80 } |
77 return(0); | 81 return(0); |
78 } | 82 } |
79 | 83 |
80 void | 84 void |
81 message_input_line(line) | 85 message_input_line(line, unterm, prev_unterm) |
82 char *line; | 86 char *line; |
83 { | 87 { |
84 if (check_mp_terminator(line)) | 88 if (!prev_unterm && check_mp_terminator(line, unterm)) |
85 return; | 89 return; |
86 switch (msg_state) { | 90 switch (msg_state) { |
87 case MSG_STATE_UNDEF: | 91 case MSG_STATE_UNDEF: |
88 emit_prefrom_warning(); | 92 emit_prefrom_warning(); |
89 puts(line); | 93 fputs(line, stdout); |
94 return; | |
95 case MSG_STATE_DELIM_UNTERM: | |
96 fputs(line, stdout); | |
97 if (!unterm) | |
98 msg_state = MSG_STATE_HEADER; | |
90 return; | 99 return; |
91 case MSG_STATE_HEADER: | 100 case MSG_STATE_HEADER: |
92 header_input_line(line); | 101 header_input_line(line, unterm, prev_unterm); |
93 return; | 102 return; |
94 case MSG_STATE_BODY_PASS: | 103 case MSG_STATE_BODY_PASS: |
95 puts(line); | 104 fputs(line, stdout); |
96 return; | 105 return; |
97 case MSG_STATE_PTEXT_B64: | 106 case MSG_STATE_PTEXT_B64: |
98 case MSG_STATE_BLOB_B64: | 107 case MSG_STATE_BLOB_B64: |
99 case MSG_STATE_B64_TO_QP: | 108 case MSG_STATE_B64_TO_QP: |
100 base64_input_line(line); | 109 base64_input_line(line); |
101 return; | 110 return; |
102 case MSG_STATE_PTEXT_QP: | 111 case MSG_STATE_PTEXT_QP: |
103 qpdec_input_line(line); | 112 qpdec_input_line(line, unterm); |
104 return; | 113 return; |
105 default: | 114 default: |
106 fprintf(stderr, | 115 fprintf(stderr, |
107 "f-demime internal error: bad state in message_input_line()\n"); | 116 "f-demime internal error: bad state in message_input_line()\n"); |
108 abort(); | 117 abort(); |