When checking the local_parts router precondition after a
[exim.git] / src / src / expand.c
index afa898205331db1496567457323144fb379bd6fe..beb72aa678470696e617dcc3fc874598c6ee3477 100644 (file)
@@ -1,4 +1,4 @@
-/* $Cambridge: exim/src/src/expand.c,v 1.82 2007/02/14 14:59:02 ph10 Exp $ */
+/* $Cambridge: exim/src/src/expand.c,v 1.92 2008/01/17 13:03:35 tom Exp $ */
 
 /*************************************************
 *     Exim - an Internet mail transport agent    *
@@ -349,7 +349,8 @@ enum {
   vtype_localpart,      /* extract local part from string */
   vtype_domain,         /* extract domain from string */
   vtype_recipients,     /* extract recipients from recipients list */
-                        /* (enabled only during system filtering */
+                        /* (available only in system filters, ACLs, and */
+                        /* local_scan()) */
   vtype_todbsdin,       /* value not used; generate BSD inbox tod */
   vtype_tode,           /* value not used; generate tod in epoch format */
   vtype_todf,           /* value not used; generate full tod */
@@ -395,6 +396,10 @@ static var_entry var_table[] = {
   { "compile_date",        vtype_stringptr,   &version_date },
   { "compile_number",      vtype_stringptr,   &version_cnumber },
   { "csa_status",          vtype_stringptr,   &csa_status },
+#ifdef EXPERIMENTAL_DCC
+  { "dcc_header",          vtype_stringptr,   &dcc_header },
+  { "dcc_result",          vtype_stringptr,   &dcc_result },
+#endif
 #ifdef WITH_OLD_DEMIME
   { "demime_errorlevel",   vtype_int,         &demime_errorlevel },
   { "demime_reason",       vtype_stringptr,   &demime_reason },
@@ -411,8 +416,13 @@ static var_entry var_table[] = {
   { "dk_signsall",         vtype_dk_verify,   NULL },
   { "dk_status",           vtype_dk_verify,   NULL },
   { "dk_testing",          vtype_dk_verify,   NULL },
+#endif
+#ifdef EXPERIMENTAL_DKIM
+  { "dkim_domain",         vtype_stringptr,   &dkim_signing_domain },
+  { "dkim_selector",       vtype_stringptr,   &dkim_signing_selector },
 #endif
   { "dnslist_domain",      vtype_stringptr,   &dnslist_domain },
+  { "dnslist_matched",     vtype_stringptr,   &dnslist_matched },
   { "dnslist_text",        vtype_stringptr,   &dnslist_text },
   { "dnslist_value",       vtype_stringptr,   &dnslist_value },
   { "domain",              vtype_stringptr,   &deliver_domain },
@@ -451,6 +461,7 @@ static var_entry var_table[] = {
 #ifdef WITH_CONTENT_SCAN
   { "malware_name",        vtype_stringptr,   &malware_name },
 #endif
+  { "max_received_linelength", vtype_int,     &max_received_linelength },
   { "message_age",         vtype_int,         &message_age },
   { "message_body",        vtype_msgbody,     &message_body },
   { "message_body_end",    vtype_msgbody_end, &message_body_end },
@@ -546,6 +557,7 @@ static var_entry var_table[] = {
   { "smtp_command",        vtype_stringptr,   &smtp_cmd_buffer },
   { "smtp_command_argument", vtype_stringptr, &smtp_cmd_argument },
   { "smtp_count_at_connection_start", vtype_int, &smtp_accept_count },
+  { "smtp_notquit_reason", vtype_stringptr,   &smtp_notquit_reason },
   { "sn0",                 vtype_filter_int,  &filter_sn[0] },
   { "sn1",                 vtype_filter_int,  &filter_sn[1] },
   { "sn2",                 vtype_filter_int,  &filter_sn[2] },
@@ -1443,7 +1455,7 @@ while (last > first)
     return var_buffer;
 
     case vtype_load_avg:
-    sprintf(CS var_buffer, "%d", os_getloadavg()); /* load_average */
+    sprintf(CS var_buffer, "%d", OS_GETLOADAVG()); /* load_average */
     return var_buffer;
 
     case vtype_host_lookup:                    /* Lookup if not done so */
@@ -1502,9 +1514,15 @@ while (last > first)
       if (len > 0)
         {
         body[len] = 0;
-        while (len > 0)
+        if (message_body_newlines)   /* Separate loops for efficiency */
+          {
+          while (len > 0)
+            { if (body[--len] == 0) body[len] = ' '; }
+          }
+        else
           {
-          if (body[--len] == '\n' || body[len] == 0) body[len] = ' ';
+          while (len > 0)
+            { if (body[--len] == '\n' || body[len] == 0) body[len] = ' '; }
           }
         }
       }
@@ -2372,7 +2390,6 @@ switch(cond_type)
 
     while (isspace(*s)) s++;
     if (*s++ != '{') goto COND_FAILED_CURLY_START;
-
     sub[0] = expand_string_internal(s, TRUE, &s, (yield == NULL));
     if (sub[0] == NULL) return NULL;
     if (*s++ != '}') goto COND_FAILED_CURLY_END;
@@ -2410,6 +2427,7 @@ switch(cond_type)
         {
         expand_string_message = string_sprintf("%s inside \"%s\" condition",
           expand_string_message, name);
+        iterate_item = save_iterate_item;
         return NULL;
         }
       DEBUG(D_expand) debug_printf("%s: condition evaluated to %s\n", name,
@@ -3698,11 +3716,11 @@ while (*s != 0)
       *domain++ = '\0';
 
       yield = string_cat(yield,&size,&ptr,US"prvs=",5);
-      string_cat(yield,&size,&ptr,sub_arg[0],Ustrlen(sub_arg[0]));
-      string_cat(yield,&size,&ptr,US"/",1);
       string_cat(yield,&size,&ptr,(sub_arg[2] != NULL) ? sub_arg[2] : US"0", 1);
       string_cat(yield,&size,&ptr,prvs_daystamp(7),3);
       string_cat(yield,&size,&ptr,p,6);
+      string_cat(yield,&size,&ptr,US"=",1);
+      string_cat(yield,&size,&ptr,sub_arg[0],Ustrlen(sub_arg[0]));
       string_cat(yield,&size,&ptr,US"@",1);
       string_cat(yield,&size,&ptr,domain,Ustrlen(domain));
 
@@ -3740,15 +3758,15 @@ while (*s != 0)
         case 3: goto EXPAND_FAILED;
         }
 
-      re = regex_must_compile(US"^prvs\\=(.+)\\/([0-9])([0-9]{3})([A-F0-9]{6})\\@(.+)$",
+      re = regex_must_compile(US"^prvs\\=([0-9])([0-9]{3})([A-F0-9]{6})\\=(.+)\\@(.+)$",
                               TRUE,FALSE);
 
       if (regex_match_and_setup(re,sub_arg[0],0,-1))
         {
-        uschar *local_part = string_copyn(expand_nstring[1],expand_nlength[1]);
-        uschar *key_num = string_copyn(expand_nstring[2],expand_nlength[2]);
-        uschar *daystamp = string_copyn(expand_nstring[3],expand_nlength[3]);
-        uschar *hash = string_copyn(expand_nstring[4],expand_nlength[4]);
+        uschar *local_part = string_copyn(expand_nstring[4],expand_nlength[4]);
+        uschar *key_num = string_copyn(expand_nstring[1],expand_nlength[1]);
+        uschar *daystamp = string_copyn(expand_nstring[2],expand_nlength[2]);
+        uschar *hash = string_copyn(expand_nstring[3],expand_nlength[3]);
         uschar *domain = string_copyn(expand_nstring[5],expand_nlength[5]);
 
         DEBUG(D_expand) debug_printf("prvscheck localpart: %s\n", local_part);
@@ -4779,6 +4797,8 @@ while (*s != 0)
           BOOL condresult;
           if (eval_condition(expr, &condresult) == NULL)
             {
+            iterate_item = save_iterate_item;
+            lookup_value = save_lookup_value;
             expand_string_message = string_sprintf("%s inside \"%s\" condition",
               expand_string_message, name);
             goto EXPAND_FAILED;
@@ -4798,6 +4818,7 @@ while (*s != 0)
           temp = expand_string_internal(expr, TRUE, NULL, skipping);
           if (temp == NULL)
             {
+            iterate_item = save_iterate_item;
             expand_string_message = string_sprintf("%s inside \"%s\" item",
               expand_string_message, name);
             goto EXPAND_FAILED;