diff options
author | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-03 15:52:39 +0200 |
---|---|---|
committer | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-03 15:52:39 +0200 |
commit | a6a7d6ce079cabdaf2fa502b2e2cf15e5428ac6f (patch) | |
tree | b88cc7a8457658d67e0321718556ac807f6bccf3 /src/received.c | |
parent | 00be7622c428f279872f84569f098ce16150f8a8 (diff) |
format files
Diffstat (limited to 'src/received.c')
-rw-r--r-- | src/received.c | 224 |
1 files changed, 149 insertions, 75 deletions
diff --git a/src/received.c b/src/received.c index 51339a9..b564fd4 100644 --- a/src/received.c +++ b/src/received.c @@ -1,17 +1,18 @@ -#include "fmt.h" -#include "qmail.h" -#include "now.h" -#include "datetime.h" -#include "date822fmt.h" #include "received.h" -#include "str.h" -#include "stralloc.h" + #include "byte.h" +#include "fmt.h" #include "str.h" +#include "stralloc.h" + +#include "date822fmt.h" +#include "datetime.h" +#include "now.h" +#include "qmail.h" static int issafe(char ch) { - if (ch == ' ') return 1; /* accept empty spaces */ + if (ch == ' ') return 1; /* accept empty spaces */ if (ch == '.') return 1; if (ch == '@') return 1; if (ch == '%') return 1; @@ -26,12 +27,12 @@ static int issafe(char ch) return 0; } -void safeput(struct qmail *qqt,char *s) +void safeput(struct qmail *qqt, char *s) { char ch; while ((ch = *s++)) { if (!issafe(ch)) ch = '?'; - qmail_put(qqt,&ch,1); + qmail_put(qqt, &ch, 1); } } @@ -42,44 +43,53 @@ static char buf[DATE822FMT]; /* " by silverton.berkeley.edu with [UTF8][E]SMTP[SA]; 26 Sep 1995 04:46:54 -0000" */ /* "X-RBL-Info: http://www.spamhaus.org/query/bl?ip=127.0.0.2 */ -void received(struct qmail *qqt,char *protocol,char *local,char *remoteip,char *remotehost,char *remoteinfo,char *helo,char *tlsinfo,char *rblinfo) +void received( + struct qmail *qqt, + char *protocol, + char *local, + char *remoteip, + char *remotehost, + char *remoteinfo, + char *helo, + char *tlsinfo, + char *rblinfo) { struct datetime dt; int i; - qmail_puts(qqt,"Received: from "); - safeput(qqt,remotehost); + qmail_puts(qqt, "Received: from "); + safeput(qqt, remotehost); if (helo) { - qmail_puts(qqt," (HELO "); - safeput(qqt,helo); - qmail_puts(qqt,")"); + qmail_puts(qqt, " (HELO "); + safeput(qqt, helo); + qmail_puts(qqt, ")"); } - qmail_puts(qqt," ("); + qmail_puts(qqt, " ("); if (remoteinfo) { - safeput(qqt,remoteinfo); - qmail_puts(qqt,"@"); + safeput(qqt, remoteinfo); + qmail_puts(qqt, "@"); } - safeput(qqt,remoteip); - qmail_puts(qqt,")"); + safeput(qqt, remoteip); + qmail_puts(qqt, ")"); if (tlsinfo) { - qmail_puts(qqt,"\n de/crypted with "); - qmail_puts(qqt,tlsinfo); + qmail_puts(qqt, "\n de/crypted with "); + qmail_puts(qqt, tlsinfo); } - qmail_puts(qqt,"\n by "); - safeput(qqt,local); - qmail_puts(qqt," with "); - qmail_puts(qqt,protocol); - qmail_puts(qqt,"; "); - datetime_tai(&dt,now()); - qmail_put(qqt,buf,date822fmt(buf,&dt)); + qmail_puts(qqt, "\n by "); + safeput(qqt, local); + qmail_puts(qqt, " with "); + qmail_puts(qqt, protocol); + qmail_puts(qqt, "; "); + datetime_tai(&dt, now()); + qmail_put(qqt, buf, date822fmt(buf, &dt)); if (rblinfo) { - i = str_chr(rblinfo,']'); - if (rblinfo[i] == ']') { - qmail_puts(qqt,"X-RBL-Info: "); - safeput(qqt,rblinfo + i + 2); - qmail_puts(qqt,"\n"); + i = str_chr(rblinfo, ']'); + if (rblinfo[i] == ']') { + qmail_puts(qqt, "X-RBL-Info: "); + safeput(qqt, rblinfo + i + 2); + qmail_puts(qqt, "\n"); } } } @@ -88,7 +98,8 @@ void received(struct qmail *qqt,char *protocol,char *local,char *remoteip,char * /* " designates Clientip as permitted sender) receiver=Hostname " */ /* " client-ip=Clientip; envelope-from=Mailfrom; " */ -void spfheader(struct qmail *qqt,char *spfinfo,char *local,char *remoteip,char *helohost,char *mailfrom) +void spfheader( + struct qmail *qqt, char *spfinfo, char *local, char *remoteip, char *helohost, char *mailfrom) { char *result = 0; char *identity = 0; @@ -105,21 +116,23 @@ void spfheader(struct qmail *qqt,char *spfinfo,char *local,char *remoteip,char * if (!len) return; for (i = 0; i < len; i++) - if (spfinfo[i] == ' ') spfinfo[i] = '\0'; - + if (spfinfo[i] == ' ') spfinfo[i] = '\0'; + for (i = 0; i < len; i++) { if (spfinfo[i] == '\0') { - switch (spfinfo[i + 1]) { + switch (spfinfo[i + 1]) { case 'S': clientip = spfinfo + i + 3; break; case 'O': envelopefrom = spfinfo + i + 3; break; case 'C': identity = spfinfo + i + 3; break; case 'H': helo = spfinfo + i + 3; break; case 'T': receiver = spfinfo + i + 3; break; case 'P': problem = spfinfo + i + 3; break; - case 'M': if ((j = str_chr(spfinfo + i,'='))) spfinfo[i + j] = '\0'; - mechanism = spfinfo + i + 1; break; + case 'M': + if ((j = str_chr(spfinfo + i, '='))) spfinfo[i + j] = '\0'; + mechanism = spfinfo + i + 1; + break; case 'R': result = spfinfo + i + 3; break; - default: break; + default: break; } } } @@ -132,41 +145,102 @@ void spfheader(struct qmail *qqt,char *spfinfo,char *local,char *remoteip,char * if (!problem || *problem == 0) problem = "unknown"; if (!mechanism || *mechanism == 0) mechanism = "unknown"; if (!identity || *identity == 0) { - j = str_rchr(envelopefrom,'@'); - if (envelopefrom[j] == '@') identity = envelopefrom + j + 1; - else identity = "unknown"; + j = str_rchr(envelopefrom, '@'); + if (envelopefrom[j] == '@') + identity = envelopefrom + j + 1; + else + identity = "unknown"; } - qmail_puts(qqt,"Received-SPF: "); + qmail_puts(qqt, "Received-SPF: "); switch (*result) { - case '+': qmail_puts(qqt," pass ("); safeput(qqt,helo); - qmail_puts(qqt,": domain of "); safeput(qqt,identity); qmail_puts(qqt,"\n"); - qmail_puts(qqt," designates "); safeput(qqt,clientip); qmail_puts(qqt," as permitted sender)\n"); - qmail_puts(qqt," receiver="); safeput(qqt,receiver); - qmail_puts(qqt,"; client-ip="); safeput(qqt,clientip); qmail_puts(qqt,"\n"); - qmail_puts(qqt," envelope-from="); safeput(qqt,envelopefrom); qmail_puts(qqt,";\n"); break; - case '-': qmail_puts(qqt," fail ("); safeput(qqt,helo); - qmail_puts(qqt,": domain of "); safeput(qqt,identity); qmail_puts(qqt,"\n"); - qmail_puts(qqt," does not designate "); safeput(qqt,clientip); qmail_puts(qqt," as permitted sender)\n"); break; - case '~': qmail_puts(qqt," softfail ("); safeput(qqt,helo); - qmail_puts(qqt,": domain of transitioning "); safeput(qqt,identity); qmail_puts(qqt,"\n"); - qmail_puts(qqt," does not designate "); safeput(qqt,clientip); qmail_puts(qqt," as permitted sender)\n"); break; - case '?': qmail_puts(qqt," neutral ("); safeput(qqt,helo); qmail_puts(qqt,"; client-ip="); safeput(qqt,clientip); - qmail_puts(qqt," is neither permitted \n"); qmail_puts(qqt," nor denied by domain of "); safeput(qqt,identity), - qmail_puts(qqt,")\n"); break; - case 'o': qmail_puts(qqt," none ("); safeput(qqt,helo); - qmail_puts(qqt,": domain of "); safeput(qqt,identity); qmail_puts(qqt," does\n"); - qmail_puts(qqt," not designate permitted sender hosts)\n"); break; - case 't': qmail_puts(qqt," temperror ("); safeput(qqt,helo); - qmail_puts(qqt,": domain of "); safeput(qqt,identity); qmail_puts(qqt," evaluated\n"); - qmail_puts(qqt," with error: "); safeput(qqt,problem); qmail_puts(qqt," for mechanism: "); safeput(qqt,mechanism); - qmail_puts(qqt,")\n"); break; - case 'e': qmail_puts(qqt," permerror ("); safeput(qqt,helo); - qmail_puts(qqt,": domain of "); safeput(qqt,identity); qmail_puts(qqt," evaluated\n"); - qmail_puts(qqt," with error: "); safeput(qqt,problem); qmail_puts(qqt," for mechanism: "); safeput(qqt,mechanism); - qmail_puts(qqt,")\n"); break; - default: qmail_puts(qqt," unknown (results for "); safeput(qqt,helo); - qmail_puts(qqt,": domain of "); safeput(qqt,identity); - qmail_puts(qqt," follow an unknown mechanism: "); safeput(qqt,mechanism); qmail_puts(qqt,")\n"); break; + case '+': + qmail_puts(qqt, " pass ("); + safeput(qqt, helo); + qmail_puts(qqt, ": domain of "); + safeput(qqt, identity); + qmail_puts(qqt, "\n"); + qmail_puts(qqt, " designates "); + safeput(qqt, clientip); + qmail_puts(qqt, " as permitted sender)\n"); + qmail_puts(qqt, " receiver="); + safeput(qqt, receiver); + qmail_puts(qqt, "; client-ip="); + safeput(qqt, clientip); + qmail_puts(qqt, "\n"); + qmail_puts(qqt, " envelope-from="); + safeput(qqt, envelopefrom); + qmail_puts(qqt, ";\n"); + break; + case '-': + qmail_puts(qqt, " fail ("); + safeput(qqt, helo); + qmail_puts(qqt, ": domain of "); + safeput(qqt, identity); + qmail_puts(qqt, "\n"); + qmail_puts(qqt, " does not designate "); + safeput(qqt, clientip); + qmail_puts(qqt, " as permitted sender)\n"); + break; + case '~': + qmail_puts(qqt, " softfail ("); + safeput(qqt, helo); + qmail_puts(qqt, ": domain of transitioning "); + safeput(qqt, identity); + qmail_puts(qqt, "\n"); + qmail_puts(qqt, " does not designate "); + safeput(qqt, clientip); + qmail_puts(qqt, " as permitted sender)\n"); + break; + case '?': + qmail_puts(qqt, " neutral ("); + safeput(qqt, helo); + qmail_puts(qqt, "; client-ip="); + safeput(qqt, clientip); + qmail_puts(qqt, " is neither permitted \n"); + qmail_puts(qqt, " nor denied by domain of "); + safeput(qqt, identity), qmail_puts(qqt, ")\n"); + break; + case 'o': + qmail_puts(qqt, " none ("); + safeput(qqt, helo); + qmail_puts(qqt, ": domain of "); + safeput(qqt, identity); + qmail_puts(qqt, " does\n"); + qmail_puts(qqt, " not designate permitted sender hosts)\n"); + break; + case 't': + qmail_puts(qqt, " temperror ("); + safeput(qqt, helo); + qmail_puts(qqt, ": domain of "); + safeput(qqt, identity); + qmail_puts(qqt, " evaluated\n"); + qmail_puts(qqt, " with error: "); + safeput(qqt, problem); + qmail_puts(qqt, " for mechanism: "); + safeput(qqt, mechanism); + qmail_puts(qqt, ")\n"); + break; + case 'e': + qmail_puts(qqt, " permerror ("); + safeput(qqt, helo); + qmail_puts(qqt, ": domain of "); + safeput(qqt, identity); + qmail_puts(qqt, " evaluated\n"); + qmail_puts(qqt, " with error: "); + safeput(qqt, problem); + qmail_puts(qqt, " for mechanism: "); + safeput(qqt, mechanism); + qmail_puts(qqt, ")\n"); + break; + default: + qmail_puts(qqt, " unknown (results for "); + safeput(qqt, helo); + qmail_puts(qqt, ": domain of "); + safeput(qqt, identity); + qmail_puts(qqt, " follow an unknown mechanism: "); + safeput(qqt, mechanism); + qmail_puts(qqt, ")\n"); + break; } } |