From: markus schnalke Date: Sun, 25 Oct 2015 20:34:20 +0000 (+0100) Subject: send: MIMEify with non-ascii header and ascii body! X-Git-Tag: mmh-0.2-RC1~4 X-Git-Url: http://git.marmaro.de/?p=mmh;a=commitdiff_plain;h=5b389106e9bfb05edbbcbdc847e09437f2390da0;hp=7d95e0861814febe23512e306b7b1e805c17bd81 send: MIMEify with non-ascii header and ascii body! This code is not perfect, as it scans body lines twice. We might want to rework it someday. But, ignoring the minor performance issue, it ensures, that we MIMEify in the case when some headers contain non-ASCII text but the body does not. --- diff --git a/uip/send.c b/uip/send.c index ec9b76d..bab1699 100644 --- a/uip/send.c +++ b/uip/send.c @@ -320,13 +320,26 @@ sendsbr(char **vec, int vecp, char *drft, struct stat *st) } static int +contains_non_ascii(char *str) +{ + char *cp; + + for (cp = str; *cp; cp++) { + if (*cp > 127 || *cp < 0) { + return 1; + } + } + return 0; +} + +static int attach(char *draft_file_name) { char buf[MAXPATHLEN + 6]; int c; int has_attachment; - int has_body; - int non_ascii; /* msg body contains non-ASCII chars */ + int has_body = 0; + int non_ascii = 0; /* msg body or hdr contains non-ASCII chars */ int length; /* length of attachment header field name */ char *p; @@ -347,6 +360,9 @@ attach(char *draft_file_name) field[length] == ':') { has_attachment = 1; } + if (contains_non_ascii(field)) { + non_ascii = 1; + } } /* @@ -355,16 +371,14 @@ attach(char *draft_file_name) ** Check if body contains at least one non-blank (= not empty) ** and if it contains any non-ASCII chars (= need MIME). */ - has_body = 0; - non_ascii = 0; while (get_line() != EOF) { - for (p = field; *p != '\0'; p++) { - if (*p != ' ' && *p != '\t') { + if (contains_non_ascii(field)) { + non_ascii = 1; + } + for (p = field; *p; p++) { + if (isgraph(*p)) { has_body = 1; } - if (*p > 127 || *p < 0) { - non_ascii = 1; - } } if (has_body && non_ascii) { break; /* that's been already enough information */