1 /*        $NetBSD: smtputf8.h,v 1.4 2025/02/25 19:15:46 christos Exp $          */
2 
3 #ifndef _SMTPUTF8_H_INCLUDED_
4 #define _SMTPUTF8_H_INCLUDED_
5 
6 /*++
7 /* NAME
8 /*        smtputf8 3h
9 /* SUMMARY
10 /*        SMTPUTF8 support
11 /* SYNOPSIS
12 /*        #include <smtputf8.h>
13 /* DESCRIPTION
14 /* .nf
15 
16  /*
17   * Global library.
18   */
19 #include <sendopts.h>
20 
21  /*
22   * Avoiding chicken-and-egg problems during the initial SMTPUTF8 roll-out in
23   * environments with pre-existing mail flows that contain UTF8.
24   *
25   * Prior to SMTPUTF8, mail flows that contain UTF8 worked because the vast
26   * majority of MTAs is perfectly capable of handling UTF8 in address
27   * localparts (and in headers), even if pre-SMTPUTF8 standards do not
28   * support this practice.
29   *
30   * When turning on Postfix SMTPUTF8 support for the first time, we don't want
31   * to suddenly break pre-existing mail flows that contain UTF8 because 1) a
32   * client does not request SMTPUTF8 support, and because 2) a down-stream
33   * MTA does not announce SMTPUTF8 support.
34   *
35   * While 1) is easy enough to avoid (keep accepting UTF8 in address localparts
36   * just like Postfix has always done), 2) presents a thornier problem. The
37   * root cause of that problem is the need for SMTPUTF8 autodetection.
38   *
39   * What is SMTPUTF8 autodetection? Postfix cannot rely solely on the sender's
40   * declaration that a message requires SMTPUTF8 support, because UTF8 may be
41   * introduced during local processing (for example, the client hostname in
42   * Postfix's Received: header, adding @$myorigin or .$mydomain to an
43   * incomplete address, address rewriting, alias expansion, automatic BCC
44   * recipients, local forwarding, and changes made by header checks or Milter
45   * applications).
46   *
47   * In summary, after local processing has happened, Postfix may decide that a
48   * message requires SMTPUTF8 support, even when that message initially did
49   * not require SMTPUTF8 support. This could make the message undeliverable
50   * to destinations that do not support SMTPUTF8. In an environment with
51   * pre-existing mail flows that contain UTF8, we want to avoid disrupting
52   * those mail flows when rolling out SMTPUTF8 support.
53   *
54   * For the vast majority of sites, the simplest solution is to autodetect
55   * SMTPUTF8 support only for Postfix sendmail command-line submissions, at
56   * least as long as SMTPUTF8 support has not yet achieved wold domination.
57   *
58   * However, sites that add UTF8 content via local processing (see above) should
59   * autodetect SMTPUTF8 support for all email.
60   *
61   * smtputf8_autodetect() uses the setting of the smtputf8_autodetect_classes
62   * parameter, and the mail source classes defined in mail_params.h.
63   */
64 extern int smtputf8_autodetect(int);
65 
66  /*
67   * The flag SMTPUTF8_FLAG_REQUESTED is raised on request by the sender, or
68   * when SMTPUTF8 auto-detection is enabled and a queue file contains at
69   * least one UTF8 envelope sender, envelope recipient, or message header.
70   * Once this flag is raised, it is preserved when mail is forwarded or
71   * bounced.
72   *
73   * The flag SMTPUTF8_FLAG_HEADER is raised when a queue file contains at least
74   * one UTF8 message header even if SMTPUTF8_FLAG_REQUESTED is disabled.
75   *
76   * The flag SMTPUTF8_FLAG_SENDER is raised when a queue file contains an UTF8
77   * envelope sender, even if SMTPUTF8_FLAG_REQUESTED is disabled.
78   *
79   * The three flags SMTPUTF8_FLAG_REQUESTED/HEADER/SENDER are stored in the
80   * queue file, are sent with delivery requests to Postfix delivery agents,
81   * and are sent with "flush" requests to the bounce daemon to ensure that
82   * the resulting notification message will have a content-transfer-encoding
83   * of 8bit. The derived flags SMTPUTF8_FLAG_HEADER/SENDER are ignored when a
84   * message is re-queued with "postsuper -r". They may be regenerated by the
85   * cleanup daemon.
86   *
87   * In the future, mailing lists will have a mix of UTF8 and non-UTF8
88   * subscribers. With the following flag, Postfix can avoid requiring
89   * SMTPUTF8 delivery when it isn't really needed.
90   *
91   * The fourth flag, SMTPUTF8_FLAG_RECIPIENT, is raised when a delivery request
92   * (NOT: message) contains at least one UTF8 envelope recipient. This flag
93   * is NOT stored in the queue file. The flag is used ONLY in requests to
94   * Postfix delivery agents, to give delivery agents flexibility when
95   * delivering messages to non-SMTPUTF8 servers. Delivery agents may then
96   * pass the flag to the bounce daemon.
97   *
98   * If a delivery request has none of the flags SMTPUTF8_FLAG_RECIPIENT,
99   * SMTPUTF8_FLAG_SENDER, or SMTPUTF8_FLAG_HEADER, then the message can
100   * safely be delivered to a non-SMTPUTF8 server (DSN original recipients
101   * will be encoded appropriately per RFC 6533).
102   *
103   * To allow even more SMTPUTF8 mail to be sent to non-SMTPUTF8 servers,
104   * implement RFC 2047 header encoding in the Postfix SMTP client, and update
105   * the SMTP client protocol engine.
106   */
107 #define SMTPUTF8_FLAG_NONE    (0)
108  /* In queue file, delivery request, or bounce request. */
109 #define SMTPUTF8_FLAG_REQUESTED         SOPT_SMTPUTF8_REQUESTED
110 #define SMTPUTF8_FLAG_HEADER  SOPT_SMTPUTF8_HEADER
111 #define SMTPUTF8_FLAG_SENDER  SOPT_SMTPUTF8_SENDER
112  /* In delivery or bounce request only. */
113 #define SMTPUTF8_FLAG_RECIPIENT         SOPT_SMTPUTF8_RECIPIENT
114 
115 #define SMTPUTF8_FLAG_ALL     SOPT_SMTPUTF8_ALL
116 #define SMTPUTF8_FLAG_DERIVED SOPT_SMTPUTF8_DERIVED
117 
118 /* LICENSE
119 /* .ad
120 /* .fi
121 /*        The Secure Mailer license must be distributed with this software.
122 /* AUTHOR(S)
123 /*        Wietse Venema
124 /*        IBM T.J. Watson Research
125 /*        P.O. Box 704
126 /*        Yorktown Heights, NY 10598, USA
127 /*
128 /*        Wietse Venema
129 /*        porcupine.org
130 /*--*/
131 
132 #endif
133