From: Thomas Roessler Date: Wed, 21 Jun 2000 09:55:24 +0000 (+0000) Subject: More character set clean-up. X-Git-Tag: mutt-1-3-5-rel~31 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f7d932671ea60ad830ad19d1ff33c9e21d54746b;p=mutt More character set clean-up. --- diff --git a/commands.c b/commands.c index fac63e04..27c358d6 100644 --- a/commands.c +++ b/commands.c @@ -846,7 +846,7 @@ void mutt_edit_content_type (HEADER *h, BODY *b) mutt_message (_("Character set changed to %s."), mutt_get_parameter ("charset", b->parameter)); - b->force_charset |= charset_changed; + b->force_charset |= charset_changed ? 1 : 0; if (!is_multipart (b) && b->parts) mutt_free_body (&b->parts); diff --git a/compose.c b/compose.c index 3775cbd7..86c1466d 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, NULL); + mutt_update_encoding(idx[i]->content); 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, NULL); + mutt_update_encoding (msg->content); 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, NULL); + mutt_update_encoding (msg->content); /* attachments may have been added */ if (idxlen && idx[idxlen - 1]->content->next) @@ -883,13 +883,13 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ for (top = msg->content; top; top = top->next) { if (top->tagged) - mutt_update_encoding (top, NULL); + mutt_update_encoding (top); } menu->redraw = REDRAW_FULL; } else { - mutt_update_encoding(idx[menu->current]->content, NULL); + mutt_update_encoding(idx[menu->current]->content); 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, NULL); + mutt_update_encoding (idx[menu->current]->content); 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, NULL); + mutt_update_encoding (idx[menu->current]->content); 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, NULL); + mutt_update_encoding (idx[menu->current]->content); 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, NULL); + mutt_update_encoding (idx[menu->current]->content); 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, NULL); + mutt_update_encoding (msg->content); menu->redraw |= REDRAW_STATUS; } break; diff --git a/muttlib.c b/muttlib.c index 089fface..8f0dc8ad 100644 --- a/muttlib.c +++ b/muttlib.c @@ -506,6 +506,13 @@ char *mutt_get_parameter (const char *s, PARAMETER *p) void mutt_set_parameter (const char *attribute, const char *value, PARAMETER **p) { PARAMETER *q; + + if (!value) + { + mutt_delete_parameter (attribute, p); + return; + } + for(q = *p; q; q = q->next) { if (mutt_strcasecmp (attribute, q->attribute) == 0) @@ -522,8 +529,21 @@ void mutt_set_parameter (const char *attribute, const char *value, PARAMETER **p *p = q; } - - +void mutt_delete_parameter (const char *attribute, PARAMETER **p) +{ + PARAMETER *q; + + for (q = *p; q; p = &q->next, q = q->next) + { + if (mutt_strcasecmp (attribute, q->attribute) == 0) + { + *p = q->next; + q->next = NULL; + mutt_free_parameter (&q); + return; + } + } +} /* returns 1 if Mutt can't display this type of data, 0 otherwise */ int mutt_needs_mailcap (BODY *m) diff --git a/pgpkey.c b/pgpkey.c index ad26526b..7d769e3c 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, NULL); + mutt_update_encoding (att); stat (tempf, &sb); att->length = sb.st_size; diff --git a/postpone.c b/postpone.c index 4121d9be..b0bfa5e0 100644 --- a/postpone.c +++ b/postpone.c @@ -596,7 +596,6 @@ int mutt_prepare_template (FILE *fp, CONTEXT *ctx, HEADER *newhdr, HEADER *hdr, newhdr->content = mutt_remove_multipart (newhdr->content); s.fpin = bfp; - s.flags = M_CHARCONV; /* create temporary files for all attachments */ for (b = newhdr->content; b; b = b->next) @@ -616,22 +615,33 @@ int mutt_prepare_template (FILE *fp, CONTEXT *ctx, HEADER *newhdr, HEADER *hdr, /* avoid Content-Disposition: header with temporary filename */ b->use_disp = 0; + if (b->type == TYPETEXT && + !mutt_strcasecmp ("yes", mutt_get_parameter ("x-mutt-noconv", b->parameter))) + { + s.flags &= ~M_CHARCONV; + b->noconv = 1; + } + else + { + s.flags |= M_CHARCONV; + b->noconv = 0; + } + + mutt_delete_parameter ("x-mutt-noconv", &b->parameter); + mutt_adv_mktemp (file, sizeof(file)); - if ((s.fpout = safe_fopen (file, "w")) == NULL) goto bail; - mutt_decode_attachment (b, &s); + mutt_decode_attachment (b, &s); + if (safe_fclose (&s.fpout) != 0) goto bail; mutt_str_replace (&b->filename, file); b->unlink = 1; - if (b->type == TYPETEXT) - b->noconv = 0; - mutt_stamp_attachment (b); mutt_free_body (&b->parts); diff --git a/protos.h b/protos.h index 609d2e2b..6f2b91e4 100644 --- a/protos.h +++ b/protos.h @@ -63,8 +63,10 @@ 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_generate_boundary (PARAMETER **); +void mutt_delete_parameter (const char *attribute, PARAMETER **p); void mutt_set_parameter (const char *, const char *, PARAMETER **); + FILE *mutt_open_read (const char *, pid_t *); void set_quadoption (int, int); @@ -207,7 +209,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, CONTENT *info); +void mutt_update_encoding (BODY *a); void mutt_update_tree (ATTACHPTR **, short); void mutt_version (void); void mutt_view_attachments (HEADER *); diff --git a/recvattach.c b/recvattach.c index bcfc5ec7..460c4172 100644 --- a/recvattach.c +++ b/recvattach.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, NULL); + mutt_update_encoding (body); mutt_message _("Attachment filtered."); } } diff --git a/send.c b/send.c index 87bf526b..47666c82 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, NULL); + mutt_update_encoding (msg->content); /* 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, NULL); + mutt_update_encoding (msg->content); if (! (flags & (SENDMAILX | SENDBATCH))) { diff --git a/sendlib.c b/sendlib.c index 1a277284..a3e6c4ac 100644 --- a/sendlib.c +++ b/sendlib.c @@ -864,7 +864,7 @@ CONTENT *mutt_get_content_info (const char *fname, BODY *b) info = safe_calloc (1, sizeof (CONTENT)); memset (&state, 0, sizeof (state)); - if (b != NULL && b->type == TYPETEXT && (!b->noconv)) + if (b != NULL && b->type == TYPETEXT && (!b->noconv && !b->force_charset)) { char *chs = mutt_get_parameter ("charset", b->parameter); if (Charset && (chs || SendCharset) && @@ -887,7 +887,7 @@ CONTENT *mutt_get_content_info (const char *fname, BODY *b) safe_fclose (&fp); - if (b != NULL && b->type == TYPETEXT && (!b->noconv)) + if (b != NULL && b->type == TYPETEXT && (!b->noconv && !b->force_charset)) mutt_set_parameter ("charset", info->hibin ? "unknown-8bit" : "us-ascii", &b->parameter); @@ -1102,7 +1102,7 @@ static void transform_to_7bit (BODY *a, FILE *fpin) } a->length = sb.st_size; - mutt_update_encoding (a, NULL); + mutt_update_encoding (a); if (a->encoding == ENC8BIT) a->encoding = ENCQUOTEDPRINTABLE; else if(a->encoding == ENCBINARY) @@ -1179,8 +1179,9 @@ char *mutt_get_body_charset (char *d, size_t dlen, BODY *b) /* Assumes called from send mode where BODY->filename points to actual file */ -void mutt_update_encoding (BODY *a, CONTENT *info) +void mutt_update_encoding (BODY *a) { + CONTENT *info; char chsbuff[STRING]; /* override noconv when it's us-ascii */ @@ -1188,9 +1189,9 @@ void mutt_update_encoding (BODY *a, CONTENT *info) a->noconv = 0; if (!a->force_charset && !a->noconv) - mutt_set_parameter ("charset", NULL, &a->parameter); + mutt_delete_parameter ("charset", &a->parameter); - if (!info && (info = mutt_get_content_info (a->filename, a)) == NULL) + if ((info = mutt_get_content_info (a->filename, a)) == NULL) return; mutt_set_encoding (a, info); @@ -1275,7 +1276,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, NULL); + mutt_update_encoding (body); body->parts = body->hdr->content; fclose(fp); @@ -1324,7 +1325,7 @@ BODY *mutt_make_file_attach (const char *path) } } - mutt_update_encoding (att, info); + mutt_update_encoding (att); return (att); } @@ -2164,6 +2165,22 @@ ADDRESS *mutt_remove_duplicates (ADDRESS *addr) return (top); } +static void set_noconv_flags (BODY *b, short flag) +{ + for(; b; b = b->next) + { + if (b->type == TYPEMESSAGE || b->type == TYPEMULTIPART) + set_noconv_flags (b->parts, flag); + else if (b->type == TYPETEXT && b->noconv) + { + if (flag) + mutt_set_parameter ("x-mutt-noconv", "yes", &b->parameter); + else + mutt_delete_parameter ("x-mutt-noconv", &b->parameter); + } + } +} + int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post, char *fcc) { CONTEXT f; @@ -2172,6 +2189,9 @@ int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post, FILE *tempfp = NULL; int r; + if (post) + set_noconv_flags (hdr->content, 1); + if (mx_open_mailbox (path, M_APPEND | M_QUIET, &f) == NULL) { dprint (1, (debugfile, "mutt_write_fcc(): unable to open mailbox %s in append-mode, aborting.\n", @@ -2316,5 +2336,8 @@ int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post, mx_close_message (&msg); mx_close_mailbox (&f, NULL); + if (post) + set_noconv_flags (hdr->content, 0); + return r; }