1 /* $NetBSD: split_addr.c,v 1.2 2017/02/14 01:16:45 christos 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_set) 12 /* char *localpart; 13 /* const char *delimiter_set; 14 /* DESCRIPTION 15 /* split_addr() null-terminates \fIlocalpart\fR at the first 16 /* occurrence of the \fIdelimiter\fR character(s) 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 #include <stringops.h> 47 48 /* Global library. */ 49 50 #include <mail_params.h> 51 #include <mail_addr.h> 52 #include <split_addr.h> 53 54 /* split_addr - split address with extreme prejudice */ 55 56 char *split_addr(char *localpart, const char *delimiter_set) 57 { 58 ssize_t len; 59 60 /* 61 * Don't split these, regardless of what the delimiter is. 62 */ 63 if (strcasecmp(localpart, MAIL_ADDR_POSTMASTER) == 0) 64 return (0); 65 if (strcasecmp(localpart, MAIL_ADDR_MAIL_DAEMON) == 0) 66 return (0); 67 if (strcasecmp_utf8(localpart, var_double_bounce_sender) == 0) 68 return (0); 69 70 /* 71 * Backwards compatibility: don't split owner-foo or foo-request. 72 */ 73 if (strchr(delimiter_set, '-') != 0 && var_ownreq_special != 0) { 74 if (strncasecmp(localpart, "owner-", 6) == 0) 75 return (0); 76 if ((len = strlen(localpart) - 8) > 0 77 && strcasecmp(localpart + len, "-request") == 0) 78 return (0); 79 } 80 81 /* 82 * Safe to split this address. Do not split the address if the result 83 * would have a null localpart. 84 */ 85 if ((len = strcspn(localpart, delimiter_set)) == 0 || localpart[len] == 0) { 86 return (0); 87 } else { 88 localpart[len] = 0; 89 return (localpart + len + 1); 90 } 91 } 92