(has_nonascii,finish_text_msg): New functions
(mhn_edit): Use quoted-printable encoding if the text contains non-ascii characters.
Showing
1 changed file
with
52 additions
and
2 deletions
... | @@ -2002,6 +2002,42 @@ finish_msg (struct compose_env *env, message_t *msg) | ... | @@ -2002,6 +2002,42 @@ finish_msg (struct compose_env *env, message_t *msg) |
2002 | *msg = NULL; | 2002 | *msg = NULL; |
2003 | } | 2003 | } |
2004 | 2004 | ||
2005 | void | ||
2006 | finish_text_msg (struct compose_env *env, message_t *msg, int ascii) | ||
2007 | { | ||
2008 | if (!ascii) | ||
2009 | { | ||
2010 | int rc; | ||
2011 | message_t newmsg; | ||
2012 | header_t hdr; | ||
2013 | body_t body; | ||
2014 | stream_t input, output, fstr; | ||
2015 | |||
2016 | message_create (&newmsg, NULL); | ||
2017 | message_get_header (newmsg, &hdr); | ||
2018 | header_set_value (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING, | ||
2019 | "quoted-printable", 0); | ||
2020 | |||
2021 | message_get_body (newmsg, &body); | ||
2022 | body_get_stream (body, &output); | ||
2023 | stream_seek (output, 0, SEEK_SET); | ||
2024 | |||
2025 | message_get_body (*msg, &body); | ||
2026 | body_get_stream (body, &input); | ||
2027 | rc = filter_create (&fstr, input, "quoted-printable", | ||
2028 | MU_FILTER_ENCODE, MU_STREAM_READ); | ||
2029 | if (rc == 0) | ||
2030 | { | ||
2031 | cat_message (output, fstr); | ||
2032 | message_unref (*msg); | ||
2033 | *msg = newmsg; | ||
2034 | } | ||
2035 | else | ||
2036 | message_destroy (&newmsg, NULL); | ||
2037 | } | ||
2038 | finish_msg (env, msg); | ||
2039 | } | ||
2040 | |||
2005 | #define EXTCONTENT "message/external-body" | 2041 | #define EXTCONTENT "message/external-body" |
2006 | 2042 | ||
2007 | int | 2043 | int |
... | @@ -2289,6 +2325,16 @@ edit_mime (char *cmd, struct compose_env *env, message_t *msg, int level) | ... | @@ -2289,6 +2325,16 @@ edit_mime (char *cmd, struct compose_env *env, message_t *msg, int level) |
2289 | return rc; | 2325 | return rc; |
2290 | } | 2326 | } |
2291 | 2327 | ||
2328 | static int | ||
2329 | has_nonascii (char *buf, size_t n) | ||
2330 | { | ||
2331 | size_t i; | ||
2332 | for (i = 0; i < n; i++) | ||
2333 | if (!isascii (buf[i])) | ||
2334 | return 1; | ||
2335 | return 0; | ||
2336 | } | ||
2337 | |||
2292 | int | 2338 | int |
2293 | mhn_edit (struct compose_env *env, int level) | 2339 | mhn_edit (struct compose_env *env, int level) |
2294 | { | 2340 | { |
... | @@ -2299,6 +2345,7 @@ mhn_edit (struct compose_env *env, int level) | ... | @@ -2299,6 +2345,7 @@ mhn_edit (struct compose_env *env, int level) |
2299 | stream_t output; | 2345 | stream_t output; |
2300 | message_t msg = NULL; | 2346 | message_t msg = NULL; |
2301 | size_t line_count = 0; | 2347 | size_t line_count = 0; |
2348 | int ascii_buf; | ||
2302 | 2349 | ||
2303 | while (status == 0 | 2350 | while (status == 0 |
2304 | && stream_getline (env->input, &buf, &bufsize, &n) == 0 && n > 0) | 2351 | && stream_getline (env->input, &buf, &bufsize, &n) == 0 && n > 0) |
... | @@ -2314,6 +2361,7 @@ mhn_edit (struct compose_env *env, int level) | ... | @@ -2314,6 +2361,7 @@ mhn_edit (struct compose_env *env, int level) |
2314 | body_get_stream (body, &output); | 2361 | body_get_stream (body, &output); |
2315 | stream_seek (output, 0, SEEK_SET); | 2362 | stream_seek (output, 0, SEEK_SET); |
2316 | line_count = 0; | 2363 | line_count = 0; |
2364 | ascii_buf = 1; /* Suppose it is ascii */ | ||
2317 | env->subpart++; | 2365 | env->subpart++; |
2318 | } | 2366 | } |
2319 | 2367 | ||
... | @@ -2348,7 +2396,7 @@ mhn_edit (struct compose_env *env, int level) | ... | @@ -2348,7 +2396,7 @@ mhn_edit (struct compose_env *env, int level) |
2348 | stream_close (output); | 2396 | stream_close (output); |
2349 | if (line_count) | 2397 | if (line_count) |
2350 | /* Close and append the previous part */ | 2398 | /* Close and append the previous part */ |
2351 | finish_msg (env, &msg); | 2399 | finish_text_msg (env, &msg, ascii_buf); |
2352 | 2400 | ||
2353 | /* Execute the directive */ | 2401 | /* Execute the directive */ |
2354 | tok = sp = buf; | 2402 | tok = sp = buf; |
... | @@ -2410,6 +2458,8 @@ mhn_edit (struct compose_env *env, int level) | ... | @@ -2410,6 +2458,8 @@ mhn_edit (struct compose_env *env, int level) |
2410 | } | 2458 | } |
2411 | else if (line_count > 0 || buf[0] != '\n') | 2459 | else if (line_count > 0 || buf[0] != '\n') |
2412 | { | 2460 | { |
2461 | if (ascii_buf && has_nonascii (buf, n)) | ||
2462 | ascii_buf = 0; | ||
2413 | stream_sequential_write (output, buf, n); | 2463 | stream_sequential_write (output, buf, n); |
2414 | line_count++; | 2464 | line_count++; |
2415 | } | 2465 | } |
... | @@ -2420,7 +2470,7 @@ mhn_edit (struct compose_env *env, int level) | ... | @@ -2420,7 +2470,7 @@ mhn_edit (struct compose_env *env, int level) |
2420 | { | 2470 | { |
2421 | stream_close (output); | 2471 | stream_close (output); |
2422 | if (line_count) | 2472 | if (line_count) |
2423 | finish_msg (env, &msg); | 2473 | finish_text_msg (env, &msg, ascii_buf); |
2424 | else | 2474 | else |
2425 | message_unref (msg); | 2475 | message_unref (msg); |
2426 | } | 2476 | } | ... | ... |
-
Please register or sign in to post a comment