diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2019-03-27 13:00:43 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2019-03-27 13:00:43 +0200 |
commit | dc0e689310121619eff2c28432997d85069d2565 (patch) | |
tree | 9ad25af0c3797c553470f1200d144afdc003e04a | |
parent | 9f7eb0a63d0c8e406636c9ad9f0d12aeb5ca077c (diff) | |
download | mailutils-dc0e689310121619eff2c28432997d85069d2565.tar.gz mailutils-dc0e689310121619eff2c28432997d85069d2565.tar.bz2 |
Minor fixes in dot filters.
The DOT decoder accepts input consisting of two characters ".\n"
and decodes it to empty output. When encoding empty input, ".\n"
is produced
Similarly, CRLFDOT handles ".\r\n" the same way.
* libmailutils/filter/crlfdot.c (_crlfdot_encoder): Accept ".\r\n"
as input.
* libmailutils/filter/dot.c: Accept ".\n" as input.
* libmailutils/tests/crlfdot.at: Add new test.
* libmailutils/tests/dot.at: Likewise.
-rw-r--r-- | libmailutils/filter/crlfdot.c | 1 | ||||
-rw-r--r-- | libmailutils/filter/dot.c | 33 | ||||
-rw-r--r-- | libmailutils/tests/crlfdot.at | 7 | ||||
-rw-r--r-- | libmailutils/tests/dot.at | 13 |
4 files changed, 32 insertions, 22 deletions
diff --git a/libmailutils/filter/crlfdot.c b/libmailutils/filter/crlfdot.c index 757437d96..3cc963039 100644 --- a/libmailutils/filter/crlfdot.c +++ b/libmailutils/filter/crlfdot.c @@ -304,6 +304,7 @@ _crlfdot_encoder (void *xd, { switch (state->at) { + case crlfdot_encode_init: case crlfdot_encode_lf: if (j + 3 > osize) result = mu_filter_again; diff --git a/libmailutils/filter/dot.c b/libmailutils/filter/dot.c index d3a3aab34..609d2e8d9 100644 --- a/libmailutils/filter/dot.c +++ b/libmailutils/filter/dot.c @@ -41,9 +41,8 @@ enum dot_decode_state { - dot_decode_init, /* initial state */ - dot_decode_char, /* Any character excepting [\r\n.] */ - dot_decode_lf, /* prev. char was \n */ + dot_decode_bol, /* beginning of line */ + dot_decode_char, /* Any character excepting [\n.] */ dot_decode_dot, /* 2 prev. chars were \n. */ dot_decode_end /* final state, a \n.\n seen. */ }; @@ -53,29 +52,21 @@ new_decode_state (enum dot_decode_state state, int c) { switch (state) { - case dot_decode_init: + case dot_decode_bol: switch (c) { case '.': return dot_decode_dot; - } - break; - - case dot_decode_char: - switch (c) - { case '\n': - return dot_decode_lf; + return dot_decode_bol; } break; - case dot_decode_lf: + case dot_decode_char: switch (c) { - case '.': - return dot_decode_dot; case '\n': - return dot_decode_lf; + return dot_decode_bol; } break; @@ -93,8 +84,7 @@ new_decode_state (enum dot_decode_state state, int c) return dot_decode_char; } -/* Move min(isize,osize) bytes from iptr to optr, replacing each \r\n - with \n. */ +/* Move min(isize,osize) bytes from iptr to optr, unstuffing '..' sequences */ static enum mu_filter_result _dot_decoder (void *xd, enum mu_filter_command cmd, @@ -110,7 +100,7 @@ _dot_decoder (void *xd, switch (cmd) { case mu_filter_init: - *pstate = dot_decode_init; + *pstate = dot_decode_bol; return mu_filter_ok; case mu_filter_done: @@ -131,8 +121,7 @@ _dot_decoder (void *xd, int curstate = *pstate; *pstate = new_decode_state (curstate, c); - if (c == '.' - && (curstate == dot_decode_init || curstate == dot_decode_lf)) + if (c == '.' && curstate == dot_decode_bol) continue; if (*pstate == dot_decode_end) { @@ -165,8 +154,8 @@ new_encode_state (int c) return dot_encode_char; } -/* Move min(isize,osize) bytes from iptr to optr, replacing each \n - with \r\n. Any input \r\n sequences remain untouched. */ +/* Move min(isize,osize) bytes from iptr to optr, byte-stuffing each + '.' appearing at the beginning of a line */ static enum mu_filter_result _dot_encoder (void *xd, enum mu_filter_command cmd, diff --git a/libmailutils/tests/crlfdot.at b/libmailutils/tests/crlfdot.at index 3c7cf8802..8d12955c3 100644 --- a/libmailutils/tests/crlfdot.at +++ b/libmailutils/tests/crlfdot.at @@ -100,3 +100,10 @@ four . EOT ]) + +MU_FILTER_TEST([decode single line],[crlfdot],[decode],[],[-gen], +[], +[tocrlf <<EOT +. +EOT +]) diff --git a/libmailutils/tests/dot.at b/libmailutils/tests/dot.at index 7be7bb6b2..dd528abb9 100644 --- a/libmailutils/tests/dot.at +++ b/libmailutils/tests/dot.at @@ -56,6 +56,19 @@ AT_CHECK([fltst dot encode read < /dev/null], ]) AT_CLEANUP +AT_SETUP([DOT decode single line input]) +AT_KEYWORDS([DOT one-line]) +AT_CHECK( +[AT_DATA([input],[ +. +]) +fltst dot decode read < input +], +[0], +[ +]) +AT_CLEANUP + AT_SETUP([DOT reversibility]) AT_KEYWORDS([filter dot]) AT_CHECK([ |