- switch (ct->c_type) {
- case CT_TEXT:
- if (ct->c_subtype == TEXT_PLAIN) {
- status = convert_codeset (ct, dest_codeset, message_mods);
- }
- break;
-
- case CT_MULTIPART: {
- struct multipart *m = (struct multipart *) ct->c_ctparams;
- struct part *part;
-
- /* Should check to see if the body for this part is encoded?
- For now, it gets passed along as-is by InitMultiPart(). */
- for (part = m->mp_parts; status == OK && part; part = part->mp_next) {
- status =
- convert_codesets (part->mp_part, dest_codeset, message_mods);
- }
- break;
- }
-
- case CT_MESSAGE:
- if (ct->c_subtype == MESSAGE_EXTERNAL) {
- struct exbody *e;
-
- e = (struct exbody *) ct->c_ctparams;
- status =
- convert_codesets (e->eb_content, dest_codeset, message_mods);
- }
- break;
-
- default:
- break;
- }
-
- return status;
-}
-
-
-static int
-convert_codeset (CT ct, char *dest_codeset, int *message_mods) {
- const char *const charset = "charset";
- char **src_codeset = NULL;
- char *default_codeset = NULL;
- CI ctinfo = &ct->c_ctinfo;
- char **ap, **vp;
- int status = OK;
-
- for (ap = ctinfo->ci_attrs, vp = ctinfo->ci_values; *ap; ++ap, ++vp) {
- if (! strcasecmp (*ap, charset)) {
- src_codeset = vp;
- break;
- }
- }
- /* RFC 2045, Sec. 5.2: default to us-ascii. */
- if (src_codeset == NULL) src_codeset = &default_codeset;
- if (*src_codeset == NULL) *src_codeset = "US-ASCII";
-
- if (strcmp (norm_charmap (*src_codeset), norm_charmap (dest_codeset))) {
-#ifdef HAVE_ICONV
- iconv_t conv_desc = NULL;
- char *dest;
- int fd = -1;
+ /* Only strip carriage returns if content is ASCII or another
+ charset that has the same readily recognizable CR followed by a
+ LF. We can include UTF-8 here because if the high-order bit of
+ a UTF-8 byte is 0, then it must be a single-byte ASCII
+ character. */
+ if (! strcmp (norm_charmap (charset), "US-ASCII") ||
+ ! strncmp (norm_charmap (charset), "ISO-8859-", 9) ||
+ ! strncmp (norm_charmap (charset), "UTF-8", 5) ||
+ ! strncmp (norm_charmap (charset), "WINDOWS-12", 10)) {