procmail
[Top] [All Lists]

Re: ideas on splitting mail saved by Outlook to IMAP folder

2006-05-29 09:10:12
G.W. Haywood schreef:


Not a Perl list, but I just couldn't resist.

======================================================================
#!/usr/bin/perl
# convert.pl

# Reads stdin, does some minor editing, outputs to stdout.

Missing:

  use strict ;
  use warnings ;


my $line_is_not_empty = 1;
while(<>)                                   # Read the input

Change that to

  while (my $line = <>)

(but you could as well drop $line and use $_ all the way)


{
    my $line = $_ ;

Now that last line can go.


    if( $line =~ m/^XXXXXXXXXXXXXXXXXX / )  # Ignore silly lines
    {
      next;
     }

That if-block be replaced by the line

      next if line =~ /^XXXXXXXXXXXXXXXXXX / ; Ignore



    $line .= "\n";                          # Add newline

Can go, because $line already has a "\n" at the end.


    $line =~ s/\r//;                        # Remove any CR

Change to

  s/\r+\n$/\n/, s/\r/ /g for $line ;


    $line =~ s/\n\n/\n/;                    # Remove duplicate LF

That last line can go.


    if( $line =~ m/^\n$/s )                 # Clear the flag
    {
      $line_is_not_empty = 0;
    }
    else
    {
      $line_is_not_empty = 1;
    }

Replace that if/else-block with the line:

     $line_is_not_empty = ( $line =~ /./ ) ;


    print $line;                            # Output the line
}
if( $line_is_not_empty ) { print "\n"; }    # Add a newline if flag


So the whole thing becomes:



#!/usr/bin/perl
# convert.pl
# Reads stdin, does some minor editing, outputs to stdout.


  use strict ;
  use warnings ;

  my $saw_empty_line = 0;

  while ( <> )                              # read line
  {
    next if /^XXXXXXXXXXXXXXXXXX / ;        # skip sillies
    s/\r+\n$/\n/, s/\r/ /g ;                # pacify any CRs
    $saw_empty_line = /^\n/ ;
    print ;                                 # write line
  }
  print "\n" unless $saw_empty_line ;       # add a newline

(untested)

-- 
Groet, Ruud


____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail