aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2020-07-02 14:35:10 +0300
committerSergey Poznyakoff <gray@gnu.org>2020-07-02 14:48:27 +0300
commit14e0558e6051671d9ebc8083467e021dfd81780a (patch)
tree20510691091f71d6f8371aa1f88693e118b78fbb /src
parent643a00fef4328566c437f9f3db293ad764f00e58 (diff)
downloadmailfromd-14e0558e6051671d9ebc8083467e021dfd81780a.tar.gz
mailfromd-14e0558e6051671d9ebc8083467e021dfd81780a.tar.bz2
Remove header_delete_nth and header_replace_nth.
Both functions were unable to do their work properly, due to the deficiences of the Milter API. Rewrite header_rename, header_prefix_all and header_prefix_pattern. * NEWS: Update. * doc/functions.texi: Update discussion of header modification functions. * mflib/header_rename.mf4: Rewrite. * src/builtin/header.bi (header_delete_nth) (header_replace_nth): Remove. * src/builtin/vars.bi (sendmail_header_count): Remove. (get_sendmail_header_count,set_sendmail_header_count): Remove. * src/engine.c (message_data): Remove members: hdrtrans, hdrcount. All uses changed. (md_hdrtrans_fill,md_hdrtrans): Remove. * src/mailfromd.h (header_delete_nth,header_replace_nth): Remove. All uses changed.
Diffstat (limited to 'src')
-rw-r--r--src/builtin/header.bi32
-rw-r--r--src/builtin/vars.bi14
-rw-r--r--src/engine.c129
-rw-r--r--src/gram.y6
-rw-r--r--src/mailfromd.h5
5 files changed, 2 insertions, 184 deletions
diff --git a/src/builtin/header.bi b/src/builtin/header.bi
index a66d1885..053592c7 100644
--- a/src/builtin/header.bi
+++ b/src/builtin/header.bi
@@ -72,22 +72,6 @@ MF_DEFUN(header_delete, VOID, STRING name, OPTIONAL, NUMBER idx)
}
END
-MF_CAPTURE
-MF_DEFUN(header_delete_nth, VOID, NUMBER idx)
-{
- struct mu_locus_range locus;
-
- env_get_locus(env, &locus);
-
- trace("%s%s:%u: %s %lu",
- mailfromd_msgid(env_get_context(env)),
- locus.beg.mu_file, locus.beg.mu_line,
- msgmod_opcode_str(header_delete_nth),
- idx);
- env_msgmod(env, header_delete_nth, NULL, NULL, idx);
-}
-END
-
MF_DEFUN(header_replace, VOID, STRING name, STRING value, OPTIONAL, NUMBER idx)
{
struct mu_locus_range locus;
@@ -103,19 +87,3 @@ MF_DEFUN(header_replace, VOID, STRING name, STRING value, OPTIONAL, NUMBER idx)
}
END
-MF_CAPTURE
-MF_DEFUN(header_replace_nth, VOID, NUMBER idx, STRING name, STRING value)
-{
- struct mu_locus_range locus;
-
- env_get_locus(env, &locus);
-
- trace("%s%s:%u: %s \"%s: %s\" (%lu)",
- mailfromd_msgid(env_get_context(env)),
- locus.beg.mu_file, locus.beg.mu_line,
- msgmod_opcode_str(header_replace_nth),
- name, value, idx);
- env_msgmod(env, header_replace_nth, name, value, idx);
-}
-END
-
diff --git a/src/builtin/vars.bi b/src/builtin/vars.bi
index df34a65d..86454673 100644
--- a/src/builtin/vars.bi
+++ b/src/builtin/vars.bi
@@ -23,7 +23,6 @@ MF_VAR(milter_client_address, STRING, SYM_PRECIOUS);
MF_VAR(milter_server_family, NUMBER, SYM_PRECIOUS);
MF_VAR(milter_server_address, STRING, SYM_PRECIOUS);
MF_VAR(milter_server_id, STRING, SYM_PRECIOUS);
-MF_VAR(sendmail_header_count, NUMBER, SYM_PRECIOUS);
/* Functions to access %rcpt_count */
unsigned long
@@ -44,19 +43,6 @@ incr_rcpt_count(eval_environ_t env)
MF_VAR_INC(rcpt_count);
}
-/* Same for sendmail_header_count */
-unsigned long
-get_sendmail_header_count(eval_environ_t env)
-{
- return MF_VAR_REF(sendmail_header_count, long);
-}
-
-void
-set_sendmail_header_count(eval_environ_t env, unsigned long v)
-{
- MF_VAR_REF(sendmail_header_count, ulong, v);
-}
-
/* define_milter_address name */
m4_define([<define_milter_address>],[<
MF_DSEXP_SUPPRESS([<set_milter_$1_address>],
diff --git a/src/engine.c b/src/engine.c
index 877ba56d..9dc736a5 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -46,25 +46,11 @@ static void ctx_msgmod(void *data, struct msgmod_closure *cmd);
/* Per-message data */
-/* Header translation table is used to translate absolute header number
- into Sendmail notation (name, idx), where name is the header name and
- idx is 1-based number of occurrence of the header with that name.
-
- This translation is needed for two functions provided by Mailfromd:
- header_delete_nth and header_replace_nth.
-*/
-struct hdrtrans {
- const char *name;
- size_t idx;
-};
-
struct message_data {
eval_environ_t env; /* Evaluation environment */
mu_list_t mmq; /* Message Modification Queue */
char *helostr; /* Domain name obtained in HELO phase */
char msgid[64]; /* Message ID */
- struct hdrtrans *hdrtrans; /* Header translation table */
- size_t hdrcount; /* No. of entries in hdrtrans */
};
static struct message_data *test_message_data;
@@ -76,8 +62,6 @@ test_message_data_init(eval_environ_t env)
test_message_data->mmq = NULL;
test_message_data->helostr = NULL;
test_message_data->msgid[0] = 0;
- test_message_data->hdrtrans = NULL;
- test_message_data->hdrcount = 0;
}
static struct message_data *
@@ -107,8 +91,6 @@ priv_get(SMFICTX *ctx)
md->mmq = NULL;
md->helostr = NULL;
md->msgid[0] = 0;
- md->hdrtrans = NULL;
- md->hdrcount = 0;
gacopyz_setpriv(ctx, md);
env_init(md->env);
if (gacopyz_server_sockname(ctx, &addr, &len) == 0)
@@ -267,7 +249,6 @@ capture_eom(eval_environ_t env)
}
-
/* Cleanup functions */
void
filter_cleanup(SMFICTX *ctx)
@@ -280,7 +261,6 @@ filter_cleanup(SMFICTX *ctx)
free(md->helostr);
destroy_environment(md->env);
mu_list_destroy(&md->mmq);
- free(md->hdrtrans);
free(md);
gacopyz_setpriv(ctx, NULL);
}
@@ -615,62 +595,10 @@ xlate_and_replace_body(SMFICTX *ctx, const char *value, size_t size)
}
static int
-md_hdrtrans_fill(struct message_data *md)
-{
- int rc;
- mu_header_t hdr;
- size_t count, i, j;
-
- if (env_get_header(md->env, &hdr))
- return 1;
- rc = mu_header_get_field_count(hdr, &count);
- if (rc) {
- mu_diag_funcall(MU_DIAG_ERROR,
- "mu_header_get_field_count",
- NULL, rc);
- return 1;
- }
- md->hdrtrans = mu_calloc(count, sizeof(md->hdrtrans[0]));
- for (i = 1; i <= count; i++) {
- const char *s;
- rc = mu_header_sget_field_name(hdr, i, &s);
- if (rc) {
- mu_diag_funcall(MU_DIAG_ERROR,
- "mu_header_sget_field_name",
- NULL, rc);
- return 1;
- }
- md->hdrtrans[i-1].name = s;
- md->hdrtrans[i-1].idx = 1;
- for (j = i - 1; j > 0; j--)
- if (mu_c_strcasecmp(md->hdrtrans[j-1].name, s) == 0) {
- md->hdrtrans[i-1].idx =
- md->hdrtrans[j-1].idx + 1;
- break;
- }
- }
- md->hdrcount = count;
- return 0;
-}
-
-static int
-md_hdrtrans(struct message_data *md, struct msgmod_closure *hdr)
-{
- if (!md->hdrtrans && md_hdrtrans_fill(md))
- return -1;
- if (hdr->idx == 0 || hdr->idx > md->hdrcount)
- return 1;
- hdr->name = (char*) md->hdrtrans[hdr->idx - 1].name;
- hdr->idx = md->hdrtrans[hdr->idx - 1].idx;
- return 0;
-}
-
-static int
run_msgmod(void *item, void *data)
{
- struct msgmod_closure *hdr = item, thdr;
+ struct msgmod_closure *hdr = item;
SMFICTX *ctx = data;
- struct message_data *md;
mu_debug(MF_SOURCE_ENGINE, MU_DEBUG_TRACE6,
("%s %s: %s %u",
@@ -691,25 +619,7 @@ run_msgmod(void *item, void *data)
break;
case header_insert:
- /* Note: The get_sendmail_header_count() call returns the
- number of headers defined by Sendmail (or other MTA) itself.
- I have found no reliable method allowing to determine
- that number automatically. In the absence of such method,
- the user has to define the header count explicitly, by
- setting the sendmail_header_count variable. For Sendmail,
- a good estimate is given by the following command:
-
- grep -c ^H /etc/mail/sendmail.cf
-
- Notice, however, that some of the headers may be defined
- conditionally, see the section 5.5. "H -- Define Header",
- in the Sendmail(tm) Installation and Operation Guide, for
- more information.
- */
- md = priv_get(ctx);
- gacopyz_insert_header(ctx,
- hdr->idx + get_sendmail_header_count(md->env),
- hdr->name, hdr->value);
+ gacopyz_insert_header(ctx, hdr->idx, hdr->name, hdr->value);
break;
case rcpt_add:
@@ -737,41 +647,6 @@ run_msgmod(void *item, void *data)
}
break;
- case header_replace_nth:
- md = priv_get(ctx);
- thdr = *hdr;
- switch (md_hdrtrans(md, &thdr)) {
- case -1:
- return 1;
- case 1:
- return 0;
- default:
- break;
- }
- /* Remove old header */
- gacopyz_change_header(ctx, thdr.idx, thdr.name, NULL);
- /* Insert the new one. For the meaning of
- get_sendmail_header_count, see the comment to the
- header_insert case above.
- */
- gacopyz_insert_header(ctx,
- hdr->idx + get_sendmail_header_count(md->env),
- hdr->name, hdr->value);
- break;
-
- case header_delete_nth:
- thdr = *hdr;
- switch (md_hdrtrans(priv_get(ctx), &thdr)) {
- case -1:
- return 1;
- case 1:
- return 0;
- default:
- break;
- }
- gacopyz_change_header(ctx, thdr.idx, thdr.name, NULL);
- break;
-
case set_from:
gacopyz_chgfrom(ctx, hdr->name, hdr->value);
break;
diff --git a/src/gram.y b/src/gram.y
index 5403484f..fbc894af 100644
--- a/src/gram.y
+++ b/src/gram.y
@@ -3303,12 +3303,6 @@ msgmod_opcode_str(enum msgmod_opcode opcode)
case body_repl_fd:
return "REPLACE BODY FROM FILE";
- case header_replace_nth:
- return "REPLACE NTH HEADER";
-
- case header_delete_nth:
- return "DELETE NTH HEADER";
-
case set_from:
return "SET FROM";
diff --git a/src/mailfromd.h b/src/mailfromd.h
index 59d0f839..520ea52a 100644
--- a/src/mailfromd.h
+++ b/src/mailfromd.h
@@ -218,8 +218,6 @@ enum msgmod_opcode { /* Message modification operation */
quarantine, /* Quarantine a message */
body_repl, /* Replace message body */
body_repl_fd, /* Replace message body from file */
- header_delete_nth, /* Delete Nth header */
- header_replace_nth, /* Replace Nth header */
set_from /* Change envelope sender */
};
@@ -757,9 +755,6 @@ unsigned long get_rcpt_count(eval_environ_t env);
void clear_rcpt_count(eval_environ_t env);
void incr_rcpt_count(eval_environ_t env);
-unsigned long get_sendmail_header_count(eval_environ_t env);
-void set_sendmail_header_count(eval_environ_t env, unsigned long v);
-
void set_last_poll_helo(eval_environ_t env, const char *text);
void set_last_poll_greeting(eval_environ_t env, const char *text);
void set_last_poll_host(eval_environ_t env, const char *host_addr);

Return to:

Send suggestions and report system problems to the System administrator.