src/mime.c
changeset 57 03f99659418e
parent 52 a667998cedf1
child 59 88429085f8da
     1.1 --- a/src/mime.c	Sun Feb 08 15:39:36 2015 -0500
     1.2 +++ b/src/mime.c	Sun Feb 08 15:47:51 2015 -0500
     1.3 @@ -44,28 +44,58 @@
     1.4  
     1.5      mailmime_set_imf_fields(msg_mime, fields);
     1.6  
     1.7 -    mime = part_multiple_new("multipart/mixed", NULL);
     1.8 -    assert(mime);
     1.9 -    if (mime == NULL)
    1.10 -        goto enomem;
    1.11 +    if (htmltext) {
    1.12 +        mime = part_multiple_new("multipart/alternative", NULL);
    1.13 +        assert(mime);
    1.14 +        if (mime == NULL)
    1.15 +            goto enomem;
    1.16  
    1.17 -    submime = get_text_part("text/plain", plaintext, strlen(plaintext),
    1.18 -            MAILMIME_MECHANISM_QUOTED_PRINTABLE);
    1.19 -    assert(submime);
    1.20 -    if (submime == NULL) {
    1.21 -        mailmime_free(msg_mime);
    1.22 -        goto enomem;
    1.23 -    }
    1.24 +        submime = get_text_part("text/plain", plaintext, strlen(plaintext),
    1.25 +                MAILMIME_MECHANISM_QUOTED_PRINTABLE);
    1.26 +        assert(submime);
    1.27 +        if (submime == NULL) {
    1.28 +            mailmime_free(msg_mime);
    1.29 +            goto enomem;
    1.30 +        }
    1.31  
    1.32 -    r = mailmime_smart_add_part(mime, submime);
    1.33 -    assert(r == MAILIMF_NO_ERROR);
    1.34 -    if (r == MAILIMF_ERROR_MEMORY) {
    1.35 -        mailmime_free(msg_mime);
    1.36 -        goto enomem;
    1.37 +        r = mailmime_smart_add_part(mime, submime);
    1.38 +        assert(r == MAILIMF_NO_ERROR);
    1.39 +        if (r == MAILIMF_ERROR_MEMORY) {
    1.40 +            mailmime_free(msg_mime);
    1.41 +            goto enomem;
    1.42 +        }
    1.43 +        else {
    1.44 +            // mailmime_smart_add_part() takes ownership of submime
    1.45 +            submime = NULL;
    1.46 +        }
    1.47 +
    1.48 +        submime = get_text_part("text/html", htmltext, strlen(htmltext),
    1.49 +                MAILMIME_MECHANISM_QUOTED_PRINTABLE);
    1.50 +        assert(submime);
    1.51 +        if (submime == NULL) {
    1.52 +            mailmime_free(msg_mime);
    1.53 +            goto enomem;
    1.54 +        }
    1.55 +
    1.56 +        r = mailmime_smart_add_part(mime, submime);
    1.57 +        assert(r == MAILIMF_NO_ERROR);
    1.58 +        if (r == MAILIMF_ERROR_MEMORY) {
    1.59 +            mailmime_free(msg_mime);
    1.60 +            goto enomem;
    1.61 +        }
    1.62 +        else {
    1.63 +            // mailmime_smart_add_part() takes ownership of submime
    1.64 +            submime = NULL;
    1.65 +        }
    1.66      }
    1.67      else {
    1.68 -        // mailmime_smart_add_part() takes ownership of submime
    1.69 -        submime = NULL;
    1.70 +        mime = get_text_part("text/plain", plaintext, strlen(plaintext),
    1.71 +                MAILMIME_MECHANISM_QUOTED_PRINTABLE);
    1.72 +        assert(mime);
    1.73 +        if (mime == NULL) {
    1.74 +            mailmime_free(msg_mime);
    1.75 +            goto enomem;
    1.76 +        }
    1.77      }
    1.78  
    1.79      r = mailmime_add_part(msg_mime, mime);