Diff for /mail2lj/mail2lj.pl between versions 1.2 and 1.3

version 1.2, 2007/08/12 21:15:36 version 1.3, 2007/08/13 15:06:38
Line 117  my %tr = ( Line 117  my %tr = (
   
 # ------------------------------------------------------------------------ #  # ------------------------------------------------------------------------ #
 # Changed by LG - added parsing of command line.  # Changed by LG - added parsing of command line.
 # Changed by BV - added options cur  # Changed by BV - added options cut
 # ------------------------------------------------------------------------ #  # ------------------------------------------------------------------------ #
 my      %Opt = ();                      # Main options go here  my      %Opt = ();                      # Main options go here
 my      $opt_h ;                        # Help flag  my      $opt_h ;                        # Help flag
 my      $opt_bounces ;                  # Alternative error recipient flag  my      $opt_bounces ;                  # Alternative error recipient flag
 my      $opt_addfrom ;                  # Add the From field to the post  my      $opt_addfrom ;                  # Add the From field to the post
 my      $opt_addfromh ;                 # Add the htmlized From to the post  my      $opt_addfromh ;                 # Add the htmlized From to the post
 my      $opt_ljcut ;                    # Add lj-cut after line number N  
 my      $opt_keepspaces ;               # HTML-encode multiple spaces in e-mail  my      $opt_keepspaces ;               # HTML-encode multiple spaces in e-mail
 my      @opt_taglist ;                  # command-line taglist first goes here  my      @opt_taglist ;                  # command-line taglist first goes here
   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      $Parse = GetOptions( \%Opt,  my      $Parse = GetOptions( \%Opt,
                         'user|u=s',                          'user|u=s',
                         'password|passwd|p=s',                          'password|passwd|p=s',
Line 146  my  $Parse = GetOptions( \%Opt, Line 148  my  $Parse = GetOptions( \%Opt,
                         'bounces|bounce|b=s' => \$opt_bounces,                          'bounces|bounce|b=s' => \$opt_bounces,
                         'addfrom|add-from|from!' => \$opt_addfrom,                          'addfrom|add-from|from!' => \$opt_addfrom,
                         'addfromh|add-fromh|fromh!' => \$opt_addfromh,                          'addfromh|add-fromh|fromh!' => \$opt_addfromh,
                         'ljcut|cut|l=s'=>\$opt_ljcut,                          '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,                          'keep-spaces|keep-space|keepspaces|keepspace|spaces|space!' => \$opt_keepspaces,
                         'help|h' => \$opt_h,                          'help|h' => \$opt_h,
                            );                             );
Line 220  my $mp = new MIME::Parser() or die "new Line 223  my $mp = new MIME::Parser() or die "new
   
 # Changed by LG - changed directory.  # Changed by LG - changed directory.
 # $mp->output_dir("$home/mimetmp") ;  # $mp->output_dir("$home/mimetmp") ;
 $mp->output_dir("/tmp/mimetmp-".$ENV{user}) ;  $mp->output_dir("/tmp/mimetmp-".$ENV{USER}) ;
 mkdir $mp->output_dir if not -d $mp->output_dir ;       # Create it if missing  mkdir $mp->output_dir if not -d $mp->output_dir ;       # Create it if missing
   
 # Get the whole mail.  # Get the whole mail.
Line 614  sub post_me2req { Line 617  sub post_me2req {
         }          }
                   
         #          #
         # Change by BV - added the option to put lj-cut after N          # Change by BV - added the option to put lj-cut after '--cut XX' lines
           #
           # Tweaked by LG - only adding lj-cut if more than $ljcut_delta lines
           # is left in the posting.
         #          #
         if ($opt_ljcut>0) {          if ($opt_ljcut>0) {
               my $nlines = scalar( my @junk=split( /\n/, $hr->{event}, -1) ) - 1;
             my $start=0;              my $start=0;
             for (my $i=0; $i<$opt_ljcut; $i++) {              for (my $i=0; $i<$opt_ljcut; $i++) {
                 $start=index($hr->{event},"\n",$start)+1;                  $start=index($hr->{event},"\n",$start)+1;
Line 624  sub post_me2req { Line 631  sub post_me2req {
                     last;                      last;
                 }                  }
             }              }
             if ($start>0) {              # And insert the lj-cut if not too close to the end of the post.
                 substr($hr->{event}, $start,0) = '<lj-cut>';              if ($start>0 ) {
                   if ( $nlines >= $opt_ljcut+$ljcut_delta ) {
                      my $ljcut = ( $opt_ljcut_text =~ /^\s*$/ ) ?
                                   '<lj-cut>' :
                                   '<lj-cut text="' . $opt_ljcut_text . '">' ;
                      substr($hr->{event}, $start,0) = $ljcut ;
                   } else {
                      print STDERR "'--cut $opt_ljcut' requested, which is " .
                                   "within $ljcut_delta of the total $nlines " .
                                   "lines. Skipping lj-cut.\n" ;
                   }
             }              }
         }          }
   
Line 944  Options: Line 961  Options:
                better preserved in the journal.  The option can be negated                 better preserved in the journal.  The option can be negated
                ('--nospaces').  Default is '--nospaces'.                 ('--nospaces').  Default is '--nospaces'.
   
 --ljcut, --cut, -l CUT  --ljcut NUM, --cut NUM, -l NUM
              add <lj-cut> after CUT lines.                 Inserts '<lj-cut>' after NUM lines of the post content.
                  If the resulting lj-cut happens to be within $ljcut_delta lines from
                  the end of the post, the cut will not be added.
   
   --ljcut-text TEXT, --cut-text TEXT, --cuttext TEXT
                  Text to use as lj-cut text parameter (in <lj-cut text="TEXT">).
                  If the text contains nothing but whitespace, it is ignored.
                  Remember to quote spaces and special characters from the shell.
   
 --charset CHARSET  --charset CHARSET
                This option tells the script that all COMMAND LINE options are                 This option tells the script that all COMMAND LINE options are
Line 955  Options: Line 979  Options:
                utf8).  It also has absolutely no effect on the in-the-body                 utf8).  It also has absolutely no effect on the in-the-body
                keywords (they are also governed by email's charset).  This                 keywords (they are also governed by email's charset).  This
                option is meaningful ONLY for the text that you supply VIA                 option is meaningful ONLY for the text that you supply VIA
                COMMAND LINE (e.g. '-s Subject').                 COMMAND LINE (e.g. '-s Subject' or '--cuttext TEXT').
                                 
 -b xxx\@yyy, --bounces xxx\@yyy  -b xxx\@yyy, --bounces xxx\@yyy
                Normally, if errors occur during posting (e.g. wrong password),                 Normally, if errors occur during posting (e.g. wrong password),

Removed from v.1.2  
changed lines
  Added in v.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>