#!/usr/bin/perl # # Basic mail2news script - takes messages from standard in, rewrites, # and sends to inews to post to newsgroups found in the newsgroups line. # Note: Dumps all headers but basic. # # Stephen K. Gielda 02-26-2004 # Version .2 beta # http://www.cotse.net/mail2news.pl.txt # # Needs Email-Simple: http://search.cpan.org/dist/Email-Simple/ # # To use: add to aliases (ex. mail2news: "|/path/to/mail2news.pl") # # To Do: # - Add blocking based upon newsgroups, from, subject, number of # crossposts, or creative dupe check. # - Add throttling to only allow X posts from X to X group per X time. # # If using as is, you'll need to use your MTA's blocking features when # addressing abuse as filtering has not yet been added. # use Email::Simple; use strict; # Declare Vars my ($tmp_inews, $tmp_post, @a, $text, $mail, $from, $newsgroups, $subject); my ($date, $msgid, $references, $xna, $ct, $mimever, $cte, $xabuse, $body); my ($npath, $inews, $comment, $m2nc, $comments, $organization); ### Variables $npath="your.domain!mail2news"; $inews = "/usr/local/inn/bin/inews"; $tmp_inews = "/tmp/inews.$$"; $tmp_post = "/tmp/post2news.$$"; ## Variable headers, uncomment to set # X-Abuse-To header # $xabuse="your.address\@your.domain"; # X-Comment header # $comment ="Posted via a mail2news gateway. Sender not verified."; # X-Mail-To-News-Contact header # $m2nc = "abuse\@your.domain"; # Organization header # $organization = "Your Organization"; ### END USER CONFIG # Gather e-mail from stdin @a=; # Write e-mail to tmpfile open(DATAFILE, ">".$tmp_post) || die "Oops. $!\n"; print DATAFILE @a; close(DATAFILE); # Read e-mail from tmpfile sub read_file { local $/; local *FH; open FH, shift or die $!; return } $text = read_file($tmp_post); # Parse e-mail $mail = Email::Simple->new($text); $from = $mail->header("From"); $newsgroups=$mail->header("Newsgroups"); $subject=$mail->header("Subject"); $date=$mail->header("Date"); $msgid=$mail->header("Message-ID"); $references=$mail->header("References"); $xna=$mail->header("X-No-Archive"); $ct=$mail->header("Content-Type"); $mimever=$mail->header("MIME-Version"); $cte=$mail->header("Content-Transfer-Encoding"); $comments=$mail->header("Comments"); $body=$mail->body; # remove spaces from newsgroups line $newsgroups=~ s/ //g; # Write e-mail to news spool open(OUTFILE, ">".$tmp_inews) || die "Oops. $!\n"; # Build up the news posting. print OUTFILE "From: $from\n"; print OUTFILE "Comments: $comments\n" if $comments; print OUTFILE "Newsgroups: $newsgroups\n"; print OUTFILE "Subject: $subject\n"; print OUTFILE "Date: $date\n"; print OUTFILE "Message-ID: $msgid\n"; print OUTFILE "References: $references\n" if $references; print OUTFILE "X-No-Archive: $xna\n" if $xna; print OUTFILE "MIME-Version: $mimever\n" if $mimever; print OUTFILE "Content-Type: $ct\n" if $ct; print OUTFILE "Content-Transfer-Encoding: $cte\n" if $cte; print OUTFILE "X-Comment: $comment\n" if $comment; print OUTFILE "Mail-To-News-Contact: $m2nc\n" if $m2nc; print OUTFILE "X-Abuse-To: $xabuse\n" if $xabuse; print OUTFILE "Organization: $organization\n" if $organization; print OUTFILE "Path: $npath\n" if $npath; print OUTFILE "\n"; print OUTFILE $body; print OUTFILE "\n"; close (OUTFILE); # Send to inews system( "$inews -h < $tmp_inews"); # Remove tmp files unlink($tmp_post); unlink($tmp_inews);