Sorry, I forgot to attach the patch to the previous message.
--- a/doc/nullmailer-queue.8
+++ b/doc/nullmailer-queue.8
@@ -29,6 +29,10 @@
 "somebody@localhost" and have it go somewhere sensible instead of
 being bounced by your relay host. To send to multiple addresses, put
 them all on one line separated by a comma.
+.TP
+.B allmailfrom
+If this file is not empty, its contents will override the envelope
+sender on all messages.
 .SH OTHER FILES
 .TP
 .B /var/spool/nullmailer/queue
--- a/src/queue.cc
+++ b/src/queue.cc
@@ -39,7 +39,7 @@
 uid_t uid = getuid();
 time_t timesecs = time(0);
 mystring adminaddr;
-bool remapadmin = false;
+mystring allmailfrom;
 
 bool is_dir(const char* path)
 {
@@ -75,16 +75,16 @@
   close(fd);
 }
 
-bool validate_addr(mystring& addr, bool doremap)
+bool validate_addr(mystring& addr, bool recipient)
 {
   int i = addr.find_last('@');
   if(i < 0)
     return false;
   mystring hostname = addr.right(i+1);
-  if(doremap && remapadmin) {
-    if(hostname == me || hostname == "localhost")
-      addr = adminaddr;
-  }
+  if (recipient && !!adminaddr && (hostname == me || hostname == "localhost"))
+    addr = adminaddr;
+  else if (!recipient && !!allmailfrom)
+    addr = allmailfrom;
   // else if(hostname.find_first('.') < 0)
     // return false;
   return true;
@@ -184,9 +184,9 @@
   umask(077);
   if(config_read("adminaddr", adminaddr) && !!adminaddr) {
     adminaddr = adminaddr.subst(',', '\n');
-    remapadmin = true;
     read_hostnames();
   }
+  config_read("allmailfrom", allmailfrom);
   
   if(!deliver())
     return 1;
--- a/test/tests/queue/rewrite
+++ b/test/tests/queue/rewrite
@@ -10,6 +10,10 @@
 	set -e
 	que | sed -e '2,/^$/!d' | grep -q "$@"
 }
+que-sender() {
+	set -e
+	que | head -n 1 | grep -q "$@"
+}
 
 echo admin@remote >/tmp/nm/etc/nullmailer/adminaddr
 
@@ -54,3 +58,25 @@
 
 data
 EOF
+
+echo "Checking that queue transmits the envelope sender normally."
+que-sender '^bru...@qcc.sk.ca$' <<EOF
+bru...@qcc.sk.ca
+user@localhost
+
+header
+
+data
+EOF
+
+echo "Checking that queue rewrites sender with allmailfrom."
+echo sender@remote3 >/tmp/nm/etc/nullmailer/allmailfrom
+que-sender '^sender@remote3$' <<EOF
+bru...@qcc.sk.ca
+user@localhost
+
+header
+
+data
+EOF
+rm -f /tmp/nm/etc/nullmailer/allmailfrom

Reply via email to