Merge tag 'exim-4_82_1'
[exim.git] / src / src / dmarc.c
index 32a1b9678b08d91ae2dcd5eb7481bfe174177ecc..ca1c29bbb5bfdaf34cc2092e44c147116620aaaf 100644 (file)
@@ -2,7 +2,7 @@
 *     Exim - an Internet mail transport agent    *
 *************************************************/
 /* Experimental DMARC support.
-   Copyright (c) Todd Lyons <tlyons@exim.org> 2012, 2013
+   Copyright (c) Todd Lyons <tlyons@exim.org> 2012 - 2014
    License: GPL */
 
 /* Portions Copyright (c) 2012, 2013, The Trusted Domain Project;
@@ -181,20 +181,24 @@ int dmarc_process() {
     dmarc_abort = TRUE;
   else
   {
-    /* I strongly encourage anybody who can make this better to contact me directly!
-     * <cannonball> Is this an insane way to extract the email address from the From: header?
-     * <jgh_hm> it's sure a horrid layer-crossing....
-     * <cannonball> I'm not denying that :-/
-     * <jgh_hm> there may well be no better though
-     */
-    header_from_sender = expand_string(
-           string_sprintf("${domain:${extract{1}{:}{${addresses:\\N%s\\N}}}}",
-                          from_header->text) );
+    uschar * errormsg;
+    int dummy, domain;
+    uschar * p;
+    uschar saveend;
+
+    parse_allow_group = TRUE;
+    p = parse_find_address_end(from_header->text, FALSE);
+    saveend = *p; *p = '\0';
+    if ((header_from_sender = parse_extract_address(from_header->text, &errormsg,
+                                &dummy, &dummy, &domain, FALSE)))
+      header_from_sender += domain;
+    *p = saveend;
+
     /* The opendmarc library extracts the domain from the email address, but
      * only try to store it if it's not empty.  Otherwise, skip out of DMARC. */
-    if ((header_from_sender == NULL) || (strcmp( CCS header_from_sender, "") == 0))
+    if (!header_from_sender || (strcmp( CCS header_from_sender, "") == 0))
       dmarc_abort = TRUE;
-    libdm_status = (dmarc_abort == TRUE) ?
+    libdm_status = dmarc_abort ?
       DMARC_PARSE_OKAY :
       opendmarc_policy_store_from_domain(dmarc_pctx, header_from_sender);
     if (libdm_status != DMARC_PARSE_OKAY)
@@ -455,7 +459,7 @@ int dmarc_write_history_file()
 
   if (spf_response != NULL)
     history_buffer = string_sprintf("%sspf %d\n", history_buffer, dmarc_spf_ares_result);
-    // history_buffer = string_sprintf("%sspf -1\n", history_buffer);
+    /* history_buffer = string_sprintf("%sspf -1\n", history_buffer); */
 
   history_buffer = string_sprintf("%s%s", history_buffer, dkim_history_buffer);
   history_buffer = string_sprintf("%spdomain %s\n", history_buffer, dmarc_used_domain);
@@ -633,5 +637,3 @@ uschar *dmarc_auth_results_header(header_line *from_header, uschar *hostname)
 
 #endif /* EXPERIMENTAL_SPF */
 #endif /* EXPERIMENTAL_DMARC */
-
-// vim:sw=2 expandtab