]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - Convert/YText.pm
modify setup for vcs (git) enable test-wiki
[git.ikiwiki.info.git] / Convert / YText.pm
index bdd155bbf2ba808f41228ea518b5f41e08f6723a..21955a87bed802440a47e03f9444e04dcfeabb5f 100644 (file)
@@ -41,10 +41,10 @@ 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.
+Spaces are replaced with "_", "/" 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
@@ -57,6 +57,9 @@ a regular character. The character '.' also seems mostly permissable.
 =cut
 
 our $digit_string="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-.";
+
+our $valid_rex=qr{[A-Za-z0-9\+\-\.\=\_\~]+};
+
 our @digits=split "",$digit_string;
 
 sub encode_num($){
@@ -72,19 +75,42 @@ 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/([^a-zA-Z0-9+\-\/. ])/"=".encode_num(ord($1))."="/ge;
+    
+    $str=~ s|/|~|g;
     $str=~ s/ /_/g;
-
+    
     return $str;
 };
 
 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;
+    $str=~ s|~|/|g;
+    return $str;
 }
 
 =head1 TODO