1
0
mirror of https://github.com/imapsync/imapsync.git synced 2024-11-17 00:02:29 +01:00
imapsync/W/learn/imap_utf7_decode

30 lines
773 B
Plaintext
Raw Normal View History

2014-11-19 23:16:16 +01:00
#!/usr/bin/perl
use Unicode::String ;
while (<>) {
chomp ;
#push( @result, sprintf( "%33s %s\n", $_, decode( $_ ) ) ) ;
push( @result, sprintf( "%s\n", imap_utf7_decode( $_ ) ) ) ;
}
print @result ;
# http://cpansearch.perl.org/src/FABPOT/Unicode-IMAPUtf7-2.01/lib/Unicode/IMAPUtf7.pm
sub imap_utf7_decode {
my ($s) = @_;
# Algorithm
# On remplace , par / dans les BASE 64 (, entre & et -)
# On remplace les &, non suivi d'un - par +
# On remplace les &- par &
$s =~ s/\+/PLUSPLACEHOLDER/g;
$s =~ s/&([^,&\-]*),([^,\-&]*)\-/&$1\/$2\-/g;
$s =~ s/&(?!\-)/\+/g;
$s =~ s/&\-/&/g;
$s =~ s/PLUSPLACEHOLDER/+-/g;
return( Unicode::String::utf7( $s )->utf8 ) ;
}