Use compressed form of ipv6 in $sender_host_address under -bh. Bug 3027
[exim.git] / src / src / auths / xtextencode.c
1 /*************************************************
2 *     Exim - an Internet mail transport agent    *
3 *************************************************/
4
5 /* Copyright (c) The Exim Maintainers 2022 */
6 /* Copyright (c) University of Cambridge 1995 - 2018 */
7 /* See the file NOTICE for conditions of use and distribution. */
8 /* SPDX-License-Identifier: GPL-2.0-or-later */
9
10 #include "../exim.h"
11
12
13 /*************************************************
14 *          Encode byte-string in xtext           *
15 *************************************************/
16
17 /* This function encodes a string of bytes, containing any values whatsoever,
18 as "xtext", as defined in RFC 1891 and required by the SMTP AUTH extension (RFC
19 2554).
20
21 Arguments:
22   clear       points to the clear text bytes
23   len         the number of bytes to encode
24
25 Returns:      a pointer to the zero-terminated xtext string, which
26               is in working store
27 */
28
29 uschar *
30 auth_xtextencode(uschar *clear, int len)
31 {
32 gstring * g = NULL;
33 for(uschar ch; len > 0; len--, clear++)
34   g = (ch = *clear) < 33 || ch > 126 || ch == '+' || ch == '='
35     ? string_fmt_append(g, "+%.02X", ch)
36     : string_catn(g, clear, 1);
37 gstring_release_unused(g);
38 return string_from_gstring(g);
39 }
40
41
42 /* End of xtextencode.c */