Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for allmailfrom #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/inject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,39 @@ static header_field& header_field_rpath = header_fields[3];
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");
Expand All @@ -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 + ">";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions src/queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -89,8 +88,6 @@ bool validate_addr(mystring& addr, bool recipient)
mystring hostname = addr.right(i+1);
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;
Expand Down Expand Up @@ -195,7 +192,6 @@ int main(int, char*[])
adminaddr = adminaddr.subst(',', '\n');
read_hostnames();
}
config_read("allmailfrom", allmailfrom);

if(!deliver())
return 1;
Expand Down