Add heuristics for empty lines in headers. - 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) README
 (DIR) LICENSE
       ---
 (DIR) commit 7511bb4e2babb078723a3372e1902e2cc99225ec
 (DIR) parent e54cce90d3001cf915f9108e7914c9beba0c316e
 (HTM) Author: Christoph Lohmann <20h@r-36.net>
       Date:   Wed,  3 Jul 2024 21:02:17 +0200
       
       Add heuristics for empty lines in headers.
       
       * Fix a warning about unused variables.
       * Add some more optional debugging printf.
       
       Diffstat:
         M mime.c                              |      43 +++++++++++++++++++++++++------
       
       1 file changed, 35 insertions(+), 8 deletions(-)
       ---
 (DIR) diff --git a/mime.c b/mime.c
       @@ -528,8 +528,10 @@ mime_sanitizeparams(llist_t *params)
        {
                llistelem_t *param, *hit, *nparam;
                llist_t *reorder, *hits;
       -        char *key, *nvalue, *dvalue;
       -        int klen, i, n;
       +        char *nvalue, *dvalue;
       +        int i, n;
       +        //char *key;
       +        //int klen;
        
                reorder = llist_new();
                //printf("mime_sanitizeparams: start\n");
       @@ -541,9 +543,9 @@ mime_sanitizeparams(llist_t *params)
                                continue;
                        }
        
       -                key = param->key;
       +                //key = param->key;
                        //printf("key = %s\n", key);
       -                klen = strlen(key);
       +                //klen = strlen(key);
        
                        nvalue = strrchr(param->key, '*');
                        if (nvalue == NULL)
       @@ -894,10 +896,10 @@ mime_parsebufintern(mime_t *mime, char *str, int len)
                rp = str;
                p = str;
                for (; (rp = sgets(buf, sizeof(buf)-1, &p));) {
       -                //printf("line '%s'\n", buf);
                        blen = strlen(buf);
                        if (buf[blen-1] == '\r')
                                buf[blen-1] = '\0';
       +                //printf("line '%s'\n", buf);
        
                        switch (mime->state) {
                        case HEADERVALUE:
       @@ -953,9 +955,34 @@ mime_parsebufintern(mime_t *mime, char *str, int len)
                                 * End of headers.
                                 */
                                if (strlen(buf) == 0) {
       -                                mime->rawhdrs = memdupz(str, (p - str));
       -                                mime->rawhdrslen = p - str;
       -                                goto mimeparsebufbodyparse;
       +                                //printf("end of headers '%c'\n", p[0]);
       +                                /*
       +                                 * Heuristics for ugly e-mail generators
       +                                 * follow.
       +                                 */
       +                                /*
       +                                 * Does the line begin with "--"? Looks
       +                                 * like a boundary. Go to next body part.
       +                                 */
       +                                if (p[0] == '-' && p[1] == '-') {
       +                                        mime->rawhdrs = memdupz(str, (p - str));
       +                                        mime->rawhdrslen = p - str;
       +                                        goto mimeparsebufbodyparse;
       +                                }
       +                                /*
       +                                 * Does the line have some "header:
       +                                 * value\n" form? Go on parsing headers.
       +                                 */
       +                                for (key = p; key[0] != '\n'; key++) {
       +                                        //printf("key[0] = '%c'\n", key[0]);
       +                                        if (key[0] == ':')
       +                                                break;
       +                                        if (key[0] == ' ') {
       +                                                mime->rawhdrs = memdupz(str, (p - str));
       +                                                mime->rawhdrslen = p - str;
       +                                                goto mimeparsebufbodyparse;
       +                                        }
       +                                }
                                }
        
                                /*