tBase64 compatible to Mozilla Thunderbird. - rohrpost - A commandline mail client to change the world as we see it.
 (HTM) git clone git://r-36.net/rohrpost
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit 9e407ff5f1deb97e2e7a0e5531d08b50544638a3
 (DIR) parent c4140c56b7d1d9a29bda32e018e57b2782caa1eb
 (HTM) Author: Christoph Lohmann <20h@r-36.net>
       Date:   Sun,  2 Apr 2017 17:07:44 +0200
       
       Base64 compatible to Mozilla Thunderbird.
       
       Diffstat:
         base64.c                            |      25 ++++++++++++++++++++++++-
       
       1 file changed, 24 insertions(+), 1 deletion(-)
       ---
 (DIR) diff --git a/base64.c b/base64.c
       t@@ -71,7 +71,7 @@ char *
        b64dec(char *istr, int *len)
        {
                char *ret, str[5];
       -        int p, po;
       +        int p, po, l, uglyline;
                char bd[256];
        
                memset(bd, 0x80, 256);
       t@@ -84,6 +84,29 @@ b64dec(char *istr, int *len)
                po = 0;
                ret = NULL;
        
       +        /*
       +         * If there is something prepended to the base64 block, take it as-is.
       +         */
       +        for (uglyline = 1; uglyline == 1; l = p) {
       +                uglyline = 0;
       +                for (; istr[l] != '\n' && istr[l]; l++) {
       +                        if (istr[l] == ' ')
       +                                uglyline = 1;
       +                }
       +                /* Take care of empty lines. */
       +                if ((l - p) == 1 && istr[l-1] == '\r')
       +                        uglyline = 1;
       +                if ((l - p) == 0)
       +                        uglyline = 1;
       +                if (uglyline)
       +                        po = p = l + 1;
       +        }
       +        if (p > 0) {
       +                ret = reallocz(ret, l, 0);
       +                memmove(ret, istr, p+1);
       +        }
       +
       +
                for (; !readnwstr(str, istr, &p, *len, 4); po += 3) {
                        ret = reallocz(ret, po + 4, 0);