summaryrefslogtreecommitdiffstats
path: root/rfc1035/spf.c
diff options
context:
space:
mode:
authorSam Varshavchik2019-07-30 19:53:45 -0400
committerSam Varshavchik2019-07-30 19:53:45 -0400
commit50bc1b68e1bedab3de35494df6f57e36ce263f41 (patch)
treeb45d673fa89406f0a4506e8a78e37ed44c6582c1 /rfc1035/spf.c
parent84d81ff062ec2451743cca505d60fe3f50c425ce (diff)
downloadcourier-libs-50bc1b68e1bedab3de35494df6f57e36ce263f41.tar.bz2
8-bit clean SPF headers.
Diffstat (limited to 'rfc1035/spf.c')
-rw-r--r--rfc1035/spf.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/rfc1035/spf.c b/rfc1035/spf.c
index f811aad..7b9d40b 100644
--- a/rfc1035/spf.c
+++ b/rfc1035/spf.c
@@ -22,6 +22,7 @@
#include <time.h>
#endif
#endif
+#include <idna.h>
struct rfc1035_spf_info {
const char *mailfrom;
@@ -1313,8 +1314,69 @@ static int do_expand(const char *str, struct rfc1035_spf_info *info,
static char *expandc(const char *ipaddr);
static char *expandi(const char *ipaddr);
+static char *get_macro2(struct rfc1035_spf_info *info, char name);
+
static char *get_macro(struct rfc1035_spf_info *info, char name)
{
+ char *v=get_macro2(info, name);
+ char *p;
+ char *buf;
+ char *newbuf;
+
+ if (!v)
+ return v;
+
+ switch (name) {
+ case 's':
+ /* s = responsible-sender */
+
+ p=strrchr(v, '@');
+
+ /* Find domain, convert to ACE */
+ if (!p || idna_to_ascii_8z(++p, &buf, 0) != IDNA_SUCCESS)
+ break;
+
+ /* Buffer for local part + ACE domain */
+
+ newbuf=malloc(p-v+strlen(buf)+1);
+
+ if (!newbuf)
+ {
+ free(buf);
+ break;
+ }
+
+ /* Rebuild address with an ACE domain */
+
+ memcpy(newbuf, v, p-v);
+ strcpy(newbuf+(p-v), buf);
+ free(v);
+ v=newbuf;
+ free(buf);
+ break;
+ case 'o':
+ /* o = responsible-domain */
+ case 'd':
+ /* d = current-domain */
+ case 'p':
+ /* p = SMTP client domain name */
+ case 'h':
+ /* h = HELO/EHLO domain */
+ case 'r':
+ /* r = receiving domain */
+
+ if (idna_to_ascii_8z(v, &buf, 0) == IDNA_SUCCESS)
+ {
+ free(v);
+ v=buf;
+ }
+ }
+
+ return v;
+}
+
+static char *get_macro2(struct rfc1035_spf_info *info, char name)
+{
char *p;
const char *cp;