]> diplodocus.org Git - nmh/commitdiff
More fixes (and tests) for the base64 encoder.
authorKen Hornstein <kenh@pobox.com>
Tue, 4 Feb 2014 17:38:34 +0000 (12:38 -0500)
committerKen Hornstein <kenh@pobox.com>
Tue, 4 Feb 2014 17:38:34 +0000 (12:38 -0500)
sbr/base64.c
test/mhbuild/test-cte

index 7ceb27b95759651d6bd36732d60904bb3150674d..2fbef4b002496960d38c697c93e248a13abb221b 100644 (file)
@@ -48,7 +48,15 @@ writeBase64aux (FILE *in, FILE *out, int crlf)
                     * everything down and push the last character back.
                     */
                    if (i == cc - 1) {
                     * everything down and push the last character back.
                     */
                    if (i == cc - 1) {
-                       ungetc('\n', in);
+                       /*
+                        * If we're at the end of the input, there might be
+                        * more room in inbuf; if so, add it there.  Otherwise
+                        * push it back to the input.
+                        */
+                       if (cc < sizeof(inbuf))
+                           inbuf[cc++] = '\n';
+                       else
+                           ungetc('\n', in);
                        skipnl = 1;
                    } else {
                        /* This only works as long as sizeof(inbuf) == 3 */
                        skipnl = 1;
                    } else {
                        /* This only works as long as sizeof(inbuf) == 3 */
index 128526a10588a3ed427f7788335bdffdf993477d..517fbc51b74a10eba61b9afb17d032ce5be2f1da 100755 (executable)
@@ -46,7 +46,8 @@ This is a test of a message with a sh=C3=B8rt line.
 EOF
 
 #
 EOF
 
 #
-# Force some text to be base64
+# Force some text to be base64, to test out the encoder.  Try at different
+# line lengths to check out the padding on the 
 #
 
 cat > "$draft" <<EOF
 #
 
 cat > "$draft" <<EOF
@@ -73,4 +74,28 @@ EOF
 
 check "$draft" "$expected"
 
 
 check "$draft" "$expected"
 
+cat > "$draft" <<EOF
+To: Mr Test <mrtest@example.com>
+cc:
+Fcc: +outbox
+------
+#<text/plain *b64
+This is a test of a mëssage with a shørt line.
+EOF
+
+run_prog mhbuild "$draft"
+
+cat > "$expected" <<EOF
+To: Mr Test <mrtest@example.com>
+cc:
+Fcc: +outbox
+MIME-Version: 1.0
+Content-Type: text/plain; charset="UTF-8"
+Content-Transfer-Encoding: base64
+
+VGhpcyBpcyBhIHRlc3Qgb2YgYSBtw6tzc2FnZSB3aXRoIGEgc2jDuHJ0IGxpbmUuDQo=
+EOF
+
+check "$draft" "$expected"
+
 exit ${failed:-0}
 exit ${failed:-0}