5
/* process Delivered-To: headers
9
/* HTABLE *delivered_init(attr)
12
/* int delivered_find(table, address)
16
/* void delivered_free(table)
19
/* This module processes addresses in Delivered-To: headers.
20
/* These headers are added by some mail delivery systems, for the
21
/* purpose of breaking mail forwarding loops. N.B. This solves
22
/* a different problem than the Received: hop count limit. Hop
23
/* counts are used to limit the impact of mail routing problems.
25
/* delivered_init() extracts Delivered-To: header addresses
26
/* from the specified message, and returns a table with the
29
/* delivered_find() looks up the address in the lookup table,
30
/* and returns non-zero when the address was found. The
31
/* address argument must be in internalized form.
33
/* delivered_free() releases storage that was allocated by
38
/* The attributes that specify the message, recipient and more.
40
/* A table with extracted Delivered-To: addresses.
42
/* A recipient address, internal form.
44
/* Fatal errors: out of memory.
49
/* The Secure Mailer license must be distributed with this software.
52
/* IBM T.J. Watson Research
54
/* Yorktown Heights, NY 10598, USA
64
/* Utility library. */
70
#include <vstring_vstream.h>
71
#include <stringops.h>
77
#include <is_header.h>
78
#include <quote_822_local.h>
79
#include <header_opts.h>
81
/* Application-specific. */
87
#define STR vstring_str
89
/* delivered_init - extract delivered-to information from the message */
91
HTABLE *delivered_init(DELIVER_ATTR attr)
94
HTABLE *table = htable_create(0);
98
buf = vstring_alloc(10);
100
if (vstream_fseek(attr.fp, attr.offset, SEEK_SET) < 0)
101
msg_fatal("seek queue file %s: %m", VSTREAM_PATH(attr.fp));
104
* XXX Assume that normal mail systems produce headers that fit in a
105
* REC_TYPE_NORM record. Lowercase the delivered-to addresses for
108
while (rec_get(attr.fp, buf, 0) == REC_TYPE_NORM) {
109
if (is_header(STR(buf))) {
110
if ((hdr = header_opts_find(STR(buf))) != 0
111
&& hdr->type == HDR_DELIVERED_TO) {
112
cp = STR(buf) + strlen(hdr->name) + 1;
117
msg_info("delivered_init: %s", cp);
118
htable_enter(table, cp, (char *) 0);
120
} else if (ISSPACE(STR(buf)[0])) {
129
/* delivered_find - look up recipient in delivered table */
131
int delivered_find(HTABLE *table, char *address)
136
* mail_copy() uses quote_822_local() when writing the Delivered-To:
137
* header. We must therefore apply the same transformation when looking
138
* up the recipient. Lowercase the delivered-to address for consistency.
140
quote_822_local(buf, address);
142
ht = htable_locate(table, STR(buf));