7 /* one-to-one address mapping
11 /* int smtp_map11_external(addr, maps, propagate)
16 /* int smtp_map11_internal(addr, maps, propagate)
21 /* int smtp_map11_tree(tree, maps, propagate)
26 /* This module performs non-recursive one-to-one address mapping.
27 /* An unmatched address extension is propagated when
28 /* \fIpropagate\fR is non-zero.
30 /* smtp_map11_external() looks up the RFC 822 external (quoted) string
31 /* form of an address in the maps specified via the \fImaps\fR argument.
33 /* smtp_map11_internal() is a wrapper around the
34 /* smtp_map11_external() routine that transforms from
35 /* internal (quoted) string form to external form and back.
37 /* smtp_map11_tree() is a wrapper around the
38 /* smtp_map11_external() routine that transforms from
39 /* internal parse tree form to external form and back.
41 /* Table lookup errors are fatal.
43 /* mail_addr_map(3) address mappings
47 /* The Secure Mailer license must be distributed with this software.
50 /* IBM T.J. Watson Research
52 /* Yorktown Heights, NY 10598, USA
60 /* Utility library. */
67 #include <valid_hostname.h>
71 #include <mail_addr_map.h>
72 #include <quote_822_local.h>
74 /* Application-specific. */
78 /* smtp_map11_external - one-to-one table lookups */
80 int smtp_map11_external(VSTRING
*addr
, MAPS
*maps
, int propagate
)
82 const char *myname
= "smtp_map11_external";
86 if ((new_addr
= mail_addr_map(maps
, STR(addr
), propagate
)) != 0) {
87 if (new_addr
->argc
> 1)
88 msg_warn("multi-valued %s result for %s", maps
->title
, STR(addr
));
89 result
= new_addr
->argv
[0];
91 msg_info("%s: %s -> %s", myname
, STR(addr
), result
);
92 vstring_strcpy(addr
, result
);
97 msg_fatal("%s map lookup problem for %s", maps
->title
, STR(addr
));
99 msg_info("%s: %s not found", myname
, STR(addr
));
104 /* smtp_map11_tree - rewrite address node */
106 int smtp_map11_tree(TOK822
*tree
, MAPS
*maps
, int propagate
)
108 VSTRING
*temp
= vstring_alloc(100);
111 tok822_externalize(temp
, tree
->head
, TOK822_STR_DEFL
);
112 ret
= smtp_map11_external(temp
, maps
, propagate
);
113 tok822_free_tree(tree
->head
);
114 tree
->head
= tok822_scan(STR(temp
), &tree
->tail
);
119 /* smtp_map11_internal - rewrite address internal form */
121 int smtp_map11_internal(VSTRING
*addr
, MAPS
*maps
, int propagate
)
123 VSTRING
*temp
= vstring_alloc(100);
126 quote_822_local(temp
, STR(addr
));
127 ret
= smtp_map11_external(temp
, maps
, propagate
);
128 unquote_822_local(addr
, STR(temp
));
135 #include <msg_vstream.h>
136 #include <stringops.h>
137 #include <mail_params.h>
139 int main(int argc
, char **argv
)
141 VSTRING
*buf
= vstring_alloc(100);
144 msg_vstream_init(basename(argv
[0]), VSTREAM_ERR
);
146 msg_fatal("usage: %s maptype:mapname address...", argv
[0]);
148 maps
= maps_create(argv
[1], argv
[1], DICT_FLAG_FOLD_FIX
);
150 if (chdir(var_queue_dir
) < 0)
151 msg_fatal("chdir(%s): %m", var_queue_dir
);
155 while (--argc
&& *++argv
) {
156 msg_info("-- start %s --", *argv
);
157 smtp_map11_external(vstring_strcpy(buf
, *argv
), maps
, 1);
158 msg_info("-- end %s --", *argv
);