Re: [PATCH] attach-sanitize (Was: few questions)
[relocated from mutt-users]
* On 2004.07.07, in <20040707200344.GA14829@xxxxxxxxxxxxxxxxxxxxxxx>,
* "Gary Johnson" <garyjohn@xxxxxxxxxxxxxxx> wrote:
>
> Here it is....
> 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.
Thanks. The idea I had was triggered as I was writing my previous
missive, and considered that there are indeed other characters that
might appear in a Content-type or Content-disposition filename, but
which you wouldn't want in your own save filename. What I decided was
that a tr-like translation map would be nifty.
Here's a derivative of your patch which implements that. (I took the
liberty of including your initials in the name.) I created a new data
structure, struct cmap (for "character map"), which contains the map
as a pair of C strings. The parse_cmap function defines a cmap from
a muttrc file, so that the functionality can be extended to other
potential character maps, should a need arise. mutt_apply_cmap()
performs in-place string translation. I've considered implementing full
"tr -d" and "tr -s" function, but have not yet. Is there interest?
This is (obviously, since it just came up today) not extensively tested,
so I'm not following up in mutt-users now. I updated the SGML doc,
though, so if it's a good idea and it works, it should be fit for CVS.
(I don't have sgmltools, so the docs actually are completely untested.)
Here's some quotation from the manual:
Filename translation map
Usage: save-attach-map from-set to-set
Some operating environments permit the use of file names
that might be uncomfortable to you or difficult to use.
(For example, they might contain spaces, or even forward
slashes.) These awkward file names can be sent in MIME
attachments. When saving such attachments, your default save
file name will match the awkward file name from the sender's
system.
The save-attach-map lets you specify automatic character
translations for attachment operations. It works much
like Unix's tr command, or perl's tr or y operators. The
from-set and to-set parameters specify an ordered set of
characters. If any character in from-set is found in an
attachment's file name, it will automatically be converted
to the corresponding character in to-set before your file
name prompt is presented.
from-set and to-set may contain character ranges. So, for
example, you could force all file names to lowercase and
translate spaces and slashes to underscores with:
save-attach-map "A-Z /" "a-z_"
Note that in this example, the to-set contains fewer
characters than the from-set. This is permissible: the last
character of a "short set" becomes the default translation
for an unmatched member of the other set. In this example,
a space character explicitly maps to an underscore, and a
forward slash implicitly maps to the underscore, because the
underscore becomes a default mapping.
As always, I'm open to any changes people think would improve it.
http://home.uchicago.edu/~dgc/sw/mutt/patch-1.5.6.gj-dgc.save_attach_map.1
--
-D. dgc@xxxxxxxxxxxx NSIT::ENSS
No money, no book. No book, no study. No study, no pass.
No pass, no graduate. No graduate, no job. No job, no money.
T h e U n i v e r s i t y o f C h i c a g o