X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fsrc%2Fexpand.c;h=cfde23610acafb6d200cfd3934179e802f45ac67;hb=91bde4a0253d38118dc227e184b793d476a013ce;hp=0fba962781807b8c6e221f932d788410e5dda468;hpb=44bc8f0c2f3576b46bd6df1b818cb29eaf84df5b;p=user%2Fhenk%2Fcode%2Fexim.git diff --git a/src/src/expand.c b/src/src/expand.c index 0fba96278..cfde23610 100644 --- a/src/src/expand.c +++ b/src/src/expand.c @@ -207,6 +207,7 @@ static uschar *op_table_main[] = { US"base64d", US"domain", US"escape", + US"escape8bit", US"eval", US"eval10", US"expand", @@ -252,6 +253,7 @@ enum { EOP_BASE64D, EOP_DOMAIN, EOP_ESCAPE, + EOP_ESCAPE8BIT, EOP_EVAL, EOP_EVAL10, EOP_EXPAND, @@ -3048,6 +3050,8 @@ switch(cond_type) "value \"%s\"", t); return NULL; } + DEBUG(D_expand) debug_printf("%s: condition evaluated to %s\n", ourname, + boolvalue? "true":"false"); if (yield != NULL) *yield = (boolvalue == testfor); return s; } @@ -3189,16 +3193,17 @@ items. */ while (isspace(*s)) s++; if (*s == '}') { - if (type[0] == 'i') - { - if (yes) *yieldptr = string_catn(*yieldptr, sizeptr, ptrptr, US"true", 4); - } - else - { - if (yes && lookup_value) - *yieldptr = string_cat(*yieldptr, sizeptr, ptrptr, lookup_value); - lookup_value = save_lookup; - } + if (!skipping) + if (type[0] == 'i') + { + if (yes) *yieldptr = string_catn(*yieldptr, sizeptr, ptrptr, US"true", 4); + } + else + { + if (yes && lookup_value) + *yieldptr = string_cat(*yieldptr, sizeptr, ptrptr, lookup_value); + lookup_value = save_lookup; + } s++; goto RETURN; } @@ -3495,7 +3500,6 @@ Returns: new value of string pointer static uschar * cat_file(FILE *f, uschar *yield, int *sizep, int *ptrp, uschar *eol) { -int eollen = eol ? Ustrlen(eol) : 0; uschar buffer[1024]; while (Ufgets(buffer, sizeof(buffer), f)) @@ -3503,8 +3507,8 @@ while (Ufgets(buffer, sizeof(buffer), f)) int len = Ustrlen(buffer); if (eol && buffer[len-1] == '\n') len--; yield = string_catn(yield, sizep, ptrp, buffer, len); - if (buffer[len] != 0) - yield = string_catn(yield, sizep, ptrp, eol, eollen); + if (eol && buffer[len]) + yield = string_cat(yield, sizep, ptrp, eol); } if (yield) yield[*ptrp] = 0; @@ -4108,7 +4112,7 @@ while (*s != 0) save_expand_strings(save_expand_nstring, save_expand_nlength); while (isspace(*s)) s++; - next_s = eval_condition(s, &resetok, skipping? NULL : &cond); + next_s = eval_condition(s, &resetok, skipping ? NULL : &cond); if (next_s == NULL) goto EXPAND_FAILED; /* message already set */ DEBUG(D_expand) @@ -4172,11 +4176,13 @@ while (*s != 0) goto EXPAND_FAILED; } - if (!(encoded = imap_utf7_encode(sub_arg[0], headers_charset, - sub_arg[1][0], sub_arg[2], &expand_string_message))) - goto EXPAND_FAILED; if (!skipping) + { + if (!(encoded = imap_utf7_encode(sub_arg[0], headers_charset, + sub_arg[1][0], sub_arg[2], &expand_string_message))) + goto EXPAND_FAILED; yield = string_cat(yield, &size, &ptr, encoded); + } continue; } #endif @@ -4654,7 +4660,6 @@ while (*s != 0) prvscheck_keynum = NULL; } else - { /* Does not look like a prvs encoded address, return the empty string. We need to make sure all subs are expanded first, so as to skip over the entire item. */ @@ -4665,7 +4670,6 @@ while (*s != 0) case 2: case 3: goto EXPAND_FAILED; } - } continue; } @@ -4960,7 +4964,10 @@ while (*s != 0) } if (skipping) /* Just pretend it worked when we're skipping */ + { runrc = 0; + lookup_value = NULL; + } else { if (!transport_set_up_command(&argv, /* anchor for arg list */ @@ -5002,9 +5009,9 @@ while (*s != 0) return code for serious disasters. Simple non-zero returns are passed on. */ - if (sigalrm_seen == TRUE || (runrc = child_close(pid, 30)) < 0) + if (sigalrm_seen || (runrc = child_close(pid, 30)) < 0) { - if (sigalrm_seen == TRUE || runrc == -256) + if (sigalrm_seen || runrc == -256) { expand_string_message = string_sprintf("command timed out"); killpg(pid, SIGKILL); /* Kill the whole process group */ @@ -7106,11 +7113,23 @@ while (*s != 0) case EOP_ESCAPE: { - const uschar *t = string_printing(sub); + const uschar * t = string_printing(sub); yield = string_cat(yield, &size, &ptr, t); continue; } + case EOP_ESCAPE8BIT: + { + const uschar * s = sub; + uschar c; + + for (s = sub; (c = *s); s++) + yield = c < 127 && c != '\\' + ? string_catn(yield, &size, &ptr, s, 1) + : string_catn(yield, &size, &ptr, string_sprintf("\\%03o", c), 4); + continue; + } + /* Handle numeric expression evaluation */ case EOP_EVAL: @@ -7408,8 +7427,7 @@ while (*s != 0) yield = NULL; size = 0; } - value = find_variable(name, FALSE, skipping, &newsize); - if (value == NULL) + if (!(value = find_variable(name, FALSE, skipping, &newsize))) { expand_string_message = string_sprintf("unknown variable in \"${%s}\"", name); @@ -7417,13 +7435,14 @@ while (*s != 0) goto EXPAND_FAILED; } len = Ustrlen(value); - if (yield == NULL && newsize != 0) + if (!yield && newsize) { yield = value; size = newsize; ptr = len; } - else yield = string_catn(yield, &size, &ptr, value, len); + else + yield = string_catn(yield, &size, &ptr, value, len); continue; }