--- mail2lj/mail2lj.pl 2007/08/14 20:59:15 1.7 +++ mail2lj/mail2lj.pl 2007/08/31 17:02:46 1.8 @@ -30,6 +30,9 @@ # original From: address). This is convenient when you want to notify # script maintainer instead of the poster (exactly what I need). # +# Changes by Boris Veytsman - added --cut option +# +# Changes by LG: added --obfuscate option to protect e-mails in the body. # # NB: to generate MD5 hash of your password, use the following command: # perl -MDigest::MD5 -e 'print Digest::MD5::md5_hex("yourpassword")."\n"' @@ -42,8 +45,6 @@ # Original script seems to be distributed as freeware, so I stick to that # decision. No warranty whatsoever, of course - use at your own risk ;-). # -# Changes by Boris Veytsman - added --cut option -# # ------------------------------------------------------------------------ use strict ; @@ -113,6 +114,10 @@ my %tr = ( 'À' => 'yu', 'Ñ' => 'ya' ); +# What to convert '@' to when obfuscating e-mail addresses (in '--add-from' +# and/or '--obfuscate' modes. +my $newdog = '[_@_]'; + # ------------------------------------------------------------------------ # # End configuration settings. # ------------------------------------------------------------------------ # @@ -132,6 +137,7 @@ my @opt_taglist ; # command-line tag my $opt_ljcut ; # Add lj-cut after line number N my $ljcut_delta = 5 ; # No lj-cut if less lines left after it my $opt_ljcut_text ; # A text for lj-cut. +my $opt_obfuscate ; # Obfuscate e-mail addresses in body my $Parse = GetOptions( \%Opt, 'user|u=s', 'password|passwd|p=s', @@ -155,6 +161,7 @@ my $Parse = GetOptions( \%Opt, 'ljcut|lj-cut|cut|l=i'=>\$opt_ljcut, 'ljcut-text|lj-cut-text|cut-text|ljcuttext|cuttext=s'=>\$opt_ljcut_text, 'keep-spaces|keep-space|keepspaces|keepspace|spaces|space!' => \$opt_keepspaces, + 'obfuscate|obfu|o!' => \$opt_obfuscate, 'help|h' => \$opt_h, ); @@ -544,6 +551,13 @@ sub post_body2href { } elsif ($var =~ /^no-?tags?$/ || $var eq "no-?taglist") { $req_data->{prop_taglist} = "" if $val =~ /^\s*((on)|(yes))\s*$/i ; + # Changed by LG - added 'Obfuscate' option to protect e-mail + # addresses in the body of the message. + } elsif ($var =~ /^obfuscate$/ ) { + $val = 1 if $val =~ /^\s*((on)|(yes))\s*$/i ; + $val = 0 if $val =~ /^\s*((off)|(no))\s*$/i ; + $opt_obfuscate = $val ; + # Anything else - just assign. } else { $req_data->{$var} = $val ; @@ -607,6 +621,8 @@ sub post_me2req { # Changed by LG. my $from = hdr2utf8($me->get('From') || "", $charset) ; chomp $from ; + my $olddog_utf8 = str2utf8("\@", "ISO-8859-1") ; # @ in utf + my $newdog_utf8 = str2utf8($newdog, "ISO-8859-1") ; # obfuscated in utf my $hr = href2utf8(post_body2href($mebh->open("r")), $charset) ; my $req = new HTTP::Request('POST', $post_uri) or @@ -626,6 +642,15 @@ sub post_me2req { # Changed by LG - removed prefixing. # $hr->{subject} = "[mail2lj] " . $hr->{subject} ; + + # Changed by LG - added option to obfuscate all e-mail addresses in + # the body of mail messages. + if ( $opt_obfuscate ) { + $hr->{event} =~ + s/\b([-+_.\w]+)($olddog_utf8)([-_.\w]+)\b/$1${newdog_utf8}$3/g ; + } + + # Changed by LG - added options to add the plain or HTML-ized 'From' # field to the posted message. # @@ -652,10 +677,10 @@ sub post_me2req { . str2utf8("\n\n", "ISO-8859-1") ; } - # Obfuscate the address. - my $olddog = str2utf8("\@", "ISO-8859-1") ; # @ in utf8 - my $newdog = str2utf8("[_\@_]", "ISO-8859-1") ; # [_@_] in utf8 - $added_from =~ s/$olddog/$newdog/g ; # Obfuscate + # This address is alway obfuscated (independently of the + # '--obfuscate' option which only governs addresses _already_ + # in the body. + $added_from =~ s/$olddog_utf8/$newdog_utf8/g ; # Obfuscate $hr->{event} = $added_from . $hr->{event} ; # And append } @@ -1005,6 +1030,9 @@ Options: any HTML-formatting - see '--fromh' for that). For slight antispam protection, '\@' is replaced by '[_\@_]'. The option can be negated ('--nofrom'). Default is '--nofrom'. + Note: this option is independent from '--obfuscate' (i.e. the + prepended From is always obfuscated, even if the rest of the + message is not). --fromh, --addfromh Same as '--from', but uses HTML-markup to highlight inserted @@ -1012,6 +1040,12 @@ Options: nice for mailing list -> Livejournal crossposting. The option can be negated ('--nofromh'). Default is '--nofromh'. +-o, --obfuscate + Obfuscate all e-mail addresses that are present in the body + of the message. For slight antispam protection, '\@' in these + addresses is replaced by '[_\@_]'. The option can be negated + ('--noobfuscate'). Default is '--noobfuscate'. + --spaces, --keepspaces Normally the script does not change original message text, and all of it is preserved in the body of resulting LJ post.