Index: ext/standard/basic_functions.c =================================================================== RCS file: /repository/php-src/ext/standard/basic_functions.c,v retrieving revision 1.725.2.31.2.64.2.46 diff -u -p -r1.725.2.31.2.64.2.46 basic_functions.c --- ext/standard/basic_functions.c 7 Aug 2008 09:25:32 -0000 1.725.2.31.2.64.2.46 +++ ext/standard/basic_functions.c 14 Aug 2008 09:33:03 -0000 @@ -2210,6 +2210,12 @@ ZEND_BEGIN_ARG_INFO(arginfo_quoted_print ZEND_ARG_INFO(0, str) ZEND_END_ARG_INFO() /* }}} */ +/* {{{ quot_print.c */ +static +ZEND_BEGIN_ARG_INFO(arginfo_quoted_printable_encode, 0) + ZEND_ARG_INFO(0, str) +ZEND_END_ARG_INFO() +/* }}} */ /* {{{ rand.c */ static ZEND_BEGIN_ARG_INFO_EX(arginfo_srand, 0, 0, 0) @@ -3370,6 +3376,7 @@ const zend_function_entry basic_function #endif PHP_FE(quoted_printable_decode, arginfo_quoted_printable_decode) + PHP_FE(quoted_printable_encode, arginfo_quoted_printable_encode) PHP_FE(convert_cyr_string, arginfo_convert_cyr_string) PHP_FE(get_current_user, arginfo_get_current_user) PHP_FE(set_time_limit, arginfo_set_time_limit) Index: ext/standard/quot_print.c =================================================================== RCS file: /repository/php-src/ext/standard/quot_print.c,v retrieving revision 1.29.2.2.2.1.2.3 diff -u -p -r1.29.2.2.2.1.2.3 quot_print.c --- ext/standard/quot_print.c 14 Aug 2008 09:29:22 -0000 1.29.2.2.2.1.2.3 +++ ext/standard/quot_print.c 14 Aug 2008 09:33:03 -0000 @@ -143,6 +143,53 @@ PHPAPI unsigned char *php_quot_print_dec } /* }}} */ +#define PHP_QPRINT_MAXL 75 + +PHPAPI unsigned char *php_quot_print_encode(const unsigned char *str, size_t length, size_t *ret_length) /* {{{ */ +{ + unsigned long lp = 0; + unsigned char c, *ret, *d; + char *hex = "0123456789ABCDEF"; + + ret = safe_emalloc(1, 3 * length + 3 * (((3 * length)/PHP_QPRINT_MAXL) + 1), 0); + d = ret; + + while (length--) { + if (((c = *str++) == '\015') && (*str == '\012') && length > 0) { + *d++ = '\015'; + *d++ = *str++; + length--; + lp = 0; + } else { + if (iscntrl (c) || (c == 0x7f) || (c & 0x80) || (c == '=') || ((c == ' ') && (*str == '\015'))) { + if ((lp += 3) > PHP_QPRINT_MAXL) { + *d++ = '='; + *d++ = '\015'; + *d++ = '\012'; + lp = 3; + } + *d++ = '='; + *d++ = hex[c >> 4]; + *d++ = hex[c & 0xf]; + } else { + if ((++lp) > PHP_QPRINT_MAXL) { + *d++ = '='; + *d++ = '\015'; + *d++ = '\012'; + lp = 1; + } + *d++ = c; + } + } + } + *d = '\0'; + *ret_length = d - ret; + + ret = erealloc(ret, *ret_length + 1); + return ret; +} +/* }}} */ + /* * * Decoding Quoted-printable string. @@ -209,6 +256,26 @@ PHP_FUNCTION(quoted_printable_decode) } /* }}} */ +/* {{{ proto string quoted_printable_encode(string str) */ +PHP_FUNCTION(quoted_printable_encode) +{ + char *str, *new_str; + int str_len; + size_t new_str_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) != SUCCESS) { + return; + } + + if (!str_len) { + RETURN_EMPTY_STRING(); + } + + new_str = php_quot_print_encode(str, str_len, &new_str_len); + RETURN_STRINGL(new_str, new_str_len, 0); +} +/* }}} */ + /* * Local variables: * tab-width: 4 Index: ext/standard/quot_print.h =================================================================== RCS file: /repository/php-src/ext/standard/quot_print.h,v retrieving revision 1.13.2.1.2.1.2.1 diff -u -p -r1.13.2.1.2.1.2.1 quot_print.h --- ext/standard/quot_print.h 31 Dec 2007 07:17:15 -0000 1.13.2.1.2.1.2.1 +++ ext/standard/quot_print.h 14 Aug 2008 09:33:03 -0000 @@ -22,7 +22,9 @@ #define QUOT_PRINT_H PHPAPI unsigned char *php_quot_print_decode(const unsigned char *str, size_t length, size_t *ret_length, int replace_us_by_ws); +PHPAPI unsigned char *php_quot_print_encode(const unsigned char *str, size_t length, size_t *ret_length); PHP_FUNCTION(quoted_printable_decode); +PHP_FUNCTION(quoted_printable_encode); #endif /* QUOT_PRINT_H */