#!/usr/bin/perl ## Copyright (C) 2003 Jeremy Andrews ## This is free software; you can redistribute it and/or modify it under the ## terms of the GNU General Public License as published by the Free Software ## Foundation; either version 2 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warrenty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for ## more details. ## ## Version 1.03 (October 08, 2003) ## ## Modified: ## 08/2003 - Jeremy Andrews ## - cleaned up lots of false-positive bugs ## - avoid encoding common html tags ## 10/2003 - JA ## - add Rusty Russel ## 11/2003 - JA ## - switch to absolute paths (otherwise emails link to localhost) ## ## Simple perl script prepares page of emails for kerneltrap posting by: ## - inserting separater at top of file for Drupal ## - inserting horizontal rule at top of file ## - wrapping block of emails with
 tags
##  - strips email address (replacing with [email blocked])
##  - encodes < and > with < and > repectively
##  - urlifying http, telnet and ftp links
##  - wraps 'From: Some Body' in '
##  - adds links to KernelTrap interviews, where applicable
##  - strips extraneous email headers
##  - strips all but first 'To:' header
##  - adds standard "related links" block at bottom
##
## Bugs:
##  - Doesn't handle html already part of email bodies well
##     (tends to encode when it shouldn't, and relinks html links, etc...
##  - Doesn't handle From: when name is in quotes
##  - Doesn't handle From: when full name is more than two names
##
## If you're good at perl, and can make this script better...  Please do!
## I can be reached by email at jeremy@kerneltrap.org

## We only allow one 'To:' header
$to=0;

## Begin with  for Drupal, add line break and open 
print "\n
\n";

$urls='(http|telnet|ftp)';
$ltrs = '\w';
$gunk = '/#~:.?+=&%@!\-';
$punc = '.:?\-';
$any = "${ltrs}${gunk}${punc}";
$strip_headers='(^To:|^Sender:|^Cc:|^Organization:|^X-Mailer:|^User-Agent:)';

while (<>) {

  ## Catch the unwrapped ones in the To: line...
  s{
    (
      To:
    )
    (
      ((\s*\w+)(-*))+(\w+)
    )
    (
      (@)((\w+)(\.))+(\w+)
    )
  }{To: $2}x;

  ## Try to strip email addresses...
  s{
    (
      (\s+)(<*)((\w+)(-*))+(\w+)(@)((\w+)(\.))+(\w+)(>*)
    )
  }{ [email blocked]}x;


  ## encode < and >
  if (!(m'
|
|||
|
|

|

||
  • |
    ')) { s//>/gx; } ## add html links s{ \b ( $urls : [$any] +? ) (?= [$punc]* [^$any] | $ ) }{$1}igox; ## Wrap 'From:' line in html tags s{ ( From: (\s+\w+)+ ) }{$1}ix; ## add links to anyone that's been interviewed interview_links("David Weinehall", 2229); interview_links("Marcelo Tosatti", 1880); interview_links("Rusty Russell", 892); interview_links("Nick Piggin", 657); interview_links("Ingo Molnar", 517); interview_links("Daniel Hartmeier", 477); interview_links("Con Kolivas", 465); interview_links("Robert Love", 336); interview_links("Rob Love", 336); interview_links("Marc-Christian Peterson", 293); interview_links("Jordan Hubbard", 278); interview_links("Peter Chubb", 242); interview_links("Larry McVoy", 222); interview_links("William Lee Irwin", 80); interview_links("Rik van Riel", 46); interview_links("Andrew Morton", 10); interview_links("Alan Cox", 9); interview_links("Matthew Dillon", 8); interview_links("Dave Jones", 7); interview_links("Theo de Raadt", 6); interview_links("Neal Walfield", 5); interview_links("John Levon", 4); interview_links("Keith Owens", 3); interview_links("Russell King", 2); ## display the prep'd result, stripping unwanted mail headers if (m/To: /i) { if (!$to) { $to=1; print; } } elsif (!(m/$strip_headers /i)) { print; } } ## display the footer stuff print "
  • \n"; print "\n
    \n"; print "Related Links:
    \n"; print "\n"; ############################# ## Helper functions: sub interview_links ($test) { my $name = shift; my $nid = shift; if (s/From:(\s+)$name/From: $name<\/a>/) { if ($links !~ m/$name/) { $links .= "
  • KernelTrap interview with $name\n"; } } }