Thread View: news.software.nntp
1 messages
1 total messages
Started by Steve Snodgrass
Thu, 27 Feb 1997 00:00
mail2inn - a primitive email to news gateway
Author: Steve Snodgrass
Date: Thu, 27 Feb 1997 00:00
Date: Thu, 27 Feb 1997 00:00
97 lines
3709 bytes
3709 bytes
A few weeks ago I started looking for an easy way to gateway email messages
into a newsgroup. I checked out the newsgate package, but it seems to be
outdated and very poorly documented. I also found a perl script called
mail2news (not to be confused with the mail2news binary from the newsgate
package), but it didn't really do what I wanted. So I hacked together my
own perl script to do this, and I thought someone else might find this
usefull so I'm posting it here. All comments and suggestions are welcome.
---CUT HERE---
#!/usr/local/bin/perl
# mail2inn - transform mail messages into a form suitable for posting
# $Id: mail2inn,v 1.3 1997/02/27 19:01:18 ssnodgra Exp $
#
# How to Use
#
# Mail2INN is a very primitive email to news gateway. To use it, you just
# need to set up some aliases in your /etc/aliases (or equivalent) file and
# possibly adjust the variables in the Configurable Parameters section below.
# Here is a sample alias:
#
# mailgw: "| /usr/local/news/bin/mail2inn my.news.group"
#
# The above entry will cause any mail sent to mailgw@your.machine to be
# posted to the my.news.group group. You can also specify multiple groups
# by separating the names with spaces or commas.
#
# Bug Reports and Enhancement Requests
#
# Mail2INN was written by Steve Snodgrass (ssnodgra@fore.com). If you would
# like to report a bug or request a feature, feel free to send email to that
# address. Mail2INN is partially based on a perl script I found called
# mail2news, I'm not sure who wrote it.
#
# Configurable Parameters - you might need to edit these
#
# Location of your inews binary
$inews = "/usr/local/news/bin/inews";
# Location of the logfile - you may need to create this file with 666 perms
$logfile = "/var/log/news/mail2inn.log";
# Temp file used to capture inews errors - should be OK on all systems
$errtmp = "/tmp/m2ierr.$$";
#
# Everything below here can be left alone unless you are hacking the script.
#
# Constants for flock
$LOCK_SH = 1; # Shared (read) lock
$LOCK_EX = 2; # Exclusive (write) lock
$LOCK_NB = 4; # Non-blocking
$LOCK_UN = 8; # Unlock
open(LOGFILE, ">>$logfile") or die "Can't open log file: $!\n";
flock(LOGFILE, $LOCK_EX) or die "Can't lock log file: $!\n";
print LOGFILE "mail2inn starting up: ", scalar(localtime), "\n";
open(INEWS, "| $inews -h 2>$errtmp") or die "Can't run inews: $!\n";
while (<STDIN>) {
last if /^$/; # Look for blank line between header and body
# Take these fields straight from the mail header
print INEWS if /^(Date|From|Subject|Message-ID):/;
print LOGFILE if /^(Date|From|Subject):/;
}
# Take list of newsgroups from parameters
$newsgroups = "";
foreach $ngroup (@ARGV) {
$newsgroups .= $ngroup . ",";
}
chop $newsgroups; # Get rid of extra comma
print INEWS "Newsgroups: $newsgroups\n";
print LOGFILE "Newsgroups: $newsgroups\n";
print INEWS "\n";
print INEWS while <STDIN>; # Send message body
close(INEWS);
$exitval = $?;
open(ERRFILE, "$errtmp");
while (<ERRFILE>) {
print LOGFILE;
}
close(ERRFILE);
unlink($errtmp);
print LOGFILE "\n";
flock(LOGFILE, $LOCK_UN);
close(LOGFILE);
exit $exitval;
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads