mmime: ensure no empty parts are generated after an include.

Reported by lhynes.
pull/213/head
Leah Neukirchen 3 years ago
parent 65d43e3cea
commit 4ccf2f08c1

@ -423,6 +423,7 @@ gen_build()
size_t linelen = 0; size_t linelen = 0;
int inheader = 1; int inheader = 1;
int intext = 0; int intext = 0;
int emptybody = 1;
int ret = 0; int ret = 0;
char *contenttype = 0; char *contenttype = 0;
char *contenttransferenc = 0; char *contenttransferenc = 0;
@ -430,12 +431,13 @@ gen_build()
while (1) { while (1) {
ssize_t read = getdelim(&line, &linelen, '\n', stdin); ssize_t read = getdelim(&line, &linelen, '\n', stdin);
if (read == -1) { if (read == -1) {
if (!intext && !rflag) if (feof(stdin)) {
if (!emptybody)
break;
line = strdup(inheader ? "\n" : ""); line = strdup(inheader ? "\n" : "");
else if (feof(stdin)) } else { // errored
break;
else
exit(1); exit(1);
}
} }
if (inheader) { if (inheader) {
if (line[0] == '\n') { if (line[0] == '\n') {
@ -476,6 +478,7 @@ gen_build()
if (gen_file(f+1, line+1) != 0) if (gen_file(f+1, line+1) != 0)
ret = 1; ret = 1;
intext = 0; intext = 0;
emptybody = 0;
continue; continue;
} }
*f = of; *f = of;
@ -496,6 +499,8 @@ gen_build()
printf("%s", line); printf("%s", line);
else else
gen_qp((uint8_t *)line, strlen(line), 78, 0); gen_qp((uint8_t *)line, strlen(line), 78, 0);
emptybody = 0;
} }
if (!rflag && !inheader) if (!rflag && !inheader)
printf("\n--%s--\n", sep); printf("\n--%s--\n", sep);

@ -1,7 +1,8 @@
#!/bin/sh -e #!/bin/sh -e
cd ${0%/*} cd ${0%/*}
. ./lib.sh . ./lib.sh
plan 16
plan 17
cat <<EOF >tmp cat <<EOF >tmp
References: <aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@a> <bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb@b> <ccccccccccccccccccccccccccccccc@c> References: <aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@a> <bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb@b> <ccccccccccccccccccccccccccccccc@c>
@ -115,3 +116,11 @@ Body.
EOF EOF
check 'non-encoded quoted-strings are kept correctly' 'mmime <tmp2 | grep \"@' check 'non-encoded quoted-strings are kept correctly' 'mmime <tmp2 | grep \"@'
cat <<EOF >tmp2
Subject: inclusion without further content
#message/rfc822#inline $PWD/tmp
EOF
check 'no empty parts are generated after inclusion lines' '! mmime <tmp2 | mshow -t - | grep -q size=0'

Loading…
Cancel
Save