1 /* $Cambridge: exim/src/src/auths/xtextencode.c,v 1.5 2009/11/16 19:50:38 nm4 Exp $ */
3 /*************************************************
4 * Exim - an Internet mail transport agent *
5 *************************************************/
7 /* Copyright (c) University of Cambridge 1995 - 2009 */
8 /* See the file NOTICE for conditions of use and distribution. */
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)
33 uschar *p = (uschar *)clear;
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);
51 if ((x = *p++) < 33 || x > 127 || x == '+' || x == '=')
53 sprintf(CS pp, "+%.02x", x); /* There's always room */
63 /* End of xtextencode.c */