Postfix3.3.1
split_addr.c
[詳解]
1 /*++
2 /* NAME
3 /* split_addr 3
4 /* SUMMARY
5 /* recipient localpart address splitter
6 /* SYNOPSIS
7 /* #include <split_addr.h>
8 /*
9 /* char *split_addr_internal(localpart, delimiter_set)
10 /* char *localpart;
11 /* const char *delimiter_set;
12 /* LEGACY SUPPORT
13 /* char *split_addr(localpart, delimiter_set)
14 /* char *localpart;
15 /* const char *delimiter_set;
16 /* DESCRIPTION
17 /* split_addr*() null-terminates \fIlocalpart\fR at the first
18 /* occurrence of the \fIdelimiter\fR character(s) found, and
19 /* returns a pointer to the remainder.
20 /*
21 /* With split_addr_internal(), the address must be in internal
22 /* (unquoted) form.
23 /*
24 /* split_addr() is a backwards-compatible form for legacy code.
25 /*
26 /* Reserved addresses are not split: postmaster, mailer-daemon,
27 /* double-bounce. Addresses that begin with owner-, or addresses
28 /* that end in -request are not split when the owner_request_special
29 /* parameter is set.
30 /* LICENSE
31 /* .ad
32 /* .fi
33 /* The Secure Mailer license must be distributed with this software.
34 /* AUTHOR(S)
35 /* Wietse Venema
36 /* IBM T.J. Watson Research
37 /* P.O. Box 704
38 /* Yorktown Heights, NY 10598, USA
39 /*
40 /* Wietse Venema
41 /* Google, Inc.
42 /* 111 8th Avenue
43 /* New York, NY 10011, USA
44 /*--*/
45 
46 /* System library. */
47 
48 #include <sys_defs.h>
49 #include <string.h>
50 
51 #ifdef STRCASECMP_IN_STRINGS_H
52 #include <strings.h>
53 #endif
54 
55 /* Utility library. */
56 
57 #include <split_at.h>
58 #include <stringops.h>
59 
60 /* Global library. */
61 
62 #include <mail_params.h>
63 #include <mail_addr.h>
64 #include <split_addr.h>
65 
66 /* split_addr_internal - split address with extreme prejudice */
67 
68 char *split_addr_internal(char *localpart, const char *delimiter_set)
69 {
70  ssize_t len;
71 
72  /*
73  * Don't split these, regardless of what the delimiter is.
74  */
75  if (strcasecmp(localpart, MAIL_ADDR_POSTMASTER) == 0)
76  return (0);
77  if (strcasecmp(localpart, MAIL_ADDR_MAIL_DAEMON) == 0)
78  return (0);
79  if (strcasecmp_utf8(localpart, var_double_bounce_sender) == 0)
80  return (0);
81 
82  /*
83  * Backwards compatibility: don't split owner-foo or foo-request.
84  */
85  if (strchr(delimiter_set, '-') != 0 && var_ownreq_special != 0) {
86  if (strncasecmp(localpart, "owner-", 6) == 0)
87  return (0);
88  if ((len = strlen(localpart) - 8) > 0
89  && strcasecmp(localpart + len, "-request") == 0)
90  return (0);
91  }
92 
93  /*
94  * Safe to split this address. Do not split the address if the result
95  * would have a null localpart.
96  */
97  if ((len = strcspn(localpart, delimiter_set)) == 0 || localpart[len] == 0) {
98  return (0);
99  } else {
100  localpart[len] = 0;
101  return (localpart + len + 1);
102  }
103 }
int var_ownreq_special
Definition: mail_params.c:283
#define MAIL_ADDR_POSTMASTER
Definition: mail_addr.h:17
#define strcasecmp_utf8(s1, s2)
Definition: stringops.h:75
int strncasecmp(const char *s1, const char *s2, size_t n)
Definition: strcasecmp.c:52
char * var_double_bounce_sender
Definition: mail_params.c:262
#define MAIL_ADDR_MAIL_DAEMON
Definition: mail_addr.h:18
int strcasecmp(const char *s1, const char *s2)
Definition: strcasecmp.c:41
char * split_addr_internal(char *localpart, const char *delimiter_set)
Definition: split_addr.c:68