Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / global / verp_sender.c
blobff6da7aeb404b8e91b2bf972659a355b844fb3d8
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* verp_sender 3
6 /* SUMMARY
7 /* quote local part of mailbox
8 /* SYNOPSIS
9 /* #include <verp_sender.h>
11 /* VSTRING *verp_sender(dst, delims, sender, recipient)
12 /* VSTRING *dst;
13 /* const char *delims;
14 /* const char *sender;
15 /* const RECIPIENT *recipient;
17 /* const char *verp_delims_verify(delims)
18 /* const char *delims;
19 /* DESCRIPTION
20 /* verp_sender() encodes the recipient address in the sender
21 /* address, using the specified delimiters. For example,
22 /* with delims +=, sender \fIprefix@origin\fR, and
23 /* recipient \fIuser@domain\fR the result is
24 /* \fIprefix+user=domain@origin\fR.
26 /* verp_delims_verify() determines if the specified VERP delimiters
27 /* have reasonable values. What is reasonable is configured with
28 /* the verp_delimiter_filter configuration parameter. The result
29 /* is null in case of success, a description of the problem in
30 /* case of error.
32 /* Arguments:
33 /* .IP dst
34 /* The result. The buffer is null terminated.
35 /* .IP delims
36 /* VERP formatting characters.
37 /* .IP sender
38 /* Sender envelope address.
39 /* .IP recipient
40 /* Recipient envelope address.
41 /* LICENSE
42 /* .ad
43 /* .fi
44 /* The Secure Mailer license must be distributed with this software.
45 /* AUTHOR(S)
46 /* Wietse Venema
47 /* IBM T.J. Watson Research
48 /* P.O. Box 704
49 /* Yorktown Heights, NY 10598, USA
50 /*--*/
52 /* System library. */
54 #include <sys_defs.h>
55 #include <string.h>
57 /* Utility library. */
59 #include <vstring.h>
61 /* Global library. */
63 #include <mail_params.h>
64 #include <recipient_list.h>
65 #include <verp_sender.h>
67 /* verp_sender - encode recipient into envelope sender address */
69 VSTRING *verp_sender(VSTRING *buf, const char *delimiters,
70 const char *sender, const RECIPIENT *rcpt_info)
72 ssize_t send_local_len;
73 ssize_t rcpt_local_len;
74 const char *recipient;
75 const char *cp;
78 * Change prefix@origin into prefix+user=domain@origin.
80 * Fix 20090115: Use the Postfix original recipient, because that is what
81 * the VERP consumer expects.
83 send_local_len = ((cp = strrchr(sender, '@')) != 0 ?
84 cp - sender : strlen(sender));
85 recipient = (rcpt_info->orig_addr[0] ?
86 rcpt_info->orig_addr : rcpt_info->address);
87 rcpt_local_len = ((cp = strrchr(recipient, '@')) != 0 ?
88 cp - recipient : strlen(recipient));
89 vstring_strncpy(buf, sender, send_local_len);
90 VSTRING_ADDCH(buf, delimiters[0] & 0xff);
91 vstring_strncat(buf, recipient, rcpt_local_len);
92 if (recipient[rcpt_local_len] && recipient[rcpt_local_len + 1]) {
93 VSTRING_ADDCH(buf, delimiters[1] & 0xff);
94 vstring_strcat(buf, recipient + rcpt_local_len + 1);
96 if (sender[send_local_len] && sender[send_local_len + 1]) {
97 VSTRING_ADDCH(buf, '@');
98 vstring_strcat(buf, sender + send_local_len + 1);
100 VSTRING_TERMINATE(buf);
101 return (buf);
104 /* verp_delims_verify - sanitize VERP delimiters */
106 const char *verp_delims_verify(const char *delims)
108 if (strlen(delims) != 2)
109 return ("bad VERP delimiter character count");
110 if (strchr(var_verp_filter, delims[0]) == 0)
111 return ("bad first VERP delimiter character");
112 if (strchr(var_verp_filter, delims[1]) == 0)
113 return ("bad second VERP delimiter character");
114 return (0);