Re: Forms, mailto-URLs, and The Right Thing

Steinar Bang (steinarb@falch.no)
Mon, 30 Jan 1995 17:04:43 +0100


>>>>> Rob Hartill <hartill@ooo.lanl.gov> writes:

> I'd probably switch to a mailto: form, if only Netscape behaved and
> sent plain text instead of URL encoded mail.

> Why not URL decode on the mail server ? - it's not my mailserver. I
> can't keep asking for it to be changed to accept different types of
> mangled data.

Even if you can't/won't mess with the local MTA, you can still use
something like procmail [1] to process your mail, here are a few lines
from my ~/.procmailrc file:

:0
* ^Content-Type: *application/x-www-form-urlencoded
{
  :0 fbw
  | $HOME/src/perl/decode-url.pl

     :0 Afhw
     | formail -I "Content-Type: x-decoded-url"
}

decode-url.pl is a tiny perl script (included at the end of this
message) which reads the old message body on stdin, and writes a new
message body on stdout. It needs a little polishing (heck! a *lot* of
polishing), but the basics are there.

- Steinar

[1] ftp://ftp.informatik.rwth-aachen.de/pub/packages/procmail/procmail.tar.gz

Here's decode-url.pl:

#!/local/bin/perl
# 
# $Id: decode-url.pl,v 1.1 1995/01/30 13:57:41 steinarb Exp $
#

$query_string = <> ;
@value_pairs = split(/&/, $query_string) ;
foreach $vp (@value_pairs) {
    local($field, $fval) = split(/=/, $vp) ;
    push(@fields,$field) ;
    $values{$field} = &unEscape($fval) ;
}


foreach $f (@fields) {
    print "$f: $values{$f}\n" ;
}

# SB 940909
#
# This subroutine returns the argument with "+" replaced with " "
# and hex sequences ("%xx") with the character they represent.
sub unEscape {
    local($s) = @_ ;
    $s =~ tr/+/ /d ;
    $s =~ s/%([0-9A-F][0-9A-F])/pack("H2",$1)/ge ;
    $s ;
}