xref: /netbsd-src/external/ibm-public/postfix/dist/src/global/split_addr.c (revision 413d532bcc3f62d122e56d92e13ac64825a40baf)
1 /*	$NetBSD: split_addr.c,v 1.1.1.1 2009/06/23 10:08:48 tron Exp $	*/
2 
3 /*++
4 /* NAME
5 /*	split_addr 3
6 /* SUMMARY
7 /*	recipient localpart address splitter
8 /* SYNOPSIS
9 /*	#include <split_addr.h>
10 /*
11 /*	char	*split_addr(localpart, delimiter)
12 /*	char	*localpart;
13 /*	int	delimiter;
14 /* DESCRIPTION
15 /*	split_addr() null-terminates \fIlocalpart\fR at the first
16 /*	occurrence of the \fIdelimiter\fR character found, and
17 /*	returns a pointer to the remainder.
18 /*
19 /*	Reserved addresses are not split: postmaster, mailer-daemon,
20 /*	double-bounce. Addresses that begin with owner-, or addresses
21 /*	that end in -request are not split when the owner_request_special
22 /*	parameter is set.
23 /* LICENSE
24 /* .ad
25 /* .fi
26 /*	The Secure Mailer license must be distributed with this software.
27 /* AUTHOR(S)
28 /*	Wietse Venema
29 /*	IBM T.J. Watson Research
30 /*	P.O. Box 704
31 /*	Yorktown Heights, NY 10598, USA
32 /*--*/
33 
34 /* System library. */
35 
36 #include <sys_defs.h>
37 #include <string.h>
38 
39 #ifdef STRCASECMP_IN_STRINGS_H
40 #include <strings.h>
41 #endif
42 
43 /* Utility library. */
44 
45 #include <split_at.h>
46 
47 /* Global library. */
48 
49 #include <mail_params.h>
50 #include <mail_addr.h>
51 #include <split_addr.h>
52 
53 /* split_addr - split address with extreme prejudice */
54 
55 char   *split_addr(char *localpart, int delimiter)
56 {
57     int     len;
58 
59     /*
60      * Don't split these, regardless of what the delimiter is.
61      */
62     if (strcasecmp(localpart, MAIL_ADDR_POSTMASTER) == 0)
63 	return (0);
64     if (strcasecmp(localpart, MAIL_ADDR_MAIL_DAEMON) == 0)
65 	return (0);
66     if (strcasecmp(localpart, var_double_bounce_sender) == 0)
67 	return (0);
68 
69     /*
70      * Backwards compatibility: don't split owner-foo or foo-request.
71      */
72     if (delimiter == '-' && var_ownreq_special != 0) {
73 	if (strncasecmp(localpart, "owner-", 6) == 0)
74 	    return (0);
75 	if ((len = strlen(localpart) - 8) > 0
76 	    && strcasecmp(localpart + len, "-request") == 0)
77 	    return (0);
78     }
79 
80     /*
81      * Safe to split this address. Do not split the address if the result
82      * would have a null localpart.
83      */
84     return (delimiter == *localpart ? 0 : split_at(localpart, delimiter));
85 }
86