Fix improper padding in B encoding
* libmailutils/stream/fltstream.c: stop encoding when no more input is available. * libmailutils/tests/encode2047.at: add new tests. * libmailutils/filter/base64.c (_base64_encoder): detect eof
Showing
3 changed files
with
42 additions
and
12 deletions
... | @@ -232,6 +232,13 @@ _base64_encoder (void *xd, | ... | @@ -232,6 +232,13 @@ _base64_encoder (void *xd, |
232 | default: | 232 | default: |
233 | break; | 233 | break; |
234 | } | 234 | } |
235 | |||
236 | if (iobuf->isize == 0) | ||
237 | { | ||
238 | iobuf->osize = 0; | ||
239 | iobuf->eof = 1; | ||
240 | return mu_filter_ok; | ||
241 | } | ||
235 | 242 | ||
236 | if (iobuf->isize <= 3) | 243 | if (iobuf->isize <= 3) |
237 | { | 244 | { | ... | ... |
... | @@ -149,7 +149,7 @@ filter_read (mu_stream_t stream, char *buf, size_t size, size_t *pret) | ... | @@ -149,7 +149,7 @@ filter_read (mu_stream_t stream, char *buf, size_t size, size_t *pret) |
149 | if (rdsize == 0 && | 149 | if (rdsize == 0 && |
150 | MFB_RDBYTES (fs->outbuf) == 0 && | 150 | MFB_RDBYTES (fs->outbuf) == 0 && |
151 | MFB_RDBYTES (fs->inbuf) == 0) | 151 | MFB_RDBYTES (fs->inbuf) == 0) |
152 | cmd = mu_filter_lastbuf; | 152 | break; |
153 | 153 | ||
154 | MFB_advance_level (&fs->inbuf, rdsize); | 154 | MFB_advance_level (&fs->inbuf, rdsize); |
155 | } | 155 | } | ... | ... |
... | @@ -14,18 +14,41 @@ | ... | @@ -14,18 +14,41 @@ |
14 | # You should have received a copy of the GNU General Public License | 14 | # You should have received a copy of the GNU General Public License |
15 | # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | ||
17 | AT_SETUP([encode2047]) | 17 | dnl ------------------------------------------------------------ |
18 | AT_KEYWORDS([encode]) | 18 | dnl TESTENC2047([NAME], [KW = `'], [OPT], [INPUT], [STDOUT = `']) |
19 | 19 | dnl | |
20 | AT_CHECK([ | 20 | m4_pushdef([TESTENC2047],[ |
21 | AT_DATA(input,[dnl | 21 | m4_pushdef([MU_TEST_GROUP],[Encode 2047]) |
22 | \\345\326\305\304\316\305\327\316\331\312\040\317\324\336\305\324 | 22 | m4_pushdef([MU_TEST_KEYWORDS],[encode2047 encode]) |
23 | m4_pushdef([MU_TEST_COMMAND],[encode2047 -eB $3]) | ||
24 | MU_GENERIC_TEST([$1],[$2],[$4],[],[$5 | ||
23 | ]) | 25 | ]) |
24 | 26 | m4_popdef([MU_TEST_COMMAND]) | |
25 | encode2047 -c koi8-r -eB -o < input], | 27 | m4_popdef([MU_TEST_KEYWORDS]) |
26 | [0], | 28 | m4_popdef([MU_TEST_GROUP]) |
27 | [=?koi8-r?B?5dbFxM7F187ZyiDP1N7F1A==?= | ||
28 | ]) | 29 | ]) |
29 | 30 | ||
30 | AT_CLEANUP | 31 | TESTENC2047([8-bit input],[enc01], |
32 | [-c koi8-r -o], | ||
33 | [\\345\326\305\304\316\305\327\316\331\312\040\317\324\336\305\324], | ||
34 | [=?koi8-r?B?5dbFxM7F187ZyiDP1N7F1A==?=]) | ||
35 | |||
36 | TESTENC2047([padding 1],[enc02], | ||
37 | [], | ||
38 | [abcd], | ||
39 | [=?iso-8859-1?B?YWJjZA==?=]) | ||
40 | |||
41 | TESTENC2047([padding 2],[enc03], | ||
42 | [], | ||
43 | [abcdef], | ||
44 | [=?iso-8859-1?B?YWJjZGVm?=]) | ||
45 | |||
46 | TESTENC2047([padding 3],[enc04], | ||
47 | [-cUTF-8], | ||
48 | [Wichtige Mitteilung zur Schaltung Ihres Anschlusses], | ||
49 | [=?UTF-8?B?V2ljaHRpZ2UgTWl0dGVpbHVuZyB6dXIgU2NoYWx0dW5nIElocmVzIEFuc2NobHVzc2Vz?=]) | ||
50 | |||
51 | |||
52 | m4_popdef([TESTENC2047]) | ||
53 | |||
31 | 54 | ... | ... |
-
Please register or sign in to post a comment