<<< Date Index >>>     <<< Thread Index >>>

[PATCH] attach-sanitize (Was: few questions)



On 2004-07-07, David Champion <dgc@xxxxxxxxxxxx> wrote:

> Gary, I'd like to see your patch. I have an idea....

Here it is.  I apologize for posting it here instead of to my web
site, but my ISP is not letting me use ftp at the moment.  Here also
is the description I tried to upload with the patch.

    This patch allows mutt to replace spaces by underscores when
    attachments are saved. The patch and the configuration variable
    that enables the feature are named attach_sanitize because the
    behavior is similar to the existing mailcap_sanitize variable.
    To enable this feature, execute the following from the mutt
    command line or put it in your muttrc.

        set attach_sanitize

Gary

-- 
Gary Johnson                               | Agilent Technologies
garyjohn@xxxxxxxxxxxxxxx                   | Wireless Division
http://www.spocom.com/users/gjohnson/mutt/ | Spokane, Washington, USA
--- PATCHES.orig        2003-04-15 06:18:34.000000000 -0700
+++ PATCHES     2004-07-07 12:45:53.000000000 -0700
@@ -0,0 +1 @@
+patch-1.5.5.1.gj.attach_sanitize.1
--- init.h.orig 2004-02-24 10:20:28.000000000 -0800
+++ init.h      2004-06-10 00:52:42.000000000 -0700
@@ -216,6 +216,13 @@
   ** .dt %|X .dd pad to the end of the line with character "X"
   ** .de
   */
+  { "attach_sanitize", DT_BOOL, R_NONE, OPTATTACHSANITIZE, 0 },
+  /*
+  ** .pp
+  ** If set, mutt will replace "unsafe" characters (such as spaces) in
+  ** attachment file names with underscores ('_') before presenting the
+  ** file name to the user at the "Save to file:" prompt.
+  */
   { "attach_sep",      DT_STR,  R_NONE, UL &AttachSep, UL "\n" },
   /*
   ** .pp
--- mutt.h.orig 2003-12-30 16:56:43.000000000 -0800
+++ mutt.h      2004-06-10 00:51:49.000000000 -0700
@@ -320,6 +320,7 @@
   OPTASCIICHARS,
   OPTASKBCC,
   OPTASKCC,
+  OPTATTACHSANITIZE,
   OPTATTACHSPLIT,
   OPTAUTOEDIT,
   OPTAUTOTAG,
--- recvattach.c.orig   2003-11-05 01:41:33.000000000 -0800
+++ recvattach.c        2004-06-10 00:54:59.000000000 -0700
@@ -374,10 +374,13 @@
   
   if (body->filename) 
   {
+    strfcpy (tfile, body->filename, sizeof (tfile));
+    if (option (OPTATTACHSANITIZE))
+      mutt_sanitize_filename (tfile, 0);
     if (directory && *directory)
-      mutt_concat_path (buf, *directory, mutt_basename (body->filename), 
sizeof (buf));
+      mutt_concat_path (buf, *directory, mutt_basename (tfile), sizeof (buf));
     else
-      strfcpy (buf, body->filename, sizeof (buf));
+      strfcpy (buf, tfile, sizeof (buf));
   }
   else if(body->hdr &&
          body->encoding != ENCBASE64 &&
@@ -464,6 +467,8 @@
          int append = 0;
 
          strfcpy (buf, NONULL (top->filename), sizeof (buf));
+         if (option (OPTATTACHSANITIZE))
+           mutt_sanitize_filename (buf, 0);
          if (mutt_get_field (_("Save to file: "), buf, sizeof (buf),
                                    M_FILE | M_CLEAR) != 0 || !buf[0])
            return;