From 54bc9cb429253d8ed52d6bf46ff55832205ad498 Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Wed, 21 Jun 2000 07:22:15 +0000 Subject: [PATCH] Fix character set selection. Postponing and recalling messages should work again, now. --- compose.c | 26 ++++++------ pgpkey.c | 2 +- protos.h | 6 +-- recvattach.c | 6 +-- send.c | 4 +- sendlib.c | 111 ++++++++++++--------------------------------------- 6 files changed, 46 insertions(+), 109 deletions(-) diff --git a/compose.c b/compose.c index 0e1215ea..3775cbd7 100644 --- a/compose.c +++ b/compose.c @@ -262,7 +262,7 @@ check_attachments(ATTACHPTR **idx, short idxlen) pretty, i+1); if((r = mutt_yesorno(msg, M_YES)) == M_YES) - mutt_update_encoding(idx[i]->content); + mutt_update_encoding(idx[i]->content, NULL); else if(r == -1) return -1; } @@ -598,7 +598,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ if (Editor && (mutt_strcmp ("builtin", Editor) != 0) && !option (OPTEDITHDRS)) { mutt_edit_file (Editor, msg->content->filename); - mutt_update_encoding (msg->content); + mutt_update_encoding (msg->content, NULL); menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; break; } @@ -618,7 +618,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ code below to regenerate the index array */ mutt_builtin_editor (msg->content->filename, msg, cur); } - mutt_update_encoding (msg->content); + mutt_update_encoding (msg->content, NULL); /* attachments may have been added */ if (idxlen && idx[idxlen - 1]->content->next) @@ -877,19 +877,19 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ case OP_COMPOSE_UPDATE_ENCODING: CHECK_COUNT; - if(menu->tagprefix) + if (menu->tagprefix) { BODY *top; - for(top = msg->content; top; top = top->next) + for (top = msg->content; top; top = top->next) { - if(top->tagged) - mutt_update_encoding(top); + if (top->tagged) + mutt_update_encoding (top, NULL); } menu->redraw = REDRAW_FULL; } else { - mutt_update_encoding(idx[menu->current]->content); + mutt_update_encoding(idx[menu->current]->content, NULL); menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; } break; @@ -906,7 +906,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ mutt_edit_content_type (NULL, idx[menu->current]->content); /* this may have been a change to text/something */ - mutt_update_encoding (idx[menu->current]->content); + mutt_update_encoding (idx[menu->current]->content, NULL); menu->redraw = REDRAW_CURRENT; } @@ -961,7 +961,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ CHECK_COUNT; mutt_edit_file ((!Editor || mutt_strcmp ("builtin", Editor) == 0) ? NONULL(Visual) : NONULL(Editor), idx[menu->current]->content->filename); - mutt_update_encoding (idx[menu->current]->content); + mutt_update_encoding (idx[menu->current]->content, NULL); menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; break; @@ -1091,7 +1091,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ if (mutt_compose_attachment (idx[menu->current]->content)) { - mutt_update_encoding (idx[menu->current]->content); + mutt_update_encoding (idx[menu->current]->content, NULL); menu->redraw = REDRAW_FULL; } } @@ -1101,7 +1101,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ CHECK_COUNT; if (mutt_edit_attachment (idx[menu->current]->content)) { - mutt_update_encoding (idx[menu->current]->content); + mutt_update_encoding (idx[menu->current]->content, NULL); menu->redraw = REDRAW_FULL; } break; @@ -1176,7 +1176,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ mutt_error (_("Error running \"%s\"!"), buf); else { - mutt_update_encoding (msg->content); + mutt_update_encoding (msg->content, NULL); menu->redraw |= REDRAW_STATUS; } break; diff --git a/pgpkey.c b/pgpkey.c index 7d769e3c..ad26526b 100644 --- a/pgpkey.c +++ b/pgpkey.c @@ -706,7 +706,7 @@ BODY *pgp_make_key_attachment (char *tempf) att->subtype = safe_strdup ("pgp-keys"); snprintf (buff, sizeof (buff), _("PGP Key %s."), tmp); att->description = safe_strdup (buff); - mutt_update_encoding (att); + mutt_update_encoding (att, NULL); stat (tempf, &sb); att->length = sb.st_size; diff --git a/protos.h b/protos.h index 1ae0e230..63e45863 100644 --- a/protos.h +++ b/protos.h @@ -62,7 +62,6 @@ typedef const char * format_t (char *, size_t, char, const char *, const char *, void mutt_FormatString (char *, size_t, const char *, format_t *, unsigned long, format_flag); void mutt_parse_content_type (char *, BODY *); -void mutt_update_encoding (BODY *a); void mutt_generate_boundary (PARAMETER **); void mutt_set_parameter (const char *, const char *, PARAMETER **); @@ -121,9 +120,9 @@ char *_mutt_expand_path (char *, size_t, int); char *mutt_find_hook (int, const char *); char *mutt_gecos_name (char *, size_t, struct passwd *); char *mutt_gen_msgid (void); +char *mutt_get_body_charset (char *, size_t, BODY *); char *mutt_get_name (ADDRESS *); char *mutt_get_parameter (const char *, PARAMETER *); -char *mutt_get_send_charset (char *, size_t, BODY *, short); #ifdef HAVE_PGP char *mutt_pgp_hook (ADDRESS *); #endif /* HAVE_PGP */ @@ -201,7 +200,6 @@ void mutt_message_hook (CONTEXT *, HEADER *, int); void _mutt_set_flag (CONTEXT *, HEADER *, int, int, int); #define mutt_set_flag(a,b,c,d) _mutt_set_flag(a,b,c,d,1) void mutt_set_followup_to (ENVELOPE *); -void mutt_set_body_charset (BODY *, const char *); void mutt_shell_escape (void); void mutt_show_error (void); void mutt_signal_init (void); @@ -210,7 +208,7 @@ void mutt_tabs_to_spaces (char *); void mutt_tag_set_flag (int, int); void mutt_unblock_signals (void); void mutt_unblock_signals_system (int); -void mutt_update_encoding (BODY *a); +void mutt_update_encoding (BODY *a, CONTENT *info); void mutt_update_tree (ATTACHPTR **, short); void mutt_version (void); void mutt_view_attachments (HEADER *); diff --git a/recvattach.c b/recvattach.c index 30a3b1a1..bcfc5ec7 100644 --- a/recvattach.c +++ b/recvattach.c @@ -193,13 +193,13 @@ const char *mutt_attach_fmt (char *dest, { snprintf (fmt, sizeof (fmt), "%%%ss", prefix); if (mutt_is_text_type (aptr->content->type, aptr->content->subtype) && - mutt_get_send_charset (charset, sizeof (charset), aptr->content, 0)) + mutt_get_body_charset (charset, sizeof (charset), aptr->content)) snprintf (dest, destlen, fmt, charset); else snprintf (dest, destlen, fmt, ""); } else if (!mutt_is_text_type (aptr->content->type, aptr->content->subtype) || - !mutt_get_send_charset (charset, sizeof (charset), aptr->content, 0)) + !mutt_get_body_charset (charset, sizeof (charset), aptr->content)) optional = 0; break; case 'c': @@ -513,7 +513,7 @@ mutt_query_pipe_attachment (char *command, FILE *fp, BODY *body, int filter) { mutt_unlink (body->filename); mutt_rename_file (tfile, body->filename); - mutt_update_encoding (body); + mutt_update_encoding (body, NULL); mutt_message _("Attachment filtered."); } } diff --git a/send.c b/send.c index 47666c82..87bf526b 100644 --- a/send.c +++ b/send.c @@ -1252,7 +1252,7 @@ ci_send_message (int flags, /* send mode */ utime (msg->content->filename, &utim); } - mutt_update_encoding (msg->content); + mutt_update_encoding (msg->content, NULL); /* If the this isn't a text message, look for a mailcap edit command */ if(! (flags & SENDKEY)) @@ -1305,7 +1305,7 @@ ci_send_message (int flags, /* send mode */ } - mutt_update_encoding (msg->content); + mutt_update_encoding (msg->content, NULL); if (! (flags & (SENDMAILX | SENDBATCH))) { diff --git a/sendlib.c b/sendlib.c index 9226b4aa..1a277284 100644 --- a/sendlib.c +++ b/sendlib.c @@ -486,7 +486,7 @@ int mutt_write_mime_body (BODY *a, FILE *f) } if (a->type == TYPETEXT && (!a->noconv)) - fc = fgetconv_open (fpin, Charset, mutt_get_send_charset (send_charset, sizeof (send_charset), a, 1)); + fc = fgetconv_open (fpin, Charset, mutt_get_body_charset (send_charset, sizeof (send_charset), a)); else fc = fgetconv_open (fpin, 0, 0); @@ -520,7 +520,6 @@ void mutt_generate_boundary (PARAMETER **parm) mutt_set_parameter ("boundary", rs, parm); } - typedef struct { int from; @@ -532,7 +531,7 @@ typedef struct CONTENT_STATE; -static void update_content_info(CONTENT *info, CONTENT_STATE *s, char *d, size_t dlen) +static void update_content_info (CONTENT *info, CONTENT_STATE *s, char *d, size_t dlen) { int from = s->from; int whitespace = s->whitespace; @@ -840,7 +839,8 @@ static size_t convert_file_from_to (FILE *file, return ret; } -/* Analyze the contents of a file to determine which MIME encoding to use. +/* + * Analyze the contents of a file to determine which MIME encoding to use. * Also set the body charset, sometimes, or not. */ CONTENT *mutt_get_content_info (const char *fname, BODY *b) @@ -873,8 +873,8 @@ CONTENT *mutt_get_content_info (const char *fname, BODY *b) { if (!chs) mutt_set_parameter ("charset", tocode, &b->parameter); - safe_free (&fromcode); - safe_free (&tocode); + safe_free ((void **) &fromcode); + safe_free ((void **) &tocode); safe_fclose (&fp); return info; } @@ -888,8 +888,7 @@ CONTENT *mutt_get_content_info (const char *fname, BODY *b) safe_fclose (&fp); if (b != NULL && b->type == TYPETEXT && (!b->noconv)) - mutt_set_parameter ("charset", - info->hibin ? "unknown-8bit" : "us-ascii", + mutt_set_parameter ("charset", info->hibin ? "unknown-8bit" : "us-ascii", &b->parameter); return info; @@ -1103,7 +1102,7 @@ static void transform_to_7bit (BODY *a, FILE *fpin) } a->length = sb.st_size; - mutt_update_encoding (a); + mutt_update_encoding (a, NULL); if (a->encoding == ENC8BIT) a->encoding = ENCQUOTEDPRINTABLE; else if(a->encoding == ENCBINARY) @@ -1112,30 +1111,6 @@ static void transform_to_7bit (BODY *a, FILE *fpin) } } -static const char *get_text_charset (char *d, size_t dlen, BODY *b, CONTENT *info) -{ - char send_charset[SHORT_STRING]; - char *chsname; - char *p; - - chsname = mutt_get_send_charset (send_charset, sizeof (send_charset), b, 1); - - /* if charset is unknown assume low bytes are ascii compatible */ - - if ((chsname == NULL || mutt_strcasecmp (chsname, "us-ascii") == 0) - && info->hibin) - p = "unknown-8bit"; - else if (info->hibin || !strcasecmp (chsname, "utf-7")) - p = chsname; - else if (info->lobin && !strncasecmp (chsname, "iso-2022-jp", 11)) - p = chsname; - else - p = "us-ascii"; - - strfcpy (d, p, dlen); - return d; -} - /* determine which Content-Transfer-Encoding to use */ static void mutt_set_encoding (BODY *b, CONTENT *info) { @@ -1143,7 +1118,7 @@ static void mutt_set_encoding (BODY *b, CONTENT *info) if (b->type == TYPETEXT) { - char *chsname = mutt_get_send_charset (send_charset, sizeof (send_charset), b, 1); + char *chsname = mutt_get_body_charset (send_charset, sizeof (send_charset), b); if ((info->lobin && strncasecmp (chsname, "iso-2022-jp", 11)) || info->linemax > 990 || (info->from && option (OPTENCODEFROM))) b->encoding = ENCQUOTEDPRINTABLE; else if (info->hibin) @@ -1182,9 +1157,9 @@ void mutt_stamp_attachment(BODY *a) a->stamp = time(NULL); } -/* Get the character set which is to be used for sending */ +/* Get a body's character set */ -char *mutt_get_send_charset (char *d, size_t dlen, BODY *b, short f) +char *mutt_get_body_charset (char *d, size_t dlen, BODY *b) { char *p = NULL; @@ -1194,54 +1169,28 @@ char *mutt_get_send_charset (char *d, size_t dlen, BODY *b, short f) if (b) p = mutt_get_parameter ("charset", b->parameter); - /* override the special "us-ascii" and "unknown-8bit" character sets */ - if (!p || (f && (!mutt_strcasecmp (p, "us-ascii") || !mutt_strcasecmp (p, "unknown-8bit")))) - { - if (SendCharset && *SendCharset) - { - p = strrchr (SendCharset, ':'); - p = p ? p + 1 : SendCharset; - } - else if (Charset) - p = Charset; - } - if (p) - { strfcpy (d, NONULL(p), dlen); - return d; - } - - /* something is seriously wrong. */ - return NULL; -} - -/* set a body structure's character set */ - -void mutt_set_body_charset(BODY *b, const char *chs) -{ - char send_charset[SHORT_STRING]; - - if(b->type != TYPETEXT) - return; - - if(!chs && !(chs = mutt_get_send_charset(send_charset, sizeof(send_charset), NULL, 1))) - return; + else + strfcpy (d, "us-ascii", dlen); - mutt_set_parameter ("charset", chs, &b->parameter); + return d; } /* Assumes called from send mode where BODY->filename points to actual file */ -void mutt_update_encoding (BODY *a) +void mutt_update_encoding (BODY *a, CONTENT *info) { - CONTENT *info; + char chsbuff[STRING]; + + /* override noconv when it's us-ascii */ + if (!mutt_strcasecmp (mutt_get_body_charset (chsbuff, sizeof (chsbuff), a), "us-ascii")) + a->noconv = 0; - /* Previous value is usually wrong, apparently. */ - if (!a->force_charset) - mutt_set_parameter ("charset", 0, &a->parameter); + if (!a->force_charset && !a->noconv) + mutt_set_parameter ("charset", NULL, &a->parameter); - if ((info = mutt_get_content_info (a->filename, a)) == NULL) + if (!info && (info = mutt_get_content_info (a->filename, a)) == NULL) return; mutt_set_encoding (a, info); @@ -1326,7 +1275,7 @@ BODY *mutt_make_message_attach (CONTEXT *ctx, HEADER *hdr, int attach_msg) #ifdef HAVE_PGP body->hdr->pgp = pgp; #endif /* HAVE_PGP */ - mutt_update_encoding (body); + mutt_update_encoding (body, NULL); body->parts = body->hdr->content; fclose(fp); @@ -1339,7 +1288,6 @@ BODY *mutt_make_file_attach (const char *path) BODY *att; CONTENT *info; char buf[SHORT_STRING]; - char chsbuf[SHORT_STRING]; int n; att = mutt_new_body (); @@ -1376,16 +1324,7 @@ BODY *mutt_make_file_attach (const char *path) } } - /* XXX - just call mutt_update_encoding? -tlr */ - - mutt_set_encoding (att, info); - mutt_stamp_attachment(att); - - if (att->type == TYPETEXT) - mutt_set_body_charset(att, get_text_charset(chsbuf, sizeof (chsbuf), att, info)); - - att->content = info; - + mutt_update_encoding (att, info); return (att); } -- 2.40.0