decoding body correctly
authorVolker Birk <vb@pep-project.org>
Fri, 27 Mar 2015 13:36:57 +0100
changeset 142025a3d115c2b
parent 141 f85607f16daa
child 146 573aa91edca2
child 147 b03a10242e4c
decoding body correctly
Makefile.conf
src/mime.c
test/Makefile
     1.1 --- a/Makefile.conf	Thu Mar 26 16:58:16 2015 +0100
     1.2 +++ b/Makefile.conf	Fri Mar 27 13:36:57 2015 +0100
     1.3 @@ -1,6 +1,6 @@
     1.4  BUILD_ON=$(shell uname)
     1.5  BUILD_FOR=$(BUILD_ON)
     1.6 -OPTIMIZE=-g -O0
     1.7 +OPTIMIZE=-g -O0 -std=c99
     1.8  #OPTIMIZE=-O3 -DNDEBUG -std=c99
     1.9  LD=$(CC)
    1.10  #CC=gcc-mp-4.9 -std=c99 -fstrict-aliasing -Wstrict-aliasing=3
     2.1 --- a/src/mime.c	Thu Mar 26 16:58:16 2015 +0100
     2.2 +++ b/src/mime.c	Fri Mar 27 13:36:57 2015 +0100
     2.3 @@ -1228,39 +1228,79 @@
     2.4                                          0) {
     2.5                                      const char *text;
     2.6                                      size_t length;
     2.7 +                                    size_t s;
     2.8 +                                    int code;
     2.9  
    2.10                                      if (part->mm_body == NULL)
    2.11                                          return PEP_ILLEGAL_VALUE;
    2.12  
    2.13                                      text = part->mm_body->
    2.14                                              dt_data.dt_text.dt_data;
    2.15 +                                    if (text == NULL)
    2.16 +                                        return PEP_ILLEGAL_VALUE;
    2.17 +
    2.18                                      length =
    2.19                                          part->mm_body->dt_data.dt_text.dt_length;
    2.20 -                                    index = 0;
    2.21 -                                    r = mailmime_encoded_phrase_parse(
    2.22 -                                            "utf-8", text, length, &index,
    2.23 -                                            "utf-8", &msg->longmsg);
    2.24 -                                    if (r)
    2.25 -                                        return PEP_ILLEGAL_VALUE;
    2.26 +
    2.27 +                                    if (part->mm_body->dt_encoded) {
    2.28 +                                        code = part->mm_body->dt_encoding;
    2.29 +                                        index = 0;
    2.30 +                                        r = mailmime_part_parse(text, length,
    2.31 +                                                &index, code, &msg->longmsg,
    2.32 +                                                &s);
    2.33 +                                        switch (r) {
    2.34 +                                            case MAILIMF_NO_ERROR:
    2.35 +                                                break;
    2.36 +                                            case MAILIMF_ERROR_MEMORY:
    2.37 +                                                return PEP_OUT_OF_MEMORY;
    2.38 +                                            default:
    2.39 +                                                return PEP_ILLEGAL_VALUE;
    2.40 +                                        }
    2.41 +                                    }
    2.42 +                                    else {
    2.43 +                                        msg->longmsg = strdup(text);
    2.44 +                                        if (msg->longmsg == NULL)
    2.45 +                                            return PEP_OUT_OF_MEMORY;
    2.46 +                                    }
    2.47                                  }
    2.48                                  else if (strcmp(content->ct_subtype, "html") ==
    2.49                                          0) {
    2.50                                      const char *html;
    2.51                                      size_t length;
    2.52 +                                    size_t s;
    2.53 +                                    int code;
    2.54  
    2.55                                      if (part->mm_body == NULL)
    2.56                                          return PEP_ILLEGAL_VALUE;
    2.57  
    2.58                                      html = part->mm_body->
    2.59                                              dt_data.dt_text.dt_data;
    2.60 +                                    if (html == NULL)
    2.61 +                                        return PEP_ILLEGAL_VALUE;
    2.62 +
    2.63                                      length =
    2.64                                          part->mm_body->dt_data.dt_text.dt_length;
    2.65 -                                    index = 0;
    2.66 -                                    r = mailmime_encoded_phrase_parse(
    2.67 -                                            "utf-8", html, length, &index,
    2.68 -                                            "utf-8", &msg->longmsg_formatted);
    2.69 -                                    if (r)
    2.70 -                                        return PEP_ILLEGAL_VALUE;
    2.71 +
    2.72 +                                    if (part->mm_body->dt_encoded) {
    2.73 +                                        code = part->mm_body->dt_encoding;
    2.74 +                                        index = 0;
    2.75 +                                        r = mailmime_part_parse(html, length,
    2.76 +                                                &index, code,
    2.77 +                                                &msg->longmsg_formatted, &s);
    2.78 +                                        switch (r) {
    2.79 +                                            case MAILIMF_NO_ERROR:
    2.80 +                                                break;
    2.81 +                                            case MAILIMF_ERROR_MEMORY:
    2.82 +                                                return PEP_OUT_OF_MEMORY;
    2.83 +                                            default:
    2.84 +                                                return PEP_ILLEGAL_VALUE;
    2.85 +                                        }
    2.86 +                                    }
    2.87 +                                    else {
    2.88 +                                        msg->longmsg_formatted = strdup(html);
    2.89 +                                        if (msg->longmsg_formatted == NULL)
    2.90 +                                            return PEP_OUT_OF_MEMORY;
    2.91 +                                    }
    2.92                                  }
    2.93                                  else {
    2.94                                      return interpret_MIME(part, msg);
     3.1 --- a/test/Makefile	Thu Mar 26 16:58:16 2015 +0100
     3.2 +++ b/test/Makefile	Fri Mar 27 13:36:57 2015 +0100
     3.3 @@ -27,3 +27,6 @@
     3.4  	for t in ./*_test ; do \
     3.5  		LD_LIBRARY_PATH=~/lib:../src $$t ; \
     3.6  	done
     3.7 +
     3.8 +install:
     3.9 +	make -C .. install