From 5d488372f06410e65bc972ade89d8e68998d7170 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20B=C3=BCrgin?= <dbuergin@gluet.ch>
Date: Fri, 9 Jul 2021 16:44:14 +0200
Subject: [PATCH] Quote results in Authentication-Results if necessary

---
 libopenarc/arc.c  |  2 +-
 openarc/openarc.c | 14 ++++++++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/libopenarc/arc.c b/libopenarc/arc.c
index 1c6c9ded..9216b341 100644
--- a/libopenarc/arc.c
+++ b/libopenarc/arc.c
@@ -3711,7 +3711,7 @@ arc_chain_custody_str(ARC_MESSAGE *msg, u_char *buf, size_t buflen)
 		kvset = msg->arc_sets[set].arcset_ams->hdr_data;
 		str = arc_param_get(kvset, "d");
 		(void) arc_dstring_printf(tmpbuf, "%s%s",
-		                          (set < msg->arc_nsets ? ":" : ""),
+		                          (set < msg->arc_nsets - 1 ? ":" : ""),
 		                          str);
 	}
 
diff --git a/openarc/openarc.c b/openarc/openarc.c
index 7e191dc1..39312b32 100644
--- a/openarc/openarc.c
+++ b/openarc/openarc.c
@@ -3851,14 +3851,24 @@ mlfi_eom(SMFICTX *ctx)
 
 		if (ipout != NULL)
 		{
+			_Bool quote = strchr(ipout, ':') != NULL;
+
 			arcf_dstring_printf(afc->mctx_tmpstr,
-			                    " smtp.remote-ip=%s", ipout);
+			                    " smtp.remote-ip=%s%s%s",
+			                    quote ? "\"" : "",
+			                    ipout,
+			                    quote ? "\"" : "");
 		}
 
 		if (conf->conf_finalreceiver && arcchainlen > 0)
 		{
+			_Bool quote = strchr(arcchainbuf, ':') != NULL;
+
 			arcf_dstring_printf(afc->mctx_tmpstr,
-			                    " arc.chain=%s", arcchainbuf);
+			                    " arc.chain=%s%s%s",
+			                    quote ? "\"" : "",
+			                    arcchainbuf,
+			                    quote ? "\"" : "");
 		}
 
 		if (arcf_insheader(ctx, 1, AUTHRESULTSHDR,