[exim-cvs] Add expansion variable $headers_added returning n…

Page principale
Supprimer ce message
Répondre à ce message
Auteur: Exim Git Commits Mailing List
Date:  
À: exim-cvs
Sujet: [exim-cvs] Add expansion variable $headers_added returning newline-sep list of headers
Gitweb: http://git.exim.org/exim.git/commitdiff/362145b5072e8d863d74c4fed8d7c1377c783b87
Commit:     362145b5072e8d863d74c4fed8d7c1377c783b87
Parent:     b1b05573117d62c3b95d854d8ac5a447df19e82e
Author:     Jeremy Harris <jgh146exb@???>
AuthorDate: Thu Oct 4 23:05:04 2012 +0100
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Thu Oct 4 23:05:04 2012 +0100


    Add expansion variable $headers_added returning newline-sep list of headers
    added in ACLs.  Bug 199.
---
 doc/doc-docbook/spec.xfpt |   12 ++++++++-
 doc/doc-txt/ChangeLog     |    4 +++
 doc/doc-txt/NewStuff      |    3 ++
 src/src/acl.c             |   38 +++++++++++++++++++++++++++++
 src/src/expand.c          |   58 ++++++++++++++++++++++++++++-----------------
 src/src/functions.h       |    2 +
 test/confs/0496           |    3 +-
 test/log/0496             |    1 +
 test/mail/0496.someone    |    2 +
 9 files changed, 99 insertions(+), 24 deletions(-)


diff --git a/doc/doc-docbook/spec.xfpt b/doc/doc-docbook/spec.xfpt
index 5961c4b..4ba31a0 100644
--- a/doc/doc-docbook/spec.xfpt
+++ b/doc/doc-docbook/spec.xfpt
@@ -11063,6 +11063,12 @@ inserting the message header line with the given name. Note that the name must
be terminated by colon or white space, because it may contain a wide variety of
characters. Note also that braces must &'not'& be used.

+.vitem &$headers_added$&
+.vindex "&$headers_added$&"
+Within an ACL this variable contains the headers added so far by
+the ACL modifier add_header (section &<<SECTaddheadacl>>&).
+The headers are a newline-separated list.
+
.vitem &$home$&
.vindex "&$home$&"
When the &%check_local_user%& option is set for a router, the user's home
@@ -27340,7 +27346,9 @@ message is rejected after DATA or by the non-SMTP ACL, all added header lines
are included in the entry that is written to the reject log.

.cindex "header lines" "added; visibility of"
-Header lines are not visible in string expansions until they are added to the
+Header lines are not visible in string expansions
+of message headers
+until they are added to the
message. It follows that header lines defined in the MAIL, RCPT, and predata
ACLs are not visible until the DATA ACL and MIME ACLs are run. Similarly,
header lines that are added by the DATA or MIME ACLs are not visible in those
@@ -27349,6 +27357,8 @@ passing data between (for example) the MAIL and RCPT ACLs. If you want to do
this, you can use ACL variables, as described in section
&<<SECTaclvariables>>&.

+The list of headers yet to be added is given by the &%$headers_added%& variable.
+
 The &%add_header%& modifier acts immediately as it is encountered during the
 processing of an ACL. Notice the difference between these two cases:
 .display
diff --git a/doc/doc-txt/ChangeLog b/doc/doc-txt/ChangeLog
index 6e91c10..84948f6 100644
--- a/doc/doc-txt/ChangeLog
+++ b/doc/doc-txt/ChangeLog
@@ -74,6 +74,10 @@ JH/07 Avoid using a waiting database for a single-message-only transport.
 JH/08 Strip leading/trailing newlines from add_header ACL modifier data.
       Bugzilla 884.


+JH/09 Add $headers_added variable, with content from use of ACL modifier
+      add_header (but not yet added to the message).  Bugzilla 199.
+
+


 Exim version 4.80
 -----------------
diff --git a/doc/doc-txt/NewStuff b/doc/doc-txt/NewStuff
index ccf2dc6..680d96c 100644
--- a/doc/doc-txt/NewStuff
+++ b/doc/doc-txt/NewStuff
@@ -115,6 +115,9 @@ Version 4.81
 13. New dnsdb lookup pseudo-type "a+".  A sequence of "a6" (if configured),
     "aaaa" and "a" lookups is done and the full set of results returned.


+14. New expansion variable $headers_added with content from ACL add_header
+    modifier (but not yet added to messsage).
+


Version 4.80
------------
diff --git a/src/src/acl.c b/src/src/acl.c
index f9a32d3..6ae3680 100644
--- a/src/src/acl.c
+++ b/src/src/acl.c
@@ -1051,6 +1051,44 @@ for (p = q = hstring; *p != 0; )


 /*************************************************
+*        List the added header lines         *
+*************************************************/
+uschar *
+fn_hdrs_added(void)
+{
+uschar * ret = NULL;
+header_line * h = acl_added_headers;
+uschar * s;
+uschar * cp;
+int size = 0;
+int ptr = 0;
+
+if (!h) return NULL;
+
+do
+  {
+  s = h->text;
+  while ((cp = Ustrchr(s, '\n')) != NULL)
+    {
+    if (cp[1] == '\0') break;
+
+    /* contains embedded newline; needs doubling */
+    ret = string_cat(ret, &size, &ptr, s, cp-s+1);
+    ret = string_cat(ret, &size, &ptr, "\n", 1);
+    s = cp+1;
+    }
+  /* last bit of header */
+
+  ret = string_cat(ret, &size, &ptr, s, cp-s+1);    /* newline-sep list */
+  }
+while(h = h->next);
+
+ret[ptr-1] = '\0';    /* overwrite last newline */
+return ret;
+}
+
+
+/*************************************************
 *        Set up removed header line(s)           *
 *************************************************/


diff --git a/src/src/expand.c b/src/src/expand.c
index 7803862..bd8a1be 100644
--- a/src/src/expand.c
+++ b/src/src/expand.c
@@ -367,9 +367,7 @@ enum {
   vtype_msgheaders_raw, /* the message's headers, unprocessed */
   vtype_localpart,      /* extract local part from string */
   vtype_domain,         /* extract domain from string */
-  vtype_recipients,     /* extract recipients from recipients list */
-                        /* (available only in system filters, ACLs, and */
-                        /* local_scan()) */
+  vtype_string_func,    /* value is string returned by given function */
   vtype_todbsdin,       /* value not used; generate BSD inbox tod */
   vtype_tode,           /* value not used; generate tod in epoch format */
   vtype_todel,          /* value not used; generate tod in epoch/usec format */
@@ -389,6 +387,8 @@ enum {
   #endif
   };


+static uschar * fn_recipients(void);
+
/* This table must be kept in alphabetical order. */

 static var_entry var_table[] = {
@@ -471,6 +471,7 @@ static var_entry var_table[] = {
 #ifdef WITH_OLD_DEMIME
   { "found_extension",     vtype_stringptr,   &found_extension },
 #endif
+  { "headers_added",       vtype_string_func, &fn_hdrs_added },
   { "home",                vtype_stringptr,   &deliver_home },
   { "host",                vtype_stringptr,   &deliver_host },
   { "host_address",        vtype_stringptr,   &deliver_host_address },
@@ -562,7 +563,7 @@ static var_entry var_table[] = {
   { "received_time",       vtype_int,         &received_time },
   { "recipient_data",      vtype_stringptr,   &recipient_data },
   { "recipient_verify_failure",vtype_stringptr,&recipient_verify_failure },
-  { "recipients",          vtype_recipients,  NULL },
+  { "recipients",          vtype_string_func, &fn_recipients },
   { "recipients_count",    vtype_int,         &recipients_count },
 #ifdef WITH_CONTENT_SCAN
   { "regex_match_string",  vtype_stringptr,   &regex_match_string },
@@ -1447,6 +1448,34 @@ return yield;



 /*************************************************
+*               Return list of recipients        *
+*************************************************/
+/* A recipients list is available only during system message filtering,
+during ACL processing after DATA, and while expanding pipe commands
+generated from a system filter, but not elsewhere. */
+
+static uschar *
+fn_recipients(void)
+{
+if (!enable_dollar_recipients) return NULL; else
+  {
+  int size = 128;
+  int ptr = 0;
+  int i;
+  uschar * s = store_get(size);
+  for (i = 0; i < recipients_count; i++)
+    {
+    if (i != 0) s = string_cat(s, &size, &ptr, US", ", 2);
+    s = string_cat(s, &size, &ptr, recipients_list[i].address,
+      Ustrlen(recipients_list[i].address));
+    }
+  s[ptr] = 0;     /* string_cat() leaves room */
+  return s;
+  }
+}
+
+
+/*************************************************
 *               Find value of a variable         *
 *************************************************/


@@ -1671,26 +1700,11 @@ while (last > first)
       }
     return (s == NULL)? US"" : s;


-    /* A recipients list is available only during system message filtering,
-    during ACL processing after DATA, and while expanding pipe commands
-    generated from a system filter, but not elsewhere. */
-
-    case vtype_recipients:
-    if (!enable_dollar_recipients) return NULL; else
+    case vtype_string_func:
       {
-      int size = 128;
-      int ptr = 0;
-      int i;
-      s = store_get(size);
-      for (i = 0; i < recipients_count; i++)
-        {
-        if (i != 0) s = string_cat(s, &size, &ptr, US", ", 2);
-        s = string_cat(s, &size, &ptr, recipients_list[i].address,
-          Ustrlen(recipients_list[i].address));
-        }
-      s[ptr] = 0;     /* string_cat() leaves room */
+      uschar * (*fn)() = var_table[middle].value;
+      return fn();
       }
-    return s;


     case vtype_pspace:
       {
diff --git a/src/src/functions.h b/src/src/functions.h
index bc791fc..034ef19 100644
--- a/src/src/functions.h
+++ b/src/src/functions.h
@@ -139,6 +139,8 @@ extern BOOL    filter_personal(string_item *, BOOL);
 extern BOOL    filter_runtest(int, uschar *, BOOL, BOOL);
 extern BOOL    filter_system_interpret(address_item **, uschar **);


+extern uschar * fn_hdrs_added(void);
+
 extern void    header_add(int, const char *, ...);
 extern int     header_checkname(header_line *, BOOL);
 extern BOOL    header_match(uschar *, BOOL, BOOL, string_item *, int, ...);
diff --git a/test/confs/0496 b/test/confs/0496
index 89375b1..9b03b85 100644
--- a/test/confs/0496
+++ b/test/confs/0496
@@ -25,7 +25,8 @@ check_rcpt:
                      :at_start:At-Start: some text\n\
                      :at_end:  At-End: some text
   warn     message = data4
-  accept
+  warn     add_header = X-multiline: foo\n\tbar
+  accept   logwrite = $headers_added



 # ----- Routers -----
diff --git a/test/log/0496 b/test/log/0496
index de056d4..ed05c12 100644
--- a/test/log/0496
+++ b/test/log/0496
@@ -1,3 +1,4 @@
+1999-03-02 09:44:33 X-ACL-Warn: data1 data1\nX-ACL-Warn: data2 data2\nX-ACL-Warn: data3\nX-ACL-Warn: \nX-ACL-Warn: data4\nAfter-Received: some text\nAt-Start: some text\nAt-End: some text\nX-multiline: foo\n\n    bar
 1999-03-02 09:44:33 10HmaX-0005vi-00 <= CALLER@??? U=CALLER P=local-smtp S=sss
 1999-03-02 09:44:33 10HmaX-0005vi-00 => someone <someone@???> R=r9 T=t1
 1999-03-02 09:44:33 10HmaX-0005vi-00 Completed
diff --git a/test/mail/0496.someone b/test/mail/0496.someone
index 263f596..32240fd 100644
--- a/test/mail/0496.someone
+++ b/test/mail/0496.someone
@@ -16,6 +16,8 @@ X-ACL-Warn: data3
 X-ACL-Warn: 
 X-ACL-Warn: data4
 At-End: some text
+X-multiline: foo
+    bar


Testing message