Docs: options after "run" of ${run } may not have space. Bug 2932
[exim.git] / src / src / expand.c
index 1daf10044df22a35c8d4edf88b1a0463dacaea2d..9f80439cbae87b0db0cebcd626885b7f074e9122 100644 (file)
@@ -2,7 +2,7 @@
 *     Exim - an Internet mail transport agent    *
 *************************************************/
 
-/* Copyright (c) The Exim Maintainers 2020 - 2022 */
+/* Copyright (c) The Exim Maintainers 2020 - 2023 */
 /* Copyright (c) University of Cambridge 1995 - 2018 */
 /* See the file NOTICE for conditions of use and distribution. */
 /* SPDX-License-Identifier: GPL-2.0-or-later */
@@ -237,6 +237,7 @@ static uschar *op_table_main[] = {
   US"expand",
   US"h",
   US"hash",
+  US"headerwrap",
   US"hex2b64",
   US"hexquote",
   US"ipv6denorm",
@@ -284,6 +285,7 @@ enum {
   EOP_EXPAND,
   EOP_H,
   EOP_HASH,
+  EOP_HEADERWRAP,
   EOP_HEX2B64,
   EOP_HEXQUOTE,
   EOP_IPV6DENORM,
@@ -478,8 +480,8 @@ typedef struct {
   int  *length;
 } alblock;
 
-static uschar * fn_recipients(void);
 typedef uschar * stringptr_fn_t(void);
+static uschar * fn_recipients(void);
 static uschar * fn_queue_size(void);
 
 /* This table must be kept in alphabetical order. */
@@ -685,7 +687,7 @@ static var_entry var_table[] = {
   { "qualify_domain",      vtype_stringptr,   &qualify_domain_sender },
   { "qualify_recipient",   vtype_stringptr,   &qualify_domain_recipient },
   { "queue_name",          vtype_stringptr,   &queue_name },
-  { "queue_size",          vtype_string_func, &fn_queue_size },
+  { "queue_size",          vtype_string_func, (void *) &fn_queue_size },
   { "rcpt_count",          vtype_int,         &rcpt_count },
   { "rcpt_defer_count",    vtype_int,         &rcpt_defer_count },
   { "rcpt_fail_count",     vtype_int,         &rcpt_fail_count },
@@ -5628,7 +5630,6 @@ while (*s)
       /* Handle options to the "run" */
 
       while (*s == ',')
-       {
        if (Ustrncmp(++s, "preexpand", 9) == 0)
          { late_expand = FALSE; s += 9; }
        else
@@ -5639,7 +5640,6 @@ while (*s)
                                                  (int)(t-s), s);
          goto EXPAND_FAILED;
          }
-       }
       Uskip_whitespace(&s);
 
       if (*s != '{')                                   /*}*/
@@ -7262,7 +7262,7 @@ NOT_ITEM: ;
        {
        uschar *t;
        unsigned long int n = Ustrtoul(sub, &t, 10);
-       if (*t != 0)
+       if (*t)
          {
          expand_string_message = string_sprintf("argument for base62 "
            "operator is \"%s\", which is not a decimal number", sub);
@@ -7278,7 +7278,7 @@ NOT_ITEM: ;
        {
        uschar *tt = sub;
        unsigned long int n = 0;
-       while (*tt != 0)
+       while (*tt)
          {
          uschar *t = Ustrchr(base62_chars, *tt++);
          if (!t)
@@ -7428,6 +7428,29 @@ NOT_ITEM: ;
        goto EXPAND_FAILED;
 #endif
 
+      /* Line-wrap a string as if it is a header line */
+
+      case EOP_HEADERWRAP:
+       {
+       unsigned col = 80, lim = 998;
+       uschar * s;
+
+       if (arg)
+         {
+         const uschar * list = arg;
+         int sep = '_';
+         if ((s = string_nextinlist(&list, &sep, NULL, 0)))
+           {
+           col = atoi(CS s);
+           if ((s = string_nextinlist(&list, &sep, NULL, 0)))
+             lim = atoi(CS s);
+           }
+         }
+         if ((s =  wrap_header(sub, col, lim, US"\t", 8)))
+           yield = string_cat(yield, s);
+       }
+       break;
+
       /* Convert hex encoding to base64 encoding */
 
       case EOP_HEX2B64: