7 /* strip extension from full or localpart-only address
9 /* #include <strip_addr.h>
11 /* char *strip_addr(address, extension, delimiter)
12 /* const char *address;
16 /* strip_addr() takes an address and either returns a null
17 /* pointer when the address contains no address extension,
18 /* or returns a copy of the address without address extension.
19 /* The caller is expected to pass the copy to myfree().
23 /* Address localpart or user@domain form.
25 /* A null pointer, or the address of a pointer that is set to
26 /* the address of a dynamic memory copy of the address extension
27 /* that had to be chopped off.
28 /* The copy includes the recipient address delimiter.
29 /* The caller is expected to pass the copy to myfree().
31 /* Recipient address delimiter.
33 /* split_addr(3) strip extension from localpart
37 /* The Secure Mailer license must be distributed with this software.
40 /* IBM T.J. Watson Research
42 /* Yorktown Heights, NY 10598, USA
50 /* Utility library. */
56 #include <split_addr.h>
57 #include <strip_addr.h>
59 /* strip_addr - strip extension from address */
61 char *strip_addr(const char *full
, char **extension
, int delimiter
)
69 * A quick test to eliminate inputs without delimiter anywhere.
71 if (delimiter
== 0 || strchr(full
, delimiter
) == 0) {
72 stripped
= saved_ext
= 0;
74 stripped
= mystrdup(full
);
75 if ((ratsign
= strrchr(stripped
, '@')) != 0)
77 if ((extent
= split_addr(stripped
, delimiter
)) != 0) {
81 saved_ext
= mystrdup(extent
);
87 memmove(extent
, ratsign
, strlen(ratsign
) + 1);
91 stripped
= saved_ext
= 0;
95 *extension
= saved_ext
;
102 #include <mail_params.h>
104 char *var_double_bounce_sender
= DEF_DOUBLE_BOUNCE
;
106 int main(int unused_argc
, char **unused_argv
)
113 * Incredible. This function takes only three arguments, and the tests
114 * already take more lines of code than the code being tested.
116 stripped
= strip_addr("foo", (char **) 0, 0);
118 msg_panic("strip_addr botch 1");
120 stripped
= strip_addr("foo", &extension
, 0);
122 msg_panic("strip_addr botch 2");
124 msg_panic("strip_addr botch 3");
126 stripped
= strip_addr("foo", (char **) 0, delim
);
128 msg_panic("strip_addr botch 4");
130 stripped
= strip_addr("foo", &extension
, delim
);
132 msg_panic("strip_addr botch 5");
134 msg_panic("strip_addr botch 6");
136 stripped
= strip_addr("foo@bar", (char **) 0, 0);
138 msg_panic("strip_addr botch 7");
140 stripped
= strip_addr("foo@bar", &extension
, 0);
142 msg_panic("strip_addr botch 8");
144 msg_panic("strip_addr botch 9");
146 stripped
= strip_addr("foo@bar", (char **) 0, delim
);
148 msg_panic("strip_addr botch 10");
150 stripped
= strip_addr("foo@bar", &extension
, delim
);
152 msg_panic("strip_addr botch 11");
154 msg_panic("strip_addr botch 12");
156 stripped
= strip_addr("foo-ext", (char **) 0, 0);
158 msg_panic("strip_addr botch 13");
160 stripped
= strip_addr("foo-ext", &extension
, 0);
162 msg_panic("strip_addr botch 14");
164 msg_panic("strip_addr botch 15");
166 stripped
= strip_addr("foo-ext", (char **) 0, delim
);
168 msg_panic("strip_addr botch 16");
169 msg_info("wanted: foo-ext -> %s", "foo");
170 msg_info("strip_addr foo-ext -> %s", stripped
);
173 stripped
= strip_addr("foo-ext", &extension
, delim
);
175 msg_panic("strip_addr botch 17");
177 msg_panic("strip_addr botch 18");
178 msg_info("wanted: foo-ext -> %s %s", "foo", "-ext");
179 msg_info("strip_addr foo-ext -> %s %s", stripped
, extension
);
183 stripped
= strip_addr("foo-ext@bar", (char **) 0, 0);
185 msg_panic("strip_addr botch 19");
187 stripped
= strip_addr("foo-ext@bar", &extension
, 0);
189 msg_panic("strip_addr botch 20");
191 msg_panic("strip_addr botch 21");
193 stripped
= strip_addr("foo-ext@bar", (char **) 0, delim
);
195 msg_panic("strip_addr botch 22");
196 msg_info("wanted: foo-ext@bar -> %s", "foo@bar");
197 msg_info("strip_addr foo-ext@bar -> %s", stripped
);
200 stripped
= strip_addr("foo-ext@bar", &extension
, delim
);
202 msg_panic("strip_addr botch 23");
204 msg_panic("strip_addr botch 24");
205 msg_info("wanted: foo-ext@bar -> %s %s", "foo@bar", "-ext");
206 msg_info("strip_addr foo-ext@bar -> %s %s", stripped
, extension
);