]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commitdiff
create Convert::YText
authorDavid Bremner <bremner@unb.ca>
Tue, 1 Jul 2008 07:53:11 +0000 (09:53 +0200)
committerDavid Bremner <bremner@unb.ca>
Tue, 1 Jul 2008 07:53:11 +0000 (09:53 +0200)
Convert/YText.pm [new file with mode: 0644]
IkiWiki/Plugin/postal.pm
encoding.pl [deleted file]
filters/expand-iki-address.pl

diff --git a/Convert/YText.pm b/Convert/YText.pm
new file mode 100644 (file)
index 0000000..a2b2193
--- /dev/null
@@ -0,0 +1,119 @@
+package Convert::YText;
+
+use strict;
+use warnings;
+use vars qw/$VERSION @ISA @EXPORT_OK/;
+@ISA = 'Exporter';
+@EXPORT_OK = qw( encode_ytext decode_ytext );
+
+use encoding "utf-8";
+
+
+$VERSION=0.1;
+
+=head1 NAME
+
+Convert::YText - Quotes strings suitably for rfc2822 local part
+
+=head1 VERSION
+
+Version 0.1 B<BETA>
+
+=head1 SYNOPSIS
+
+use Convert::YText qw(encode_ytext decode_ytext);
+
+$encoded=encode_ytext($string);
+$decoded=decode_ytext($encoded);
+
+($decoded eq $string) || die "this should never happen!";
+
+
+=head1 DESCRIPTION
+
+Convert::YText converts strings to and from "YText", a format inspired
+by xtext defined in RFC1894, the MIME base64 and quoted-printable
+types (RFC 1394).  The main goal is encode a UTF8 string into something safe
+for use as the local part in an internet email address  (RFC2822).
+
+According to RFC 2822, the following non-alphanumerics are OK for the
+local part of an address: "!#$%&'*+-/=?^_`{|}~". On the other hand, it
+seems common in practice to block addresses having "%!/|`#&?" in the
+local part.  The idea is to restrict ourselves to basic ASCII
+alphanumerics, plus a small set of printable ASCII, namely "=_+-~.".
+Spaces are replaced with "_", the characters "A-Za-z0-9.\+\-~" encode
+as themselves, and everything else is written "=USTR=" where USTR is
+the base64 (using "A-Za-z0-9\+\-\." as digits) encoding of the unicode
+character code.
+
+The characters '+' and '-' are pretty widely used to attach suffixes
+(although usually only one works on a given mail host). It seems ok to
+use '+-', since the first marks the beginning of a suffix, and then is
+a regular character. The character '.' also seems mostly permissable.
+
+
+=head1 METHODS
+
+=cut
+
+our $digit_string="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-.";
+our @digits=split "",$digit_string;
+
+sub encode_num($){
+    my $num=shift;
+    my $str="";
+
+    while ($num>0){
+       $remainder=$num % 64;
+       $num=$num >> 6;
+       
+       $str = $digits[$remainder].$str;
+    }
+    
+    return $str;
+}
+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;
+
+    return $str;
+};
+
+sub decode_ytext($){
+    my $str = shift;
+    $str=~ s/=([a-zA-Z0-9+\-\.])+=/ decode_num($1)/eg;
+}
+
+=head1 TODO
+
+Finish doc. Write tests.
+
+=head1 AUTHOR
+
+David Bremner, E<lt>bremner@unb.caE<gt>
+
+=head1 COPYRIGHT
+
+Copyright (C) 2008 David Bremner.  All Rights Reserved.
+
+This module is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=head1 CAVEAT
+
+This module is currently in B<BETA> condition.  It should not be used
+in a production environment, and is released with no warranty of any
+kind whatsoever.
+
+Corrections, suggestions, bugreports and tests are welcome!
+
+=head1 SEE ALSO
+
+L<MIME::Base64>, L<MIME::Decoder::Base64>, L<MIME::Decoder::QuotedPrint>.
+
+=cut
+
+1;
index 57f87914841de230c53b1c51b7456848f0db6404..bc34102802499d3d67009410ece04e6cf83730dc 100644 (file)
@@ -31,8 +31,7 @@ package IkiWiki::Plugin::postal;
 use warnings;
 use strict;
 use IkiWiki 2.00;
-use Compress::LZF ;
-use MIME::Base64::URLSafe; 
+
 
 \f
 sub import
@@ -43,7 +42,7 @@ sub import
 sub pagetemplate (@)
 {
     my %params = @_;
-    my $page = $params{page};
+    my $page = IkiWiki::pagetitle($params{page});
     my $destpage = $params{destpage};
 
     my $template = $params{template};
@@ -52,7 +51,7 @@ sub pagetemplate (@)
        ! defined $template->param ('comments'))
     {
        debug("adding comments to ".$page);
-       my $key = urlsafe_b64encode(compress($page));
+       my $key = uri_escape_utf8($page);
        debug("using key ".$key);
 
 
@@ -74,4 +73,18 @@ sub pagetemplate (@)
     }
 }
 \f
-1
+sub strict_rfc2822_escape($){
+# according to rfc 2822, the following non-alphanumerics are OK for
+# the local part of an address: "!#$%&'*+-/=?^_`{|}~". On the other
+# hand, a fairly common exim configuration, for example, blocks
+# addresses having "@%!/|`#&?" in the local part.  '+' and '-' are
+# pretty widely used to attach suffixes (although usually only one
+# works on a given mail host).
+    my $str=shift;
+
+    $str=s/[^a-zA-Z0-9+\-~_]/= ord($1)/;
+
+};
+
+
+1;
diff --git a/encoding.pl b/encoding.pl
deleted file mode 100644 (file)
index 9e8a896..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-use encoding "utf-8";
-
-our @digits=split "","ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-";
-
-sub encode_num($){
-    my $num=shift;
-    my $str="";
-
-    while ($num>0){
-       $remainder=$num % 64;
-       $num=$num >> 6;
-       
-       $str = $digits[$remainder].$str;
-    }
-    
-    return $str;
-}
-sub strict_rfc2822_escape($){
-# according to rfc 2822, the following non-alphanumerics are OK for
-# the local part of an address: "!#$%&'*+-/=?^_`{|}~". On the other
-# hand, a fairly common exim configuration, for example, blocks
-# addresses having "@%!/|`#&?" in the local part.  '+' and '-' are
-# pretty widely used to attach suffixes (although usually only one
-# works on a given mail host). It seems ok to use '+-', since the first 
-# marks the beginning of a suffix, and then is a regular character.
-#  '.' also seems mostly permissable
-    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;
-
-    return $str;
-};
-
-while(<>){
-    chomp();
-    print strict_rfc2822_escape($_);
-}
-
index a11e6d9d0b04f9503efa99159268a0f1667dcaad..e4e541cee08fd43eb18790d74b499643d0e3a172 100644 (file)
@@ -1,8 +1,7 @@
 #!/usr/bin/perl
 
 use Mail::Internet;
-use Compress::LZF ;
-use MIME::Base64::URLSafe; 
+use URI::Escape;
 
 my $prefix="-comment-";
 my $mail = Mail::Internet->new([<>]);
@@ -11,7 +10,7 @@ my $to = $mail->get('To:');
 
 if ($to =~ m/$prefix([A-Za-z0-9\-_]+)\@/){
     my $key=$1;
-    my $page=decompress(urlsafe_b64decode($key));
+    my $page=uri_unescape($key);
     $mail->replace('X-IkiWiki-Page:',$page);
 }