#!/usr/local/bin/perl # $Id: retag.pl 69 2008-03-29 07:29:20Z dleigh $ # # Takes a mail/nntp/similar plaintext message and adds a quote after your # signature (assumies ~/.signature). Quote number and attribution (if present) # are placed in the headers. # # Quotes are taken from ~/.taglines, which should be in strfile format. # Basically, the quotes are seperated with '%' on a blank line. An attribution # line (with --) in the quote will be added to the headers instead of the # signature. # # Usage: retag [] # # If a search string is specified retag will match it against both the # attribution and the quote. If no matches are found there will be no quote # and you will get the quote header "1 of 0"... # # ----- # # Sample .taglines (without the hashes): # # I will NEVER EVER EVER SEE ANOTHER PETER PAN MOVIE # % # "Trombonists do it in 7 positions" # -- alt.music.trombone # % # FURRIES ARE PEOPLE TOO! # (and animals) # never speaking to you again # % # Because it destroys the flow of conversation. # Why is top-posting wrong? # -- clover_kicker # # ----- # # Based on retag (also a perl script) by Emil Mikulic. # See http://dmr.ath.cx/stuff/code/quote.c # # ----- # # Copyright (c) 2004-2005 Dylan Leigh. # # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # 3. Modified versions must be plainly marked as such, and must not be # misrepresented as being the original software. # # 4. The names of the authors or copyright holders must not be used to endorse # or promote products derived from this software without prior written # permission. # # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # # ----- # use strict; my $tagfile = $ENV{'HOME'}."/.taglines"; my $sigfile = $ENV{'HOME'}."/.signature"; #parse commandline args, nab search string if exist #atm search is the only argument. my $search = ""; if (scalar @ARGV == 1) { $search = $ARGV[0]; } # --- parse taglines my (@taglines, @tagline_attribs); open TAGS, "<$tagfile" or die $!; @taglines = ; close TAGS; my @tmp = split /%\n/, join "", @taglines; #my @tmp = split /\n/, join "", @taglines; #use this for single lines undef @taglines; foreach (@tmp) { next if $_ eq ""; #search argument added 2005-06-15 if ($search ne "") { next unless /$search/; } my @lines = split /\n/m, $_; my $attr = ""; if ($lines[-1] =~ /^-- /) { $attr = substr(pop @lines, 3); } my ($quote) = join "\n", @lines; push @taglines, $quote; push @tagline_attribs, $attr; } # --- parse message from stdin my ($header, $body); while ($_ = ) { last if $_ eq "\n"; $header .= $_ unless /^X-Quote/; } while ($_ = ) { last if $_ eq "-- \n"; $body .= $_; } # -- add signature and stuff open SIG, "<$sigfile" or die $!; my @sig = ; close SIG; # --- reconstruct message my $total = scalar @taglines; my $index; $index = int(rand $total); print $header; if ($search eq "") { print "X-Quote: ".($index+1)." of $total\n"; } else { print "X-Quote: ".($index+1)." of $total matching \"$search\"\n"; } print "X-Quote-Attribution: ".$tagline_attribs[$index]."\n" unless $tagline_attribs[$index] eq ""; print "\n"; print "$body"; print "-- \n"; #add sig bit here print($_) for @sig; print $taglines[$index]."\n"; # vim:set tabstop=3 shiftwidth=3 textwidth=78 expandtab: