xref: /netbsd-src/external/ibm-public/postfix/dist/src/global/smtputf8.c (revision e89934bbf778a6d6d6894877c4da59d0c7835b0f)
1 /*	$NetBSD: smtputf8.c,v 1.2 2017/02/14 01:16:45 christos Exp $	*/
2 
3 /*++
4 /* NAME
5 /*	smtputf8 3
6 /* SUMMARY
7 /*	SMTPUTF8 support
8 /* SYNOPSIS
9 /*	#include <smtputf8.h>
10 /*
11 /*	int	smtputf8_autodetect(class)
12 /*	int	class;
13 /* DESCRIPTION
14 /*	smtputf8_autodetect() determines whether the cleanup server
15 /*	should perform SMTPUTF8 detection, depending on the declared
16 /*	source class and the setting of the smtputf8_autodetect_classes
17 /*	configuration parameter.
18 /*
19 /*	Specify one of the following:
20 /* .IP MAIL_SRC_MASK_SENDMAIL
21 /*	Submission with the Postfix sendmail(1) command.
22 /* .IP MAIL_SRC_MASK_SMTPD
23 /*	Mail received with the smtpd(8) daemon.
24 /* .IP MAIL_SRC_MASK_QMQPD
25 /*	Mail received with the qmqpd(8) daemon.
26 /* .IP MAIL_SRC_MASK_FORWARD
27 /*	Local forwarding or aliasing.
28 /* .IP MAIL_SRC_MASK_BOUNCE
29 /*	Submission by the bounce(8) daemon.
30 /* .IP MAIL_SRC_MASK_NOTIFY
31 /*	Postmaster notification from the smtp(8) or smtpd(8) daemon.
32 /* .IP MAIL_SRC_MASK_VERIFY
33 /*	Address verification probe.
34 /* DIAGNOSTICS
35 /*	Panic: no valid class argument.
36 /*
37 /*	Specify one of the following:
38 /*	Warning: the smtputf8_autodetect_classes parameter specifies
39 /*	an invalid source category name.
40 /* LICENSE
41 /* .ad
42 /* .fi
43 /*	The Secure Mailer license must be distributed with this software.
44 /* AUTHOR(S)
45 /*	Wietse Venema
46 /*	IBM T.J. Watson Research
47 /*	P.O. Box 704
48 /*	Yorktown Heights, NY 10598, USA
49 /*--*/
50 
51 /* System library. */
52 
53 #include <sys_defs.h>
54 
55 /* Utility library. */
56 
57 #include <name_mask.h>
58 #include <msg.h>
59 
60 /* Global library. */
61 
62 #include <mail_params.h>
63 #include <cleanup_user.h>
64 #include <mail_proto.h>
65 #include <smtputf8.h>
66 
67 /* smtputf8_autodetect - enable SMTPUTF8 autodetection */
68 
smtputf8_autodetect(int class)69 int     smtputf8_autodetect(int class)
70 {
71     static const char myname[] = "smtputf8_autodetect";
72     static const NAME_MASK table[] = {
73 	MAIL_SRC_NAME_SENDMAIL, MAIL_SRC_MASK_SENDMAIL,
74 	MAIL_SRC_NAME_SMTPD, MAIL_SRC_MASK_SMTPD,
75 	MAIL_SRC_NAME_QMQPD, MAIL_SRC_MASK_QMQPD,
76 	MAIL_SRC_NAME_FORWARD, MAIL_SRC_MASK_FORWARD,
77 	MAIL_SRC_NAME_BOUNCE, MAIL_SRC_MASK_BOUNCE,
78 	MAIL_SRC_NAME_NOTIFY, MAIL_SRC_MASK_NOTIFY,
79 	MAIL_SRC_NAME_VERIFY, MAIL_SRC_MASK_VERIFY,
80 	MAIL_SRC_NAME_ALL, MAIL_SRC_MASK_ALL,
81 	0,
82     };
83     int     autodetect_classes = 0;
84 
85     if (class == 0 || (class & ~MAIL_SRC_MASK_ALL) != 0)
86 	msg_panic("%s: bad source class: %d", myname, class);
87     if (*var_smtputf8_autoclass) {
88 	autodetect_classes =
89 	    name_mask(VAR_SMTPUTF8_AUTOCLASS, table, var_smtputf8_autoclass);
90 	if (autodetect_classes == 0)
91 	    msg_warn("%s: bad input: %s", VAR_SMTPUTF8_AUTOCLASS,
92 		     var_smtputf8_autoclass);
93 	if (autodetect_classes & class)
94 	    return (CLEANUP_FLAG_AUTOUTF8);
95     }
96     return (0);
97 }
98