1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
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 */
13 /*************************************************
14 * Encode byte-string in xtext *
15 *************************************************/
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
22 clear points to the clear text bytes
23 len the number of bytes to encode
25 Returns: a pointer to the zero-terminated xtext string, which
30 auth_xtextencode(uschar *clear, int len)
39 /* We have to do a prepass to find out how many specials there are,
40 in order to get the right amount of store. */
43 count += ((x = *p++) < 33 || x > 127 || x == '+' || x == '=')? 3 : 1;
45 pp = code = store_get(count, clear);
50 if ((x = *p++) < 33 || x > 127 || x == '+' || x == '=')
51 pp += sprintf(CS pp, "+%.02x", x); /* There's always room */
59 /* End of xtextencode.c */