mailpost crosspost patch
Kenichi Okada
okada at opaopa.org
Thu Jul 26 18:09:54 UTC 2001
Hi, all
This patch contains a bug fix and new feature for crosspost.
The follow command did not work.
~news/bin/mailpost local.test1 local.test2
The new feature is for the crosspost of *ML2news*.
For example, if we post one mail to two MLs which mailpost respectively,
MLs call mailpost twice and later one will be reject for Duplicate.
The patch provides an additional option '-c wait-time'.
If you set '-c', mailpost waits for the wait-time seconds and
checks later messages which have the same message-id.
If mailpost receives the plural messages, it do crosspost.
--
Kenichi Okada
mailto:okada at opaopa.org
*** inn-2.3.2/frontends/mailpost.in-ORIG Wed Jun 20 15:48:18 2001
--- inn-2.3.2/frontends/mailpost.in Fri Jul 27 01:59:44 2001
***************
*** 19,28 ****
--- 19,30 ----
my $debugging = 0 ;
my $tmpfile ;
+ my $tmpfile2 ;
my $msg ;
END {
unlink ($tmpfile) if $tmpfile ; # incase we die()
+ unlink ($tmpfile2) if $tmpfile2 ; # incase we die()
}
my $LOCK_SH = 1;
***************
*** 37,46 ****
openlog $usage, "pid", $inn::syslog_facility ;
$usage .= "[ -r addr ][ -f addr ][ -a approved ][ -d distribution ]" .
! " [ -m mailing-list ][ -b database ][ -o output-path ] newsgroups" ;
! use vars qw($opt_r $opt_f $opt_a $opt_d $opt_m $opt_b $opt_n $opt_o $opt_h) ;
! getopts("hr:f:a:d:m:b:no:") || die "usage: $usage\n" ;
die "usage: $usage\n" if $opt_h ;
#
--- 39,48 ----
openlog $usage, "pid", $inn::syslog_facility ;
$usage .= "[ -r addr ][ -f addr ][ -a approved ][ -d distribution ]" .
! " [ -m mailing-list ][ -b database ][ -o output-path ] [ -c wait-time ] newsgroups" ;
! use vars qw($opt_r $opt_f $opt_a $opt_d $opt_m $opt_b $opt_n $opt_o $opt_h $opt_c) ;
! getopts("hr:f:a:d:m:b:no:c:") || die "usage: $usage\n" ;
die "usage: $usage\n" if $opt_h ;
#
***************
*** 104,110 ****
push @errorText, "((mailing_list: $mailing_list))\n";
}
! $newsgroups = join ", ", @ARGV ;
die "usage: $0 newsgroup [newsgroup]\n" unless $newsgroups;
--- 106,112 ----
push @errorText, "((mailing_list: $mailing_list))\n";
}
! $newsgroups = join ",", @ARGV ;
die "usage: $0 newsgroup [newsgroup]\n" unless $newsgroups;
***************
*** 350,358 ****
my %DATABASE ;
dbmopen %DATABASE, $Database, 0666 || mailArtAndDie ("can't dbmopen $lockfile: $!");
! exit 0 if defined $DATABASE{$message_id}; # already seen.
! $DATABASE{$message_id} = sprintf "%d.%s", time, 'mailpost' ;
mailArtAndDie ("TAS didn't set $message_id") unless defined $DATABASE{$message_id};
--- 352,368 ----
my %DATABASE ;
dbmopen %DATABASE, $Database, 0666 || mailArtAndDie ("can't dbmopen $lockfile: $!");
! if (defined $DATABASE{$message_id}) {
! exit 0 if (!$opt_c) ;
!
! ## crosspost -c
! $newsgroups = append_newsgroups($DATABASE{$message_id}, $newsgroups) ;
! syslog "err", "crosspost $newsgroups\n" if $debugging ;
! }
!
! #$DATABASE{$message_id} = sprintf "%d.%s", time, 'mailpost' ;
! $DATABASE{$message_id} = $newsgroups ;
mailArtAndDie ("TAS didn't set $message_id") unless defined $DATABASE{$message_id};
***************
*** 361,366 ****
--- 371,444 ----
flock LOCKFILE, $LOCK_UN || mailArtAndDie ("can't unlock $lockfile: $!");
close LOCKFILE ;
+ ## for crosspost
+
+ if ($opt_c) {
+ sleep $opt_c ;
+
+ open LOCKFILE, "<$lockfile" ||
+ open LOCKFILE, ">$lockfile" ||
+ mailArtAndDie ("can't open $lockfile: $!") ;
+
+ my $i ;
+ for ($i = 0 ; $i < 5 ; $i++) {
+ flock LOCKFILE, $LOCK_EX && last ;
+ sleep 1 ;
+ }
+ mailArtAndDie ("can't lock $lockfile: $!") if ($i == 5) ;
+
+ my $umask_bak = umask();
+ umask(000);
+ dbmopen %DATABASE, $Database, 0666 || mailArtAndDie ("can't dbmopen $lockfile: $!");
+ umask($umask_bak);
+
+ my $dup = undef ;
+ syslog "err", "check " . $DATABASE{$message_id} . " : $newsgroups\n" if $debugging ;
+ $dup = 1 if ($DATABASE{$message_id} ne $newsgroups) ;
+
+ dbmclose %DATABASE || mailArtAndDie ("can't dbmclose $lockfile: $!") ;
+
+ flock LOCKFILE, $LOCK_UN || mailArtAndDie ("can't unlock $lockfile: $!");
+ close LOCKFILE ;
+
+ if (defined($dup)) {
+ syslog "err", "mismatch $newsgroups\n" if $debugging ;
+ exit 0 ;
+ }
+
+ # replace Newsgroups
+ open TMPFILE, "$tmpfile" || mailArtAndDie ("cannot open temp file ($tmpfile): $!") ;
+ $tmpfile2 = sprintf "%s/mailpost-crosspost.%d.%d", $Tmpdir, time, $$ ;
+ if ( !open TMPFILE2, ">$tmpfile2") {
+ $msg = "cant open temp file ($tmpfile2): $!" ;
+ $tmpfile2 = undef ;
+ die $msg ;
+ }
+ for (;;) {
+ $_ = <TMPFILE> ;
+ chomp ;
+ last if defined($_) && /^$/ ;
+
+ if (/^Newsgroups:\s*/sio) {
+ printf TMPFILE2 "Newsgroups: %s\n", $newsgroups ;
+ next ;
+ }
+ print TMPFILE2 "$_\n" ;
+ }
+ printf TMPFILE2 "\n" ;
+
+ my $rest;
+ $rest .= $_ while (<TMPFILE>);
+ $rest =~ s/\n*$/\n/g; # Remove trailing \n except very last
+
+ print TMPFILE2 $rest;
+ close TMPFILE2 ;
+ close TMPFILE ;
+ rename $tmpfile2, $tmpfile || mailArtAndDie ("cannot rename $tmpfile2 $tmpfile: $!") ;
+ $tmpfile2 = undef ;
+
+ }
+
if (!open INEWS, "$WhereTo < $tmpfile 2>&1 |") {
mailArtAndDie ("cant start: $WhereTo: $!") ;
}
***************
*** 456,458 ****
--- 534,551 ----
return $str;
}
+ sub append_newsgroups ($$) {
+ my (@orig) = split(/,/,$_[0]) ;
+ my (@new) = split(/,/,$_[1]) ;
+ my $newsgroup ;
+
+ foreach $newsgroup (@new) {
+ if ( !grep($_ eq $newsgroup, at orig)) {
+ push @orig, $newsgroup ;
+ } else {
+ # mailArtAndDie ("Duplicated Newsgroups: $newsgroup") ;
+ }
+ }
+ return join ",", @orig ;
+
+ }
More information about the inn-patches
mailing list