X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fsrc%2Fmoan.c;h=31d033c1adcf66ed51c9ad65307212fea66804a5;hb=5fcc791a74a6f6933b3fb03f36e9ea3553152cf7;hp=1dcc6c4991b6c1e3ca27afc91f6745eaddd4425a;hpb=5455f54826fe81cddb761ca943ea0b1ef5836dbc;p=user%2Fhenk%2Fcode%2Fexim.git diff --git a/src/src/moan.c b/src/src/moan.c index 1dcc6c499..31d033c1a 100644 --- a/src/src/moan.c +++ b/src/src/moan.c @@ -28,7 +28,7 @@ Returns: nothing void moan_write_from(FILE *f) { -uschar *s = expand_string(dsn_from); +uschar * s = expand_string(dsn_from); if (!s) { log_write(0, LOG_MAIN|LOG_PANIC, @@ -40,6 +40,80 @@ fprintf(f, "From: %s\n", s); +/************************************************* +* Write References: line for DSN * +*************************************************/ + +/* Generate a References: header if there is in the header_list +at least one of Message-ID:, References:, or In-Reply-To: (see RFC 2822). + +Arguments: f the FILE to write to + message_id optional already-found message-id, or NULL + +Returns: nothing +*/ + +void +moan_write_references(FILE * fp, uschar * message_id) +{ +header_line * h; + +if (!message_id) + for (h = header_list; h; h = h->next) + if (h->type == htype_id) + { + message_id = Ustrchr(h->text, ':') + 1; + while (isspace(*message_id)) message_id++; + } + +for (h = header_list; h; h = h->next) + if (h->type != htype_old && strncmpic(US"References:", h->text, 11) == 0) + break; + +if (!h) + for (h = header_list; h; h = h->next) + if (h->type != htype_old && strncmpic(US"In-Reply-To:", h->text, 12) == 0) + break; + +/* We limit the total length of references. Although there is no fixed +limit, some systems do not like headers growing beyond recognition. +Keep the first message ID for the thread root and the last few for +the position inside the thread, up to a maximum of 12 altogether. */ + +if (h || message_id) + { + fprintf(fp, "References:"); + if (h) + { + uschar * s, * id, * error; + uschar * referenced_ids[12]; + int reference_count = 0; + + s = Ustrchr(h->text, ':') + 1; + f.parse_allow_group = FALSE; + while (*s && (s = parse_message_id(s, &id, &error))) + if (reference_count == nelem(referenced_ids)) + { + memmove(referenced_ids + 1, referenced_ids + 2, + sizeof(referenced_ids) - 2*sizeof(uschar *)); + referenced_ids[reference_count - 1] = id; + } + else + referenced_ids[reference_count++] = id; + + for (int i = 0; i < reference_count; ++i) + fprintf(fp, " %s", referenced_ids[i]); + } + + /* The message id will have a newline on the end of it. */ + + if (message_id) fprintf(fp, " %s", message_id); + else fprintf(fp, "\n"); + } +} + + + /************************************************* * Send error message * *************************************************/ @@ -73,7 +147,7 @@ int size_limit = bounce_return_size_limit; FILE * fp; int pid; -#ifdef EXPERIMENTAL_DMARC +#ifdef SUPPORT_DMARC uschar * s, * s2; /* For DMARC if there is a specific sender set, expand the variable for the @@ -111,7 +185,7 @@ fp = fdopen(fd, "wb"); if (errors_reply_to) fprintf(fp, "Reply-To: %s\n", errors_reply_to); fprintf(fp, "Auto-Submitted: auto-replied\n"); -#ifdef EXPERIMENTAL_DMARC +#ifdef SUPPORT_DMARC if (s) fprintf(fp, "From: %s\n", s); else @@ -119,6 +193,7 @@ else moan_write_from(fp); fprintf(fp, "To: %s\n", recipient); +moan_write_references(fp, NULL); switch(ident) { @@ -145,7 +220,7 @@ switch(ident) "A message that you sent contained one or more recipient addresses that were\n" "incorrectly constructed:\n\n"); - while (eblock != NULL) + while (eblock) { fprintf(fp, " %s: %s\n", eblock->text1, eblock->text2); count++; @@ -228,7 +303,7 @@ switch(ident) fprintf(fp, "\n"); break; -#ifdef EXPERIMENTAL_DMARC +#ifdef SUPPORT_DMARC case ERRMESS_DMARC_FORENSIC: bounce_return_message = TRUE; bounce_return_body = FALSE; @@ -308,7 +383,7 @@ if (bounce_return_message) if (bounce_return_body && message_file) { BOOL enddot = f.dot_ends && message_file == stdin; - uschar * buf = store_get(bounce_return_linesize_limit+2); + uschar * buf = store_get(bounce_return_linesize_limit+2, TRUE); if (firstline) fprintf(fp, "%s", CS firstline); @@ -339,7 +414,7 @@ if (bounce_return_message) fputs(CS buf, fp); } } -#ifdef EXPERIMENTAL_DMARC +#ifdef SUPPORT_DMARC /* Overkill, but use exact test in case future code gets inserted */ else if (bounce_return_body && message_file == NULL) { @@ -522,21 +597,22 @@ f = fdopen(fd, "wb"); fprintf(f, "Auto-Submitted: auto-replied\n"); moan_write_from(f); fprintf(f, "To: %s\n", who); +moan_write_references(f, NULL); fprintf(f, "Subject: %s\n\n", subject); va_start(ap, format); vfprintf(f, format, ap); va_end(ap); -if (addr != NULL) +if (addr) { fprintf(f, "\nThe following address(es) have yet to be delivered:\n"); - for (; addr != NULL; addr = addr->next) + for (; addr; addr = addr->next) { - uschar *parent = (addr->parent == NULL)? NULL : addr->parent->address; + uschar * parent = addr->parent ? addr->parent->address : NULL; fprintf(f, " %s", addr->address); - if (parent != NULL) fprintf(f, " <%s>", parent); + if (parent) fprintf(f, " <%s>", parent); if (addr->basic_errno > 0) fprintf(f, ": %s", strerror(addr->basic_errno)); - if (addr->message != NULL) fprintf(f, ": %s", addr->message); + if (addr->message) fprintf(f, ": %s", addr->message); fprintf(f, "\n"); } } @@ -656,8 +732,7 @@ llen = domain++ - recipient; /* Scan through the configured items */ -while ((item = string_nextinlist(&listptr, &sep, buffer, sizeof(buffer))) - != NULL) +while ((item = string_nextinlist(&listptr, &sep, buffer, sizeof(buffer)))) { const uschar *newaddress = item; const uschar *pattern = string_dequote(&newaddress); @@ -724,22 +799,18 @@ moan_skipped_syntax_errors(uschar *rname, error_block *eblock, int pid, fd; uschar *s, *t; FILE *f; -error_block *e; -for (e = eblock; e != NULL; e = e->next) - { +for (error_block * e = eblock; e; e = e->next) if (e->text2 != NULL) log_write(0, LOG_MAIN, "%s router: skipped error: %s in \"%s\"", rname, e->text1, e->text2); else log_write(0, LOG_MAIN, "%s router: skipped error: %s", rname, e->text1); - } -if (syntax_errors_to == NULL) return TRUE; +if (!syntax_errors_to) return TRUE; -s = expand_string(syntax_errors_to); -if (s == NULL) +if (!(s = expand_string(syntax_errors_to))) { log_write(0, LOG_MAIN, "%s router failed to expand %s: %s", rname, syntax_errors_to, expand_string_message); @@ -763,11 +834,11 @@ fprintf(f, "Auto-Submitted: auto-replied\n"); moan_write_from(f); fprintf(f, "To: %s\n", s); fprintf(f, "Subject: error(s) in forwarding or filtering\n\n"); +moan_write_references(f, NULL); -if (custom != NULL) +if (custom) { - t = expand_string(custom); - if (t == NULL) + if (!(t = expand_string(custom))) { log_write(0, LOG_MAIN, "%s router failed to expand %s: %s", rname, custom, expand_string_message); @@ -779,7 +850,7 @@ if (custom != NULL) fprintf(f, "The %s router encountered the following error(s):\n\n", rname); -for (e = eblock; e != NULL; e = e->next) +for (error_block * e = eblock; e; e = e->next) { fprintf(f, " %s", e->text1); if (e->text2 != NULL)