+ /* ${base32:${eval:$tod_epoch/86400&0x3ff}}= */
+ {
+ struct timeval now;
+ unsigned long i;
+ gstring * h = NULL;
+
+ gettimeofday(&now, NULL);
+ for (unsigned long i = (now.tv_sec / 86400) & 0x3ff; i; i >>= 5)
+ h = string_catn(h, &base32_chars[i & 0x1f], 1);
+ if (h) while (h->ptr > 0)
+ g = string_catn(g, &h->s[--h->ptr], 1);
+ }
+ g = string_catn(g, US"=", 1);
+
+ /* ${domain:$return_path}=${local_part:$return_path} */
+ {
+ int start, end, domain;
+ uschar * t = parse_extract_address(sub[1], &expand_string_message,
+ &start, &end, &domain, FALSE);
+ uschar * s;
+
+ if (!t)
+ goto EXPAND_FAILED;
+
+ if (domain > 0) g = string_cat(g, t + domain);
+ g = string_catn(g, US"=", 1);
+
+ s = domain > 0 ? string_copyn(t, domain - 1) : t;
+ if ((quoted = Ustrchr(s, '"') != NULL))
+ {
+ gstring * h = NULL;
+ DEBUG(D_expand) debug_printf_indent("auto-quoting local part\n");
+ while (*s) /* de-quote */
+ {
+ while (*s && *s != '"') h = string_catn(h, s++, 1);
+ if (*s) s++;
+ while (*s && *s != '"') h = string_catn(h, s++, 1);
+ if (*s) s++;
+ }
+ gstring_release_unused(h);
+ s = string_from_gstring(h);
+ }
+ g = string_cat(g, s);
+ }
+
+ /* Assume that if the original local_part had quotes
+ it was for good reason */
+
+ if (quoted) yield = string_catn(yield, US"\"", 1);
+ yield = string_catn(yield, g->s, g->ptr);
+ if (quoted) yield = string_catn(yield, US"\"", 1);
+
+ /* @$original_domain */
+ yield = string_catn(yield, US"@", 1);
+ yield = string_cat(yield, sub[2]);
+
+ if (skipping) continue;
+ break;
+ }
+#endif /*SUPPORT_SRS*/
+
+ default:
+ goto NOT_ITEM;
+ } /* EITEM_* switch */
+ /*NOTREACHED*/
+
+ DEBUG(D_expand)
+ if (yield && (start > 0 || *s)) /* only if not the sole expansion of the line */
+ debug_expansion_interim(US"item-res",
+ yield->s + start, yield->ptr - start, skipping);
+ continue;
+
+NOT_ITEM: ;
+ }
+
+ /* Control reaches here if the name is not recognized as one of the more
+ complicated expansion items. Check for the "operator" syntax (name terminated
+ by a colon). Some of the operators have arguments, separated by _ from the
+ name. */
+
+ if (*s == ':')
+ {
+ int c;
+ uschar * arg = NULL, * sub;
+#ifndef DISABLE_TLS
+ var_entry * vp = NULL;
+#endif
+
+ /* Owing to an historical mis-design, an underscore may be part of the
+ operator name, or it may introduce arguments. We therefore first scan the
+ table of names that contain underscores. If there is no match, we cut off
+ the arguments and then scan the main table. */
+
+ if ((c = chop_match(name, op_table_underscore,
+ nelem(op_table_underscore))) < 0)
+ {
+ if ((arg = Ustrchr(name, '_')))
+ *arg = 0;
+ if ((c = chop_match(name, op_table_main, nelem(op_table_main))) >= 0)
+ c += nelem(op_table_underscore);
+ if (arg) *arg++ = '_'; /* Put back for error messages */
+ }
+
+ /* Deal specially with operators that might take a certificate variable
+ as we do not want to do the usual expansion. For most, expand the string.*/
+ switch(c)
+ {