Skip to content

Instantly share code, notes, and snippets.

@mtfurlan
Created June 22, 2023 19:48
Show Gist options
  • Save mtfurlan/2d0538e99674ae777dd99b861aa2c8c1 to your computer and use it in GitHub Desktop.
Save mtfurlan/2d0538e99674ae777dd99b861aa2c8c1 to your computer and use it in GitHub Desktop.
nullmailer debian patch
Description: allmailfrom modifies header now
https://github.com/bruceg/nullmailer/pull/84
Author: Mark <mark@fur.land>
Index: nullmailer-2.2/doc/nullmailer-inject.1
===================================================================
--- nullmailer-2.2.orig/doc/nullmailer-inject.1
+++ nullmailer-2.2/doc/nullmailer-inject.1
@@ -218,6 +218,10 @@ to queue the formatted message.
When reading the following files, a single line is read and stripped
of all leading and trailing whitespace characters.
.TP
+.B allmailfrom
+If this file is not empty, its contents will override the envelope
+sender and From header on all messages.
+.TP
.B defaultdomain
The content of this file is appended to any host name that does not
contain a period (except
Index: nullmailer-2.2/doc/nullmailer-queue.8
===================================================================
--- nullmailer-2.2.orig/doc/nullmailer-queue.8
+++ nullmailer-2.2/doc/nullmailer-queue.8
@@ -29,10 +29,6 @@ This is provided to allow local daemons
"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
Index: nullmailer-2.2/doc/nullmailer.7
===================================================================
--- nullmailer-2.2.orig/doc/nullmailer.7
+++ nullmailer-2.2/doc/nullmailer.7
@@ -22,7 +22,7 @@ The following table lists all the contro
.ta 5c
control file used by
.I adminaddr \fBnullmailer-dsn\fR, \fBnullmailer-queue
-.I allmailfrom \fBnullmailer-queue
+.I allmailfrom \fBnullmailer-inject
.I defaultdomain \fBnullmailer-dsn\fR, \fBnullmailer-inject
.I defaulthost \fBnullmailer-dsn\fR, \fBnullmailer-inject
.I doublebounceto \fBnullmailer-dsn
Index: nullmailer-2.2/src/inject.cc
===================================================================
--- nullmailer-2.2.orig/src/inject.cc
+++ nullmailer-2.2/src/inject.cc
@@ -253,6 +253,39 @@ static header_field& header_field_rpath
static bool use_name_address_style = true;
static mystring from;
+bool allmailfrom=false;
+mystring allmailfrom_user;
+mystring allmailfrom_hostname;
+
+bool
+config_allmailfrom(){
+ char* str = NULL;
+ char* char_pos = NULL;
+ mystring amf_config;
+ if(config_read("allmailfrom", amf_config)){
+ str=(char*)amf_config.c_str();
+ //remove newline character
+ char_pos=strchr(str, '\n');
+ if(char_pos)
+ *char_pos = '\0';
+ char_pos=strchr(str, '@');
+ if(char_pos){
+ *char_pos='\0';
+ allmailfrom_user = mystring( str );
+ allmailfrom_hostname = mystring( char_pos+1 );
+ }else{
+ // address doesn't contain @, probablty malformed
+ return false;
+ }
+ // success, this flag overwrites 'From: ' field
+ // which may already be in the mail header.
+ allmailfrom=true;
+ return true;
+ }
+ return false;
+}
+
+
void setup_from()
{
mystring user = getenv("NULLMAILER_USER");
@@ -276,6 +309,10 @@ void setup_from()
if(!name) name = getenv("NAME");
if(!name) name = user;
+ if(allmailfrom){
+ user = allmailfrom_user;
+ host = allmailfrom_hostname;}
+
if(use_name_address_style) {
if(!name) from = "<" + user + "@" + host + ">";
else from = name + " <" + user + "@" + host + ">";
@@ -399,6 +436,8 @@ bool fix_header()
headers.append("Message-Id: " + make_messageid(idhost));
if(!header_has_from)
headers.append("From: " + from);
+ if(header_has_from && allmailfrom)
+ headers.append("From: " + from);
if(!header_has_to && !header_has_cc && header_add_to &&
recipients.count() > 0) {
header_has_to = true;
@@ -509,6 +548,9 @@ bool parse_args(int argc, char* argv[])
{
if(!parse_flags())
return false;
+ config_allmailfrom();
+ if(allmailfrom){
+ header_field_from.ignore=header_field_from.remove=true;}
if(o_from) {
mystring list;
mystring tmp(o_from);
Index: nullmailer-2.2/src/queue.cc
===================================================================
--- nullmailer-2.2.orig/src/queue.cc
+++ nullmailer-2.2/src/queue.cc
@@ -43,7 +43,6 @@ pid_t pid = getpid();
uid_t uid = getuid();
time_t timesecs = time(0);
mystring adminaddr;
-mystring allmailfrom;
static mystring trigger_path;
static mystring msg_dir;
@@ -89,8 +88,6 @@ bool validate_addr(mystring& addr, bool
mystring hostname = addr.right(i+1);
if (recipient && !!adminaddr && (hostname == me || hostname == "localhost"))
addr = adminaddr;
- else if (!recipient && !!allmailfrom)
- addr = allmailfrom;
return true;
}
@@ -193,8 +190,7 @@ int main(int, char*[])
adminaddr = adminaddr.subst(',', '\n');
read_hostnames();
}
- config_read("allmailfrom", allmailfrom);
-
+
if(!deliver())
return 1;
trigger();
Index: nullmailer-2.2/test/tests/inject/from
===================================================================
--- nullmailer-2.2.orig/test/tests/inject/from
+++ nullmailer-2.2/test/tests/inject/from
@@ -39,6 +39,11 @@ echo "Checking that inject ignores confi
echo localhost >$SYSCONFDIR/defaulthost
inj | grep -q '@localhost>$'
+echo "Checking that inject respects config/allmailfrom"
+echo admin@domain.tld >$SYSCONFDIR/allmailfrom
+inj | grep -q '<admin@domain.tld>'
+rm $SYSCONFDIR/allmailfrom
+
testvar HOSTNAME test1.org '@test1.org>$'
testvar MAILHOST test2.org '@test2.org>$'
Index: nullmailer-2.2/test/tests/queue/rewrite
===================================================================
--- nullmailer-2.2.orig/test/tests/queue/rewrite
+++ nullmailer-2.2/test/tests/queue/rewrite
@@ -68,15 +68,3 @@ header
data
EOF
-
-echo "Checking that queue rewrites sender with allmailfrom."
-echo sender@remote3 >$SYSCONFDIR/allmailfrom
-que-sender '^sender@remote3$' <<EOF
-bruceg@qcc.sk.ca
-user@localhost
-
-header
-
-data
-EOF
-rm -f $SYSCONFDIR/allmailfrom
nullmailer (1:2.2-3~allmailfrom-patch) UNRELEASED; urgency=medium
* allmailfrom patch https://github.com/bruceg/nullmailer/pull/84
-- mtfurlan <mtf@fur.land> Thu, 22 Jun 2023 15:01:15 -0400
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment