masqmail
changeset 429:5593964ec779
Added route conditions based on the From header
New route config directives: allowed_from_hdrs, denied_from_hdrs.
This feature was motivated by Philipp Takacs <philipp29@t-online.de>.
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Thu, 20 Nov 2014 20:36:20 +0100 |
parents | e972c3cbe1e0 |
children | 180a7f6a9383 |
files | man/masqmail.route.5 src/conf.c src/deliver.c src/masqmail.h src/route.c |
diffstat | 5 files changed, 71 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- a/man/masqmail.route.5 Wed Apr 03 21:45:57 2013 +0200 1.2 +++ b/man/masqmail.route.5 Thu Nov 20 20:36:20 2014 +0100 1.3 @@ -78,6 +78,36 @@ 1.4 (See also examples for \fIallowed_senders\fP) 1.5 1.6 .TP 1.7 +\fBallowed_from_hdrs\fR = \fIlist\fR 1.8 + 1.9 +This is a semicolon `;' separated list of From header addresses. 1.10 +Messages which have one of these addresses as the From header 1.11 +are allowed to use this route 1.12 +(if not also in \fBdenied_from_hdrs\fR). 1.13 + 1.14 +Glob patterns containing `?' and `*' can be used. 1.15 +If the pattern doesn't contain an `@', it is seen as a pattern for the 1.16 +local part only. 1.17 + 1.18 +Example: \fImeillo;*@*example.org;web*@example.com\fP 1.19 + 1.20 +(``meillo'' equals ``meillo@*'', i.e. the local part.) 1.21 + 1.22 +.TP 1.23 +\fBdenied_from_hdrs\fR = \fIlist\fR 1.24 + 1.25 +This is a semicolon `;' separated list of From header addresses. 1.26 +Messages which have one of these addresses as the From header 1.27 +will not be sent using this route (even if also in 1.28 +\fBallowed_from_hdrs\fR). 1.29 + 1.30 +Glob patterns containing `?' and `*' can be used. 1.31 +If the pattern doesn't contain an `@', it is seen as a pattern for the 1.32 +local part only. 1.33 + 1.34 +Example: (see \fIallowed_from_hdrs\fP) 1.35 + 1.36 +.TP 1.37 \fBlast_route\fR = \fIboolean\fR 1.38 1.39 If this is set, a mail which would have been delivered using this route,
2.1 --- a/src/conf.c Wed Apr 03 21:45:57 2013 +0200 2.2 +++ b/src/conf.c Thu Nov 20 20:36:20 2014 +0100 2.3 @@ -624,6 +624,10 @@ 2.4 route->allowed_recipients = parse_address_glob_list(rval); 2.5 } else if (strcmp(lval, "denied_recipients")==0) { 2.6 route->denied_recipients = parse_address_glob_list(rval); 2.7 + } else if (strcmp(lval, "allowed_from_hdrs")==0) { 2.8 + route->allowed_from_hdrs = parse_address_glob_list(rval); 2.9 + } else if (strcmp(lval, "denied_from_hdrs")==0) { 2.10 + route->denied_from_hdrs = parse_address_glob_list(rval); 2.11 2.12 } else if (strcmp(lval, "set_h_from_domain")==0) { 2.13 route->set_h_from_domain = g_strdup(rval);
3.1 --- a/src/deliver.c Wed Apr 03 21:45:57 2013 +0200 3.2 +++ b/src/deliver.c Thu Nov 20 20:36:20 2014 +0100 3.3 @@ -667,6 +667,21 @@ 3.4 continue; 3.5 } 3.6 3.7 + /* filter by allowed from header */ 3.8 + GList *from_hdrs = NULL; 3.9 + char *from_hdr = NULL; 3.10 + from_hdrs = find_header(msgout->msg->hdr_list, HEAD_FROM, 3.11 + NULL); 3.12 + if (from_hdrs) { 3.13 + from_hdr = (char *) ((header *)from_hdrs->data)->value; 3.14 + if (!route_from_hdr_is_allowed(route, from_hdr)){ 3.15 + DEBUG(6) debugf("from hdr `%s' is not allowed for this " 3.16 + "route\n", from_hdr); 3.17 + destroy_msg_out(msgout_cloned); 3.18 + continue; 3.19 + } 3.20 + } 3.21 + 3.22 logwrite(LOG_NOTICE, "%s using '%s'\n", msgout->msg->uid, 3.23 route->name); 3.24
4.1 --- a/src/masqmail.h Wed Apr 03 21:45:57 2013 +0200 4.2 +++ b/src/masqmail.h Thu Nov 20 20:36:20 2014 +0100 4.3 @@ -85,6 +85,8 @@ 4.4 GList *denied_senders; 4.5 GList *allowed_recipients; 4.6 GList *denied_recipients; 4.7 + GList *allowed_from_hdrs; 4.8 + GList *denied_from_hdrs; 4.9 4.10 interface *mail_host; 4.11 gboolean connect_error_fail;
5.1 --- a/src/route.c Wed Apr 03 21:45:57 2013 +0200 5.2 +++ b/src/route.c Thu Nov 20 20:36:20 2014 +0100 5.3 @@ -344,6 +344,26 @@ 5.4 g_list_free(tmp_list); 5.5 } 5.6 5.7 +gboolean 5.8 +route_from_hdr_is_allowed(connect_route *route, char *from_hdr) 5.9 +{ 5.10 + address *addr = create_address_qualified(from_hdr, FALSE, 5.11 + conf.host_name); 5.12 + if (route->denied_from_hdrs && g_list_find_custom(route->denied_from_hdrs, addr, _g_list_addrcmp)) { 5.13 + return FALSE; 5.14 + } 5.15 + if (route->allowed_from_hdrs) { 5.16 + if (g_list_find_custom(route->allowed_from_hdrs, addr, 5.17 + _g_list_addrcmp)) { 5.18 + return TRUE; 5.19 + } else { 5.20 + return FALSE; 5.21 + } 5.22 + } 5.23 + return TRUE; 5.24 +} 5.25 + 5.26 + 5.27 msg_out* 5.28 route_prepare_msgout(connect_route *route, msg_out *msgout) 5.29 {