From 10b7c16c8905d1b7ceaeeb6cfab9ad2ec03d8780 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Thu, 16 Nov 2006 18:46:10 +0100 Subject: [PATCH] make charset_canonicalize set the answer to "us-ascii" if s is NULL. some small improvements. Signed-off-by: Pierre Habouzit --- charset.c | 24 +++++++++++------------- copy.c | 3 +-- protos.h | 3 --- sendlib.c | 46 +++++++++++----------------------------------- 4 files changed, 23 insertions(+), 53 deletions(-) diff --git a/charset.c b/charset.c index cd672b5..90a7307 100644 --- a/charset.c +++ b/charset.c @@ -98,6 +98,11 @@ void charset_canonicalize(char *dest, ssize_t dlen, const char *name) const char *p; int i = 0; + if (!name) { + m_strcpy(dest, dlen, "us-ascii"); + return; + } + // canonize name: only keep a-z0-9 and dots, put into lowercase for (p = name; *p && *p != ':' && i < ssizeof(scratch) - 1; p++) { if (isalnum(*p) || *p== '.') { @@ -129,25 +134,18 @@ const char *charset_getfirst(const char *charset) return fcharset; } -static int mutt_chscmp(const char *s, const char *chs) -{ - char buffer[SHORT_STRING]; - - if (!s) - return 0; - - charset_canonicalize(buffer, sizeof(buffer), s); - return !strcmp(buffer, chs); -} - int charset_is_utf8(const char *s) { - return mutt_chscmp(s, "utf-8"); + char buf[SHORT_STRING]; + charset_canonicalize(buf, sizeof(buf), s); + return !strcmp(buf, "utf-8"); } int charset_is_us_ascii(const char *s) { - return mutt_chscmp(s, "us-ascii"); + char buf[SHORT_STRING]; + charset_canonicalize(buf, sizeof(buf), s); + return !strcmp(buf, "us-ascii"); } diff --git a/copy.c b/copy.c index ccbf308..661b389 100644 --- a/copy.c +++ b/copy.c @@ -346,8 +346,7 @@ mutt_copy_header (FILE * in, HEADER * h, FILE * out, int flags, fputs ("MIME-Version: 1.0\n", out); fputs ("Content-Transfer-Encoding: 8bit\n", out); fputs ("Content-Type: text/plain; charset=", out); - charset_canonicalize (chsbuf, sizeof (chsbuf), - Charset ? Charset : "us-ascii"); + charset_canonicalize(chsbuf, sizeof (chsbuf), Charset); rfc822_strcpy(buffer, sizeof(buffer), chsbuf, MimeSpecials); fputs (buffer, out); fputc ('\n', out); diff --git a/protos.h b/protos.h index 6a47672..bff2205 100644 --- a/protos.h +++ b/protos.h @@ -248,9 +248,6 @@ pid_t mutt_create_filter_fd (const char *, FILE **, FILE **, FILE **, int, void mutt_to_base64 (unsigned char *, const unsigned char *, ssize_t, ssize_t); int mutt_from_base64 (char *, const char *); -/* utf8.c */ -int mutt_wctoutf8 (char *s, unsigned int c); - #define IsPrint(c) (isprint((unsigned char)(c)) || \ (option (OPTLOCALES) ? 0 : \ ((unsigned char)(c) >= 0xa0))) diff --git a/sendlib.c b/sendlib.c index e5bb57f..2c5611a 100644 --- a/sendlib.c +++ b/sendlib.c @@ -364,8 +364,6 @@ int mutt_write_mime_header (BODY * a, FILE * f) return (ferror (f) ? -1 : 0); } -# define write_as_text_part(a) (mutt_is_text_part(a) || mutt_is_application_pgp(a)) - int mutt_write_mime_body (BODY * a, FILE * f) { const char *p; @@ -414,6 +412,7 @@ int mutt_write_mime_body (BODY * a, FILE * f) else fc = fgetconv_open (fpin, 0, 0, 0); +#define write_as_text_part(a) (mutt_is_text_part(a) || mutt_is_application_pgp(a)) if (a->encoding == ENCQUOTEDPRINTABLE) encode_quoted (fc, f, write_as_text_part (a)); else if (a->encoding == ENCBASE64) @@ -422,6 +421,7 @@ int mutt_write_mime_body (BODY * a, FILE * f) encode_8bit (fc, f, write_as_text_part (a)); else mutt_copy_stream (fpin, f); +#undef write_as_text_part fgetconv_close (&fc); fclose (fpin); @@ -429,8 +429,6 @@ int mutt_write_mime_body (BODY * a, FILE * f) return (ferror (f) ? -1 : 0); } -#undef write_as_text_part - typedef struct { int from; int whitespace; @@ -1095,22 +1093,16 @@ void mutt_stamp_attachment (BODY * a) /* Get a body's character set */ -char *mutt_get_body_charset (char *d, ssize_t dlen, BODY * b) +char *mutt_get_body_charset(char *d, ssize_t dlen, BODY * b) { - const char *p = NULL; - - if (b && b->type != TYPETEXT) - return NULL; - - if (b) - p = parameter_getval(b->parameter, "charset"); + const char *p; - if (p) - charset_canonicalize (d, dlen, p); - else - m_strcpy(d, dlen, "us-ascii"); + if (b && b->type != TYPETEXT) + return NULL; - return d; + p = b ? parameter_getval(b->parameter, "charset") : NULL; + charset_canonicalize(d, dlen, p); + return d; } @@ -1223,23 +1215,8 @@ BODY *mutt_make_file_attach (const char *path) /* Attempt to determine the appropriate content-type based on the filename * suffix. */ - -#if 0 - - if ((n = - mutt_lookup_mime_type (buf, sizeof (buf), xbuf, sizeof (xbuf), - path)) != TYPEOTHER || *xbuf != '\0') { - att->type = n; - att->subtype = m_strdup(buf); - att->xtype = m_strdup(xbuf); - } - -#else - mutt_lookup_mime_type (att, path); -#endif - if ((info = mutt_get_content_info (path, att)) == NULL) { body_list_wipe(&att); return NULL; @@ -1254,15 +1231,14 @@ BODY *mutt_make_file_attach (const char *path) */ att->type = TYPETEXT; att->subtype = m_strdup("plain"); - } - else { + } else { att->type = TYPEAPPLICATION; att->subtype = m_strdup("octet-stream"); } } mutt_update_encoding (att); - return (att); + return att; } static int get_toplevel_encoding (BODY * a) -- 2.20.1