--- mailpost.org	Mon Nov 22 16:30:08 1999
+++ mailpost	Fri Oct 20 15:09:39 2000
@@ -51,7 +51,8 @@
 my $Sendmail = $inn::mta ;
 my $Submit = $inn::inews . " -S -h";
 my $Database = ($opt_b || $inn::pathtmp) . "/mailpost-msgid" ;
-my $Maintainer = $inn::newsmaster || "usenet" ; 
+my $Maintainer = "newserror" ; 
+# my $Maintainer = $inn::newsmaster || "usenet" ; 
 my $WhereTo = $opt_o || $Submit ;
 my $Mailname = $inn::fromhost ;
 
@@ -83,6 +84,8 @@
 my $mailing_list = undef;
 my $references = undef;
 my @errorText = ();
+my $cc = undef;
+my $reply_to = undef;
 
 if ($opt_r || $opt_f) {
     $path = $opt_r || $opt_f ;
@@ -123,8 +126,9 @@
 my $date = undef;
 my $hdr = undef;
 my $txt = undef;
+my $organization = "Newsgate at Example Corp., Berlin, Germany";
 my $message_id ;
-my $subject = "(NONE)";
+my $subject = 'Subject set by mailpost '.scalar(localtime);
 
 $_ = <STDIN>;
 if (!$_) {
@@ -181,11 +185,22 @@
     next if /^Approved:\s/sio && defined($approved);
     next if /^Distribution:\s/sio && defined($distribution);
 
-    if (/^(Organization|Distribution):\s*/sio) {
+    if (/^Distribution:\s*/sio) {
 	$real_news_hdrs .= "$_\n";
 	next;
+      }
+
+    if (/^Organization:\s*/sio){
+       $organization = $';
+       next;
     }
 
+## if there is no subject, then give it the subject "Subject set by mailpost" with date
+    if (/^Subject:.?$/sio) {
+       $subject = 'Subject set by mailpost '.scalar(localtime);
+       next;
+    }
+    
     if (/^Subject:\s*/sio) {
 	$subject = $';
 	next;
@@ -193,6 +208,23 @@
 
     if (/^Message-ID:\s*/sio) {
 	$message_id = $';
+	# get from inside angle brackets:
+	if ( $message_id =~ /\<([^\>]*)\>/sio ){
+	  $message_id = $1;
+	  # strip trailing dot if there:
+	  $message_id =~ s/\.$//sio;
+
+	  # split into 'local part' and domain
+	  # some mailers set no domain
+	  # some even more dumb mailers set two '@'s as was rumored...
+	  $message_id =~/(.*)\@+([^\@]*)/sio;
+	  my $local = $1;
+	  $local =~ s/\@/\_/sio;
+	  my $domain = $2;
+	  $domain = $Mailname if $domain eq "";
+	  
+	  $message_id = '<'.$local.'@'.$domain.'>';
+	}
 	next;
     }
 
@@ -223,6 +255,16 @@
 	next;
     }
 
+    if (/^Cc:\s*/sio) {
+	$cc = $';
+	next;
+    }
+
+    if (/^Reply-To:\s*/sio) {
+	$reply_to = $';
+	next;
+    }
+
     if (/^References:\s*/sio) {
 	$references = $';
 	next;
@@ -244,20 +286,25 @@
 }
 
 
-$msgIdHdr = $message_id if $message_id ;
+$msgIdHdr = $message_id if ck822($message_id);
 $fromHdr = $from if $from ;
 $dateHdr = $date if $date ;
 
-if ($path !~ /\!/) {
-    $path = "$'!$`" if ($path =~ /\@/);
-}
+# set path to 'mailpost' (oku, Jan 25 2000)
+$path = 'mailpost!not-for-mail';
+#if ($path !~ /\!/) {
+#    $path = "$'!$`" if ($path =~ /\@/);
+#}
 
 $real_news_hdrs .= "Subject: ${subject}\n";
 $real_news_hdrs .= "Message-ID: ${msgIdHdr}\n"     if defined($message_id);
 $real_news_hdrs .= "Mailing-List: ${mailing_list}\n" if defined($mailing_list);
 $real_news_hdrs .= "Distribution: ${distribution}\n" if defined($distribution);
+$real_news_hdrs .= "Organization: ${organization}\n";
 $real_news_hdrs .= "Approved: ${approved}\n"         if defined($approved);
 $real_news_hdrs .= "References: ${references}\n"     if defined($references);
+$real_news_hdrs .= "Cc: ${cc}\n"                     if defined($cc);
+$real_news_hdrs .= "Reply-To: ${reply_to}\n"         if defined($reply_to);
 
 # Remove duplicate headers.
 my %headers = ();
@@ -449,3 +496,109 @@
     return $str;
 }
 
+sub ck822 { 
+  
+  # ck822 -- check whether address is valid rfc 822 address
+  # tchrist@perl.com
+  #
+  # pattern developed in program by jfriedl; 
+  # see "Mastering Regular Expressions" from ORA for details
+  
+  # this will error on something like "ftp.perl.com." because
+  # even though dns wants it, rfc822 hates it.  shucks.
+  
+  my $what = 'address';
+  
+  my $hispass = shift;
+  my $id;
+
+  $_ = $hispass;
+  s/^-+//;
+  tr/A-Z/a-z/;
+  
+  my $is_a_valid_rfc_822_addr = '';
+  
+  while (<DATA>) {
+    chomp;
+    $is_a_valid_rfc_822_addr .= $_;
+  } 
+  
+  if ($hispass =~ /^${is_a_valid_rfc_822_addr}$/o)
+  {
+	 return $hispass;
+  }
+else
+  {
+	 $id = (split('@',$hispass))[0];
+	 return $id . '@your.host.example.com';
+  }
+}
+
+#return 1;
+
+# don't touch this stuff down here or you'll break the rfc822 matcher.
+#__END__
+__DATA__
+(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n
+\015()]|\\[^\x80-\xff])*\))*\))*(?:(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\
+xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"(?:[^\\\x80-\xff\n\015"
+]|\\[^\x80-\xff])*")(?:(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xf
+f]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*\.(?:[\040\t]|\((?:[
+^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\
+xff])*\))*\))*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;
+:".\\\[\]\000-\037\x80-\xff])|"(?:[^\\\x80-\xff\n\015"]|\\[^\x80-\xff])*"))
+*(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\
+n\015()]|\\[^\x80-\xff])*\))*\))*@(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\
+\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*(?:[^(\04
+0)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-
+\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])(?:(?:[\040\t]|\((?
+:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80
+-\xff])*\))*\))*\.(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\(
+(?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*(?:[^(\040)<>@,;:".\\\[\]
+\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\
+\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\]))*|(?:[^(\040)<>@,;:".\\\[\]\000-\0
+37\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"(?:[^\\\x80-\xf
+f\n\015"]|\\[^\x80-\xff])*")(?:[^()<>@,;:".\\\[\]\x80-\xff\000-\010\012-\03
+7]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\
+\[^\x80-\xff])*\))*\)|"(?:[^\\\x80-\xff\n\015"]|\\[^\x80-\xff])*")*<(?:[\04
+0\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]
+|\\[^\x80-\xff])*\))*\))*(?:@(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x
+80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*(?:[^(\040)<>@
+,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]
+)|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])(?:(?:[\040\t]|\((?:[^\\
+\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff
+])*\))*\))*\.(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^
+\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*(?:[^(\040)<>@,;:".\\\[\]\000-
+\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-
+\xff\n\015\[\]]|\\[^\x80-\xff])*\]))*(?:(?:[\040\t]|\((?:[^\\\x80-\xff\n\01
+5()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*,(?
+:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\0
+15()]|\\[^\x80-\xff])*\))*\))*@(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^
+\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*(?:[^(\040)<
+>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xf
+f])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])(?:(?:[\040\t]|\((?:[^
+\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\x
+ff])*\))*\))*\.(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:
+[^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*(?:[^(\040)<>@,;:".\\\[\]\00
+0-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x8
+0-\xff\n\015\[\]]|\\[^\x80-\xff])*\]))*)*:(?:[\040\t]|\((?:[^\\\x80-\xff\n\
+015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*)
+?(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000
+-\037\x80-\xff])|"(?:[^\\\x80-\xff\n\015"]|\\[^\x80-\xff])*")(?:(?:[\040\t]
+|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[
+^\x80-\xff])*\))*\))*\.(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xf
+f]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*(?:[^(\040)<>@,;:".\
+\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"(?:
+[^\\\x80-\xff\n\015"]|\\[^\x80-\xff])*"))*(?:[\040\t]|\((?:[^\\\x80-\xff\n\
+015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*@
+(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n
+\015()]|\\[^\x80-\xff])*\))*\))*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff
+]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\
+]]|\\[^\x80-\xff])*\])(?:(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\
+xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*\.(?:[\040\t]|\((?
+:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80
+-\xff])*\))*\))*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@
+,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff
+])*\]))*(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x8
+0-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*>)(?:[\040\t]|\((?:[^\\\x80-\xff\n\
+015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*
