]> granicus.if.org Git - mutt/commitdiff
Fix character set selection. Postponing and recalling messages
authorThomas Roessler <roessler@does-not-exist.org>
Wed, 21 Jun 2000 07:22:15 +0000 (07:22 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Wed, 21 Jun 2000 07:22:15 +0000 (07:22 +0000)
should work again, now.

compose.c
pgpkey.c
protos.h
recvattach.c
send.c
sendlib.c

index 0e1215ea651dbf750c9620b4fdf981fe7e886445..3775cbd7996615c3cd19f487e3b40ad2b29b8683 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);
+       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;
index 7d769e3c4d6a8733fb184bd47e32bece29d897a5..ad26526bc022673b3f550164b7203277baaaf488 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);
+  mutt_update_encoding (att, NULL);
 
   stat (tempf, &sb);
   att->length = sb.st_size;
index 1ae0e230251c06b131019ba194512b5ba6da16e8..63e458632dfed12d52cafb8277fef78d2cdefc81 100644 (file)
--- 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 *);
index 30a3b1a1d1fe757c07da6a69eb056ddd14ff1279..bcfc5ec7c60942bdbef950876da2c4e3307e3881 100644 (file)
@@ -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 47666c824a9999b7ba8eb8bbbb2820067a137b96..87bf526b4d18ab34e328c02374ed3148a18bd18f 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);
+    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)))
   {
index 9226b4aa248023b544f919324b94c9caef136e6c..1a2772849d451f07b99646cf67ebf1be7be7a861 100644 (file)
--- 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);
 }