From 14b64b556650c4c33f051fe7d23c64743ed8bf08 Mon Sep 17 00:00:00 2001 From: David Bremner Date: Tue, 1 Jul 2008 14:01:18 +0200 Subject: [PATCH] add ytext decoding --- Convert/YText.pm | 25 ++++++++++++++++++++-- filters/expand-iki-address.pl | 6 +++--- filters/test1.eml | 39 +++++++++++++++++++++++++---------- 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/Convert/YText.pm b/Convert/YText.pm index bdd155bbf..0ce9b48f1 100644 --- a/Convert/YText.pm +++ b/Convert/YText.pm @@ -72,9 +72,27 @@ sub encode_num($){ return $str; } -sub encode_ytext($){ +sub decode_str($){ my $str=shift; + my @chars=split "",$str; + my $num=0; + + while (scalar(@chars)>0){ + my $remainder=index $digit_string,$chars[0]; + + # convert this to carp or something + die if ($remainder <0); + $num=$num << 6; + $num+=$remainder; + print STDERR "num=$num\n"; + shift @chars; + } + + return chr($num); +} +sub encode_ytext($){ + my $str=shift; # "=" we use as an escape, and '_' for space $str=~ s/([^a-zA-Z0-9+\-~. ])/"=".encode_num(ord($1))."="/ge; $str=~ s/ /_/g; @@ -84,7 +102,10 @@ sub encode_ytext($){ sub decode_ytext($){ my $str = shift; - $str=~ s/=([a-zA-Z0-9+\-\.])+=/ decode_num($1)/eg; + $str=~ s/=([a-zA-Z0-9+\-\.])+=/ decode_str($1)/eg; + $str=~ s/_/ /g; + + return $str; } =head1 TODO diff --git a/filters/expand-iki-address.pl b/filters/expand-iki-address.pl index e4e541cee..734a50e37 100644 --- a/filters/expand-iki-address.pl +++ b/filters/expand-iki-address.pl @@ -1,16 +1,16 @@ #!/usr/bin/perl use Mail::Internet; -use URI::Escape; +use Convert::YText 'decode_ytext'; my $prefix="-comment-"; my $mail = Mail::Internet->new([<>]); my $to = $mail->get('To:'); -if ($to =~ m/$prefix([A-Za-z0-9\-_]+)\@/){ +if ($to =~ m/$prefix([A-Za-z0-9\.\+\=\-_]+)\@/){ my $key=$1; - my $page=uri_unescape($key); + my $page=decode_ytext($key); $mail->replace('X-IkiWiki-Page:',$page); } diff --git a/filters/test1.eml b/filters/test1.eml index 2dde8a351..ee0c87ec8 100644 --- a/filters/test1.eml +++ b/filters/test1.eml @@ -1,14 +1,31 @@ -From: David Bremner -To: bremner-comment-AHNpdGVtYXA@mailhost.imaginary.org -Subject: I hate your sitemap -Fcc: %sent-mail -User-Agent: EMIKO/1.14.1 (Choanoflagellata) FLIM/1.14.9 (=?ISO-8859-4?Q?Go?= - =?ISO-8859-4?Q?j=F2?=) APEL/10.7 EasyPG/0.0.15 Emacs/22.2 - (i486-pc-linux-gnu) MULE/5.0 (SAKAKI) -MIME-Version: 1.0 (generated by EMIKO 1.14.1 - "Choanoflagellata") -Content-Type: text/plain; charset=US-ASCII +From bremner@unb.ca Tue Jul 01 08:47:05 2008 +Return-path: +Envelope-to: bremner-comment-blog=v=posts=v=user_level_NetworkManager_dispatcher@pivot.cs.unb.ca +Delivery-date: Tue, 01 Jul 2008 08:47:05 -0300 +Received: from [141.44.229.26] (helo=rocinante.cs.unb.ca) + by pivot.cs.unb.ca with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) + (Exim 4.69) + (envelope-from ) + id 1KDeK9-0006DB-7Y + for bremner-comment-blog=v=posts=v=user_level_NetworkManager_dispatcher@pivot.cs.unb.ca; Tue, 01 Jul 2008 08:47:05 -0300 +Received: from bremner by rocinante.cs.unb.ca with local (Exim 4.69) + (envelope-from ) + id 1KDeJF-0007AA-Hp + for bremner-comment-blog=v=posts=v=user_level_NetworkManager_dispatcher@pivot.cs.unb.ca; Tue, 01 Jul 2008 13:46:09 +0200 +From: David Bremner +Organization: University of New Brunswick, Alpha Centurai Campus +To: bremner-comment-blog=v=posts=v=user_level_NetworkManager_dispatcher@pivot.cs.unb.ca +Subject: this is a test of the postal plugin +Date: Tue, 1 Jul 2008 13:46:09 +0200 +User-Agent: KMail/1.9.9 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: 7bit +Content-Disposition: inline +Message-Id: <200807011346.09526.bremner@unb.ca> +X-Host-Lookup-Failed: Reverse DNS lookup failed for 141.44.229.26 (failed) +X-Sender-Verified: bremner@unb.ca -It is stupid. -Why don't you put more work into your blog? -- 2.26.2