if (whole) *whole = FALSE;
-/* Scan the rewriting rules */
+/* Scan the rewriting rules, ignoring any without matching flag */
for (rewrite_rule * rule = rewrite_rules;
rule && !done;
- rule_number++, rule = rule->next)
+ rule_number++, rule = rule->next) if (rule->flags & flag)
{
int start, end, pdomain;
int count = 0;
const uschar *save_domain;
uschar *error, *new, *newparsed;
- /* Ensure that the flag matches the flags in the rule. */
-
- if (!(rule->flags & flag)) continue;
-
/* Come back here for a repeat after a successful rewrite. We do this
only so many times. */
uschar *p1 = new + start - 1;
uschar *p2 = new + end + 1;
const uschar *pf1, *pf2;
- uschar buff1[256], buff2[256];
while (p1 > new && p1[-1] == ' ') p1--;
- pf1 = parse_fix_phrase(new, p1 - new, buff1, sizeof(buff1));
+ pf1 = parse_fix_phrase(new, p1 - new);
while (*p2 == ' ') p2++;
- pf2 = parse_fix_phrase(p2, Ustrlen(p2), buff2, sizeof(buff2));
-
- /* Note that pf1 and pf2 are NOT necessarily buff1 and buff2. For
- a non-RFC 2047 phrase that does not need to be RFC 2822 quoted, they
- will be buff1+1 and buff2+1. */
+ pf2 = parse_fix_phrase(p2, Ustrlen(p2));
start = Ustrlen(pf1) + start + new - p1;
end = start + Ustrlen(newparsed);
{
int lastnewline = 0;
header_line *newh = NULL;
-void *function_reset_point = store_get(0);
+rmark function_reset_point = store_mark();
uschar *s = Ustrchr(h->text, ':') + 1;
+
while (isspace(*s)) s++;
DEBUG(D_rewrite)
uschar *sprev;
uschar *ss = parse_find_address_end(s, FALSE);
uschar *recipient, *new, *errmess;
- void *loop_reset_point = store_get(0);
+ rmark loop_reset_point = store_mark();
BOOL changed = FALSE;
int terminator = *ss;
int start, end, domain;
the next address, saving the start of the old one. */
*ss = 0;
- recipient = parse_extract_address(s,&errmess,&start,&end,&domain,FALSE);
+ recipient = parse_extract_address(s, &errmess, &start, &end, &domain, FALSE);
*ss = terminator;
sprev = s;
- s = ss + (terminator? 1:0);
+ s = ss + (terminator ? 1 :0);
while (isspace(*s)) s++;
/* There isn't much we can do for syntactic disasters at this stage.
if (!recipient)
{
- store_reset(loop_reset_point);
+ loop_reset_point = store_reset(loop_reset_point);
continue;
}
as abc@xyz, which the DNS lookup turns into abc@xyz.foo.com). However, if no
change is made here, don't bother carrying on. */
- if (routed_old != NULL)
+ if (routed_old)
{
if (domain <= 0 || strcmpic(recipient+domain, routed_old) != 0) continue;
recipient[domain-1] = 0;
if (changed && ((is_recipient && !f.allow_unqualified_recipient) ||
(!is_recipient && !f.allow_unqualified_sender)))
{
- store_reset(loop_reset_point);
+ loop_reset_point = store_reset(loop_reset_point);
continue;
}
}
"whole" flag set, adjust the pointers so that the whole address gets
replaced, except possibly a final \n. */
- if ((existflags & flag) != 0)
+ if (existflags & flag)
{
BOOL whole;
new = rewrite_one(recipient, flag, &whole, FALSE, NULL, rewrite_rules);
point, because we may have a rewritten line from a previous time round the
loop. */
- if (!changed) store_reset(loop_reset_point);
+ if (!changed) loop_reset_point = store_reset(loop_reset_point);
/* If the address has changed, create a new header containing the
rewritten address. We do not need to set the chain pointers at this
int newlen = Ustrlen(new);
int oldlen = end - start;
- header_line *prev = (newh == NULL)? h : newh;
- uschar *newt = store_malloc(prev->slen - oldlen + newlen + 4);
- uschar *newtstart = newt;
+ header_line * prev = newh ? newh : h;
+ uschar * newt = store_get_perm(prev->slen - oldlen + newlen + 4, TRUE);
+ uschar * newtstart = newt;
int type = prev->type;
int slen = prev->slen - oldlen + newlen;
if (*p != '\n')
{
lastnewline = newt - newtstart;
- Ustrcat(newt, "\n\t");
+ Ustrcat(newt, US"\n\t");
slen += 2;
}
}
rewritten copy from a previous time round this loop. */
store_reset(function_reset_point);
- newh = store_get(sizeof(header_line));
+ function_reset_point = store_mark();
+ newh = store_get(sizeof(header_line), FALSE);
newh->type = type;
newh->slen = slen;
newh->text = string_copyn(newtstart, slen);
- store_free(newtstart);
/* Set up for scanning the rest of the header */
s = newh->text + remlen;
- DEBUG(D_rewrite) debug_printf("remainder: %s", (*s == 0)? US"\n" : s);
+ DEBUG(D_rewrite) debug_printf("remainder: %s", *s ? s : US"\n");
}
}
/* If a rewrite happened and "replace" is true, put the new header into the
chain following the old one, and mark the old one as replaced. */
-if (newh != NULL && replace)
+if (newh && replace)
{
newh->next = h->next;
- if (newh->next == NULL) header_last = newh;
+ if (!newh->next) header_last = newh;
h->type = htype_old;
h->next = newh;
}