#!/usr/bin/perl use strict; use warnings; use Mail::Header; # borrowed from mutt: # http://www.mutt.org/doc/manual/manual-6.html#quote_regexp my $quote_regex = qr/([ \t]*[|>:}#])/; my $header = new Mail::Header; my @raw_lines = <>; $header->header(\@raw_lines); my $tagged_message = ''; $tagged_message .= $header->as_string(); foreach my $raw_line (@raw_lines) { chomp $raw_line; my $tagged_line = ''; if( my @quote_chars = ($raw_line =~ m/$quote_regex/g) ) { $raw_line =~ s#$quote_regex##g; # we can strip out the quote chars now my $quote_depth = scalar(@quote_chars); $tagged_line = "$raw_line\n"; } else { $tagged_line = "$raw_line\n"; } $tagged_message .= $tagged_line; } print $tagged_message;