]> granicus.if.org Git - mutt/commitdiff
More character set clean-up.
authorThomas Roessler <roessler@does-not-exist.org>
Wed, 21 Jun 2000 09:55:24 +0000 (09:55 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Wed, 21 Jun 2000 09:55:24 +0000 (09:55 +0000)
commands.c
compose.c
muttlib.c
pgpkey.c
postpone.c
protos.h
recvattach.c
send.c
sendlib.c

index fac63e04510cefbc414e6de64dc2d23adfa9d12f..27c358d6c5e05aeb640717bb7251320c7789601f 100644 (file)
@@ -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);
index 3775cbd7996615c3cd19f487e3b40ad2b29b8683..86c1466d387065d91c826f1ffb2278ad31c80fed 100644 (file)
--- 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;
index 089ffacecd69ea3ffb3571fa3534c0ff3a7099cd..8f0dc8ad1e5d04a01d32456f1bc814b64a53387d 100644 (file)
--- 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)
index ad26526bc022673b3f550164b7203277baaaf488..7d769e3c4d6a8733fb184bd47e32bece29d897a5 100644 (file)
--- 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;
index 4121d9bee461ed03129e3ee9c5accb2639c62161..b0bfa5e0ef4d2cd5644cfbef042bf4fa93910299 100644 (file)
@@ -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);
index 609d2e2bfe7cb4506debd939de419d073b771ba7..6f2b91e4fdf3df440b37af796248c835ab2be4ff 100644 (file)
--- 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 *);
index bcfc5ec7c60942bdbef950876da2c4e3307e3881..460c417264fe9b14566f84e9b7019be4be7ec321 100644 (file)
@@ -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 87bf526b4d18ab34e328c02374ed3148a18bd18f..47666c824a9999b7ba8eb8bbbb2820067a137b96 100644 (file)
--- 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)))
   {
index 1a2772849d451f07b99646cf67ebf1be7be7a861..a3e6c4acc7e6baf86fcd275f757754c2e6b6a8ae 100644 (file)
--- 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;
 }