1*33881f77Schristos /* $NetBSD: smtp_misc.c,v 1.2 2020/03/18 19:05:20 christos Exp $ */
2f3bc92a4Schristos
3f3bc92a4Schristos /*++
4f3bc92a4Schristos /* NAME
5f3bc92a4Schristos /* smtp_misc 3
6f3bc92a4Schristos /* SUMMARY
7f3bc92a4Schristos /* SMTP client address rewriting
8f3bc92a4Schristos /* SYNOPSIS
9f3bc92a4Schristos /* #include <smtp_addr.h>
10f3bc92a4Schristos /*
11f3bc92a4Schristos /* void smtp_rewrite_generic_internal(
12f3bc92a4Schristos /* VSTRING *dst,
13f3bc92a4Schristos /* const char *src);
14f3bc92a4Schristos /*
15f3bc92a4Schristos /* void smtp_quote_822_address_flags(
16f3bc92a4Schristos /* VSTRING *dst,
17f3bc92a4Schristos /* const char *src,
18f3bc92a4Schristos /* int flags);
19f3bc92a4Schristos /*
20f3bc92a4Schristos /* void smtp_quote_821_address(
21f3bc92a4Schristos /* VSTRING *dst,
22f3bc92a4Schristos /* const char *src);
23f3bc92a4Schristos /* DESCRIPTION
24f3bc92a4Schristos /* smtp_rewrite_generic_internal() rewrites a non-empty address
25f3bc92a4Schristos /* if generic mapping is enabled, otherwise copies it literally.
26f3bc92a4Schristos /*
27f3bc92a4Schristos /* smtp_quote_822_address_flags() is a wrapper around
28f3bc92a4Schristos /* quote_822_local_flags(), except for the empty address which
29f3bc92a4Schristos /* is copied literally.
30f3bc92a4Schristos /*
31f3bc92a4Schristos /* smtp_quote_821_address() is a wrapper around quote_821_local(),
32f3bc92a4Schristos /* except for the empty address or with "smtp_quote_rfc821_envelope
33f3bc92a4Schristos /* = no"; in those cases the address is copied literally.
34f3bc92a4Schristos /* DIAGNOSTICS
35f3bc92a4Schristos /* Fatal: out of memory.
36f3bc92a4Schristos /* LICENSE
37f3bc92a4Schristos /* .ad
38f3bc92a4Schristos /* .fi
39f3bc92a4Schristos /* The Secure Mailer license must be distributed with this software.
40f3bc92a4Schristos /* AUTHOR(S)
41f3bc92a4Schristos /* Wietse Venema
42f3bc92a4Schristos /* Google, Inc.
43f3bc92a4Schristos /* 111 8th Avenue
44f3bc92a4Schristos /* New York, NY 10011, USA
45f3bc92a4Schristos /*--*/
46f3bc92a4Schristos
47f3bc92a4Schristos /*
48f3bc92a4Schristos * System library.
49f3bc92a4Schristos */
50f3bc92a4Schristos #include <sys_defs.h>
51f3bc92a4Schristos
52f3bc92a4Schristos /*
53f3bc92a4Schristos * Utility library.
54f3bc92a4Schristos */
55f3bc92a4Schristos #include <vstring.h>
56f3bc92a4Schristos
57f3bc92a4Schristos /*
58f3bc92a4Schristos * Global library.
59f3bc92a4Schristos */
60f3bc92a4Schristos #include <ext_prop.h>
61f3bc92a4Schristos #include <mail_params.h>
62f3bc92a4Schristos #include <quote_821_local.h>
63f3bc92a4Schristos #include <quote_822_local.h>
64f3bc92a4Schristos
65f3bc92a4Schristos /*
66f3bc92a4Schristos * Application-specific.
67f3bc92a4Schristos */
68f3bc92a4Schristos #include <smtp.h>
69f3bc92a4Schristos
70f3bc92a4Schristos /* smtp_rewrite_generic_internal - generic non-empty address rewriting */
71f3bc92a4Schristos
smtp_rewrite_generic_internal(VSTRING * dst,const char * src)72f3bc92a4Schristos void smtp_rewrite_generic_internal(VSTRING *dst, const char *src)
73f3bc92a4Schristos {
74f3bc92a4Schristos vstring_strcpy(dst, src);
75f3bc92a4Schristos if (*src && smtp_generic_maps)
76f3bc92a4Schristos smtp_map11_internal(dst, smtp_generic_maps,
77f3bc92a4Schristos smtp_ext_prop_mask & EXT_PROP_GENERIC);
78f3bc92a4Schristos }
79f3bc92a4Schristos
80f3bc92a4Schristos /* smtp_quote_822_address_flags - quote non-empty header address */
81f3bc92a4Schristos
smtp_quote_822_address_flags(VSTRING * dst,const char * src,int flags)82f3bc92a4Schristos void smtp_quote_822_address_flags(VSTRING *dst, const char *src, int flags)
83f3bc92a4Schristos {
84f3bc92a4Schristos if (*src) {
85f3bc92a4Schristos quote_822_local_flags(dst, src, flags);
86f3bc92a4Schristos } else if (flags & QUOTE_FLAG_APPEND) {
87f3bc92a4Schristos vstring_strcat(dst, src);
88f3bc92a4Schristos } else {
89f3bc92a4Schristos vstring_strcpy(dst, src);
90f3bc92a4Schristos }
91f3bc92a4Schristos }
92f3bc92a4Schristos
93f3bc92a4Schristos /* smtp_quote_821_address - quote non-empty envelope address */
94f3bc92a4Schristos
smtp_quote_821_address(VSTRING * dst,const char * src)95f3bc92a4Schristos void smtp_quote_821_address(VSTRING *dst, const char *src)
96f3bc92a4Schristos {
97f3bc92a4Schristos if (*src && var_smtp_quote_821_env) {
98f3bc92a4Schristos quote_821_local(dst, src);
99f3bc92a4Schristos } else {
100f3bc92a4Schristos vstring_strcpy(dst, src);
101f3bc92a4Schristos }
102f3bc92a4Schristos }
103