2000-04-02 00:49:39 +08:00
/*
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2004-01-08 16:18:22 +08:00
| PHP Version 5 |
2000-04-02 00:49:39 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2007-12-31 15:17:19 +08:00
| Copyright ( c ) 1997 - 2008 The PHP Group |
2000-04-02 00:49:39 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2006-01-01 20:51:34 +08:00
| This source file is subject to version 3.01 of the PHP license , |
2000-04-19 21:15:57 +08:00
| that is bundled with this package in the file LICENSE , and is |
2003-06-11 04:04:29 +08:00
| available through the world - wide - web at the following url : |
2006-01-01 20:51:34 +08:00
| http : //www.php.net/license/3_01.txt |
2000-04-02 00:49:39 +08:00
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world - wide - web , please send a note to |
| license @ php . net so we can mail you a copy immediately . |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| Authors : Rex Logan < veebert @ dimensional . com > |
| Mark Musone < musone @ afterfive . com > |
| Brian Wang < brian @ vividnet . com > |
| Kaj - Michael Lang < milang @ tal . org > |
| Antoni Pamies Olive < toni @ readysoft . net > |
2002-02-28 16:29:35 +08:00
| Rasmus Lerdorf < rasmus @ php . net > |
2000-04-02 00:49:39 +08:00
| Chuck Hagenbuch < chuck @ horde . org > |
2000-04-18 03:28:58 +08:00
| Andrew Skalski < askalski @ chekinc . com > |
2002-11-25 20:30:28 +08:00
| Hartmut Holzgraefe < hholzgra @ php . net > |
2000-07-30 02:45:06 +08:00
| Jani Taskinen < sniper @ iki . fi > |
2002-07-27 00:22:43 +08:00
| Daniel R . Kalowsky < kalowsky @ php . net > |
2000-04-02 00:49:39 +08:00
| PHP 4.0 updates : Zeev Suraski < zeev @ zend . com > |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
*/
/* $Id$ */
# define IMAP41
2001-05-24 18:07:29 +08:00
# ifdef HAVE_CONFIG_H
# include "config.h"
# endif
2000-04-02 00:49:39 +08:00
# include "php.h"
# include "php_ini.h"
2006-01-28 03:46:11 +08:00
# include "php_streams.h"
2000-04-02 00:49:39 +08:00
# include "ext/standard/php_string.h"
2000-04-07 00:57:33 +08:00
# include "ext/standard/info.h"
2003-06-13 22:39:22 +08:00
# include "ext/standard/file.h"
2000-04-02 00:49:39 +08:00
2000-04-20 22:23:35 +08:00
# ifdef ERROR
# undef ERROR
# endif
# include "php_imap.h"
2000-04-02 00:49:39 +08:00
# include <time.h>
# include <stdio.h>
# include <ctype.h>
# include <signal.h>
2001-08-08 00:18:05 +08:00
2000-04-03 05:27:32 +08:00
# ifdef PHP_WIN32
2003-02-16 11:48:49 +08:00
# include <winsock2.h>
2002-07-03 03:29:15 +08:00
# include <stdlib.h>
# include "win32/sendmail.h"
2000-04-02 00:49:39 +08:00
MAILSTREAM DEFAULTPROTO ;
# endif
2005-01-19 07:36:08 +08:00
# define CRLF "\015\012"
# define CRLF_LEN sizeof("\015\012") - 1
2000-04-02 00:49:39 +08:00
# define PHP_EXPUNGE 32768
2002-10-09 04:07:52 +08:00
# define PHP_IMAP_ADDRESS_SIZE_BUF 10
2006-12-25 23:28:57 +08:00
# ifndef SENDBUFLEN
2006-12-25 22:23:18 +08:00
# define SENDBUFLEN 16385
# endif
2000-04-02 00:49:39 +08:00
2008-02-01 02:46:03 +08:00
# if defined(__GNUC__) && __GNUC__ >= 4
# define PHP_IMAP_EXPORT __attribute__ ((visibility("default")))
# else
# define PHP_IMAP_EXPORT
# endif
2001-08-08 01:40:10 +08:00
static void _php_make_header_object ( zval * myzvalue , ENVELOPE * en TSRMLS_DC ) ;
static void _php_imap_add_body ( zval * arg , BODY * body TSRMLS_DC ) ;
2002-06-28 06:16:53 +08:00
static void _php_imap_parse_address ( ADDRESS * addresslist , char * * fulladdress , zval * paddress TSRMLS_DC ) ;
static int _php_imap_address_size ( ADDRESS * addresslist ) ;
2000-04-02 00:49:39 +08:00
2006-01-28 03:46:11 +08:00
/* the gets we use */
static char * php_mail_gets ( readfn_t f , void * stream , unsigned long size , GETS_DATA * md ) ;
2000-04-02 00:49:39 +08:00
/* These function declarations are missing from the IMAP header files... */
void rfc822_date ( char * date ) ;
char * cpystr ( const char * str ) ;
char * cpytxt ( SIZEDTEXT * dst , char * text , unsigned long size ) ;
2006-09-25 02:06:37 +08:00
# ifndef HAVE_NEW_MIME2TEXT
2000-04-02 00:49:39 +08:00
long utf8_mime2text ( SIZEDTEXT * src , SIZEDTEXT * dst ) ;
2006-09-25 02:06:37 +08:00
# else
long utf8_mime2text ( SIZEDTEXT * src , SIZEDTEXT * dst , long flags ) ;
# endif
2000-04-02 00:49:39 +08:00
unsigned long find_rightmost_bit ( unsigned long * valptr ) ;
void fs_give ( void * * block ) ;
void * fs_get ( size_t size ) ;
2006-06-16 02:33:09 +08:00
ZEND_DECLARE_MODULE_GLOBALS ( imap )
static PHP_GINIT_FUNCTION ( imap ) ;
2000-04-02 00:49:39 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ imap_functions[]
*/
2007-09-28 02:00:48 +08:00
const zend_function_entry imap_functions [ ] = {
2001-08-08 00:18:05 +08:00
PHP_FE ( imap_open , NULL )
PHP_FE ( imap_reopen , NULL )
PHP_FE ( imap_close , NULL )
PHP_FE ( imap_num_msg , NULL )
PHP_FE ( imap_num_recent , NULL )
PHP_FE ( imap_headers , NULL )
PHP_FE ( imap_headerinfo , NULL )
PHP_FE ( imap_rfc822_parse_headers , NULL )
PHP_FE ( imap_rfc822_write_address , NULL )
PHP_FE ( imap_rfc822_parse_adrlist , NULL )
PHP_FE ( imap_body , NULL )
PHP_FE ( imap_bodystruct , NULL )
PHP_FE ( imap_fetchbody , NULL )
2006-01-28 03:46:11 +08:00
PHP_FE ( imap_savebody , NULL )
2001-08-08 00:18:05 +08:00
PHP_FE ( imap_fetchheader , NULL )
PHP_FE ( imap_fetchstructure , NULL )
PHP_FE ( imap_expunge , NULL )
PHP_FE ( imap_delete , NULL )
PHP_FE ( imap_undelete , NULL )
PHP_FE ( imap_check , NULL )
PHP_FE ( imap_mail_copy , NULL )
PHP_FE ( imap_mail_move , NULL )
PHP_FE ( imap_mail_compose , NULL )
PHP_FE ( imap_createmailbox , NULL )
PHP_FE ( imap_renamemailbox , NULL )
PHP_FE ( imap_deletemailbox , NULL )
PHP_FE ( imap_subscribe , NULL )
PHP_FE ( imap_unsubscribe , NULL )
PHP_FE ( imap_append , NULL )
PHP_FE ( imap_ping , NULL )
PHP_FE ( imap_base64 , NULL )
PHP_FE ( imap_qprint , NULL )
PHP_FE ( imap_8bit , NULL )
PHP_FE ( imap_binary , NULL )
2004-08-13 03:31:36 +08:00
PHP_FE ( imap_utf8 , NULL )
2001-08-08 00:18:05 +08:00
PHP_FE ( imap_status , NULL )
PHP_FE ( imap_mailboxmsginfo , NULL )
PHP_FE ( imap_setflag_full , NULL )
PHP_FE ( imap_clearflag_full , NULL )
PHP_FE ( imap_sort , NULL )
PHP_FE ( imap_uid , NULL )
PHP_FE ( imap_msgno , NULL )
PHP_FE ( imap_list , NULL )
PHP_FE ( imap_lsub , NULL )
PHP_FE ( imap_fetch_overview , NULL )
PHP_FE ( imap_alerts , NULL )
PHP_FE ( imap_errors , NULL )
PHP_FE ( imap_last_error , NULL )
PHP_FE ( imap_search , NULL )
PHP_FE ( imap_utf7_decode , NULL )
PHP_FE ( imap_utf7_encode , NULL )
PHP_FE ( imap_mime_header_decode , NULL )
PHP_FE ( imap_thread , NULL )
2003-06-13 22:39:22 +08:00
PHP_FE ( imap_timeout , NULL )
2001-08-08 00:18:05 +08:00
# if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
PHP_FE ( imap_get_quota , NULL )
2002-07-27 00:26:01 +08:00
PHP_FE ( imap_get_quotaroot , NULL )
2001-08-08 00:18:05 +08:00
PHP_FE ( imap_set_quota , NULL )
2004-08-13 03:31:36 +08:00
PHP_FE ( imap_setacl , NULL )
PHP_FE ( imap_getacl , NULL )
2001-02-26 23:17:12 +08:00
# endif
2001-08-08 00:18:05 +08:00
PHP_FE ( imap_mail , NULL )
2004-08-13 03:31:36 +08:00
PHP_FALIAS ( imap_header , imap_headerinfo , NULL )
PHP_FALIAS ( imap_listmailbox , imap_list , NULL )
PHP_FALIAS ( imap_getmailboxes , imap_list_full , NULL )
PHP_FALIAS ( imap_scanmailbox , imap_listscan , NULL )
PHP_FALIAS ( imap_listsubscribed , imap_lsub , NULL )
PHP_FALIAS ( imap_getsubscribed , imap_lsub_full , NULL )
2001-08-08 00:18:05 +08:00
PHP_FALIAS ( imap_fetchtext , imap_body , NULL )
PHP_FALIAS ( imap_scan , imap_listscan , NULL )
PHP_FALIAS ( imap_create , imap_createmailbox , NULL )
PHP_FALIAS ( imap_rename , imap_renamemailbox , NULL )
2000-04-02 00:49:39 +08:00
{ NULL , NULL , NULL }
} ;
2001-06-05 21:12:10 +08:00
/* }}} */
2000-04-02 00:49:39 +08:00
2006-11-24 18:28:51 +08:00
/* {{{ imap dependencies */
2007-09-28 02:00:48 +08:00
static const zend_module_dep imap_deps [ ] = {
2006-11-24 18:28:51 +08:00
ZEND_MOD_REQUIRED ( " standard " )
{ NULL , NULL , NULL }
} ;
/* }}} */
2001-08-08 00:18:05 +08:00
/* {{{ imap_module_entry
*/
zend_module_entry imap_module_entry = {
2006-11-24 18:28:51 +08:00
STANDARD_MODULE_HEADER_EX , NULL ,
imap_deps ,
2001-08-08 00:18:05 +08:00
" imap " ,
imap_functions ,
PHP_MINIT ( imap ) ,
2001-10-12 07:33:59 +08:00
NULL ,
PHP_RINIT ( imap ) ,
2001-08-08 00:18:05 +08:00
PHP_RSHUTDOWN ( imap ) ,
PHP_MINFO ( imap ) ,
2002-08-17 07:25:53 +08:00
NO_VERSION_YET ,
2006-06-16 02:33:09 +08:00
PHP_MODULE_GLOBALS ( imap ) ,
PHP_GINIT ( imap ) ,
NULL ,
NULL ,
STANDARD_MODULE_PROPERTIES_EX
2001-08-08 00:18:05 +08:00
} ;
/* }}} */
2000-05-23 17:33:51 +08:00
# ifdef COMPILE_DL_IMAP
2000-05-02 08:30:36 +08:00
ZEND_GET_MODULE ( imap )
2000-04-02 00:49:39 +08:00
# endif
2001-08-08 00:18:05 +08:00
/* True globals, no need for thread safety */
2000-04-02 00:49:39 +08:00
static int le_imap ;
2004-07-22 05:57:03 +08:00
# define PHP_IMAP_CHECK_MSGNO(msgindex) \
if ( ( msgindex < 1 ) | | ( ( unsigned ) msgindex > imap_le_struct - > imap_stream - > nmsgs ) ) { \
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Bad message number " ) ; \
RETURN_FALSE ; \
} \
2001-08-08 00:18:05 +08:00
/* {{{ mail_close_it
*/
static void mail_close_it ( zend_rsrc_list_entry * rsrc TSRMLS_DC )
2000-04-02 00:49:39 +08:00
{
2000-10-21 02:25:16 +08:00
pils * imap_le_struct = ( pils * ) rsrc - > ptr ;
2001-01-07 20:22:50 +08:00
2000-04-20 22:23:35 +08:00
mail_close_full ( imap_le_struct - > imap_stream , imap_le_struct - > flags ) ;
2001-01-07 15:47:46 +08:00
2001-02-19 02:15:01 +08:00
if ( IMAPG ( imap_user ) ) {
efree ( IMAPG ( imap_user ) ) ;
IMAPG ( imap_user ) = 0 ;
}
if ( IMAPG ( imap_password ) ) {
efree ( IMAPG ( imap_password ) ) ;
IMAPG ( imap_password ) = 0 ;
}
2000-04-02 00:49:39 +08:00
efree ( imap_le_struct ) ;
}
2001-08-08 00:18:05 +08:00
/* }}} */
/* {{{ add_assoc_object
*/
2003-01-05 04:06:32 +08:00
static int add_assoc_object ( zval * arg , char * key , zval * tmp TSRMLS_DC )
2000-04-02 00:49:39 +08:00
{
HashTable * symtable ;
2001-09-26 05:58:48 +08:00
if ( Z_TYPE_P ( arg ) = = IS_OBJECT ) {
2001-08-14 00:13:25 +08:00
symtable = Z_OBJPROP_P ( arg ) ;
2000-04-02 00:49:39 +08:00
} else {
2001-09-26 05:58:48 +08:00
symtable = Z_ARRVAL_P ( arg ) ;
2000-04-02 00:49:39 +08:00
}
2000-04-20 22:23:35 +08:00
return zend_hash_update ( symtable , key , strlen ( key ) + 1 , ( void * ) & tmp , sizeof ( zval * ) , NULL ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 00:18:05 +08:00
/* }}} */
2000-04-02 00:49:39 +08:00
2001-08-08 00:18:05 +08:00
/* {{{ add_next_index_object
*/
2003-01-05 04:06:32 +08:00
static inline int add_next_index_object ( zval * arg , zval * tmp TSRMLS_DC )
2001-08-08 00:18:05 +08:00
{
HashTable * symtable ;
2001-09-26 05:58:48 +08:00
if ( Z_TYPE_P ( arg ) = = IS_OBJECT ) {
2001-08-14 00:13:25 +08:00
symtable = Z_OBJPROP_P ( arg ) ;
2001-08-08 00:18:05 +08:00
} else {
2001-09-26 05:58:48 +08:00
symtable = Z_ARRVAL_P ( arg ) ;
2001-08-08 00:18:05 +08:00
}
return zend_hash_next_index_insert ( symtable , ( void * ) & tmp , sizeof ( zval * ) , NULL ) ;
}
/* }}} */
/* {{{ mail_newfolderobjectlist
*
* Mail instantiate FOBJECTLIST
2000-04-02 00:49:39 +08:00
* Returns : new FOBJECTLIST list
* Author : CJH
*/
FOBJECTLIST * mail_newfolderobjectlist ( void )
{
2001-08-08 00:18:05 +08:00
return ( FOBJECTLIST * ) memset ( fs_get ( sizeof ( FOBJECTLIST ) ) , 0 , sizeof ( FOBJECTLIST ) ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 00:18:05 +08:00
/* }}} */
2000-04-02 00:49:39 +08:00
2001-08-08 00:18:05 +08:00
/* {{{ mail_free_foblist
*
* Mail garbage collect FOBJECTLIST
2000-04-02 00:49:39 +08:00
* Accepts : pointer to FOBJECTLIST pointer
* Author : CJH
*/
2002-05-13 04:53:25 +08:00
void mail_free_foblist ( FOBJECTLIST * * foblist , FOBJECTLIST * * tail )
2000-04-02 00:49:39 +08:00
{
2002-08-17 07:25:53 +08:00
FOBJECTLIST * cur , * next ;
2002-05-13 04:53:25 +08:00
2002-08-17 07:25:53 +08:00
for ( cur = * foblist , next = cur - > next ; cur ; cur = next ) {
next = cur - > next ;
if ( cur - > text . data )
fs_give ( ( void * * ) & ( cur - > text . data ) ) ;
2002-05-13 04:53:25 +08:00
2002-08-17 07:25:53 +08:00
fs_give ( ( void * * ) & cur ) ;
}
2002-05-13 04:53:25 +08:00
2002-08-17 07:25:53 +08:00
* tail = NIL ;
* foblist = NIL ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 00:18:05 +08:00
/* }}} */
2000-04-02 00:49:39 +08:00
2001-08-08 00:18:05 +08:00
/* {{{ mail_newerrorlist
*
* Mail instantiate ERRORLIST
2000-04-02 00:49:39 +08:00
* Returns : new ERRORLIST list
* Author : CJH
*/
ERRORLIST * mail_newerrorlist ( void )
{
2000-04-19 03:42:22 +08:00
return ( ERRORLIST * ) memset ( fs_get ( sizeof ( ERRORLIST ) ) , 0 , sizeof ( ERRORLIST ) ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 00:18:05 +08:00
/* }}} */
2000-04-02 00:49:39 +08:00
2001-08-08 00:18:05 +08:00
/* {{{ mail_free_errorlist
*
* Mail garbage collect FOBJECTLIST
2000-04-02 00:49:39 +08:00
* Accepts : pointer to FOBJECTLIST pointer
* Author : CJH
*/
void mail_free_errorlist ( ERRORLIST * * errlist )
{
2000-04-19 03:42:22 +08:00
if ( * errlist ) { /* only free if exists */
if ( ( * errlist ) - > text . data ) {
fs_give ( ( void * * ) & ( * errlist ) - > text . data ) ;
}
mail_free_errorlist ( & ( * errlist ) - > next ) ;
fs_give ( ( void * * ) errlist ) ; /* return string to free storage */
}
2000-04-02 00:49:39 +08:00
}
2001-08-08 00:18:05 +08:00
/* }}} */
2000-04-02 00:49:39 +08:00
2001-08-08 00:18:05 +08:00
/* {{{ mail_newmessagelist
*
* Mail instantiate MESSAGELIST
2000-04-02 00:49:39 +08:00
* Returns : new MESSAGELIST list
* Author : CJH
*/
MESSAGELIST * mail_newmessagelist ( void )
{
2001-08-17 04:13:27 +08:00
return ( MESSAGELIST * ) memset ( fs_get ( sizeof ( MESSAGELIST ) ) , 0 , sizeof ( MESSAGELIST ) ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 00:18:05 +08:00
/* }}} */
/* {{{ mail_free_messagelist
*
* Mail garbage collect MESSAGELIST
* Accepts : pointer to MESSAGELIST pointer
* Author : CJH
*/
2001-08-17 04:13:27 +08:00
void mail_free_messagelist ( MESSAGELIST * * msglist , MESSAGELIST * * tail )
2001-08-08 00:18:05 +08:00
{
2001-08-17 04:13:27 +08:00
MESSAGELIST * cur , * next ;
for ( cur = * msglist , next = cur - > next ; cur ; cur = next ) {
next = cur - > next ;
fs_give ( ( void * * ) & cur ) ;
2001-08-08 00:18:05 +08:00
}
2001-08-17 04:13:27 +08:00
* tail = NIL ;
* msglist = NIL ;
2001-08-08 00:18:05 +08:00
}
/* }}} */
2000-04-02 00:49:39 +08:00
2001-08-08 00:18:05 +08:00
# if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
/* {{{ mail_getquota
*
* Mail GET_QUOTA callback
2001-02-25 12:41:18 +08:00
* Called via the mail_parameter function in c - client : src / c - client / mail . c
* Author DRK
*/
2003-06-13 22:39:22 +08:00
2001-08-12 00:39:07 +08:00
void mail_getquota ( MAILSTREAM * stream , char * qroot , QUOTALIST * qlist )
2001-02-25 12:41:18 +08:00
{
2003-01-21 05:28:09 +08:00
zval * t_map , * return_value ;
2001-07-28 19:36:37 +08:00
TSRMLS_FETCH ( ) ;
2003-01-21 05:28:09 +08:00
return_value = * IMAPG ( quota_return ) ;
2002-07-27 00:22:43 +08:00
/* put parsing code here */
for ( ; qlist ; qlist = qlist - > next ) {
MAKE_STD_ZVAL ( t_map ) ;
2003-01-18 00:07:39 +08:00
array_init ( t_map ) ;
2002-08-01 22:47:48 +08:00
if ( strncmp ( qlist - > name , " STORAGE " , 7 ) = = 0 )
{
/* this is to add backwards compatibility */
2003-01-21 05:28:09 +08:00
add_assoc_long_ex ( return_value , " usage " , sizeof ( " usage " ) , qlist - > usage ) ;
add_assoc_long_ex ( return_value , " limit " , sizeof ( " limit " ) , qlist - > limit ) ;
2002-08-01 22:47:48 +08:00
}
2001-03-16 21:17:54 +08:00
2002-07-31 09:03:31 +08:00
add_assoc_long_ex ( t_map , " usage " , sizeof ( " usage " ) , qlist - > usage ) ;
add_assoc_long_ex ( t_map , " limit " , sizeof ( " limit " ) , qlist - > limit ) ;
2003-01-21 05:28:09 +08:00
add_assoc_zval_ex ( return_value , qlist - > name , strlen ( qlist - > name ) + 1 , t_map ) ;
2001-02-25 12:41:18 +08:00
}
}
2001-08-08 00:18:05 +08:00
/* }}} */
2003-05-21 01:37:53 +08:00
/* {{{ mail_getquota
*
* Mail GET_ACL callback
* Called via the mail_parameter function in c - client : src / c - client / mail . c
*/
void mail_getacl ( MAILSTREAM * stream , char * mailbox , ACLLIST * alist )
{
TSRMLS_FETCH ( ) ;
/* walk through the ACLLIST */
for ( ; alist ; alist = alist - > next ) {
add_assoc_stringl ( IMAPG ( imap_acl_list ) , alist - > identifier , alist - > rights , strlen ( alist - > rights ) , 1 ) ;
}
}
/* }}} */
2001-02-26 23:17:12 +08:00
# endif
2001-02-25 12:41:18 +08:00
2002-07-27 00:22:43 +08:00
2006-06-16 02:33:09 +08:00
/* {{{ PHP_GINIT_FUNCTION
2000-04-02 00:49:39 +08:00
*/
2006-06-16 02:33:09 +08:00
static PHP_GINIT_FUNCTION ( imap )
2000-04-02 00:49:39 +08:00
{
2001-08-17 04:13:27 +08:00
imap_globals - > imap_user = NIL ;
imap_globals - > imap_password = NIL ;
2002-05-13 04:53:25 +08:00
2001-08-17 04:13:27 +08:00
imap_globals - > imap_alertstack = NIL ;
imap_globals - > imap_errorstack = NIL ;
2002-05-13 04:53:25 +08:00
imap_globals - > imap_folders = NIL ;
imap_globals - > imap_folders_tail = NIL ;
imap_globals - > imap_sfolders = NIL ;
imap_globals - > imap_sfolders_tail = NIL ;
2001-08-17 04:13:27 +08:00
imap_globals - > imap_messages = NIL ;
imap_globals - > imap_messages_tail = NIL ;
imap_globals - > imap_folder_objects = NIL ;
2002-05-13 04:53:25 +08:00
imap_globals - > imap_folder_objects_tail = NIL ;
2001-08-17 04:13:27 +08:00
imap_globals - > imap_sfolder_objects = NIL ;
2002-05-13 04:53:25 +08:00
imap_globals - > imap_sfolder_objects_tail = NIL ;
2000-04-02 00:49:39 +08:00
imap_globals - > folderlist_style = FLIST_ARRAY ;
2002-07-27 00:22:43 +08:00
# if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
2003-05-21 00:34:04 +08:00
imap_globals - > quota_return = NIL ;
2003-05-21 01:37:53 +08:00
imap_globals - > imap_acl_list = NIL ;
2002-07-27 00:22:43 +08:00
# endif
2006-01-28 03:46:11 +08:00
imap_globals - > gets_stream = NIL ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 00:18:05 +08:00
/* }}} */
2000-04-02 00:49:39 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ PHP_MINIT_FUNCTION
*/
2000-04-02 00:49:39 +08:00
PHP_MINIT_FUNCTION ( imap )
{
2001-08-06 23:58:37 +08:00
unsigned long sa_all = SA_MESSAGES | SA_RECENT | SA_UNSEEN | SA_UIDNEXT | SA_UIDVALIDITY ;
2000-04-02 00:49:39 +08:00
2000-04-03 05:27:32 +08:00
# ifndef PHP_WIN32
2001-04-08 09:13:07 +08:00
mail_link ( & unixdriver ) ; /* link in the unix driver */
mail_link ( & mhdriver ) ; /* link in the mh driver */
2002-04-24 23:29:52 +08:00
/* mail_link(&mxdriver); */ /* According to c-client docs (internal.txt) this shouldn't be used. */
2001-04-08 09:13:07 +08:00
mail_link ( & mmdfdriver ) ; /* link in the mmdf driver */
mail_link ( & newsdriver ) ; /* link in the news driver */
mail_link ( & philedriver ) ; /* link in the phile driver */
2000-04-02 00:49:39 +08:00
# endif
2001-08-06 23:58:37 +08:00
mail_link ( & imapdriver ) ; /* link in the imap driver */
mail_link ( & nntpdriver ) ; /* link in the nntp driver */
mail_link ( & pop3driver ) ; /* link in the pop3 driver */
mail_link ( & mbxdriver ) ; /* link in the mbx driver */
mail_link ( & tenexdriver ) ; /* link in the tenex driver */
mail_link ( & mtxdriver ) ; /* link in the mtx driver */
2001-04-08 09:13:07 +08:00
mail_link ( & dummydriver ) ; /* link in the dummy driver */
2000-04-25 06:21:34 +08:00
2002-04-24 23:29:52 +08:00
# ifndef PHP_WIN32
auth_link ( & auth_log ) ; /* link in the log authenticator */
auth_link ( & auth_md5 ) ; /* link in the cram-md5 authenticator */
2003-01-24 18:12:55 +08:00
# if HAVE_IMAP_KRB && defined(HAVE_IMAP_AUTH_GSS)
2003-01-18 15:00:47 +08:00
auth_link ( & auth_gss ) ; /* link in the gss authenticator */
# endif
2006-12-18 02:22:53 +08:00
auth_link ( & auth_pla ) ; /* link in the plain authenticator */
2007-02-20 00:03:42 +08:00
# endif
2003-01-18 15:00:47 +08:00
# ifdef HAVE_IMAP_SSL
2002-04-24 23:29:52 +08:00
ssl_onceonlyinit ( ) ;
# endif
2000-04-02 00:49:39 +08:00
/* lets allow NIL */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " NIL " , NIL , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
2006-01-28 03:46:11 +08:00
/* plug in our gets */
mail_parameters ( NIL , SET_GETS , ( void * ) php_mail_gets ) ;
2003-06-13 22:39:22 +08:00
/* set default timeout values */
mail_parameters ( NIL , SET_OPENTIMEOUT , ( void * ) FG ( default_socket_timeout ) ) ;
mail_parameters ( NIL , SET_READTIMEOUT , ( void * ) FG ( default_socket_timeout ) ) ;
mail_parameters ( NIL , SET_WRITETIMEOUT , ( void * ) FG ( default_socket_timeout ) ) ;
mail_parameters ( NIL , SET_CLOSETIMEOUT , ( void * ) FG ( default_socket_timeout ) ) ;
/* timeout constants */
REGISTER_LONG_CONSTANT ( " IMAP_OPENTIMEOUT " , 1 , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " IMAP_READTIMEOUT " , 2 , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " IMAP_WRITETIMEOUT " , 3 , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " IMAP_CLOSETIMEOUT " , 4 , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* Open Options */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " OP_DEBUG " , OP_DEBUG , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* debug protocol negotiations */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " OP_READONLY " , OP_READONLY , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* read-only open */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " OP_ANONYMOUS " , OP_ANONYMOUS , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* anonymous open of newsgroup */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " OP_SHORTCACHE " , OP_SHORTCACHE , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* short (elt-only) caching */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " OP_SILENT " , OP_SILENT , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* don't pass up events (internal use) */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " OP_PROTOTYPE " , OP_PROTOTYPE , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* return driver prototype */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " OP_HALFOPEN " , OP_HALFOPEN , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* half-open (IMAP connect but no select) */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " OP_EXPUNGE " , OP_EXPUNGE , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* silently expunge recycle stream */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " OP_SECURE " , OP_SECURE , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* don't do non-secure authentication */
/*
PHP re - assigns CL_EXPUNGE a custom value that can be used as part of the imap_open ( ) bitfield
because it seems like a good idea to be able to indicate that the mailbox should be
automatically expunged during imap_open in case the script get interrupted and it doesn ' t get
to the imap_close ( ) where this option is normally placed . If the c - client library adds other
options and the value for this one conflicts , simply make PHP_EXPUNGE higher at the top of
this file
*/
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " CL_EXPUNGE " , PHP_EXPUNGE , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* expunge silently */
/* Fetch options */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " FT_UID " , FT_UID , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* argument is a UID */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " FT_PEEK " , FT_PEEK , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* peek at data */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " FT_NOT " , FT_NOT , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* NOT flag for header lines fetch */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " FT_INTERNAL " , FT_INTERNAL , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* text can be internal strings */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " FT_PREFETCHTEXT " , FT_PREFETCHTEXT , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* IMAP prefetch text when fetching header */
/* Flagging options */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " ST_UID " , ST_UID , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* argument is a UID sequence */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " ST_SILENT " , ST_SILENT , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* don't return results */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " ST_SET " , ST_SET , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* set vs. clear */
2001-08-06 23:58:37 +08:00
2000-04-02 00:49:39 +08:00
/* Copy options */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " CP_UID " , CP_UID , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* argument is a UID sequence */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " CP_MOVE " , CP_MOVE , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* delete from source after copying */
/* Search/sort options */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " SE_UID " , SE_UID , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* return UID */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " SE_FREE " , SE_FREE , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* free search program after finished */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " SE_NOPREFETCH " , SE_NOPREFETCH , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* no search prefetching */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " SO_FREE " , SO_FREE , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* free sort program after finished */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " SO_NOSERVER " , SO_NOSERVER , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* don't do server-based sort */
2001-08-06 23:58:37 +08:00
2000-04-02 00:49:39 +08:00
/* Status options */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " SA_MESSAGES " , SA_MESSAGES , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* number of messages */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " SA_RECENT " , SA_RECENT , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* number of recent messages */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " SA_UNSEEN " , SA_UNSEEN , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* number of unseen messages */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " SA_UIDNEXT " , SA_UIDNEXT , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* next UID to be assigned */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " SA_UIDVALIDITY " , SA_UIDVALIDITY , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* UID validity value */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " SA_ALL " , sa_all , CONST_PERSISTENT | CONST_CS ) ;
2002-08-17 07:25:53 +08:00
/* get all status information */
2000-04-02 00:49:39 +08:00
/* Bits for mm_list() and mm_lsub() */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " LATT_NOINFERIORS " , LATT_NOINFERIORS , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " LATT_NOSELECT " , LATT_NOSELECT , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " LATT_MARKED " , LATT_MARKED , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " LATT_UNMARKED " , LATT_UNMARKED , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
2004-01-08 09:01:39 +08:00
# ifdef LATT_REFERRAL
REGISTER_LONG_CONSTANT ( " LATT_REFERRAL " , LATT_REFERRAL , CONST_PERSISTENT | CONST_CS ) ;
# endif
# ifdef LATT_HASCHILDREN
REGISTER_LONG_CONSTANT ( " LATT_HASCHILDREN " , LATT_HASCHILDREN , CONST_PERSISTENT | CONST_CS ) ;
# endif
# ifdef LATT_HASNOCHILDREN
REGISTER_LONG_CONSTANT ( " LATT_HASNOCHILDREN " , LATT_HASNOCHILDREN , CONST_PERSISTENT | CONST_CS ) ;
# endif
2000-04-02 00:49:39 +08:00
/* Sort functions */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " SORTDATE " , SORTDATE , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* date */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " SORTARRIVAL " , SORTARRIVAL , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* arrival date */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " SORTFROM " , SORTFROM , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* from */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " SORTSUBJECT " , SORTSUBJECT , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* subject */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " SORTTO " , SORTTO , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* to */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " SORTCC " , SORTCC , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* cc */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " SORTSIZE " , SORTSIZE , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/* size */
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " TYPETEXT " , TYPETEXT , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " TYPEMULTIPART " , TYPEMULTIPART , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " TYPEMESSAGE " , TYPEMESSAGE , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " TYPEAPPLICATION " , TYPEAPPLICATION , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " TYPEAUDIO " , TYPEAUDIO , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " TYPEIMAGE " , TYPEIMAGE , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " TYPEVIDEO " , TYPEVIDEO , CONST_PERSISTENT | CONST_CS ) ;
2003-09-04 15:47:58 +08:00
REGISTER_LONG_CONSTANT ( " TYPEMODEL " , TYPEMODEL , CONST_PERSISTENT | CONST_CS ) ;
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " TYPEOTHER " , TYPEOTHER , CONST_PERSISTENT | CONST_CS ) ;
2001-08-06 23:58:37 +08:00
/*
TYPETEXT unformatted text
2000-04-02 00:49:39 +08:00
TYPEMULTIPART multiple part
TYPEMESSAGE encapsulated message
TYPEAPPLICATION application data
TYPEAUDIO audio
TYPEIMAGE static image ( GIF , JPEG , etc . )
TYPEVIDEO video
2003-09-04 15:47:58 +08:00
TYPEMODEL model
2000-04-02 00:49:39 +08:00
TYPEOTHER unknown
*/
2001-08-06 23:58:37 +08:00
2001-12-04 04:54:23 +08:00
REGISTER_LONG_CONSTANT ( " ENC7BIT " , ENC7BIT , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " ENC8BIT " , ENC8BIT , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " ENCBINARY " , ENCBINARY , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " ENCBASE64 " , ENCBASE64 , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " ENCQUOTEDPRINTABLE " , ENCQUOTEDPRINTABLE , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_LONG_CONSTANT ( " ENCOTHER " , ENCOTHER , CONST_PERSISTENT | CONST_CS ) ;
2000-04-02 00:49:39 +08:00
/*
ENC7BIT 7 bit SMTP semantic data
ENC8BIT 8 bit SMTP semantic data
ENCBINARY 8 bit binary data
ENCBASE64 base - 64 encoded data
ENCQUOTEDPRINTABLE human - readable 8 - as - 7 bit data
ENCOTHER unknown
*/
2002-08-17 07:25:53 +08:00
le_imap = zend_register_list_destructors_ex ( mail_close_it , NULL , " imap " , module_number ) ;
2002-08-17 00:56:55 +08:00
return SUCCESS ;
2000-04-02 00:49:39 +08:00
}
2001-06-05 21:12:10 +08:00
/* }}} */
2000-04-02 00:49:39 +08:00
2001-08-08 00:18:05 +08:00
/* {{{ PHP_RINIT_FUNCTION
*/
PHP_RINIT_FUNCTION ( imap )
{
IMAPG ( imap_errorstack ) = NIL ;
IMAPG ( imap_alertstack ) = NIL ;
2006-01-28 03:46:11 +08:00
IMAPG ( gets_stream ) = NIL ;
2001-08-08 00:18:05 +08:00
return SUCCESS ;
}
/* }}} */
/* {{{ PHP_RSHUTDOWN_FUNCTION
*/
PHP_RSHUTDOWN_FUNCTION ( imap )
{
ERRORLIST * ecur = NIL ;
STRINGLIST * acur = NIL ;
if ( IMAPG ( imap_errorstack ) ! = NIL ) {
/* output any remaining errors at their original error level */
2002-06-27 07:28:31 +08:00
if ( EG ( error_reporting ) & E_NOTICE ) {
ecur = IMAPG ( imap_errorstack ) ;
while ( ecur ! = NIL ) {
2003-08-29 03:17:34 +08:00
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " %s (errflg=%ld) " , ecur - > LTEXT , ecur - > errflg ) ;
2002-06-27 07:28:31 +08:00
ecur = ecur - > next ;
}
2001-08-08 00:18:05 +08:00
}
mail_free_errorlist ( & IMAPG ( imap_errorstack ) ) ;
}
if ( IMAPG ( imap_alertstack ) ! = NIL ) {
/* output any remaining alerts at E_NOTICE level */
2002-06-27 07:28:31 +08:00
if ( EG ( error_reporting ) & E_NOTICE ) {
acur = IMAPG ( imap_alertstack ) ;
while ( acur ! = NIL ) {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " %s " , acur - > LTEXT ) ;
2002-06-27 07:28:31 +08:00
acur = acur - > next ;
}
2001-08-08 00:18:05 +08:00
}
mail_free_stringlist ( & IMAPG ( imap_alertstack ) ) ;
2002-05-13 04:53:25 +08:00
IMAPG ( imap_alertstack ) = NIL ;
2001-08-08 00:18:05 +08:00
}
return SUCCESS ;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION
*/
PHP_MINFO_FUNCTION ( imap )
{
php_info_print_table_start ( ) ;
2005-01-11 12:56:06 +08:00
# if HAVE_IMAP2004
php_info_print_table_row ( 2 , " IMAP c-Client Version " , " 2004 " ) ;
# elif HAVE_IMAP2001
2002-08-17 07:25:53 +08:00
php_info_print_table_row ( 2 , " IMAP c-Client Version " , " 2001 " ) ;
2001-08-08 00:18:05 +08:00
# elif HAVE_IMAP2000
2002-08-17 07:25:53 +08:00
php_info_print_table_row ( 2 , " IMAP c-Client Version " , " 2000 " ) ;
2001-08-08 00:18:05 +08:00
# elif defined(IMAP41)
2002-08-17 07:25:53 +08:00
php_info_print_table_row ( 2 , " IMAP c-Client Version " , " 4.1 " ) ;
2001-08-08 00:18:05 +08:00
# else
2002-08-17 07:25:53 +08:00
php_info_print_table_row ( 2 , " IMAP c-Client Version " , " 4.0 " ) ;
2001-08-08 00:18:05 +08:00
# endif
# if HAVE_IMAP_SSL
2002-08-17 07:25:53 +08:00
php_info_print_table_row ( 2 , " SSL Support " , " enabled " ) ;
2001-08-08 00:18:05 +08:00
# endif
2005-01-11 12:56:06 +08:00
# if HAVE_IMAP_KRB && HAVE_IMAP_AUTH_GSS
2002-08-17 07:25:53 +08:00
php_info_print_table_row ( 2 , " Kerberos Support " , " enabled " ) ;
2001-08-08 00:18:05 +08:00
# endif
php_info_print_table_end ( ) ;
}
/* }}} */
2001-06-05 21:12:10 +08:00
/* {{{ imap_do_open
*/
2001-08-08 00:18:05 +08:00
static void php_imap_do_open ( INTERNAL_FUNCTION_PARAMETERS , int persistent )
2000-04-02 00:49:39 +08:00
{
2006-11-06 02:31:41 +08:00
zval * * mailbox , * * user , * * passwd , * * options , * * retries ;
2000-04-02 00:49:39 +08:00
MAILSTREAM * imap_stream ;
pils * imap_le_struct ;
long flags = NIL ;
long cl_flags = NIL ;
2001-08-08 10:55:07 +08:00
int myargc = ZEND_NUM_ARGS ( ) ;
2000-04-02 00:49:39 +08:00
2006-11-07 00:44:03 +08:00
if ( myargc < 3 | | myargc > 5 | | zend_get_parameters_ex ( myargc , & mailbox , & user , & passwd , & options , & retries ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2000-04-19 06:22:48 +08:00
convert_to_string_ex ( mailbox ) ;
convert_to_string_ex ( user ) ;
convert_to_string_ex ( passwd ) ;
2006-11-06 02:31:41 +08:00
if ( myargc > = 4 ) {
2000-04-19 06:22:48 +08:00
convert_to_long_ex ( options ) ;
2000-04-20 22:52:54 +08:00
flags = Z_LVAL_PP ( options ) ;
2000-04-19 03:42:22 +08:00
if ( flags & PHP_EXPUNGE ) {
2000-04-02 00:49:39 +08:00
cl_flags = CL_EXPUNGE ;
flags ^ = PHP_EXPUNGE ;
}
}
2001-02-19 02:15:01 +08:00
if ( IMAPG ( imap_user ) ) {
efree ( IMAPG ( imap_user ) ) ;
}
if ( IMAPG ( imap_password ) ) {
efree ( IMAPG ( imap_password ) ) ;
}
2006-08-05 04:31:19 +08:00
/* local filename, need to perform open_basedir and safe_mode checks */
if ( Z_STRVAL_PP ( mailbox ) [ 0 ] ! = ' { ' & &
( php_check_open_basedir ( Z_STRVAL_PP ( mailbox ) TSRMLS_CC ) | |
( PG ( safe_mode ) & & ! php_checkuid ( Z_STRVAL_PP ( mailbox ) , NULL , CHECKUID_CHECK_FILE_AND_DIR ) ) ) ) {
RETURN_FALSE ;
}
2000-10-17 23:42:05 +08:00
IMAPG ( imap_user ) = estrndup ( Z_STRVAL_PP ( user ) , Z_STRLEN_PP ( user ) ) ;
IMAPG ( imap_password ) = estrndup ( Z_STRVAL_PP ( passwd ) , Z_STRLEN_PP ( passwd ) ) ;
2003-06-13 22:39:22 +08:00
2006-11-06 02:31:41 +08:00
# ifdef SET_MAXLOGINTRIALS
if ( myargc = = 5 ) {
convert_to_long_ex ( retries ) ;
2008-04-02 02:28:45 +08:00
if ( retries < 0 ) {
2008-04-02 02:48:11 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Retries must be greater or equal to 0 " ) ;
2008-04-02 02:28:45 +08:00
} else {
mail_parameters ( NIL , SET_MAXLOGINTRIALS , ( void * ) Z_LVAL_PP ( retries ) ) ;
}
2006-11-06 02:31:41 +08:00
}
# endif
2002-08-06 05:53:09 +08:00
imap_stream = mail_open ( NIL , Z_STRVAL_PP ( mailbox ) , flags ) ;
2000-04-02 00:49:39 +08:00
2002-08-06 05:53:09 +08:00
if ( imap_stream = = NIL ) {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Couldn't open stream %s " , Z_STRVAL_PP ( mailbox ) ) ;
2002-08-06 05:53:09 +08:00
efree ( IMAPG ( imap_user ) ) ; IMAPG ( imap_user ) = 0 ;
efree ( IMAPG ( imap_password ) ) ; IMAPG ( imap_password ) = 0 ;
RETURN_FALSE ;
2000-04-02 00:49:39 +08:00
}
2002-08-06 05:53:09 +08:00
imap_le_struct = emalloc ( sizeof ( pils ) ) ;
imap_le_struct - > imap_stream = imap_stream ;
imap_le_struct - > flags = cl_flags ;
ZEND_REGISTER_RESOURCE ( return_value , imap_le_struct , le_imap ) ;
2000-04-02 00:49:39 +08:00
}
2001-06-05 21:12:10 +08:00
/* }}} */
2000-04-02 00:49:39 +08:00
2006-11-06 02:31:41 +08:00
/* {{{ proto resource imap_open(string mailbox, string user, string password [, int options [, int n_retries]])
2000-04-02 00:49:39 +08:00
Open an IMAP stream to a mailbox */
PHP_FUNCTION ( imap_open )
{
2001-08-08 00:18:05 +08:00
php_imap_do_open ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 0 ) ;
2000-04-02 00:49:39 +08:00
}
/* }}} */
2006-11-06 02:31:41 +08:00
/* {{{ proto bool imap_reopen(resource stream_id, string mailbox [, int options [, int n_retries]])
2000-04-04 08:51:38 +08:00
Reopen an IMAP stream to a new mailbox */
2000-04-02 00:49:39 +08:00
PHP_FUNCTION ( imap_reopen )
{
2006-11-06 02:31:41 +08:00
zval * * streamind , * * mailbox , * * options , * * retries ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
2001-08-08 10:55:07 +08:00
MAILSTREAM * imap_stream ;
2000-04-02 00:49:39 +08:00
long flags = NIL ;
long cl_flags = NIL ;
2000-04-19 21:15:57 +08:00
int myargc = ZEND_NUM_ARGS ( ) ;
2000-04-02 00:49:39 +08:00
2006-11-06 02:31:41 +08:00
if ( myargc < 2 | | myargc > 4 | | zend_get_parameters_ex ( myargc , & streamind , & mailbox , & options , & retries ) = = FAILURE ) {
2001-08-08 00:18:05 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
}
2000-04-02 00:49:39 +08:00
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-02 00:49:39 +08:00
2000-04-19 06:22:48 +08:00
convert_to_string_ex ( mailbox ) ;
2001-08-08 10:55:07 +08:00
2006-11-06 02:31:41 +08:00
if ( myargc > = 3 ) {
2000-04-19 06:22:48 +08:00
convert_to_long_ex ( options ) ;
2000-04-20 22:52:54 +08:00
flags = Z_LVAL_PP ( options ) ;
2000-04-19 03:42:22 +08:00
if ( flags & PHP_EXPUNGE ) {
2000-04-02 00:49:39 +08:00
cl_flags = CL_EXPUNGE ;
flags ^ = PHP_EXPUNGE ;
}
imap_le_struct - > flags = cl_flags ;
}
2006-11-06 02:31:41 +08:00
# ifdef SET_MAXLOGINTRIALS
if ( myargc = = 4 ) {
convert_to_long_ex ( retries ) ;
mail_parameters ( NIL , SET_MAXLOGINTRIALS , ( void * ) Z_LVAL_PP ( retries ) ) ;
}
# endif
2006-08-11 23:07:29 +08:00
/* local filename, need to perform open_basedir and safe_mode checks */
if ( Z_STRVAL_PP ( mailbox ) [ 0 ] ! = ' { ' & &
( php_check_open_basedir ( Z_STRVAL_PP ( mailbox ) TSRMLS_CC ) | |
( PG ( safe_mode ) & & ! php_checkuid ( Z_STRVAL_PP ( mailbox ) , NULL , CHECKUID_CHECK_FILE_AND_DIR ) ) ) ) {
RETURN_FALSE ;
}
2001-08-08 10:55:07 +08:00
imap_stream = mail_open ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( mailbox ) , flags ) ;
2000-04-02 00:49:39 +08:00
if ( imap_stream = = NIL ) {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Couldn't re-open stream " ) ;
2000-04-02 00:49:39 +08:00
RETURN_FALSE ;
}
imap_le_struct - > imap_stream = imap_stream ;
RETURN_TRUE ;
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto bool imap_append(resource stream_id, string folder, string message [, string options])
2000-04-04 08:51:38 +08:00
Append a new message to a specified mailbox */
2000-04-02 00:49:39 +08:00
PHP_FUNCTION ( imap_append )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * folder , * * message , * * flags ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
STRING st ;
2000-04-19 21:15:57 +08:00
int myargc = ZEND_NUM_ARGS ( ) ;
2000-04-02 00:49:39 +08:00
2000-04-20 22:23:35 +08:00
if ( myargc < 3 | | myargc > 4 | | zend_get_parameters_ex ( myargc , & streamind , & folder , & message , & flags ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-19 06:22:48 +08:00
convert_to_string_ex ( folder ) ;
convert_to_string_ex ( message ) ;
2001-08-08 10:55:07 +08:00
2000-04-19 06:22:48 +08:00
if ( myargc = = 4 ) {
convert_to_string_ex ( flags ) ;
}
2000-04-02 00:49:39 +08:00
2001-08-08 10:55:07 +08:00
INIT ( & st , mail_string , ( void * ) Z_STRVAL_PP ( message ) , Z_STRLEN_PP ( message ) ) ;
if ( mail_append_full ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( folder ) , myargc = = 4 ? Z_STRVAL_PP ( flags ) : NIL , NIL , & st ) ) {
2000-04-02 00:49:39 +08:00
RETURN_TRUE ;
} else {
RETURN_FALSE ;
}
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto int imap_num_msg(resource stream_id)
2000-04-02 00:49:39 +08:00
Gives the number of messages in the current mailbox */
PHP_FUNCTION ( imap_num_msg )
{
2000-04-20 22:23:35 +08:00
zval * * streamind ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
2000-04-20 22:23:35 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & streamind ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-02 00:49:39 +08:00
RETURN_LONG ( imap_le_struct - > imap_stream - > nmsgs ) ;
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto bool imap_ping(resource stream_id)
2000-04-02 00:49:39 +08:00
Check if the IMAP stream is still active */
PHP_FUNCTION ( imap_ping )
{
2000-04-20 22:23:35 +08:00
zval * * streamind ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
2000-04-20 22:23:35 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & streamind ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-02 00:49:39 +08:00
2002-10-09 17:20:46 +08:00
RETURN_BOOL ( mail_ping ( imap_le_struct - > imap_stream ) ) ;
2000-04-02 00:49:39 +08:00
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto int imap_num_recent(resource stream_id)
2000-04-02 00:49:39 +08:00
Gives the number of recent messages in current mailbox */
PHP_FUNCTION ( imap_num_recent )
{
2000-04-20 22:23:35 +08:00
zval * * streamind ;
pils * imap_le_struct ;
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & streamind ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-02 00:49:39 +08:00
RETURN_LONG ( imap_le_struct - > imap_stream - > recent ) ;
}
/* }}} */
2001-08-08 00:18:05 +08:00
# if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
2002-10-09 17:20:46 +08:00
/* {{{ proto array imap_get_quota(resource stream_id, string qroot)
2001-02-25 12:41:18 +08:00
Returns the quota set to the mailbox account qroot */
PHP_FUNCTION ( imap_get_quota )
{
zval * * streamind , * * qroot ;
pils * imap_le_struct ;
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & streamind , & qroot ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2001-02-25 12:41:18 +08:00
2001-08-08 10:55:07 +08:00
convert_to_string_ex ( qroot ) ;
2001-02-25 12:41:18 +08:00
2003-01-21 03:41:58 +08:00
array_init ( return_value ) ;
2003-01-21 05:28:09 +08:00
IMAPG ( quota_return ) = & return_value ;
2002-07-27 00:22:43 +08:00
2001-02-25 12:41:18 +08:00
/* set the callback for the GET_QUOTA function */
mail_parameters ( NIL , SET_QUOTA , ( void * ) mail_getquota ) ;
if ( ! imap_getquota ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( qroot ) ) ) {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " c-client imap_getquota failed " ) ;
zval_dtor ( return_value ) ;
2001-02-25 12:41:18 +08:00
RETURN_FALSE ;
}
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto array imap_get_quotaroot(resource stream_id, string mbox)
2002-07-27 00:26:01 +08:00
Returns the quota set to the mailbox account mbox */
PHP_FUNCTION ( imap_get_quotaroot )
{
zval * * streamind , * * mbox ;
pils * imap_le_struct ;
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & streamind , & mbox ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
}
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
convert_to_string_ex ( mbox ) ;
2003-01-21 03:41:58 +08:00
array_init ( return_value ) ;
2003-01-21 05:28:09 +08:00
IMAPG ( quota_return ) = & return_value ;
2002-07-27 00:26:01 +08:00
/* set the callback for the GET_QUOTAROOT function */
2002-07-31 09:03:31 +08:00
mail_parameters ( NIL , SET_QUOTA , ( void * ) mail_getquota ) ;
2002-07-27 00:26:01 +08:00
if ( ! imap_getquotaroot ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( mbox ) ) ) {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " c-client imap_getquotaroot failed " ) ;
zval_dtor ( return_value ) ;
2002-07-27 00:26:01 +08:00
RETURN_FALSE ;
}
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto bool imap_set_quota(resource stream_id, string qroot, int mailbox_size)
2001-02-25 12:41:18 +08:00
Will set the quota for qroot mailbox */
PHP_FUNCTION ( imap_set_quota )
{
zval * * streamind , * * qroot , * * mailbox_size ;
pils * imap_le_struct ;
2001-08-08 10:55:07 +08:00
STRINGLIST limits ;
2001-02-25 12:41:18 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 3 | | zend_get_parameters_ex ( 3 , & streamind , & qroot , & mailbox_size ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2001-02-25 12:41:18 +08:00
convert_to_string_ex ( qroot ) ;
convert_to_long_ex ( mailbox_size ) ;
limits . text . data = " STORAGE " ;
limits . text . size = Z_LVAL_PP ( mailbox_size ) ;
limits . next = NIL ;
2002-10-09 17:20:46 +08:00
RETURN_BOOL ( imap_setquota ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( qroot ) , & limits ) ) ;
2001-02-25 12:41:18 +08:00
}
/* }}} */
2001-08-11 02:32:56 +08:00
2002-10-09 17:20:46 +08:00
/* {{{ proto bool imap_setacl(resource stream_id, string mailbox, string id, string rights)
2002-07-27 00:22:43 +08:00
Sets the ACL for a given mailbox */
2001-08-11 02:32:56 +08:00
PHP_FUNCTION ( imap_setacl )
{
zval * * streamind , * * mailbox , * * id , * * rights ;
pils * imap_le_struct ;
2001-08-11 04:32:33 +08:00
2001-08-11 02:32:56 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 4 | | zend_get_parameters_ex ( 4 , & streamind , & mailbox , & id , & rights ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
}
2001-08-11 04:32:33 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2001-08-11 02:32:56 +08:00
convert_to_string_ex ( mailbox ) ;
2008-03-29 00:45:05 +08:00
convert_to_string_ex ( id ) ;
2001-08-11 02:32:56 +08:00
convert_to_string_ex ( rights ) ;
2002-10-09 17:20:46 +08:00
RETURN_BOOL ( imap_setacl ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( mailbox ) , Z_STRVAL_PP ( id ) , Z_STRVAL_PP ( rights ) ) ) ;
2001-08-11 02:32:56 +08:00
}
/* }}} */
2003-05-21 01:37:53 +08:00
2003-11-14 04:55:00 +08:00
/* {{{ proto array imap_getacl(resource stream_id, string mailbox)
2003-05-21 01:37:53 +08:00
Gets the ACL for a given mailbox */
PHP_FUNCTION ( imap_getacl )
{
zval * * streamind , * * mailbox ;
pils * imap_le_struct ;
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & streamind , & mailbox ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
}
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
convert_to_string_ex ( mailbox ) ;
/* initializing the special array for the return values */
array_init ( return_value ) ;
IMAPG ( imap_acl_list ) = return_value ;
/* set the callback for the GET_ACL function */
mail_parameters ( NIL , SET_ACL , ( void * ) mail_getacl ) ;
if ( ! imap_getacl ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( mailbox ) ) ) {
php_error ( E_WARNING , " c-client imap_getacl failed " ) ;
2005-01-21 18:55:41 +08:00
zval_dtor ( return_value ) ;
2003-05-21 01:37:53 +08:00
RETURN_FALSE ;
}
IMAPG ( imap_acl_list ) = NIL ;
}
/* }}} */
2001-08-11 04:32:33 +08:00
# endif /* HAVE_IMAP2000 || HAVE_IMAP2001 */
2001-02-25 12:41:18 +08:00
2002-10-09 17:20:46 +08:00
/* {{{ proto bool imap_expunge(resource stream_id)
2000-04-04 08:51:38 +08:00
Permanently delete all messages marked for deletion */
2000-04-02 00:49:39 +08:00
PHP_FUNCTION ( imap_expunge )
{
2000-04-20 22:23:35 +08:00
zval * * streamind ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
2000-04-20 22:23:35 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & streamind ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-02 00:49:39 +08:00
mail_expunge ( imap_le_struct - > imap_stream ) ;
RETURN_TRUE ;
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto bool imap_close(resource stream_id [, int options])
2000-04-02 00:49:39 +08:00
Close an IMAP stream */
PHP_FUNCTION ( imap_close )
{
2001-08-08 10:55:07 +08:00
zval * * options , * * streamind = NULL ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct = NULL ;
long flags = NIL ;
2001-08-08 10:55:07 +08:00
int myargcount = ZEND_NUM_ARGS ( ) ;
2000-04-02 00:49:39 +08:00
2000-04-20 22:23:35 +08:00
if ( myargcount < 1 | | myargcount > 2 | | zend_get_parameters_ex ( myargcount , & streamind , & options ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 00:18:05 +08:00
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2001-08-08 00:18:05 +08:00
2001-08-08 10:55:07 +08:00
if ( myargcount = = 2 ) {
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( options ) ;
2000-04-20 22:52:54 +08:00
flags = Z_LVAL_PP ( options ) ;
2000-04-02 00:49:39 +08:00
/* Do the translation from PHP's internal PHP_EXPUNGE define to c-client's CL_EXPUNGE */
2000-04-19 03:42:22 +08:00
if ( flags & PHP_EXPUNGE ) {
2000-04-02 00:49:39 +08:00
flags ^ = PHP_EXPUNGE ;
flags | = CL_EXPUNGE ;
}
imap_le_struct - > flags = flags ;
}
2000-06-17 02:24:02 +08:00
2001-08-08 10:55:07 +08:00
zend_list_delete ( Z_RESVAL_PP ( streamind ) ) ;
2000-04-02 00:49:39 +08:00
RETURN_TRUE ;
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto array imap_headers(resource stream_id)
2000-04-02 00:49:39 +08:00
Returns headers for all messages in a mailbox */
PHP_FUNCTION ( imap_headers )
{
2000-04-20 22:23:35 +08:00
zval * * streamind ;
2001-08-08 10:55:07 +08:00
pils * imap_le_struct ;
2000-04-02 00:49:39 +08:00
unsigned long i ;
char * t ;
unsigned int msgno ;
char tmp [ MAILTMPLEN ] ;
2000-04-20 22:23:35 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & streamind ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-02 00:49:39 +08:00
/* Initialize return array */
2003-01-18 00:07:39 +08:00
array_init ( return_value ) ;
2000-04-02 00:49:39 +08:00
for ( msgno = 1 ; msgno < = imap_le_struct - > imap_stream - > nmsgs ; msgno + + ) {
2001-08-12 00:39:07 +08:00
MESSAGECACHE * cache = mail_elt ( imap_le_struct - > imap_stream , msgno ) ;
mail_fetchstructure ( imap_le_struct - > imap_stream , msgno , NIL ) ;
2000-04-02 00:49:39 +08:00
tmp [ 0 ] = cache - > recent ? ( cache - > seen ? ' R ' : ' N ' ) : ' ' ;
tmp [ 1 ] = ( cache - > recent | cache - > seen ) ? ' ' : ' U ' ;
tmp [ 2 ] = cache - > flagged ? ' F ' : ' ' ;
tmp [ 3 ] = cache - > answered ? ' A ' : ' ' ;
tmp [ 4 ] = cache - > deleted ? ' D ' : ' ' ;
tmp [ 5 ] = cache - > draft ? ' X ' : ' ' ;
2007-02-24 10:17:47 +08:00
snprintf ( tmp + 6 , sizeof ( tmp ) - 6 , " %4ld) " , cache - > msgno ) ;
2000-04-07 12:43:26 +08:00
mail_date ( tmp + 11 , cache ) ;
2000-07-21 23:50:37 +08:00
tmp [ 22 ] = ' ' ;
tmp [ 23 ] = ' \0 ' ;
mail_fetchfrom ( tmp + 23 , imap_le_struct - > imap_stream , msgno , ( long ) 20 ) ;
2000-04-07 12:43:26 +08:00
strcat ( tmp , " " ) ;
2000-04-02 00:49:39 +08:00
if ( ( i = cache - > user_flags ) ) {
strcat ( tmp , " { " ) ;
while ( i ) {
2007-01-18 22:03:38 +08:00
strlcat ( tmp , imap_le_struct - > imap_stream - > user_flags [ find_rightmost_bit ( & i ) ] , sizeof ( tmp ) ) ;
if ( i ) strlcat ( tmp , " " , sizeof ( tmp ) ) ;
2000-04-02 00:49:39 +08:00
}
2007-01-18 22:03:38 +08:00
strlcat ( tmp , " } " , sizeof ( tmp ) ) ;
2000-04-02 00:49:39 +08:00
}
2000-04-07 12:43:26 +08:00
mail_fetchsubject ( t = tmp + strlen ( tmp ) , imap_le_struct - > imap_stream , msgno , ( long ) 25 ) ;
2007-01-18 22:03:38 +08:00
snprintf ( t + = strlen ( t ) , sizeof ( tmp ) - strlen ( tmp ) , " (%ld chars) " , cache - > rfc822_size ) ;
2000-04-07 12:43:26 +08:00
add_next_index_string ( return_value , tmp , 1 ) ;
2000-04-02 00:49:39 +08:00
}
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto string imap_body(resource stream_id, int msg_no [, int options])
2000-04-02 00:49:39 +08:00
Read the message body */
PHP_FUNCTION ( imap_body )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * msgno , * * flags ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
2001-08-08 10:55:07 +08:00
int msgindex , myargc = ZEND_NUM_ARGS ( ) ;
2001-05-04 03:44:42 +08:00
if ( myargc < 2 | | myargc > 3 | | zend_get_parameters_ex ( myargc , & streamind , & msgno , & flags ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( msgno ) ;
2000-04-19 03:42:22 +08:00
if ( myargc = = 3 ) {
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( flags ) ;
2000-04-19 03:42:22 +08:00
}
2001-05-04 03:44:42 +08:00
if ( ( myargc = = 3 ) & & ( Z_LVAL_PP ( flags ) & FT_UID ) ) {
/* This should be cached; if it causes an extra RTT to the
IMAP server , then that ' s the price we pay for making
sure we don ' t crash . */
msgindex = mail_msgno ( imap_le_struct - > imap_stream , Z_LVAL_PP ( msgno ) ) ;
} else {
msgindex = Z_LVAL_PP ( msgno ) ;
}
if ( ( msgindex < 1 ) | | ( ( unsigned ) msgindex > imap_le_struct - > imap_stream - > nmsgs ) ) {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Bad message number " ) ;
2001-05-04 03:44:42 +08:00
RETURN_FALSE ;
}
2002-08-17 07:25:53 +08:00
2000-04-20 22:52:54 +08:00
RETVAL_STRING ( mail_fetchtext_full ( imap_le_struct - > imap_stream , Z_LVAL_PP ( msgno ) , NIL , myargc = = 3 ? Z_LVAL_PP ( flags ) : NIL ) , 1 ) ;
2000-04-02 00:49:39 +08:00
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto bool imap_mail_copy(resource stream_id, int msg_no, string mailbox [, int options])
2000-04-02 00:49:39 +08:00
Copy specified message to a mailbox */
PHP_FUNCTION ( imap_mail_copy )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * seq , * * folder , * * options ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
2000-04-19 21:15:57 +08:00
int myargcount = ZEND_NUM_ARGS ( ) ;
2000-04-20 22:23:35 +08:00
2001-08-08 10:55:07 +08:00
if ( myargcount > 4 | | myargcount < 3 | | zend_get_parameters_ex ( myargcount , & streamind , & seq , & folder , & options ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( seq ) ;
convert_to_string_ex ( folder ) ;
2000-04-19 03:42:22 +08:00
if ( myargcount = = 4 ) {
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( options ) ;
2000-04-19 03:42:22 +08:00
}
2000-04-02 00:49:39 +08:00
2000-04-20 22:52:54 +08:00
if ( mail_copy_full ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( seq ) , Z_STRVAL_PP ( folder ) , myargcount = = 4 ? Z_LVAL_PP ( options ) : NIL ) = = T ) {
2002-08-17 07:25:53 +08:00
RETURN_TRUE ;
2000-04-02 00:49:39 +08:00
} else {
RETURN_FALSE ;
}
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto bool imap_mail_move(resource stream_id, int msg_no, string mailbox [, int options])
2000-04-02 00:49:39 +08:00
Move specified message to a mailbox */
PHP_FUNCTION ( imap_mail_move )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * seq , * * folder , * * options ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
2000-04-19 21:15:57 +08:00
int myargcount = ZEND_NUM_ARGS ( ) ;
2000-04-20 22:23:35 +08:00
2001-08-08 10:55:07 +08:00
if ( myargcount > 4 | | myargcount < 3 | | zend_get_parameters_ex ( myargcount , & streamind , & seq , & folder , & options ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( seq ) ;
convert_to_string_ex ( folder ) ;
2000-04-07 12:43:26 +08:00
if ( myargcount = = 4 ) {
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( options ) ;
2000-04-07 12:43:26 +08:00
}
2001-08-08 10:55:07 +08:00
if ( mail_copy_full ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( seq ) , Z_STRVAL_PP ( folder ) , myargcount = = 4 ? ( Z_LVAL_PP ( options ) | CP_MOVE ) : CP_MOVE ) = = T ) {
2002-08-17 07:25:53 +08:00
RETURN_TRUE ;
2000-04-02 00:49:39 +08:00
} else {
RETURN_FALSE ;
}
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto bool imap_createmailbox(resource stream_id, string mailbox)
2000-04-02 00:49:39 +08:00
Create a new mailbox */
PHP_FUNCTION ( imap_createmailbox )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * folder ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
2001-08-08 10:55:07 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & streamind , & folder ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-02 00:49:39 +08:00
2001-08-08 10:55:07 +08:00
convert_to_string_ex ( folder ) ;
2000-04-02 00:49:39 +08:00
2001-08-08 10:55:07 +08:00
if ( mail_create ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( folder ) ) = = T ) {
2002-08-17 07:25:53 +08:00
RETURN_TRUE ;
2000-04-02 00:49:39 +08:00
} else {
RETURN_FALSE ;
}
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto bool imap_renamemailbox(resource stream_id, string old_name, string new_name)
2000-04-02 00:49:39 +08:00
Rename a mailbox */
PHP_FUNCTION ( imap_renamemailbox )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * old_mailbox , * * new_mailbox ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
2001-08-08 10:55:07 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 3 | | zend_get_parameters_ex ( 3 , & streamind , & old_mailbox , & new_mailbox ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( old_mailbox ) ;
convert_to_string_ex ( new_mailbox ) ;
2000-04-02 00:49:39 +08:00
2000-04-20 22:52:54 +08:00
if ( mail_rename ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( old_mailbox ) , Z_STRVAL_PP ( new_mailbox ) ) = = T ) {
2002-08-17 07:25:53 +08:00
RETURN_TRUE ;
2000-04-02 00:49:39 +08:00
} else {
RETURN_FALSE ;
}
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto bool imap_deletemailbox(resource stream_id, string mailbox)
2000-04-02 00:49:39 +08:00
Delete a mailbox */
PHP_FUNCTION ( imap_deletemailbox )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * folder ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
2001-08-08 10:55:07 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & streamind , & folder ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-02 00:49:39 +08:00
2001-08-08 10:55:07 +08:00
convert_to_string_ex ( folder ) ;
2000-04-02 00:49:39 +08:00
2000-04-20 22:52:54 +08:00
if ( mail_delete ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( folder ) ) = = T ) {
2002-08-17 07:25:53 +08:00
RETURN_TRUE ;
2000-04-02 00:49:39 +08:00
} else {
RETURN_FALSE ;
}
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto array imap_list(resource stream_id, string ref, string pattern)
2000-04-02 00:49:39 +08:00
Read the list of mailboxes */
PHP_FUNCTION ( imap_list )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * ref , * * pat ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
STRINGLIST * cur = NIL ;
2001-08-08 00:18:05 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 3 | | zend_get_parameters_ex ( 3 , & streamind , & ref , & pat ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( ref ) ;
convert_to_string_ex ( pat ) ;
2000-04-02 00:49:39 +08:00
2001-08-08 10:55:07 +08:00
/* set flag for normal, old mailbox list */
IMAPG ( folderlist_style ) = FLIST_ARRAY ;
2002-05-13 04:53:25 +08:00
IMAPG ( imap_folders ) = IMAPG ( imap_folders_tail ) = NIL ;
2000-04-20 22:52:54 +08:00
mail_list ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( ref ) , Z_STRVAL_PP ( pat ) ) ;
2000-04-02 00:49:39 +08:00
if ( IMAPG ( imap_folders ) = = NIL ) {
RETURN_FALSE ;
}
2001-08-08 10:55:07 +08:00
2000-04-02 00:49:39 +08:00
array_init ( return_value ) ;
2001-08-08 00:18:05 +08:00
cur = IMAPG ( imap_folders ) ;
while ( cur ! = NIL ) {
2000-04-20 22:23:35 +08:00
add_next_index_string ( return_value , cur - > LTEXT , 1 ) ;
2001-08-08 00:18:05 +08:00
cur = cur - > next ;
}
2000-04-02 00:49:39 +08:00
mail_free_stringlist ( & IMAPG ( imap_folders ) ) ;
2002-05-13 04:53:25 +08:00
IMAPG ( imap_folders ) = IMAPG ( imap_folders_tail ) = NIL ;
2000-04-02 00:49:39 +08:00
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto array imap_getmailboxes(resource stream_id, string ref, string pattern)
2000-04-02 00:49:39 +08:00
Reads the list of mailboxes and returns a full array of objects containing name , attributes , and delimiter */
/* Author: CJH */
PHP_FUNCTION ( imap_list_full )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * ref , * * pat , * mboxob ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
FOBJECTLIST * cur = NIL ;
char * delim = NIL ;
2001-08-08 10:55:07 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 3 | | zend_get_parameters_ex ( 3 , & streamind , & ref , & pat ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( ref ) ;
convert_to_string_ex ( pat ) ;
2001-08-08 10:55:07 +08:00
/* set flag for new, improved array of objects mailbox list */
IMAPG ( folderlist_style ) = FLIST_OBJECT ;
2000-04-02 00:49:39 +08:00
2002-05-13 04:53:25 +08:00
IMAPG ( imap_folder_objects ) = IMAPG ( imap_folder_objects_tail ) = NIL ;
2000-04-20 22:52:54 +08:00
mail_list ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( ref ) , Z_STRVAL_PP ( pat ) ) ;
2000-04-02 00:49:39 +08:00
if ( IMAPG ( imap_folder_objects ) = = NIL ) {
RETURN_FALSE ;
}
array_init ( return_value ) ;
2003-08-12 08:58:52 +08:00
delim = safe_emalloc ( 2 , sizeof ( char ) , 0 ) ;
2000-04-02 00:49:39 +08:00
cur = IMAPG ( imap_folder_objects ) ;
while ( cur ! = NIL ) {
MAKE_STD_ZVAL ( mboxob ) ;
object_init ( mboxob ) ;
2000-04-20 22:23:35 +08:00
add_property_string ( mboxob , " name " , cur - > LTEXT , 1 ) ;
2000-04-02 00:49:39 +08:00
add_property_long ( mboxob , " attributes " , cur - > attributes ) ;
# ifdef IMAP41
delim [ 0 ] = ( char ) cur - > delimiter ;
delim [ 1 ] = 0 ;
add_property_string ( mboxob , " delimiter " , delim , 1 ) ;
# else
add_property_string ( mboxob , " delimiter " , cur - > delimiter , 1 ) ;
# endif
2003-01-05 04:06:32 +08:00
add_next_index_object ( return_value , mboxob TSRMLS_CC ) ;
2000-04-02 00:49:39 +08:00
cur = cur - > next ;
}
2002-05-13 04:53:25 +08:00
mail_free_foblist ( & IMAPG ( imap_folder_objects ) , & IMAPG ( imap_folder_objects_tail ) ) ;
2000-04-02 00:49:39 +08:00
efree ( delim ) ;
IMAPG ( folderlist_style ) = FLIST_ARRAY ; /* reset to default */
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto array imap_scan(resource stream_id, string ref, string pattern, string content)
2000-04-02 00:49:39 +08:00
Read list of mailboxes containing a certain string */
PHP_FUNCTION ( imap_listscan )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * ref , * * pat , * * content ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
STRINGLIST * cur = NIL ;
2001-08-08 10:55:07 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 4 | | zend_get_parameters_ex ( 4 , & streamind , & ref , & pat , & content ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( ref ) ;
convert_to_string_ex ( pat ) ;
convert_to_string_ex ( content ) ;
2000-04-02 00:49:39 +08:00
IMAPG ( imap_folders ) = NIL ;
2000-04-20 22:52:54 +08:00
mail_scan ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( ref ) , Z_STRVAL_PP ( pat ) , Z_STRVAL_PP ( content ) ) ;
2000-04-02 00:49:39 +08:00
if ( IMAPG ( imap_folders ) = = NIL ) {
RETURN_FALSE ;
}
2001-08-08 10:55:07 +08:00
2000-04-02 00:49:39 +08:00
array_init ( return_value ) ;
cur = IMAPG ( imap_folders ) ;
2000-04-19 03:42:22 +08:00
while ( cur ! = NIL ) {
2000-04-20 22:23:35 +08:00
add_next_index_string ( return_value , cur - > LTEXT , 1 ) ;
2000-04-02 00:49:39 +08:00
cur = cur - > next ;
}
mail_free_stringlist ( & IMAPG ( imap_folders ) ) ;
2002-05-13 04:53:25 +08:00
IMAPG ( imap_folders ) = IMAPG ( imap_folders_tail ) = NIL ;
2000-04-02 00:49:39 +08:00
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto object imap_check(resource stream_id)
2000-04-02 00:49:39 +08:00
Get mailbox properties */
PHP_FUNCTION ( imap_check )
{
2000-04-20 22:23:35 +08:00
zval * * streamind ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
char date [ 100 ] ;
2000-04-20 22:23:35 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & streamind ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-02 00:49:39 +08:00
2000-04-19 03:42:22 +08:00
if ( mail_ping ( imap_le_struct - > imap_stream ) = = NIL ) {
2000-04-02 00:49:39 +08:00
RETURN_FALSE ;
2001-08-08 00:18:05 +08:00
}
2000-04-02 00:49:39 +08:00
if ( imap_le_struct - > imap_stream & & imap_le_struct - > imap_stream - > mailbox ) {
2000-04-19 06:22:48 +08:00
rfc822_date ( date ) ;
2000-04-02 00:49:39 +08:00
object_init ( return_value ) ;
2000-04-20 22:23:35 +08:00
add_property_string ( return_value , " Date " , date , 1 ) ;
add_property_string ( return_value , " Driver " , imap_le_struct - > imap_stream - > dtb - > name , 1 ) ;
add_property_string ( return_value , " Mailbox " , imap_le_struct - > imap_stream - > mailbox , 1 ) ;
add_property_long ( return_value , " Nmsgs " , imap_le_struct - > imap_stream - > nmsgs ) ;
add_property_long ( return_value , " Recent " , imap_le_struct - > imap_stream - > recent ) ;
2000-04-02 00:49:39 +08:00
} else {
RETURN_FALSE ;
}
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto bool imap_delete(resource stream_id, int msg_no [, int options])
2000-04-02 00:49:39 +08:00
Mark a message for deletion */
PHP_FUNCTION ( imap_delete )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * sequence , * * flags ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
2000-04-19 21:15:57 +08:00
int myargc = ZEND_NUM_ARGS ( ) ;
2000-04-07 12:43:26 +08:00
2000-04-20 22:23:35 +08:00
if ( myargc < 2 | | myargc > 3 | | zend_get_parameters_ex ( myargc , & streamind , & sequence , & flags ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2000-04-07 12:43:26 +08:00
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( sequence ) ;
2000-04-07 12:43:26 +08:00
if ( myargc = = 3 ) {
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( flags ) ;
2000-04-07 12:43:26 +08:00
}
2000-04-20 22:52:54 +08:00
mail_setflag_full ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( sequence ) , " \\ DELETED " , myargc = = 3 ? Z_LVAL_PP ( flags ) : NIL ) ;
2000-04-02 00:49:39 +08:00
RETVAL_TRUE ;
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto bool imap_undelete(resource stream_id, int msg_no)
2000-04-02 00:49:39 +08:00
Remove the delete flag from a message */
PHP_FUNCTION ( imap_undelete )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * sequence , * * flags ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
2000-04-19 21:15:57 +08:00
int myargc = ZEND_NUM_ARGS ( ) ;
2000-04-02 00:49:39 +08:00
2000-04-20 22:23:35 +08:00
if ( myargc < 2 | | myargc > 3 | | zend_get_parameters_ex ( myargc , & streamind , & sequence , & flags ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2000-04-07 12:43:26 +08:00
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( sequence ) ;
2000-04-07 12:43:26 +08:00
if ( myargc = = 3 ) {
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( flags ) ;
2000-04-07 12:43:26 +08:00
}
2000-04-02 00:49:39 +08:00
2000-04-20 22:52:54 +08:00
mail_clearflag_full ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( sequence ) , " \\ DELETED " , myargc = = 3 ? Z_LVAL_PP ( flags ) : NIL ) ;
2000-04-02 00:49:39 +08:00
RETVAL_TRUE ;
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto object imap_headerinfo(resource stream_id, int msg_no [, int from_length [, int subject_length [, string default_host]]])
2000-04-04 08:51:38 +08:00
Read the headers of the message */
2000-04-02 00:49:39 +08:00
PHP_FUNCTION ( imap_headerinfo )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * msgno , * * fromlength , * * subjectlength , * * defaulthost ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
MESSAGECACHE * cache ;
ENVELOPE * en ;
2002-05-13 08:29:22 +08:00
char dummy [ 2000 ] , fulladdress [ MAILTMPLEN ] ;
2000-04-19 21:15:57 +08:00
int myargc = ZEND_NUM_ARGS ( ) ;
2001-08-08 10:55:07 +08:00
if ( myargc < 2 | | myargc > 5 | | zend_get_parameters_ex ( myargc , & streamind , & msgno , & fromlength , & subjectlength , & defaulthost ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( msgno ) ;
2000-04-19 03:42:22 +08:00
if ( myargc > = 3 ) {
2005-01-20 22:04:50 +08:00
convert_to_long_ex ( fromlength ) ;
2008-04-03 00:26:39 +08:00
if ( Z_LVAL_PP ( fromlength ) < 0 | | Z_LVAL_PP ( fromlength ) > = MAILTMPLEN ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " From length has to be between 1 and %i " , MAILTMPLEN ) ;
2005-01-20 22:04:50 +08:00
RETURN_FALSE ;
}
2000-04-19 03:42:22 +08:00
} else {
fromlength = 0x00 ;
}
if ( myargc > = 4 ) {
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( subjectlength ) ;
2008-04-03 00:26:39 +08:00
if ( Z_LVAL_PP ( subjectlength ) < 0 | | Z_LVAL_PP ( subjectlength ) > = MAILTMPLEN ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Subject length has to be between 1 and %i " , MAILTMPLEN ) ;
2005-01-21 02:03:35 +08:00
RETURN_FALSE ;
2005-01-20 22:04:50 +08:00
}
2000-04-19 03:42:22 +08:00
} else {
subjectlength = 0x00 ;
}
if ( myargc = = 5 ) {
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( defaulthost ) ;
2000-04-19 03:42:22 +08:00
}
2000-04-02 00:49:39 +08:00
2004-07-22 05:57:03 +08:00
PHP_IMAP_CHECK_MSGNO ( Z_LVAL_PP ( msgno ) ) ;
2000-04-20 22:52:54 +08:00
if ( mail_fetchstructure ( imap_le_struct - > imap_stream , Z_LVAL_PP ( msgno ) , NIL ) ) {
cache = mail_elt ( imap_le_struct - > imap_stream , Z_LVAL_PP ( msgno ) ) ;
2000-04-02 00:49:39 +08:00
} else {
RETURN_FALSE ;
}
2002-05-13 08:29:22 +08:00
en = mail_fetchenvelope ( imap_le_struct - > imap_stream , Z_LVAL_PP ( msgno ) ) ;
2000-04-02 00:49:39 +08:00
/* call a function to parse all the text, so that we can use the
2001-08-08 00:18:05 +08:00
same function to parse text from other sources */
2001-08-08 01:40:10 +08:00
_php_make_header_object ( return_value , en TSRMLS_CC ) ;
2000-04-02 00:49:39 +08:00
/* now run through properties that are only going to be returned
2001-08-08 00:18:05 +08:00
from a server , not text headers */
2000-04-02 00:49:39 +08:00
add_property_string ( return_value , " Recent " , cache - > recent ? ( cache - > seen ? " R " : " N " ) : " " , 1 ) ;
add_property_string ( return_value , " Unseen " , ( cache - > recent | cache - > seen ) ? " " : " U " , 1 ) ;
add_property_string ( return_value , " Flagged " , cache - > flagged ? " F " : " " , 1 ) ;
add_property_string ( return_value , " Answered " , cache - > answered ? " A " : " " , 1 ) ;
add_property_string ( return_value , " Deleted " , cache - > deleted ? " D " : " " , 1 ) ;
add_property_string ( return_value , " Draft " , cache - > draft ? " X " : " " , 1 ) ;
2007-02-24 10:17:47 +08:00
snprintf ( dummy , sizeof ( dummy ) , " %4ld " , cache - > msgno ) ;
2000-04-02 00:49:39 +08:00
add_property_string ( return_value , " Msgno " , dummy , 1 ) ;
mail_date ( dummy , cache ) ;
add_property_string ( return_value , " MailDate " , dummy , 1 ) ;
2007-02-24 10:17:47 +08:00
snprintf ( dummy , sizeof ( dummy ) , " %ld " , cache - > rfc822_size ) ;
2000-04-02 00:49:39 +08:00
add_property_string ( return_value , " Size " , dummy , 1 ) ;
add_property_long ( return_value , " udate " , mail_longdate ( cache ) ) ;
if ( en - > from & & fromlength ) {
fulladdress [ 0 ] = 0x00 ;
2000-04-20 22:52:54 +08:00
mail_fetchfrom ( fulladdress , imap_le_struct - > imap_stream , Z_LVAL_PP ( msgno ) , Z_LVAL_PP ( fromlength ) ) ;
2000-04-02 00:49:39 +08:00
add_property_string ( return_value , " fetchfrom " , fulladdress , 1 ) ;
}
if ( en - > subject & & subjectlength ) {
fulladdress [ 0 ] = 0x00 ;
2000-04-20 22:52:54 +08:00
mail_fetchsubject ( fulladdress , imap_le_struct - > imap_stream , Z_LVAL_PP ( msgno ) , Z_LVAL_PP ( subjectlength ) ) ;
2000-04-02 00:49:39 +08:00
add_property_string ( return_value , " fetchsubject " , fulladdress , 1 ) ;
}
}
/* }}} */
2000-06-19 00:31:52 +08:00
/* {{{ proto object imap_rfc822_parse_headers(string headers [, string default_host])
2000-04-02 00:49:39 +08:00
Parse a set of mail headers contained in a string , and return an object similar to imap_headerinfo ( ) */
PHP_FUNCTION ( imap_rfc822_parse_headers )
{
zval * * headers , * * defaulthost ;
ENVELOPE * en ;
2000-04-19 21:15:57 +08:00
int myargc = ZEND_NUM_ARGS ( ) ;
2001-08-08 10:55:07 +08:00
2000-04-02 00:49:39 +08:00
if ( myargc < 1 | | myargc > 2 | | zend_get_parameters_ex ( myargc , & headers , & defaulthost ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
convert_to_string_ex ( headers ) ;
2000-04-07 12:43:26 +08:00
if ( myargc = = 2 ) {
convert_to_string_ex ( defaulthost ) ;
}
2000-04-02 00:49:39 +08:00
2000-04-07 12:43:26 +08:00
if ( myargc = = 2 ) {
2001-08-08 10:55:07 +08:00
rfc822_parse_msg ( & en , NULL , Z_STRVAL_PP ( headers ) , Z_STRLEN_PP ( headers ) , NULL , Z_STRVAL_PP ( defaulthost ) , NIL ) ;
2000-04-02 00:49:39 +08:00
} else {
2001-08-08 10:55:07 +08:00
rfc822_parse_msg ( & en , NULL , Z_STRVAL_PP ( headers ) , Z_STRLEN_PP ( headers ) , NULL , " UNKNOWN " , NIL ) ;
2000-04-02 00:49:39 +08:00
}
/* call a function to parse all the text, so that we can use the
2001-08-08 00:18:05 +08:00
same function no matter where the headers are from */
2001-08-08 01:40:10 +08:00
_php_make_header_object ( return_value , en TSRMLS_CC ) ;
2000-04-19 06:22:48 +08:00
mail_free_envelope ( & en ) ;
2000-04-02 00:49:39 +08:00
}
/* }}} */
2000-04-20 22:23:35 +08:00
2000-04-02 00:49:39 +08:00
/* KMLANG */
2002-10-09 17:20:46 +08:00
/* {{{ proto array imap_lsub(resource stream_id, string ref, string pattern)
2000-04-02 00:49:39 +08:00
Return a list of subscribed mailboxes */
PHP_FUNCTION ( imap_lsub )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * ref , * * pat ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
STRINGLIST * cur = NIL ;
2001-08-08 10:55:07 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 3 | | zend_get_parameters_ex ( 3 , & streamind , & ref , & pat ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( ref ) ;
convert_to_string_ex ( pat ) ;
2000-04-02 00:49:39 +08:00
2001-08-08 10:55:07 +08:00
/* set flag for normal, old mailbox list */
IMAPG ( folderlist_style ) = FLIST_ARRAY ;
2000-04-02 00:49:39 +08:00
IMAPG ( imap_sfolders ) = NIL ;
2000-04-20 22:52:54 +08:00
mail_lsub ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( ref ) , Z_STRVAL_PP ( pat ) ) ;
2000-04-02 00:49:39 +08:00
if ( IMAPG ( imap_sfolders ) = = NIL ) {
RETURN_FALSE ;
}
2001-08-08 10:55:07 +08:00
2000-04-02 00:49:39 +08:00
array_init ( return_value ) ;
cur = IMAPG ( imap_sfolders ) ;
2000-04-19 03:42:22 +08:00
while ( cur ! = NIL ) {
2000-04-20 22:23:35 +08:00
add_next_index_string ( return_value , cur - > LTEXT , 1 ) ;
2000-04-02 00:49:39 +08:00
cur = cur - > next ;
}
mail_free_stringlist ( & IMAPG ( imap_sfolders ) ) ;
2002-05-13 04:53:25 +08:00
IMAPG ( imap_sfolders ) = IMAPG ( imap_sfolders_tail ) = NIL ;
2000-04-02 00:49:39 +08:00
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto array imap_getsubscribed(resource stream_id, string ref, string pattern)
2000-04-04 08:51:38 +08:00
Return a list of subscribed mailboxes , in the same format as imap_getmailboxes ( ) */
2000-04-02 00:49:39 +08:00
/* Author: CJH */
PHP_FUNCTION ( imap_lsub_full )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * ref , * * pat , * mboxob ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
FOBJECTLIST * cur = NIL ;
char * delim = NIL ;
2001-08-08 10:55:07 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 3 | | zend_get_parameters_ex ( 3 , & streamind , & ref , & pat ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( ref ) ;
convert_to_string_ex ( pat ) ;
2004-05-13 04:17:19 +08:00
2001-08-08 10:55:07 +08:00
/* set flag for new, improved array of objects list */
IMAPG ( folderlist_style ) = FLIST_OBJECT ;
2000-04-02 00:49:39 +08:00
2002-05-13 04:53:25 +08:00
IMAPG ( imap_sfolder_objects ) = IMAPG ( imap_sfolder_objects_tail ) = NIL ;
2000-04-20 22:52:54 +08:00
mail_lsub ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( ref ) , Z_STRVAL_PP ( pat ) ) ;
2000-04-02 00:49:39 +08:00
if ( IMAPG ( imap_sfolder_objects ) = = NIL ) {
RETURN_FALSE ;
}
array_init ( return_value ) ;
2004-05-13 04:17:19 +08:00
delim = safe_emalloc ( 2 , sizeof ( char ) , 0 ) ;
2000-04-02 00:49:39 +08:00
cur = IMAPG ( imap_sfolder_objects ) ;
2000-04-19 03:42:22 +08:00
while ( cur ! = NIL ) {
2000-04-02 00:49:39 +08:00
MAKE_STD_ZVAL ( mboxob ) ;
object_init ( mboxob ) ;
add_property_string ( mboxob , " name " , cur - > LTEXT , 1 ) ;
add_property_long ( mboxob , " attributes " , cur - > attributes ) ;
# ifdef IMAP41
delim [ 0 ] = ( char ) cur - > delimiter ;
delim [ 1 ] = 0 ;
add_property_string ( mboxob , " delimiter " , delim , 1 ) ;
# else
add_property_string ( mboxob , " delimiter " , cur - > delimiter , 1 ) ;
# endif
2003-01-05 04:06:32 +08:00
add_next_index_object ( return_value , mboxob TSRMLS_CC ) ;
2000-04-02 00:49:39 +08:00
cur = cur - > next ;
}
2002-05-13 04:53:25 +08:00
mail_free_foblist ( & IMAPG ( imap_sfolder_objects ) , & IMAPG ( imap_sfolder_objects_tail ) ) ;
2000-04-02 00:49:39 +08:00
efree ( delim ) ;
2000-06-14 20:28:21 +08:00
IMAPG ( folderlist_style ) = FLIST_ARRAY ; /* reset to default */
2000-04-02 00:49:39 +08:00
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto bool imap_subscribe(resource stream_id, string mailbox)
2000-04-02 00:49:39 +08:00
Subscribe to a mailbox */
PHP_FUNCTION ( imap_subscribe )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * folder ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
2001-08-08 10:55:07 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & streamind , & folder ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-02 00:49:39 +08:00
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( folder ) ;
2000-04-02 00:49:39 +08:00
2000-04-20 22:52:54 +08:00
if ( mail_subscribe ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( folder ) ) = = T ) {
2000-04-02 00:49:39 +08:00
RETURN_TRUE ;
} else {
RETURN_FALSE ;
}
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto bool imap_unsubscribe(resource stream_id, string mailbox)
2000-04-02 00:49:39 +08:00
Unsubscribe from a mailbox */
PHP_FUNCTION ( imap_unsubscribe )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * folder ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
2001-08-08 10:55:07 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & streamind , & folder ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( folder ) ;
2000-04-02 00:49:39 +08:00
2000-04-20 22:52:54 +08:00
if ( mail_unsubscribe ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( folder ) ) = = T ) {
2000-04-02 00:49:39 +08:00
RETURN_TRUE ;
} else {
RETURN_FALSE ;
}
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto object imap_fetchstructure(resource stream_id, int msg_no [, int options])
2000-04-02 00:49:39 +08:00
Read the full structure of a message */
PHP_FUNCTION ( imap_fetchstructure )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * msgno , * * flags ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
BODY * body ;
2001-08-08 10:55:07 +08:00
int msgindex , myargc = ZEND_NUM_ARGS ( ) ;
2000-04-20 22:23:35 +08:00
if ( myargc < 2 | | myargc > 3 | | zend_get_parameters_ex ( myargc , & streamind , & msgno , & flags ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( msgno ) ;
2000-04-20 22:52:54 +08:00
if ( Z_LVAL_PP ( msgno ) < 1 ) {
2000-04-02 00:49:39 +08:00
RETURN_FALSE ;
}
2000-04-19 03:42:22 +08:00
if ( myargc = = 3 ) {
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( flags ) ;
2000-04-19 03:42:22 +08:00
}
2001-08-08 10:55:07 +08:00
2000-04-02 00:49:39 +08:00
object_init ( return_value ) ;
2002-08-17 07:25:53 +08:00
2000-10-17 23:42:05 +08:00
if ( ( myargc = = 3 ) & & ( Z_LVAL_PP ( flags ) & FT_UID ) ) {
2001-05-04 03:44:42 +08:00
/* This should be cached; if it causes an extra RTT to the
IMAP server , then that ' s the price we pay for making
sure we don ' t crash . */
2000-10-17 23:42:05 +08:00
msgindex = mail_msgno ( imap_le_struct - > imap_stream , Z_LVAL_PP ( msgno ) ) ;
} else {
msgindex = Z_LVAL_PP ( msgno ) ;
}
2004-07-22 05:57:03 +08:00
PHP_IMAP_CHECK_MSGNO ( msgindex ) ;
2002-08-17 07:25:53 +08:00
2001-08-12 00:39:07 +08:00
mail_fetchstructure_full ( imap_le_struct - > imap_stream , Z_LVAL_PP ( msgno ) , & body , myargc = = 3 ? Z_LVAL_PP ( flags ) : NIL ) ;
2000-04-02 00:49:39 +08:00
if ( ! body ) {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " No body information available " ) ;
2000-04-02 00:49:39 +08:00
RETURN_FALSE ;
}
2001-08-08 01:40:10 +08:00
_php_imap_add_body ( return_value , body TSRMLS_CC ) ;
2000-04-02 00:49:39 +08:00
}
/* }}} */
2005-01-20 22:04:50 +08:00
/* {{{ proto string imap_fetchbody(resource stream_id, int msg_no, string section [, int options])
2000-04-02 00:49:39 +08:00
Get a specific body section */
PHP_FUNCTION ( imap_fetchbody )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * msgno , * * sec , * * flags ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
char * body ;
unsigned long len ;
2000-04-19 21:15:57 +08:00
int myargc = ZEND_NUM_ARGS ( ) ;
2000-04-19 03:42:22 +08:00
2001-08-08 10:55:07 +08:00
if ( myargc < 3 | | myargc > 4 | | zend_get_parameters_ex ( myargc , & streamind , & msgno , & sec , & flags ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( msgno ) ;
convert_to_string_ex ( sec ) ;
2000-04-19 03:42:22 +08:00
if ( myargc = = 4 ) {
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( flags ) ;
2000-04-19 03:42:22 +08:00
}
2004-08-13 02:01:45 +08:00
2004-08-13 03:20:15 +08:00
if ( myargc < 4 | | ! ( Z_LVAL_PP ( flags ) & FT_UID ) ) {
/* only perform the check if the msgno is a message number and not a UID */
PHP_IMAP_CHECK_MSGNO ( Z_LVAL_PP ( msgno ) ) ;
}
2004-08-13 03:31:36 +08:00
2000-04-20 22:52:54 +08:00
body = mail_fetchbody_full ( imap_le_struct - > imap_stream , Z_LVAL_PP ( msgno ) , Z_STRVAL_PP ( sec ) , & len , myargc = = 4 ? Z_LVAL_PP ( flags ) : NIL ) ;
2000-04-02 00:49:39 +08:00
2000-04-19 03:42:22 +08:00
if ( ! body ) {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " No body information available " ) ;
2000-04-02 00:49:39 +08:00
RETURN_FALSE ;
}
2000-04-19 03:42:22 +08:00
RETVAL_STRINGL ( body , len , 1 ) ;
2000-04-02 00:49:39 +08:00
}
/* }}} */
2006-01-28 03:46:11 +08:00
/* {{{ proto bool imap_savebody(resource stream_id, string|resource file, int msg_no[, string section = ""[, int options = 0]])
Save a specific body section to a file */
PHP_FUNCTION ( imap_savebody )
{
2006-09-01 00:15:24 +08:00
zval * stream , * * out ;
2006-01-28 03:46:11 +08:00
pils * imap_ptr = NULL ;
php_stream * writer = NULL ;
char * section = " " ;
int section_len = 0 , close_stream = 1 ;
long msgno , flags = 0 ;
2006-09-01 00:15:24 +08:00
if ( SUCCESS ! = zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " rZl|sl " , & stream , & out , & msgno , & section , & section_len , & flags ) ) {
2006-01-28 03:46:11 +08:00
RETURN_FALSE ;
}
ZEND_FETCH_RESOURCE ( imap_ptr , pils * , & stream , - 1 , " imap " , le_imap ) ;
if ( ! imap_ptr ) {
RETURN_FALSE ;
}
2006-09-01 00:15:24 +08:00
switch ( Z_TYPE_PP ( out ) )
2006-01-28 03:46:11 +08:00
{
case IS_LONG :
case IS_RESOURCE :
close_stream = 0 ;
2006-09-01 00:15:24 +08:00
php_stream_from_zval ( writer , out ) ;
2006-01-28 03:46:11 +08:00
break ;
default :
2006-09-01 00:15:24 +08:00
convert_to_string_ex ( out ) ;
writer = php_stream_open_wrapper ( Z_STRVAL_PP ( out ) , " wb " , REPORT_ERRORS | ENFORCE_SAFE_MODE , NULL ) ;
2006-01-28 03:46:11 +08:00
break ;
}
if ( ! writer ) {
RETURN_FALSE ;
}
IMAPG ( gets_stream ) = writer ;
mail_fetchbody_full ( imap_ptr - > imap_stream , msgno , section , NULL , flags ) ;
IMAPG ( gets_stream ) = NULL ;
if ( close_stream ) {
php_stream_close ( writer ) ;
}
RETURN_TRUE ;
}
/* }}} */
2000-04-02 00:49:39 +08:00
/* {{{ proto string imap_base64(string text)
Decode BASE64 encoded text */
PHP_FUNCTION ( imap_base64 )
{
2000-04-20 22:23:35 +08:00
zval * * text ;
2000-04-02 00:49:39 +08:00
char * decode ;
unsigned long newlength ;
2000-04-19 06:22:48 +08:00
2000-04-20 22:23:35 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & text ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( text ) ;
2000-04-02 00:49:39 +08:00
2000-04-20 22:52:54 +08:00
decode = ( char * ) rfc822_base64 ( ( unsigned char * ) Z_STRVAL_PP ( text ) , Z_STRLEN_PP ( text ) , & newlength ) ;
2001-08-08 10:55:07 +08:00
2001-04-30 18:23:13 +08:00
if ( decode = = NULL ) {
RETURN_FALSE ;
}
2001-08-08 10:55:07 +08:00
2000-04-20 22:23:35 +08:00
RETVAL_STRINGL ( decode , newlength , 1 ) ;
2000-04-25 06:21:34 +08:00
fs_give ( ( void * * ) & decode ) ;
2000-04-02 00:49:39 +08:00
}
/* }}} */
/* {{{ proto string imap_qprint(string text)
Convert a quoted - printable string to an 8 - bit string */
PHP_FUNCTION ( imap_qprint )
{
2000-04-20 22:23:35 +08:00
zval * * text ;
2000-04-02 00:49:39 +08:00
char * decode ;
unsigned long newlength ;
2000-04-19 06:22:48 +08:00
2000-04-20 22:23:35 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & text ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( text ) ;
2000-04-02 00:49:39 +08:00
2000-04-20 22:52:54 +08:00
decode = ( char * ) rfc822_qprint ( ( unsigned char * ) Z_STRVAL_PP ( text ) , Z_STRLEN_PP ( text ) , & newlength ) ;
2001-08-08 10:55:07 +08:00
2001-04-30 18:23:13 +08:00
if ( decode = = NULL ) {
RETURN_FALSE ;
}
2001-08-08 10:55:07 +08:00
2000-04-20 22:23:35 +08:00
RETVAL_STRINGL ( decode , newlength , 1 ) ;
2000-04-25 06:21:34 +08:00
fs_give ( ( void * * ) & decode ) ;
2000-04-02 00:49:39 +08:00
}
/* }}} */
/* {{{ proto string imap_8bit(string text)
Convert an 8 - bit string to a quoted - printable string */
PHP_FUNCTION ( imap_8bit )
{
2000-04-20 22:23:35 +08:00
zval * * text ;
2000-04-02 00:49:39 +08:00
char * decode ;
unsigned long newlength ;
2000-04-19 06:22:48 +08:00
2000-04-20 22:23:35 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & text ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( text ) ;
2000-04-02 00:49:39 +08:00
2000-04-20 22:52:54 +08:00
decode = ( char * ) rfc822_8bit ( ( unsigned char * ) Z_STRVAL_PP ( text ) , Z_STRLEN_PP ( text ) , & newlength ) ;
2001-08-08 10:55:07 +08:00
if ( decode = = NULL ) {
RETURN_FALSE ;
}
2000-04-19 06:22:48 +08:00
RETVAL_STRINGL ( decode , newlength , 1 ) ;
2000-04-25 06:21:34 +08:00
fs_give ( ( void * * ) & decode ) ;
2000-04-02 00:49:39 +08:00
}
/* }}} */
/* {{{ proto string imap_binary(string text)
Convert an 8 bit string to a base64 string */
PHP_FUNCTION ( imap_binary )
{
2000-04-20 22:23:35 +08:00
zval * * text ;
2000-04-19 06:22:48 +08:00
char * decode ;
2001-08-08 10:55:07 +08:00
unsigned long newlength ;
2000-04-19 06:22:48 +08:00
2000-04-20 22:23:35 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & text ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( text ) ;
2001-08-08 10:55:07 +08:00
decode = rfc822_binary ( Z_STRVAL_PP ( text ) , Z_STRLEN_PP ( text ) , & newlength ) ;
if ( decode = = NULL ) {
RETURN_FALSE ;
}
RETVAL_STRINGL ( decode , newlength , 1 ) ;
2000-04-25 06:21:34 +08:00
fs_give ( ( void * * ) & decode ) ;
2000-04-02 00:49:39 +08:00
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto object imap_mailboxmsginfo(resource stream_id)
2000-06-15 11:02:36 +08:00
Returns info about the current mailbox */
2000-04-02 00:49:39 +08:00
PHP_FUNCTION ( imap_mailboxmsginfo )
{
2000-04-20 22:23:35 +08:00
zval * * streamind ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
2001-08-08 10:55:07 +08:00
char date [ 100 ] ;
unsigned int msgno , unreadmsg , deletedmsg , msize ;
2000-04-02 00:49:39 +08:00
2000-04-20 22:23:35 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & streamind ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-02 00:49:39 +08:00
2000-06-15 11:02:36 +08:00
/* Initialize return object */
2003-01-30 10:33:16 +08:00
object_init ( return_value ) ;
2000-04-02 00:49:39 +08:00
unreadmsg = 0 ;
2000-06-15 11:02:36 +08:00
deletedmsg = 0 ;
2000-04-02 00:49:39 +08:00
msize = 0 ;
2001-08-08 10:55:07 +08:00
2000-04-02 00:49:39 +08:00
for ( msgno = 1 ; msgno < = imap_le_struct - > imap_stream - > nmsgs ; msgno + + ) {
2001-08-12 00:39:07 +08:00
MESSAGECACHE * cache = mail_elt ( imap_le_struct - > imap_stream , msgno ) ;
mail_fetchstructure ( imap_le_struct - > imap_stream , msgno , NIL ) ;
2001-08-08 10:55:07 +08:00
if ( ! cache - > seen | | cache - > recent ) {
unreadmsg + + ;
}
if ( cache - > deleted ) {
deletedmsg + + ;
}
2000-04-02 00:49:39 +08:00
msize = msize + cache - > rfc822_size ;
}
2000-04-20 22:23:35 +08:00
add_property_long ( return_value , " Unread " , unreadmsg ) ;
2001-08-08 10:55:07 +08:00
add_property_long ( return_value , " Deleted " , deletedmsg ) ;
2000-04-20 22:23:35 +08:00
add_property_long ( return_value , " Nmsgs " , imap_le_struct - > imap_stream - > nmsgs ) ;
add_property_long ( return_value , " Size " , msize ) ;
2000-04-02 00:49:39 +08:00
rfc822_date ( date ) ;
2000-04-20 22:23:35 +08:00
add_property_string ( return_value , " Date " , date , 1 ) ;
add_property_string ( return_value , " Driver " , imap_le_struct - > imap_stream - > dtb - > name , 1 ) ;
add_property_string ( return_value , " Mailbox " , imap_le_struct - > imap_stream - > mailbox , 1 ) ;
add_property_long ( return_value , " Recent " , imap_le_struct - > imap_stream - > recent ) ;
2000-04-02 00:49:39 +08:00
}
/* }}} */
/* {{{ proto string imap_rfc822_write_address(string mailbox, string host, string personal)
Returns a properly formatted email address given the mailbox , host , and personal info */
PHP_FUNCTION ( imap_rfc822_write_address )
{
2000-04-20 22:23:35 +08:00
zval * * mailbox , * * host , * * personal ;
2000-04-02 00:49:39 +08:00
ADDRESS * addr ;
char string [ MAILTMPLEN ] ;
2000-04-20 22:23:35 +08:00
2001-08-08 10:55:07 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 3 | | zend_get_parameters_ex ( 3 , & mailbox , & host , & personal ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( mailbox ) ;
convert_to_string_ex ( host ) ;
convert_to_string_ex ( personal ) ;
2001-08-08 10:55:07 +08:00
2000-04-02 00:49:39 +08:00
addr = mail_newaddr ( ) ;
2001-08-08 10:55:07 +08:00
2000-04-19 03:42:22 +08:00
if ( mailbox ) {
2000-04-20 22:52:54 +08:00
addr - > mailbox = cpystr ( Z_STRVAL_PP ( mailbox ) ) ;
2000-04-19 03:42:22 +08:00
}
2001-08-08 10:55:07 +08:00
2000-04-19 03:42:22 +08:00
if ( host ) {
2000-04-20 22:52:54 +08:00
addr - > host = cpystr ( Z_STRVAL_PP ( host ) ) ;
2000-04-19 03:42:22 +08:00
}
2001-08-08 10:55:07 +08:00
2000-04-19 03:42:22 +08:00
if ( personal ) {
2000-04-20 22:52:54 +08:00
addr - > personal = cpystr ( Z_STRVAL_PP ( personal ) ) ;
2000-04-19 03:42:22 +08:00
}
2001-08-08 10:55:07 +08:00
2000-04-02 00:49:39 +08:00
addr - > next = NIL ;
addr - > error = NIL ;
addr - > adl = NIL ;
2000-06-19 12:33:40 +08:00
2003-06-17 01:41:52 +08:00
if ( _php_imap_address_size ( addr ) > = MAILTMPLEN ) {
RETURN_FALSE ;
}
2000-06-19 12:33:40 +08:00
string [ 0 ] = ' \0 ' ;
2000-04-19 03:42:22 +08:00
rfc822_write_address ( string , addr ) ;
RETVAL_STRING ( string , 1 ) ;
2000-04-02 00:49:39 +08:00
}
/* }}} */
/* {{{ proto array imap_rfc822_parse_adrlist(string address_string, string default_host)
Parses an address string */
PHP_FUNCTION ( imap_rfc822_parse_adrlist )
{
2001-08-08 10:55:07 +08:00
zval * * str , * * defaulthost , * tovals ;
2000-04-02 00:49:39 +08:00
ADDRESS * addresstmp ;
ENVELOPE * env ;
2000-04-23 04:54:07 +08:00
2001-08-08 10:55:07 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & str , & defaulthost ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
2001-12-08 00:48:36 +08:00
SEPARATE_ZVAL ( str ) ;
2001-08-08 10:55:07 +08:00
convert_to_string_ex ( str ) ;
convert_to_string_ex ( defaulthost ) ;
env = mail_newenvelope ( ) ;
rfc822_parse_adrlist ( & env - > to , Z_STRVAL_PP ( str ) , Z_STRVAL_PP ( defaulthost ) ) ;
2003-01-18 00:07:39 +08:00
array_init ( return_value ) ;
2001-08-08 10:55:07 +08:00
addresstmp = env - > to ;
2000-04-19 03:42:22 +08:00
if ( addresstmp ) do {
2000-04-02 00:49:39 +08:00
MAKE_STD_ZVAL ( tovals ) ;
object_init ( tovals ) ;
2000-04-19 03:42:22 +08:00
if ( addresstmp - > mailbox ) {
2000-04-20 22:23:35 +08:00
add_property_string ( tovals , " mailbox " , addresstmp - > mailbox , 1 ) ;
2000-04-19 03:42:22 +08:00
}
if ( addresstmp - > host ) {
2000-04-20 22:23:35 +08:00
add_property_string ( tovals , " host " , addresstmp - > host , 1 ) ;
2000-04-19 03:42:22 +08:00
}
if ( addresstmp - > personal ) {
2000-04-20 22:23:35 +08:00
add_property_string ( tovals , " personal " , addresstmp - > personal , 1 ) ;
2000-04-19 03:42:22 +08:00
}
if ( addresstmp - > adl ) {
2000-04-20 22:23:35 +08:00
add_property_string ( tovals , " adl " , addresstmp - > adl , 1 ) ;
2000-04-19 03:42:22 +08:00
}
2003-01-05 04:06:32 +08:00
add_next_index_object ( return_value , tovals TSRMLS_CC ) ;
2000-04-02 00:49:39 +08:00
} while ( ( addresstmp = addresstmp - > next ) ) ;
}
/* }}} */
2003-04-01 04:36:46 +08:00
/* {{{ proto string imap_utf8(string mime_encoded_text)
Convert a mime - encoded text to UTF - 8 */
2000-04-02 00:49:39 +08:00
PHP_FUNCTION ( imap_utf8 )
{
2000-04-20 22:23:35 +08:00
zval * * str ;
2000-04-02 00:49:39 +08:00
SIZEDTEXT src , dest ;
2001-08-08 10:55:07 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & str ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
}
convert_to_string_ex ( str ) ;
2000-04-02 00:49:39 +08:00
src . data = NULL ;
src . size = 0 ;
dest . data = NULL ;
dest . size = 0 ;
2001-08-08 10:55:07 +08:00
2000-04-20 22:52:54 +08:00
cpytxt ( & src , Z_STRVAL_PP ( str ) , Z_STRLEN_PP ( str ) ) ;
2006-10-05 22:25:41 +08:00
# ifndef HAVE_NEW_MIME2TEXT
2000-04-02 00:49:39 +08:00
utf8_mime2text ( & src , & dest ) ;
2006-10-05 22:25:41 +08:00
# else
utf8_mime2text ( & src , & dest , U8T_CANONICAL ) ;
# endif
2006-09-05 19:24:49 +08:00
RETVAL_STRINGL ( dest . data , dest . size , 1 ) ;
if ( dest . data ) {
free ( dest . data ) ;
}
2007-02-16 21:28:03 +08:00
if ( src . data & & src . data ! = dest . data ) {
2007-02-14 04:12:52 +08:00
free ( src . data ) ;
}
2000-04-02 00:49:39 +08:00
}
/* }}} */
2000-04-20 22:23:35 +08:00
2001-08-08 10:55:07 +08:00
/* {{{ macros for the modified utf7 conversion functions
*
* author : Andrew Skalski < askalski @ chek . com >
*/
2000-04-02 00:49:39 +08:00
/* tests `c' and returns true if it is a special character */
# define SPECIAL(c) ((c) <= 0x1f || (c) >= 0x7f)
2001-08-08 10:55:07 +08:00
2000-04-02 00:49:39 +08:00
/* validate a modified-base64 character */
# define B64CHAR(c) (isalnum(c) || (c) == '+' || (c) == ',')
2001-08-08 10:55:07 +08:00
2000-04-02 00:49:39 +08:00
/* map the low 64 bits of `n' to the modified-base64 characters */
# define B64(n) ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
" abcdefghijklmnopqrstuvwxyz0123456789+, " [ ( n ) & 0x3f ] )
2001-08-08 10:55:07 +08:00
2000-04-02 00:49:39 +08:00
/* map the modified-base64 character `c' to its 64 bit value */
# define UNB64(c) ((c) == '+' ? 62 : (c) == ',' ? 63 : (c) >= 'a' ? \
( c ) - 71 : ( c ) > = ' A ' ? ( c ) - 65 : ( c ) + 4 )
2001-08-08 10:55:07 +08:00
/* }}} */
2000-04-02 00:49:39 +08:00
/* {{{ proto string imap_utf7_decode(string buf)
Decode a modified UTF - 7 string */
PHP_FUNCTION ( imap_utf7_decode )
{
/* author: Andrew Skalski <askalski@chek.com> */
2000-04-20 22:23:35 +08:00
zval * * arg ;
2000-04-02 00:49:39 +08:00
const unsigned char * in , * inp , * endp ;
unsigned char * out , * outp ;
2002-08-15 04:55:11 +08:00
unsigned char c ;
2000-04-25 06:21:34 +08:00
int inlen , outlen ;
2000-04-02 00:49:39 +08:00
enum {
ST_NORMAL , /* printable text */
ST_DECODE0 , /* encoded text rotation... */
ST_DECODE1 ,
ST_DECODE2 ,
ST_DECODE3
} state ;
2000-04-25 06:21:34 +08:00
2001-08-08 10:55:07 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & arg ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2004-01-14 16:50:02 +08:00
convert_to_string_ex ( arg ) ; /* Is this string really modified?
If it is use and you don ' t want it to be seen outside of the function
then use zend_get_parameters ( ) */
2001-08-08 10:55:07 +08:00
2000-04-20 22:52:54 +08:00
in = ( const unsigned char * ) Z_STRVAL_PP ( arg ) ;
inlen = Z_STRLEN_PP ( arg ) ;
2000-04-02 00:49:39 +08:00
/* validate and compute length of output string */
outlen = 0 ;
state = ST_NORMAL ;
for ( endp = ( inp = in ) + inlen ; inp < endp ; inp + + ) {
if ( state = = ST_NORMAL ) {
/* process printable character */
if ( SPECIAL ( * inp ) ) {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Invalid modified UTF-7 character: `%c' " , * inp ) ;
2000-04-02 00:49:39 +08:00
RETURN_FALSE ;
2000-04-20 22:23:35 +08:00
} else if ( * inp ! = ' & ' ) {
2000-04-02 00:49:39 +08:00
outlen + + ;
2000-04-20 22:23:35 +08:00
} else if ( inp + 1 = = endp ) {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unexpected end of string " ) ;
2000-04-02 00:49:39 +08:00
RETURN_FALSE ;
2000-04-20 22:23:35 +08:00
} else if ( inp [ 1 ] ! = ' - ' ) {
2000-04-02 00:49:39 +08:00
state = ST_DECODE0 ;
2000-04-20 22:23:35 +08:00
} else {
2000-04-02 00:49:39 +08:00
outlen + + ;
inp + + ;
}
2000-04-20 22:23:35 +08:00
} else if ( * inp = = ' - ' ) {
2000-04-02 00:49:39 +08:00
/* return to NORMAL mode */
if ( state = = ST_DECODE1 ) {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Stray modified base64 character: `%c' " , * - - inp ) ;
2000-04-02 00:49:39 +08:00
RETURN_FALSE ;
}
state = ST_NORMAL ;
2000-04-20 22:23:35 +08:00
} else if ( ! B64CHAR ( * inp ) ) {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Invalid modified base64 character: `%c' " , * inp ) ;
2000-04-02 00:49:39 +08:00
RETURN_FALSE ;
2000-04-20 22:23:35 +08:00
} else {
2000-04-02 00:49:39 +08:00
switch ( state ) {
2000-04-20 22:23:35 +08:00
case ST_DECODE3 :
outlen + + ;
state = ST_DECODE0 ;
break ;
case ST_DECODE2 :
case ST_DECODE1 :
outlen + + ;
case ST_DECODE0 :
state + + ;
case ST_NORMAL :
break ;
2000-04-02 00:49:39 +08:00
}
}
}
/* enforce end state */
if ( state ! = ST_NORMAL ) {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unexpected end of string " ) ;
2000-04-02 00:49:39 +08:00
RETURN_FALSE ;
}
/* allocate output buffer */
2003-01-21 03:41:58 +08:00
out = emalloc ( outlen + 1 ) ;
2000-04-02 00:49:39 +08:00
/* decode input string */
outp = out ;
state = ST_NORMAL ;
for ( endp = ( inp = in ) + inlen ; inp < endp ; inp + + ) {
if ( state = = ST_NORMAL ) {
if ( * inp = = ' & ' & & inp [ 1 ] ! = ' - ' ) {
state = ST_DECODE0 ;
}
else if ( ( * outp + + = * inp ) = = ' & ' ) {
inp + + ;
}
}
else if ( * inp = = ' - ' ) {
state = ST_NORMAL ;
}
else {
/* decode input character */
switch ( state ) {
case ST_DECODE0 :
* outp = UNB64 ( * inp ) < < 2 ;
state = ST_DECODE1 ;
break ;
case ST_DECODE1 :
outp [ 1 ] = UNB64 ( * inp ) ;
2002-08-15 04:55:11 +08:00
c = outp [ 1 ] > > 4 ;
* outp + + | = c ;
2000-04-02 00:49:39 +08:00
* outp < < = 4 ;
state = ST_DECODE2 ;
break ;
case ST_DECODE2 :
outp [ 1 ] = UNB64 ( * inp ) ;
2002-08-15 04:55:11 +08:00
c = outp [ 1 ] > > 2 ;
* outp + + | = c ;
2000-04-02 00:49:39 +08:00
* outp < < = 6 ;
state = ST_DECODE3 ;
break ;
case ST_DECODE3 :
* outp + + | = UNB64 ( * inp ) ;
state = ST_DECODE0 ;
case ST_NORMAL :
break ;
}
}
}
* outp = 0 ;
# if PHP_DEBUG
/* warn if we computed outlen incorrectly */
if ( outp - out ! = outlen ) {
2007-07-06 08:13:56 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " outp - out [%ld] != outlen [%d] " , outp - out , outlen ) ;
2000-04-02 00:49:39 +08:00
}
# endif
RETURN_STRINGL ( out , outlen , 0 ) ;
}
/* }}} */
/* {{{ proto string imap_utf7_encode(string buf)
Encode a string in modified UTF - 7 */
PHP_FUNCTION ( imap_utf7_encode )
{
/* author: Andrew Skalski <askalski@chek.com> */
2000-04-20 22:23:35 +08:00
zval * * arg ;
2000-04-25 06:21:34 +08:00
const unsigned char * in , * inp , * endp ;
2000-04-20 22:23:35 +08:00
unsigned char * out , * outp ;
2002-08-15 04:55:11 +08:00
unsigned char c ;
2000-04-25 06:21:34 +08:00
int inlen , outlen ;
2000-04-20 22:23:35 +08:00
enum {
ST_NORMAL , /* printable text */
2000-04-02 00:49:39 +08:00
ST_ENCODE0 , /* encoded text rotation... */
ST_ENCODE1 ,
ST_ENCODE2
2000-04-20 22:23:35 +08:00
} state ;
2000-04-02 00:49:39 +08:00
2001-08-08 10:55:07 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & arg ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
2000-04-25 06:21:34 +08:00
convert_to_string_ex ( arg ) ;
2001-08-08 10:55:07 +08:00
2000-04-20 22:52:54 +08:00
in = ( const unsigned char * ) Z_STRVAL_PP ( arg ) ;
inlen = Z_STRLEN_PP ( arg ) ;
2000-04-02 00:49:39 +08:00
/* compute the length of the result string */
outlen = 0 ;
state = ST_NORMAL ;
endp = ( inp = in ) + inlen ;
while ( inp < endp ) {
if ( state = = ST_NORMAL ) {
if ( SPECIAL ( * inp ) ) {
2000-04-25 06:21:34 +08:00
state = ST_ENCODE0 ;
outlen + + ;
} else if ( * inp + + = = ' & ' ) {
2000-04-02 00:49:39 +08:00
outlen + + ;
}
outlen + + ;
2000-04-20 22:23:35 +08:00
} else if ( ! SPECIAL ( * inp ) ) {
2000-04-02 00:49:39 +08:00
state = ST_NORMAL ;
2000-04-20 22:23:35 +08:00
} else {
2000-04-25 06:21:34 +08:00
/* ST_ENCODE0 -> ST_ENCODE1 - two chars
* ST_ENCODE1 - > ST_ENCODE2 - one char
* ST_ENCODE2 - > ST_ENCODE0 - one char
*/
if ( state = = ST_ENCODE2 ) {
state = ST_ENCODE0 ;
}
else if ( state + + = = ST_ENCODE0 ) {
outlen + + ;
}
outlen + + ;
inp + + ;
2000-04-02 00:49:39 +08:00
}
2000-04-19 03:42:22 +08:00
}
2000-04-02 00:49:39 +08:00
/* allocate output buffer */
2003-01-21 03:41:58 +08:00
out = emalloc ( outlen + 1 ) ;
2000-04-02 00:49:39 +08:00
/* encode input string */
outp = out ;
state = ST_NORMAL ;
endp = ( inp = in ) + inlen ;
while ( inp < endp | | state ! = ST_NORMAL ) {
if ( state = = ST_NORMAL ) {
if ( SPECIAL ( * inp ) ) {
/* begin encoding */
* outp + + = ' & ' ;
state = ST_ENCODE0 ;
2000-04-20 22:23:35 +08:00
} else if ( ( * outp + + = * inp + + ) = = ' & ' ) {
2000-04-02 00:49:39 +08:00
* outp + + = ' - ' ;
}
2000-04-20 22:23:35 +08:00
} else if ( inp = = endp | | ! SPECIAL ( * inp ) ) {
2000-04-02 00:49:39 +08:00
/* flush overflow and terminate region */
if ( state ! = ST_ENCODE0 ) {
2002-09-10 05:01:33 +08:00
c = B64 ( * outp ) ;
* outp + + = c ;
2000-04-02 00:49:39 +08:00
}
* outp + + = ' - ' ;
state = ST_NORMAL ;
2000-04-20 22:23:35 +08:00
} else {
2000-04-02 00:49:39 +08:00
/* encode input character */
switch ( state ) {
2000-04-20 22:23:35 +08:00
case ST_ENCODE0 :
2000-04-25 06:21:34 +08:00
* outp + + = B64 ( * inp > > 2 ) ;
* outp = * inp + + < < 4 ;
2000-04-20 22:23:35 +08:00
state = ST_ENCODE1 ;
break ;
case ST_ENCODE1 :
2002-08-15 04:55:11 +08:00
c = B64 ( * outp | * inp > > 4 ) ;
* outp + + = c ;
2000-04-25 06:21:34 +08:00
* outp = * inp + + < < 2 ;
2000-04-20 22:23:35 +08:00
state = ST_ENCODE2 ;
break ;
case ST_ENCODE2 :
2002-08-15 04:55:11 +08:00
c = B64 ( * outp | * inp > > 6 ) ;
* outp + + = c ;
2000-04-25 06:21:34 +08:00
* outp + + = B64 ( * inp + + ) ;
2000-04-20 22:23:35 +08:00
state = ST_ENCODE0 ;
case ST_NORMAL :
break ;
2000-04-02 00:49:39 +08:00
}
}
}
* outp = 0 ;
# if PHP_DEBUG
/* warn if we computed outlen incorrectly */
if ( outp - out ! = outlen ) {
2007-07-06 08:13:56 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " outp - out [%ld] != outlen [%d] " , outp - out , outlen ) ;
2000-04-02 00:49:39 +08:00
}
# endif
RETURN_STRINGL ( out , outlen , 0 ) ;
}
/* }}} */
# undef SPECIAL
# undef B64CHAR
# undef B64
# undef UNB64
2002-10-09 17:20:46 +08:00
/* {{{ proto bool imap_setflag_full(resource stream_id, string sequence, string flag [, int options])
2000-04-02 00:49:39 +08:00
Sets flags on messages */
PHP_FUNCTION ( imap_setflag_full )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * sequence , * * flag , * * flags ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
2001-08-08 10:55:07 +08:00
int myargc = ZEND_NUM_ARGS ( ) ;
2000-04-02 00:49:39 +08:00
2001-08-08 00:18:05 +08:00
if ( myargc < 3 | | myargc > 4 | | zend_get_parameters_ex ( myargc , & streamind , & sequence , & flag , & flags ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( sequence ) ;
convert_to_string_ex ( flag ) ;
2000-04-19 03:42:22 +08:00
if ( myargc = = 4 ) {
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( flags ) ;
2000-04-19 03:42:22 +08:00
}
2000-04-02 00:49:39 +08:00
2000-04-20 22:52:54 +08:00
mail_setflag_full ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( sequence ) , Z_STRVAL_PP ( flag ) , myargc = = 4 ? Z_LVAL_PP ( flags ) : NIL ) ;
2000-04-02 00:49:39 +08:00
RETURN_TRUE ;
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto bool imap_clearflag_full(resource stream_id, string sequence, string flag [, int options])
2000-04-02 00:49:39 +08:00
Clears flags on messages */
PHP_FUNCTION ( imap_clearflag_full )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * sequence , * * flag , * * flags ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
2001-08-08 10:55:07 +08:00
int myargc = ZEND_NUM_ARGS ( ) ;
2000-04-20 22:23:35 +08:00
if ( myargc < 3 | | myargc > 4 | | zend_get_parameters_ex ( myargc , & streamind , & sequence , & flag , & flags ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( sequence ) ;
convert_to_string_ex ( flag ) ;
2000-04-19 03:42:22 +08:00
if ( myargc = = 4 ) {
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( flags ) ;
2000-04-19 03:42:22 +08:00
}
2001-08-08 10:55:07 +08:00
2000-04-20 22:52:54 +08:00
mail_clearflag_full ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( sequence ) , Z_STRVAL_PP ( flag ) , myargc = = 4 ? Z_LVAL_PP ( flags ) : NIL ) ;
2002-08-17 07:25:53 +08:00
RETURN_TRUE ;
2000-04-02 00:49:39 +08:00
}
/* }}} */
2003-06-13 03:46:44 +08:00
/* {{{ proto array imap_sort(resource stream_id, int criteria, int reverse [, int options [, string search_criteria [, string charset]]])
2000-10-19 09:32:50 +08:00
Sort an array of message headers , optionally including only messages that meet specified criteria . */
2000-04-02 00:49:39 +08:00
PHP_FUNCTION ( imap_sort )
{
2003-06-13 03:46:44 +08:00
zval * * streamind , * * pgm , * * rev , * * flags , * * criteria , * * charset ;
2001-08-08 10:55:07 +08:00
pils * imap_le_struct ;
2000-04-20 22:23:35 +08:00
unsigned long * slst , * sl ;
2000-10-19 09:32:50 +08:00
char * search_criteria ;
2000-04-02 00:49:39 +08:00
SORTPGM * mypgm = NIL ;
SEARCHPGM * spg = NIL ;
2000-10-19 09:32:50 +08:00
int myargc = ZEND_NUM_ARGS ( ) ;
2003-06-13 03:46:44 +08:00
if ( myargc < 3 | | myargc > 6 | | zend_get_parameters_ex ( myargc , & streamind , & pgm , & rev , & flags , & criteria , & charset ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( rev ) ;
convert_to_long_ex ( pgm ) ;
2000-10-19 09:32:50 +08:00
if ( Z_LVAL_PP ( pgm ) > SORTSIZE ) {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unrecognized sort criteria " ) ;
2000-04-02 00:49:39 +08:00
RETURN_FALSE ;
}
2000-10-19 09:32:50 +08:00
if ( myargc > = 4 ) {
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( flags ) ;
2005-01-21 02:03:35 +08:00
if ( Z_LVAL_PP ( flags ) < 0 ) {
2005-01-21 02:08:08 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Search options parameter has to be greater than or equal to 0 " ) ;
2005-01-21 02:03:35 +08:00
RETURN_FALSE ;
}
2000-04-20 22:23:35 +08:00
}
2003-06-13 03:46:44 +08:00
if ( myargc > = 5 ) {
2005-01-21 02:03:35 +08:00
convert_to_string_ex ( criteria ) ;
2000-10-19 09:32:50 +08:00
search_criteria = estrndup ( Z_STRVAL_PP ( criteria ) , Z_STRLEN_PP ( criteria ) ) ;
spg = mail_criteria ( search_criteria ) ;
efree ( search_criteria ) ;
2003-06-13 03:46:44 +08:00
if ( myargc = = 6 ) {
convert_to_string_ex ( charset ) ;
}
2000-10-19 09:32:50 +08:00
} else {
spg = mail_newsearchpgm ( ) ;
}
2000-04-02 00:49:39 +08:00
2000-04-20 22:23:35 +08:00
mypgm = mail_newsortpgm ( ) ;
2000-04-20 22:52:54 +08:00
mypgm - > reverse = Z_LVAL_PP ( rev ) ;
mypgm - > function = ( short ) Z_LVAL_PP ( pgm ) ;
2000-04-20 22:23:35 +08:00
mypgm - > next = NIL ;
2000-04-02 00:49:39 +08:00
2003-06-13 03:46:44 +08:00
slst = mail_sort ( imap_le_struct - > imap_stream , ( myargc = = 6 ? Z_STRVAL_PP ( charset ) : NIL ) , spg , mypgm , ( myargc > = 4 ? Z_LVAL_PP ( flags ) : NIL ) ) ;
2001-08-08 10:55:07 +08:00
2001-04-24 05:58:44 +08:00
if ( spg ) {
mail_free_searchpgm ( & spg ) ;
}
2000-10-19 09:32:50 +08:00
array_init ( return_value ) ;
2001-04-24 05:58:44 +08:00
if ( slst ! = NIL & & slst ! = 0 ) {
for ( sl = slst ; * sl ; sl + + ) {
add_next_index_long ( return_value , * sl ) ;
}
fs_give ( ( void * * ) & slst ) ;
2000-04-02 00:49:39 +08:00
}
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto string imap_fetchheader(resource stream_id, int msg_no [, int options])
2000-04-02 00:49:39 +08:00
Get the full unfiltered header for a message */
PHP_FUNCTION ( imap_fetchheader )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * msgno , * * flags ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
2001-08-08 10:55:07 +08:00
int msgindex , myargc = ZEND_NUM_ARGS ( ) ;
2000-08-01 17:11:46 +08:00
2000-04-20 22:23:35 +08:00
if ( myargc < 2 | | myargc > 3 | | zend_get_parameters_ex ( myargc , & streamind , & msgno , & flags ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( msgno ) ;
if ( myargc = = 3 ) {
convert_to_long_ex ( flags ) ;
}
2000-04-02 00:49:39 +08:00
2000-04-20 22:52:54 +08:00
if ( ( myargc = = 3 ) & & ( Z_LVAL_PP ( flags ) & FT_UID ) ) {
2000-04-02 00:49:39 +08:00
/* This should be cached; if it causes an extra RTT to the
2002-08-17 07:25:53 +08:00
IMAP server , then that ' s the price we pay for making sure
we don ' t crash . */
2000-04-20 22:52:54 +08:00
msgindex = mail_msgno ( imap_le_struct - > imap_stream , Z_LVAL_PP ( msgno ) ) ;
2000-04-02 00:49:39 +08:00
} else {
2000-04-20 22:52:54 +08:00
msgindex = Z_LVAL_PP ( msgno ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 00:18:05 +08:00
2004-07-22 05:57:03 +08:00
PHP_IMAP_CHECK_MSGNO ( msgindex ) ;
2000-08-01 17:11:46 +08:00
2001-08-08 00:18:05 +08:00
RETVAL_STRING ( mail_fetchheader_full ( imap_le_struct - > imap_stream , Z_LVAL_PP ( msgno ) , NIL , NIL , ( myargc = = 3 ? Z_LVAL_PP ( flags ) : NIL ) ) , 1 ) ;
2000-04-02 00:49:39 +08:00
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto int imap_uid(resource stream_id, int msg_no)
2000-04-02 00:49:39 +08:00
Get the unique message id associated with a standard sequential message number */
PHP_FUNCTION ( imap_uid )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * msgno ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
2001-08-08 10:55:07 +08:00
int msgindex ;
2000-04-02 00:49:39 +08:00
2000-04-20 22:23:35 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & streamind , & msgno ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-02 00:49:39 +08:00
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( msgno ) ;
2000-04-02 00:49:39 +08:00
2001-08-08 00:18:05 +08:00
msgindex = Z_LVAL_PP ( msgno ) ;
2000-09-10 04:26:15 +08:00
if ( ( msgindex < 1 ) | | ( ( unsigned ) msgindex > imap_le_struct - > imap_stream - > nmsgs ) ) {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Bad message number " ) ;
2000-09-10 04:26:15 +08:00
RETURN_FALSE ;
}
2002-08-17 07:25:53 +08:00
2000-04-20 22:52:54 +08:00
RETURN_LONG ( mail_uid ( imap_le_struct - > imap_stream , Z_LVAL_PP ( msgno ) ) ) ;
2000-04-02 00:49:39 +08:00
}
/* }}} */
2000-04-20 22:23:35 +08:00
2002-10-09 17:20:46 +08:00
/* {{{ proto int imap_msgno(resource stream_id, int unique_msg_id)
2000-04-02 00:49:39 +08:00
Get the sequence number associated with a UID */
PHP_FUNCTION ( imap_msgno )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * msgno ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
2001-08-08 10:55:07 +08:00
2000-04-20 22:23:35 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & streamind , & msgno ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-02 00:49:39 +08:00
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( msgno ) ;
2000-04-02 00:49:39 +08:00
2000-04-20 22:52:54 +08:00
RETURN_LONG ( mail_msgno ( imap_le_struct - > imap_stream , Z_LVAL_PP ( msgno ) ) ) ;
2000-04-02 00:49:39 +08:00
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto object imap_status(resource stream_id, string mailbox, int options)
2000-04-02 00:49:39 +08:00
Get status info from a mailbox */
PHP_FUNCTION ( imap_status )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * mbx , * * flags ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
2001-08-08 10:55:07 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 3 | | zend_get_parameters_ex ( 3 , & streamind , & mbx , & flags ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( mbx ) ;
convert_to_long_ex ( flags ) ;
2001-08-08 00:18:05 +08:00
2003-01-30 10:33:16 +08:00
object_init ( return_value ) ;
2001-02-25 12:41:18 +08:00
2000-04-20 22:52:54 +08:00
if ( mail_status ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( mbx ) , Z_LVAL_PP ( flags ) ) ) {
2002-08-17 07:25:53 +08:00
add_property_long ( return_value , " flags " , IMAPG ( status_flags ) ) ;
2000-04-02 00:49:39 +08:00
if ( IMAPG ( status_flags ) & SA_MESSAGES ) {
2000-04-20 22:23:35 +08:00
add_property_long ( return_value , " messages " , IMAPG ( status_messages ) ) ;
2000-04-02 00:49:39 +08:00
}
if ( IMAPG ( status_flags ) & SA_RECENT ) {
2000-04-20 22:23:35 +08:00
add_property_long ( return_value , " recent " , IMAPG ( status_recent ) ) ;
2000-04-02 00:49:39 +08:00
}
if ( IMAPG ( status_flags ) & SA_UNSEEN ) {
2000-04-20 22:23:35 +08:00
add_property_long ( return_value , " unseen " , IMAPG ( status_unseen ) ) ;
2000-04-02 00:49:39 +08:00
}
if ( IMAPG ( status_flags ) & SA_UIDNEXT ) {
2000-04-20 22:23:35 +08:00
add_property_long ( return_value , " uidnext " , IMAPG ( status_uidnext ) ) ;
2000-04-02 00:49:39 +08:00
}
if ( IMAPG ( status_flags ) & SA_UIDVALIDITY ) {
2000-04-20 22:23:35 +08:00
add_property_long ( return_value , " uidvalidity " , IMAPG ( status_uidvalidity ) ) ;
2000-04-02 00:49:39 +08:00
}
} else {
RETURN_FALSE ;
}
}
/* }}} */
2000-04-20 22:23:35 +08:00
2005-01-20 22:04:50 +08:00
/* {{{ proto object imap_bodystruct(resource stream_id, int msg_no, string section)
2000-04-02 00:49:39 +08:00
Read the structure of a specified body section of a specific message */
PHP_FUNCTION ( imap_bodystruct )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * msg , * * section ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
2000-04-20 22:23:35 +08:00
zval * parametres , * param , * dparametres , * dparam ;
2000-04-02 00:49:39 +08:00
PARAMETER * par , * dpar ;
BODY * body ;
2001-08-08 10:55:07 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 3 | | zend_get_parameters_ex ( 3 , & streamind , & msg , & section ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-02 00:49:39 +08:00
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( msg ) ;
convert_to_string_ex ( section ) ;
2001-08-08 00:18:05 +08:00
2002-01-12 13:39:07 +08:00
if ( ! Z_LVAL_PP ( msg ) | | Z_LVAL_PP ( msg ) < 1 | | ( unsigned ) Z_LVAL_PP ( msg ) > imap_le_struct - > imap_stream - > nmsgs ) {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Bad message number " ) ;
2002-08-17 07:25:53 +08:00
RETURN_FALSE ;
}
2002-01-12 13:39:07 +08:00
2003-01-30 10:33:16 +08:00
object_init ( return_value ) ;
2000-04-02 00:49:39 +08:00
2000-04-20 22:52:54 +08:00
body = mail_body ( imap_le_struct - > imap_stream , Z_LVAL_PP ( msg ) , Z_STRVAL_PP ( section ) ) ;
2005-01-25 22:20:02 +08:00
if ( body = = NULL ) {
zval_dtor ( return_value ) ;
RETURN_FALSE ;
}
2002-06-27 09:47:36 +08:00
if ( body - > type < = TYPEMAX ) {
add_property_long ( return_value , " type " , body - > type ) ;
2000-04-19 03:42:22 +08:00
}
2001-05-15 02:24:27 +08:00
if ( body - > encoding < = ENCMAX ) {
2000-04-19 03:42:22 +08:00
add_property_long ( return_value , " encoding " , body - > encoding ) ;
}
2000-04-02 00:49:39 +08:00
2000-04-19 03:42:22 +08:00
if ( body - > subtype ) {
add_property_long ( return_value , " ifsubtype " , 1 ) ;
add_property_string ( return_value , " subtype " , body - > subtype , 1 ) ;
2000-04-02 00:49:39 +08:00
} else {
2000-04-19 03:42:22 +08:00
add_property_long ( return_value , " ifsubtype " , 0 ) ;
2000-04-02 00:49:39 +08:00
}
2000-04-19 03:42:22 +08:00
if ( body - > description ) {
add_property_long ( return_value , " ifdescription " , 1 ) ;
add_property_string ( return_value , " description " , body - > description , 1 ) ;
2000-04-02 00:49:39 +08:00
} else {
2000-04-19 03:42:22 +08:00
add_property_long ( return_value , " ifdescription " , 0 ) ;
2000-04-02 00:49:39 +08:00
}
2000-04-19 03:42:22 +08:00
if ( body - > id ) {
add_property_long ( return_value , " ifid " , 1 ) ;
add_property_string ( return_value , " id " , body - > id , 1 ) ;
2000-04-02 00:49:39 +08:00
} else {
2000-04-19 03:42:22 +08:00
add_property_long ( return_value , " ifid " , 0 ) ;
2000-04-02 00:49:39 +08:00
}
2000-04-19 03:42:22 +08:00
if ( body - > size . lines ) {
add_property_long ( return_value , " lines " , body - > size . lines ) ;
}
if ( body - > size . bytes ) {
add_property_long ( return_value , " bytes " , body - > size . bytes ) ;
}
2000-04-02 00:49:39 +08:00
# ifdef IMAP41
2002-06-27 09:47:36 +08:00
if ( body - > disposition . type ) {
2000-04-19 03:42:22 +08:00
add_property_long ( return_value , " ifdisposition " , 1 ) ;
2002-06-27 09:47:36 +08:00
add_property_string ( return_value , " disposition " , body - > disposition . type , 1 ) ;
2000-04-02 00:49:39 +08:00
} else {
2000-04-19 03:42:22 +08:00
add_property_long ( return_value , " ifdisposition " , 0 ) ;
2000-04-02 00:49:39 +08:00
}
if ( body - > disposition . parameter ) {
dpar = body - > disposition . parameter ;
2000-04-19 03:42:22 +08:00
add_property_long ( return_value , " ifdparameters " , 1 ) ;
2000-04-02 00:49:39 +08:00
MAKE_STD_ZVAL ( dparametres ) ;
array_init ( dparametres ) ;
do {
MAKE_STD_ZVAL ( dparam ) ;
object_init ( dparam ) ;
add_property_string ( dparam , " attribute " , dpar - > attribute , 1 ) ;
add_property_string ( dparam , " value " , dpar - > value , 1 ) ;
2003-01-05 04:06:32 +08:00
add_next_index_object ( dparametres , dparam TSRMLS_CC ) ;
2000-04-02 00:49:39 +08:00
} while ( ( dpar = dpar - > next ) ) ;
2003-01-05 04:06:32 +08:00
add_assoc_object ( return_value , " dparameters " , dparametres TSRMLS_CC ) ;
2000-04-02 00:49:39 +08:00
} else {
add_property_long ( return_value , " ifdparameters " , 0 ) ;
}
# endif
if ( ( par = body - > parameter ) ) {
add_property_long ( return_value , " ifparameters " , 1 ) ;
MAKE_STD_ZVAL ( parametres ) ;
array_init ( parametres ) ;
do {
MAKE_STD_ZVAL ( param ) ;
object_init ( param ) ;
2000-04-19 03:42:22 +08:00
if ( par - > attribute ) {
add_property_string ( param , " attribute " , par - > attribute , 1 ) ;
}
if ( par - > value ) {
add_property_string ( param , " value " , par - > value , 1 ) ;
}
2000-04-02 00:49:39 +08:00
2003-01-05 04:06:32 +08:00
add_next_index_object ( parametres , param TSRMLS_CC ) ;
2000-04-02 00:49:39 +08:00
} while ( ( par = par - > next ) ) ;
} else {
MAKE_STD_ZVAL ( parametres ) ;
object_init ( parametres ) ;
add_property_long ( return_value , " ifparameters " , 0 ) ;
}
2003-01-05 04:06:32 +08:00
add_assoc_object ( return_value , " parameters " , parametres TSRMLS_CC ) ;
2000-04-02 00:49:39 +08:00
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto array imap_fetch_overview(resource stream_id, int msg_no [, int options])
2000-04-04 08:51:38 +08:00
Read an overview of the information in the headers of the given message sequence */
2000-04-02 00:49:39 +08:00
PHP_FUNCTION ( imap_fetch_overview )
{
2000-04-20 22:23:35 +08:00
zval * * streamind , * * sequence , * * pflags ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
2000-04-20 22:23:35 +08:00
zval * myoverview ;
2000-04-02 00:49:39 +08:00
char address [ MAILTMPLEN ] ;
2000-04-07 12:43:26 +08:00
long status , flags = 0L ;
2001-08-08 10:55:07 +08:00
int myargc = ZEND_NUM_ARGS ( ) ;
if ( myargc < 2 | | myargc > 3 | | zend_get_parameters_ex ( myargc , & streamind , & sequence , & pflags ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( sequence ) ;
2001-08-08 10:55:07 +08:00
if ( myargc = = 3 ) {
convert_to_long_ex ( pflags ) ;
flags = Z_LVAL_PP ( pflags ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 00:18:05 +08:00
2000-04-02 00:49:39 +08:00
array_init ( return_value ) ;
2000-04-07 12:43:26 +08:00
2001-08-08 10:55:07 +08:00
status = ( flags & FT_UID )
2000-04-20 22:52:54 +08:00
? mail_uid_sequence ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( sequence ) )
2001-08-08 10:55:07 +08:00
: mail_sequence ( imap_le_struct - > imap_stream , Z_STRVAL_PP ( sequence ) ) ;
2000-04-07 12:43:26 +08:00
if ( status ) {
2000-04-02 00:49:39 +08:00
MESSAGECACHE * elt ;
ENVELOPE * env ;
unsigned long i ;
2000-04-07 12:43:26 +08:00
2000-04-02 00:49:39 +08:00
for ( i = 1 ; i < = imap_le_struct - > imap_stream - > nmsgs ; i + + ) {
2000-04-20 22:23:35 +08:00
if ( ( ( elt = mail_elt ( imap_le_struct - > imap_stream , i ) ) - > sequence ) & &
( env = mail_fetch_structure ( imap_le_struct - > imap_stream , i , NIL , NIL ) ) ) {
2000-04-02 00:49:39 +08:00
MAKE_STD_ZVAL ( myoverview ) ;
object_init ( myoverview ) ;
2000-04-19 03:42:22 +08:00
if ( env - > subject ) {
2000-04-20 22:23:35 +08:00
add_property_string ( myoverview , " subject " , env - > subject , 1 ) ;
2000-04-19 03:42:22 +08:00
}
2003-06-17 21:59:44 +08:00
if ( env - > from & & _php_imap_address_size ( env - > from ) < MAILTMPLEN ) {
2000-04-07 12:43:26 +08:00
env - > from - > next = NULL ;
2000-06-20 05:35:01 +08:00
address [ 0 ] = ' \0 ' ;
2000-04-20 22:23:35 +08:00
rfc822_write_address ( address , env - > from ) ;
add_property_string ( myoverview , " from " , address , 1 ) ;
2000-04-02 00:49:39 +08:00
}
2003-06-17 22:13:17 +08:00
if ( env - > to & & _php_imap_address_size ( env - > to ) < MAILTMPLEN ) {
2001-05-31 00:52:17 +08:00
env - > to - > next = NULL ;
2002-08-17 07:25:53 +08:00
address [ 0 ] = ' \0 ' ;
2001-05-31 00:52:17 +08:00
rfc822_write_address ( address , env - > to ) ;
add_property_string ( myoverview , " to " , address , 1 ) ;
}
2000-04-19 03:42:22 +08:00
if ( env - > date ) {
2000-04-20 22:23:35 +08:00
add_property_string ( myoverview , " date " , env - > date , 1 ) ;
2000-04-19 03:42:22 +08:00
}
if ( env - > message_id ) {
2000-04-20 22:23:35 +08:00
add_property_string ( myoverview , " message_id " , env - > message_id , 1 ) ;
2000-04-19 03:42:22 +08:00
}
if ( env - > references ) {
2000-04-20 22:23:35 +08:00
add_property_string ( myoverview , " references " , env - > references , 1 ) ;
2000-04-19 03:42:22 +08:00
}
2002-06-13 14:32:14 +08:00
if ( env - > in_reply_to ) {
add_property_string ( myoverview , " in_reply_to " , env - > in_reply_to , 1 ) ;
}
2000-04-20 22:23:35 +08:00
add_property_long ( myoverview , " size " , elt - > rfc822_size ) ;
add_property_long ( myoverview , " uid " , mail_uid ( imap_le_struct - > imap_stream , i ) ) ;
add_property_long ( myoverview , " msgno " , i ) ;
add_property_long ( myoverview , " recent " , elt - > recent ) ;
add_property_long ( myoverview , " flagged " , elt - > flagged ) ;
add_property_long ( myoverview , " answered " , elt - > answered ) ;
add_property_long ( myoverview , " deleted " , elt - > deleted ) ;
add_property_long ( myoverview , " seen " , elt - > seen ) ;
add_property_long ( myoverview , " draft " , elt - > draft ) ;
2003-01-05 04:06:32 +08:00
add_next_index_object ( return_value , myoverview TSRMLS_CC ) ;
2000-04-02 00:49:39 +08:00
}
}
}
}
/* }}} */
/* {{{ proto string imap_mail_compose(array envelope, array body)
Create a MIME message based on given envelope and body sections */
PHP_FUNCTION ( imap_mail_compose )
{
2000-04-20 22:23:35 +08:00
zval * * envelope , * * body ;
2000-04-02 00:49:39 +08:00
char * key ;
2001-05-03 01:42:10 +08:00
zval * * data , * * pvalue , * * disp_data , * * env_data ;
2000-04-02 00:49:39 +08:00
ulong ind ;
char * cookie = NIL ;
ENVELOPE * env ;
BODY * bod = NULL , * topbod = NULL ;
2006-01-05 08:47:16 +08:00
PART * mypart = NULL , * part ;
2001-05-03 01:42:10 +08:00
PARAMETER * param , * disp_param = NULL , * custom_headers_param = NULL , * tmp_param = NULL ;
2007-02-16 11:32:06 +08:00
char * tmp = NULL , * mystring = NULL , * t = NULL , * tempstring = NULL ;
2006-01-05 08:47:16 +08:00
int toppart = 0 ;
2000-07-30 02:45:06 +08:00
2001-08-08 10:55:07 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & envelope , & body ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2000-07-30 02:45:06 +08:00
2001-08-08 10:55:07 +08:00
if ( Z_TYPE_PP ( envelope ) ! = IS_ARRAY ) {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Expected Array as envelope parameter " ) ;
2000-07-30 02:45:06 +08:00
RETURN_FALSE ;
}
2001-08-08 10:55:07 +08:00
if ( Z_TYPE_PP ( body ) ! = IS_ARRAY ) {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Expected Array as body parameter " ) ;
2000-07-30 02:45:06 +08:00
RETURN_FALSE ;
}
2001-05-03 01:42:10 +08:00
env = mail_newenvelope ( ) ;
2000-04-20 22:52:54 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( envelope ) , " remail " , sizeof ( " remail " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( pvalue ) ;
2000-04-20 22:52:54 +08:00
env - > remail = cpystr ( Z_STRVAL_PP ( pvalue ) ) ;
2000-04-20 22:23:35 +08:00
}
2000-04-20 22:52:54 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( envelope ) , " return_path " , sizeof ( " return_path " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( pvalue )
2000-04-20 22:52:54 +08:00
rfc822_parse_adrlist ( & env - > return_path , Z_STRVAL_PP ( pvalue ) , " NO HOST " ) ;
2000-04-20 22:23:35 +08:00
}
2000-04-20 22:52:54 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( envelope ) , " date " , sizeof ( " date " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( pvalue ) ;
2000-04-20 22:52:54 +08:00
env - > date = cpystr ( Z_STRVAL_PP ( pvalue ) ) ;
2000-04-20 22:23:35 +08:00
}
2000-04-20 22:52:54 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( envelope ) , " from " , sizeof ( " from " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( pvalue ) ;
2000-04-20 22:52:54 +08:00
rfc822_parse_adrlist ( & env - > from , Z_STRVAL_PP ( pvalue ) , " NO HOST " ) ;
2000-04-20 22:23:35 +08:00
}
2000-04-20 22:52:54 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( envelope ) , " reply_to " , sizeof ( " reply_to " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( pvalue ) ;
2000-04-20 22:52:54 +08:00
rfc822_parse_adrlist ( & env - > reply_to , Z_STRVAL_PP ( pvalue ) , " NO HOST " ) ;
2000-04-20 22:23:35 +08:00
}
2001-08-08 10:55:07 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( envelope ) , " in_reply_to " , sizeof ( " in_reply_to " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
convert_to_string_ex ( pvalue ) ;
2001-05-05 04:03:47 +08:00
env - > in_reply_to = cpystr ( Z_STRVAL_PP ( pvalue ) ) ;
2001-08-08 10:55:07 +08:00
}
2000-08-09 05:16:09 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( envelope ) , " subject " , sizeof ( " subject " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
convert_to_string_ex ( pvalue ) ;
env - > subject = cpystr ( Z_STRVAL_PP ( pvalue ) ) ;
}
2000-04-20 22:52:54 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( envelope ) , " to " , sizeof ( " to " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( pvalue ) ;
2000-04-20 22:52:54 +08:00
rfc822_parse_adrlist ( & env - > to , Z_STRVAL_PP ( pvalue ) , " NO HOST " ) ;
2000-04-20 22:23:35 +08:00
}
2000-04-20 22:52:54 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( envelope ) , " cc " , sizeof ( " cc " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( pvalue ) ;
2000-04-20 22:52:54 +08:00
rfc822_parse_adrlist ( & env - > cc , Z_STRVAL_PP ( pvalue ) , " NO HOST " ) ;
2000-04-20 22:23:35 +08:00
}
2000-04-20 22:52:54 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( envelope ) , " bcc " , sizeof ( " bcc " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( pvalue ) ;
2000-04-20 22:52:54 +08:00
rfc822_parse_adrlist ( & env - > bcc , Z_STRVAL_PP ( pvalue ) , " NO HOST " ) ;
2000-04-20 22:23:35 +08:00
}
2000-04-20 22:52:54 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( envelope ) , " message_id " , sizeof ( " message_id " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( pvalue ) ;
2000-04-20 22:52:54 +08:00
env - > message_id = cpystr ( Z_STRVAL_PP ( pvalue ) ) ;
2000-04-02 00:49:39 +08:00
}
2000-07-30 02:45:06 +08:00
2001-08-08 10:55:07 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( envelope ) , " custom_headers " , sizeof ( " custom_headers " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
2001-05-03 01:42:10 +08:00
if ( Z_TYPE_PP ( pvalue ) = = IS_ARRAY ) {
custom_headers_param = tmp_param = NULL ;
while ( zend_hash_get_current_data ( Z_ARRVAL_PP ( pvalue ) , ( void * * ) & env_data ) = = SUCCESS ) {
custom_headers_param = mail_newbody_parameter ( ) ;
convert_to_string_ex ( env_data ) ;
custom_headers_param - > value = ( char * ) fs_get ( Z_STRLEN_PP ( env_data ) + 1 ) ;
2005-08-31 06:03:29 +08:00
custom_headers_param - > attribute = NULL ;
2001-05-03 01:42:10 +08:00
memcpy ( custom_headers_param - > value , Z_STRVAL_PP ( env_data ) , Z_STRLEN_PP ( env_data ) + 1 ) ;
zend_hash_move_forward ( Z_ARRVAL_PP ( pvalue ) ) ;
custom_headers_param - > next = tmp_param ;
tmp_param = custom_headers_param ;
}
}
}
2000-04-20 22:52:54 +08:00
zend_hash_internal_pointer_reset ( Z_ARRVAL_PP ( body ) ) ;
2008-04-08 08:01:48 +08:00
if ( zend_hash_get_current_data ( Z_ARRVAL_PP ( body ) , ( void * * ) & data ) ! = SUCCESS | | Z_TYPE_PP ( data ) ! = IS_ARRAY ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " body parameter must be a non-empty array " ) ;
2003-02-04 05:24:32 +08:00
RETURN_FALSE ;
}
2000-07-30 02:45:06 +08:00
if ( Z_TYPE_PP ( data ) = = IS_ARRAY ) {
2001-05-03 01:42:10 +08:00
bod = mail_newbody ( ) ;
topbod = bod ;
2000-07-30 02:45:06 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " type " , sizeof ( " type " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
convert_to_long_ex ( pvalue ) ;
2002-06-27 09:47:36 +08:00
bod - > type = ( short ) Z_LVAL_PP ( pvalue ) ;
2000-07-30 02:45:06 +08:00
}
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " encoding " , sizeof ( " encoding " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
convert_to_long_ex ( pvalue ) ;
bod - > encoding = ( short ) Z_LVAL_PP ( pvalue ) ;
}
2001-05-24 11:06:10 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " charset " , sizeof ( " charset " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
convert_to_string_ex ( pvalue ) ;
tmp_param = mail_newbody_parameter ( ) ;
tmp_param - > value = cpystr ( Z_STRVAL_PP ( pvalue ) ) ;
2005-08-31 06:03:29 +08:00
tmp_param - > attribute = cpystr ( " CHARSET " ) ;
2001-05-24 11:06:10 +08:00
tmp_param - > next = bod - > parameter ;
bod - > parameter = tmp_param ;
2002-09-19 10:32:48 +08:00
}
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " type.parameters " , sizeof ( " type.parameters " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
if ( Z_TYPE_PP ( pvalue ) = = IS_ARRAY ) {
disp_param = tmp_param = NULL ;
while ( zend_hash_get_current_data ( Z_ARRVAL_PP ( pvalue ) , ( void * * ) & disp_data ) = = SUCCESS ) {
disp_param = mail_newbody_parameter ( ) ;
zend_hash_get_current_key ( Z_ARRVAL_PP ( pvalue ) , & key , & ind , 0 ) ;
2005-08-31 06:03:29 +08:00
disp_param - > attribute = cpystr ( key ) ;
2002-09-19 10:32:48 +08:00
convert_to_string_ex ( disp_data ) ;
disp_param - > value = ( char * ) fs_get ( Z_STRLEN_PP ( disp_data ) + 1 ) ;
memcpy ( disp_param - > value , Z_STRVAL_PP ( disp_data ) , Z_STRLEN_PP ( disp_data ) + 1 ) ;
zend_hash_move_forward ( Z_ARRVAL_PP ( pvalue ) ) ;
disp_param - > next = tmp_param ;
tmp_param = disp_param ;
}
bod - > parameter = disp_param ;
}
}
2000-07-30 02:45:06 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " subtype " , sizeof ( " subtype " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
convert_to_string_ex ( pvalue ) ;
bod - > subtype = cpystr ( Z_STRVAL_PP ( pvalue ) ) ;
}
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " id " , sizeof ( " id " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
convert_to_string_ex ( pvalue ) ;
bod - > id = cpystr ( Z_STRVAL_PP ( pvalue ) ) ;
}
2001-05-03 01:42:10 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " description " , sizeof ( " description " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
convert_to_string_ex ( pvalue ) ;
bod - > description = cpystr ( Z_STRVAL_PP ( pvalue ) ) ;
}
2002-05-29 16:40:43 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " disposition.type " , sizeof ( " disposition.type " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
2001-05-03 01:42:10 +08:00
convert_to_string_ex ( pvalue ) ;
2002-06-27 09:47:36 +08:00
bod - > disposition . type = ( char * ) fs_get ( Z_STRLEN_PP ( pvalue ) + 1 ) ;
memcpy ( bod - > disposition . type , Z_STRVAL_PP ( pvalue ) , Z_STRLEN_PP ( pvalue ) + 1 ) ;
2001-05-03 01:42:10 +08:00
}
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " disposition " , sizeof ( " disposition " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
if ( Z_TYPE_PP ( pvalue ) = = IS_ARRAY ) {
disp_param = tmp_param = NULL ;
while ( zend_hash_get_current_data ( Z_ARRVAL_PP ( pvalue ) , ( void * * ) & disp_data ) = = SUCCESS ) {
disp_param = mail_newbody_parameter ( ) ;
zend_hash_get_current_key ( Z_ARRVAL_PP ( pvalue ) , & key , & ind , 0 ) ;
2005-08-31 06:03:29 +08:00
disp_param - > attribute = cpystr ( key ) ;
2001-05-03 01:42:10 +08:00
convert_to_string_ex ( disp_data ) ;
disp_param - > value = ( char * ) fs_get ( Z_STRLEN_PP ( disp_data ) + 1 ) ;
memcpy ( disp_param - > value , Z_STRVAL_PP ( disp_data ) , Z_STRLEN_PP ( disp_data ) + 1 ) ;
2002-08-17 07:25:53 +08:00
zend_hash_move_forward ( Z_ARRVAL_PP ( pvalue ) ) ;
2001-05-03 01:42:10 +08:00
disp_param - > next = tmp_param ;
tmp_param = disp_param ;
}
bod - > disposition . parameter = disp_param ;
}
}
2000-07-30 02:45:06 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " contents.data " , sizeof ( " contents.data " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
convert_to_string_ex ( pvalue ) ;
2001-05-03 01:42:10 +08:00
bod - > contents . text . data = ( char * ) fs_get ( Z_STRLEN_PP ( pvalue ) + 1 ) ;
2000-07-30 02:45:06 +08:00
memcpy ( bod - > contents . text . data , Z_STRVAL_PP ( pvalue ) , Z_STRLEN_PP ( pvalue ) + 1 ) ;
bod - > contents . text . size = Z_STRLEN_PP ( pvalue ) ;
2004-12-21 23:47:14 +08:00
} else {
bod - > contents . text . data = ( char * ) fs_get ( 1 ) ;
2004-12-30 13:31:55 +08:00
memcpy ( bod - > contents . text . data , " " , 1 ) ;
2004-12-21 23:47:14 +08:00
bod - > contents . text . size = 0 ;
2000-04-02 00:49:39 +08:00
}
2000-07-30 02:45:06 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " lines " , sizeof ( " lines " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
convert_to_long_ex ( pvalue ) ;
bod - > size . lines = Z_LVAL_PP ( pvalue ) ;
}
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " bytes " , sizeof ( " bytes " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
convert_to_long_ex ( pvalue ) ;
bod - > size . bytes = Z_LVAL_PP ( pvalue ) ;
}
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " md5 " , sizeof ( " md5 " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
convert_to_string_ex ( pvalue ) ;
bod - > md5 = cpystr ( Z_STRVAL_PP ( pvalue ) ) ;
}
}
zend_hash_move_forward ( Z_ARRVAL_PP ( body ) ) ;
2001-05-03 01:42:10 +08:00
while ( zend_hash_get_current_data ( Z_ARRVAL_PP ( body ) , ( void * * ) & data ) = = SUCCESS ) {
2000-04-20 22:52:54 +08:00
if ( Z_TYPE_PP ( data ) = = IS_ARRAY ) {
2006-01-05 08:47:16 +08:00
short type = - 1 ;
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " type " , sizeof ( " type " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
convert_to_long_ex ( pvalue ) ;
type = ( short ) Z_LVAL_PP ( pvalue ) ;
}
2000-07-30 02:45:06 +08:00
if ( ! toppart ) {
2001-05-03 01:42:10 +08:00
bod - > nested . part = mail_newbody_part ( ) ;
mypart = bod - > nested . part ;
2006-01-05 08:47:16 +08:00
toppart = 1 ;
2000-07-30 02:45:06 +08:00
} else {
2006-01-05 08:47:16 +08:00
mypart - > next = mail_newbody_part ( ) ;
mypart = mypart - > next ;
2000-07-30 02:45:06 +08:00
}
2006-01-05 08:47:16 +08:00
bod = & mypart - > body ;
if ( type ! = TYPEMULTIPART ) {
bod - > type = type ;
}
2000-04-20 22:52:54 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " encoding " , sizeof ( " encoding " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( pvalue ) ;
2000-04-20 22:52:54 +08:00
bod - > encoding = ( short ) Z_LVAL_PP ( pvalue ) ;
2000-04-02 00:49:39 +08:00
}
2001-05-24 11:06:10 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " charset " , sizeof ( " charset " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
convert_to_string_ex ( pvalue ) ;
tmp_param = mail_newbody_parameter ( ) ;
2005-04-05 22:47:47 +08:00
tmp_param - > value = ( char * ) fs_get ( Z_STRLEN_PP ( pvalue ) + 1 ) ;
2005-04-08 23:04:34 +08:00
memcpy ( tmp_param - > value , Z_STRVAL_PP ( pvalue ) , Z_STRLEN_PP ( pvalue ) + 1 ) ;
2005-08-31 06:03:29 +08:00
tmp_param - > attribute = cpystr ( " CHARSET " ) ;
2001-05-24 11:06:10 +08:00
tmp_param - > next = bod - > parameter ;
bod - > parameter = tmp_param ;
}
2002-09-19 10:32:48 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " type.parameters " , sizeof ( " type.parameters " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
if ( Z_TYPE_PP ( pvalue ) = = IS_ARRAY ) {
disp_param = tmp_param = NULL ;
while ( zend_hash_get_current_data ( Z_ARRVAL_PP ( pvalue ) , ( void * * ) & disp_data ) = = SUCCESS ) {
disp_param = mail_newbody_parameter ( ) ;
zend_hash_get_current_key ( Z_ARRVAL_PP ( pvalue ) , & key , & ind , 0 ) ;
2005-08-31 06:03:29 +08:00
disp_param - > attribute = cpystr ( key ) ;
2002-09-19 10:32:48 +08:00
convert_to_string_ex ( disp_data ) ;
disp_param - > value = ( char * ) fs_get ( Z_STRLEN_PP ( disp_data ) + 1 ) ;
memcpy ( disp_param - > value , Z_STRVAL_PP ( disp_data ) , Z_STRLEN_PP ( disp_data ) + 1 ) ;
zend_hash_move_forward ( Z_ARRVAL_PP ( pvalue ) ) ;
disp_param - > next = tmp_param ;
tmp_param = disp_param ;
}
2007-03-20 06:56:57 +08:00
bod - > parameter = disp_param ;
2002-09-19 10:32:48 +08:00
}
}
2000-04-20 22:52:54 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " subtype " , sizeof ( " subtype " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( pvalue ) ;
2000-07-30 02:45:06 +08:00
bod - > subtype = cpystr ( Z_STRVAL_PP ( pvalue ) ) ;
2000-04-02 00:49:39 +08:00
}
2000-04-20 22:52:54 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " id " , sizeof ( " id " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( pvalue ) ;
2000-04-20 22:52:54 +08:00
bod - > id = cpystr ( Z_STRVAL_PP ( pvalue ) ) ;
2000-04-02 00:49:39 +08:00
}
2001-05-03 01:42:10 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " description " , sizeof ( " description " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
convert_to_string_ex ( pvalue ) ;
bod - > description = cpystr ( Z_STRVAL_PP ( pvalue ) ) ;
}
2002-05-29 16:40:43 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " disposition.type " , sizeof ( " disposition.type " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
2001-05-03 01:42:10 +08:00
convert_to_string_ex ( pvalue ) ;
2002-06-27 09:47:36 +08:00
bod - > disposition . type = ( char * ) fs_get ( Z_STRLEN_PP ( pvalue ) + 1 ) ;
memcpy ( bod - > disposition . type , Z_STRVAL_PP ( pvalue ) , Z_STRLEN_PP ( pvalue ) + 1 ) ;
2001-05-03 01:42:10 +08:00
}
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " disposition " , sizeof ( " disposition " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
if ( Z_TYPE_PP ( pvalue ) = = IS_ARRAY ) {
disp_param = tmp_param = NULL ;
while ( zend_hash_get_current_data ( Z_ARRVAL_PP ( pvalue ) , ( void * * ) & disp_data ) = = SUCCESS ) {
disp_param = mail_newbody_parameter ( ) ;
zend_hash_get_current_key ( Z_ARRVAL_PP ( pvalue ) , & key , & ind , 0 ) ;
2005-08-31 06:03:29 +08:00
disp_param - > attribute = cpystr ( key ) ;
2001-05-03 01:42:10 +08:00
convert_to_string_ex ( disp_data ) ;
disp_param - > value = ( char * ) fs_get ( Z_STRLEN_PP ( disp_data ) + 1 ) ;
memcpy ( disp_param - > value , Z_STRVAL_PP ( disp_data ) , Z_STRLEN_PP ( disp_data ) + 1 ) ;
2002-08-17 07:25:53 +08:00
zend_hash_move_forward ( Z_ARRVAL_PP ( pvalue ) ) ;
2001-05-03 01:42:10 +08:00
disp_param - > next = tmp_param ;
tmp_param = disp_param ;
}
bod - > disposition . parameter = disp_param ;
}
}
2000-04-20 22:52:54 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " contents.data " , sizeof ( " contents.data " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( pvalue ) ;
2001-05-03 01:42:10 +08:00
bod - > contents . text . data = ( char * ) fs_get ( Z_STRLEN_PP ( pvalue ) + 1 ) ;
memcpy ( bod - > contents . text . data , Z_STRVAL_PP ( pvalue ) , Z_STRLEN_PP ( pvalue ) + 1 ) ;
2000-04-20 22:52:54 +08:00
bod - > contents . text . size = Z_STRLEN_PP ( pvalue ) ;
2004-12-21 23:47:14 +08:00
} else {
bod - > contents . text . data = ( char * ) fs_get ( 1 ) ;
2005-01-19 00:32:53 +08:00
memcpy ( bod - > contents . text . data , " " , 1 ) ;
2004-12-21 23:47:14 +08:00
bod - > contents . text . size = 0 ;
2000-04-02 00:49:39 +08:00
}
2000-04-20 22:52:54 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " lines " , sizeof ( " lines " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( pvalue ) ;
2000-04-20 22:52:54 +08:00
bod - > size . lines = Z_LVAL_PP ( pvalue ) ;
2000-04-02 00:49:39 +08:00
}
2000-04-20 22:52:54 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " bytes " , sizeof ( " bytes " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( pvalue ) ;
2000-04-20 22:52:54 +08:00
bod - > size . bytes = Z_LVAL_PP ( pvalue ) ;
2000-04-02 00:49:39 +08:00
}
2000-04-20 22:52:54 +08:00
if ( zend_hash_find ( Z_ARRVAL_PP ( data ) , " md5 " , sizeof ( " md5 " ) , ( void * * ) & pvalue ) = = SUCCESS ) {
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( pvalue ) ;
2000-04-20 22:52:54 +08:00
bod - > md5 = cpystr ( Z_STRVAL_PP ( pvalue ) ) ;
2000-04-02 00:49:39 +08:00
}
}
2005-01-19 00:32:53 +08:00
zend_hash_move_forward ( Z_ARRVAL_PP ( body ) ) ;
2000-04-02 00:49:39 +08:00
}
2005-01-19 07:36:08 +08:00
if ( bod & & bod - > type = = TYPEMULTIPART & & ( ! bod - > nested . part | | ! bod - > nested . part - > next ) ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " cannot generate multipart e-mail without components. " ) ;
RETVAL_FALSE ;
goto done ;
}
2006-12-25 06:15:06 +08:00
rfc822_encode_body_7bit ( env , topbod ) ;
2007-02-16 11:32:06 +08:00
tmp = emalloc ( SENDBUFLEN + 1 ) ;
2006-12-25 06:15:06 +08:00
rfc822_header ( tmp , env , topbod ) ;
2001-05-03 01:42:10 +08:00
/* add custom envelope headers */
if ( custom_headers_param ) {
2005-01-19 07:36:08 +08:00
int l = strlen ( tmp ) - 2 , l2 ;
PARAMETER * tp = custom_headers_param ;
2001-05-03 01:42:10 +08:00
/* remove last CRLF from tmp */
2005-01-19 07:36:08 +08:00
tmp [ l ] = ' \0 ' ;
tempstring = emalloc ( l ) ;
memcpy ( tempstring , tmp , l ) ;
2001-05-03 01:42:10 +08:00
do {
2005-01-19 07:36:08 +08:00
l2 = strlen ( custom_headers_param - > value ) ;
tempstring = erealloc ( tempstring , l + l2 + CRLF_LEN + 1 ) ;
memcpy ( tempstring + l , custom_headers_param - > value , l2 ) ;
memcpy ( tempstring + l + l2 , CRLF , CRLF_LEN ) ;
l + = l2 + CRLF_LEN ;
2001-05-03 01:42:10 +08:00
} while ( ( custom_headers_param = custom_headers_param - > next ) ) ;
2005-01-19 07:36:08 +08:00
mail_free_body_parameter ( & tp ) ;
mystring = emalloc ( l + CRLF_LEN + 1 ) ;
memcpy ( mystring , tempstring , l ) ;
memcpy ( mystring + l , CRLF , CRLF_LEN ) ;
mystring [ l + CRLF_LEN ] = ' \0 ' ;
2001-05-03 01:42:10 +08:00
efree ( tempstring ) ;
} else {
2005-02-21 02:23:33 +08:00
mystring = estrdup ( tmp ) ;
2001-05-03 01:42:10 +08:00
}
2000-04-02 00:49:39 +08:00
2001-05-03 01:42:10 +08:00
bod = topbod ;
2000-07-30 02:45:06 +08:00
2002-06-27 09:47:36 +08:00
if ( bod & & bod - > type = = TYPEMULTIPART ) {
2000-07-30 02:45:06 +08:00
/* first body part */
part = bod - > nested . part ;
/* find cookie */
2000-04-02 00:49:39 +08:00
for ( param = bod - > parameter ; param & & ! cookie ; param = param - > next ) {
2000-04-20 22:23:35 +08:00
if ( ! strcmp ( param - > attribute , " BOUNDARY " ) ) {
2000-04-02 00:49:39 +08:00
cookie = param - > value ;
}
}
2000-07-30 02:45:06 +08:00
/* yucky default */
2000-04-02 00:49:39 +08:00
if ( ! cookie ) {
2000-07-30 02:45:06 +08:00
cookie = " - " ;
2007-02-16 11:32:06 +08:00
} else if ( strlen ( cookie ) > ( SENDBUFLEN - 2 - 2 - 2 ) ) { /* validate cookie length -- + CRLF * 2 */
2006-12-25 06:15:06 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " The boudary should be no longer then 4kb " ) ;
RETVAL_FALSE ;
goto done ;
2000-04-02 00:49:39 +08:00
}
2000-07-30 02:45:06 +08:00
/* for each part */
do {
2007-02-16 11:32:06 +08:00
t = tmp ;
2000-07-30 02:45:06 +08:00
/* append mini-header */
2007-02-16 11:32:06 +08:00
* t = ' \0 ' ;
2000-04-20 22:23:35 +08:00
rfc822_write_body_header ( & t , & part - > body ) ;
2000-07-30 02:45:06 +08:00
/* output cookie, mini-header, and contents */
2007-02-16 11:32:06 +08:00
spprintf ( & tempstring , 0 , " %s--%s%s%s%s " , mystring , cookie , CRLF , tmp , CRLF ) ;
2000-04-02 00:49:39 +08:00
efree ( mystring ) ;
mystring = tempstring ;
bod = & part - > body ;
2006-12-25 06:15:06 +08:00
spprintf ( & tempstring , 0 , " %s%s%s " , mystring , bod - > contents . text . data , CRLF ) ;
2000-04-02 00:49:39 +08:00
efree ( mystring ) ;
mystring = tempstring ;
2002-08-17 07:25:53 +08:00
} while ( ( part = part - > next ) ) ; /* until done */
2000-04-02 00:49:39 +08:00
2002-08-17 07:25:53 +08:00
/* output trailing cookie */
2007-03-20 06:56:57 +08:00
spprintf ( & tempstring , 0 , " %s--%s--%s " , mystring , cookie , CRLF ) ;
2000-04-02 00:49:39 +08:00
efree ( mystring ) ;
mystring = tempstring ;
2001-05-03 01:42:10 +08:00
} else if ( bod ) {
2007-02-16 11:32:06 +08:00
spprintf ( & tempstring , 0 , " %s%s%s " , mystring , bod - > contents . text . data , CRLF ) ;
efree ( mystring ) ;
mystring = tempstring ;
2000-07-30 02:45:06 +08:00
} else {
efree ( mystring ) ;
2004-12-30 05:33:03 +08:00
RETVAL_FALSE ;
goto done ;
2000-04-02 00:49:39 +08:00
}
2004-12-30 05:56:42 +08:00
RETVAL_STRING ( tempstring , 0 ) ;
2004-12-30 05:33:03 +08:00
done :
2007-02-16 11:32:06 +08:00
if ( tmp ) {
efree ( tmp ) ;
}
2004-12-30 05:33:03 +08:00
mail_free_body ( & topbod ) ;
mail_free_envelope ( & env ) ;
2000-04-02 00:49:39 +08:00
}
/* }}} */
2000-04-20 22:23:35 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ _php_imap_mail
*/
2002-06-28 22:35:20 +08:00
int _php_imap_mail ( char * to , char * subject , char * message , char * headers , char * cc , char * bcc , char * rpath TSRMLS_DC )
2000-04-02 00:49:39 +08:00
{
# ifdef PHP_WIN32
int tsm_err ;
# else
FILE * sendmail ;
int ret ;
# endif
# ifdef PHP_WIN32
2002-07-03 03:29:15 +08:00
char * tempMailTo ;
2002-07-03 07:45:32 +08:00
char * tsm_errmsg = NULL ;
2002-07-03 03:29:15 +08:00
ADDRESS * addr ;
2002-12-01 05:49:20 +08:00
char * bufferTo = NULL , * bufferCc = NULL , * bufferBcc = NULL , * bufferHeader = NULL ;
2007-02-24 10:17:47 +08:00
int offset , bufferLen = 0 ;
size_t bt_len ;
2002-12-01 05:49:20 +08:00
2002-12-07 14:05:06 +08:00
if ( headers ) {
2002-12-01 05:49:20 +08:00
bufferLen + = strlen ( headers ) ;
2002-12-07 14:05:06 +08:00
}
if ( to ) {
2002-12-01 05:49:20 +08:00
bufferLen + = strlen ( to ) + 6 ;
2002-12-07 14:05:06 +08:00
}
if ( cc ) {
2002-12-01 05:49:20 +08:00
bufferLen + = strlen ( cc ) + 6 ;
2002-12-07 14:05:06 +08:00
}
2002-12-01 05:49:20 +08:00
2004-05-13 04:17:19 +08:00
# define PHP_IMAP_CLEAN if (bufferTo) efree(bufferTo); if (bufferCc) efree(bufferCc); if (bufferBcc) efree(bufferBcc); if (bufferHeader) efree(bufferHeader);
# define PHP_IMAP_BAD_DEST PHP_IMAP_CLEAN; efree(tempMailTo); return (BAD_MSG_DESTINATION);
2007-01-18 22:03:38 +08:00
bufferHeader = ( char * ) emalloc ( bufferLen + 1 ) ;
2002-12-01 05:49:20 +08:00
memset ( bufferHeader , 0 , bufferLen ) ;
2002-07-03 07:45:32 +08:00
if ( to & & * to ) {
2007-01-18 22:03:38 +08:00
strlcat ( bufferHeader , " To: " , bufferLen + 1 ) ;
strlcat ( bufferHeader , to , bufferLen + 1 ) ;
strlcat ( bufferHeader , " \r \n " , bufferLen + 1 ) ;
2002-07-03 07:45:32 +08:00
tempMailTo = estrdup ( to ) ;
2007-02-24 10:17:47 +08:00
bt_len = strlen ( to ) ;
bufferTo = ( char * ) safe_emalloc ( bt_len , 1 , 1 ) ;
bt_len + + ;
2002-07-03 07:45:32 +08:00
offset = 0 ;
addr = NULL ;
rfc822_parse_adrlist ( & addr , tempMailTo , NULL ) ;
while ( addr ) {
2007-07-31 08:31:10 +08:00
if ( addr - > host = = NULL | | strcmp ( addr - > host , ERRHOST ) = = 0 ) {
2004-05-13 04:17:19 +08:00
PHP_IMAP_BAD_DEST ;
} else {
2007-02-24 10:17:47 +08:00
bufferTo = safe_erealloc ( bufferTo , bt_len , 1 , strlen ( addr - > mailbox ) ) ;
bt_len + = strlen ( addr - > mailbox ) ;
bufferTo = safe_erealloc ( bufferTo , bt_len , 1 , strlen ( addr - > host ) ) ;
bt_len + = strlen ( addr - > host ) ;
2007-02-27 11:04:40 +08:00
offset + = slprintf ( bufferTo + offset , bt_len - offset , " %s@%s, " , addr - > mailbox , addr - > host ) ;
2002-07-03 07:45:32 +08:00
}
addr = addr - > next ;
}
efree ( tempMailTo ) ;
2002-11-28 02:52:31 +08:00
if ( offset > 0 ) {
bufferTo [ offset - 1 ] = 0 ;
}
2002-07-03 07:45:32 +08:00
}
2002-07-03 03:29:15 +08:00
if ( cc & & * cc ) {
2007-01-18 22:03:38 +08:00
strlcat ( bufferHeader , " Cc: " , bufferLen + 1 ) ;
strlcat ( bufferHeader , cc , bufferLen + 1 ) ;
strlcat ( bufferHeader , " \r \n " , bufferLen + 1 ) ;
2002-07-03 03:29:15 +08:00
tempMailTo = estrdup ( cc ) ;
2007-02-24 10:17:47 +08:00
bt_len = strlen ( cc ) ;
bufferCc = ( char * ) safe_emalloc ( bt_len , 1 , 1 ) ;
bt_len + + ;
2002-07-03 03:29:15 +08:00
offset = 0 ;
addr = NULL ;
rfc822_parse_adrlist ( & addr , tempMailTo , NULL ) ;
while ( addr ) {
2007-07-31 08:31:10 +08:00
if ( addr - > host = = NULL | | strcmp ( addr - > host , ERRHOST ) = = 0 ) {
2004-05-13 04:17:19 +08:00
PHP_IMAP_BAD_DEST ;
} else {
2007-02-24 10:17:47 +08:00
bufferCc = safe_erealloc ( bufferCc , bt_len , 1 , strlen ( addr - > mailbox ) ) ;
bt_len + = strlen ( addr - > mailbox ) ;
bufferCc = safe_erealloc ( bufferCc , bt_len , 1 , strlen ( addr - > host ) ) ;
bt_len + = strlen ( addr - > host ) ;
2007-02-27 11:04:40 +08:00
offset + = slprintf ( bufferCc + offset , bt_len - offset , " %s@%s, " , addr - > mailbox , addr - > host ) ;
2002-07-03 03:29:15 +08:00
}
addr = addr - > next ;
}
efree ( tempMailTo ) ;
2002-11-28 02:52:31 +08:00
if ( offset > 0 ) {
bufferCc [ offset - 1 ] = 0 ;
}
2002-07-03 03:29:15 +08:00
}
if ( bcc & & * bcc ) {
tempMailTo = estrdup ( bcc ) ;
2007-02-24 10:17:47 +08:00
bt_len = strlen ( bcc ) ;
bufferBcc = ( char * ) safe_emalloc ( bt_len , 1 , 1 ) ;
bt_len + + ;
2002-07-03 03:29:15 +08:00
offset = 0 ;
addr = NULL ;
rfc822_parse_adrlist ( & addr , tempMailTo , NULL ) ;
while ( addr ) {
2007-07-31 08:31:10 +08:00
if ( addr - > host = = NULL | | strcmp ( addr - > host , ERRHOST ) = = 0 ) {
2004-05-13 04:17:19 +08:00
PHP_IMAP_BAD_DEST ;
} else {
2007-02-24 10:17:47 +08:00
bufferBcc = safe_erealloc ( bufferBcc , bt_len , 1 , strlen ( addr - > mailbox ) ) ;
bt_len + = strlen ( addr - > mailbox ) ;
bufferBcc = safe_erealloc ( bufferBcc , bt_len , 1 , strlen ( addr - > host ) ) ;
bt_len + = strlen ( addr - > host ) ;
2007-02-27 11:04:40 +08:00
offset + = slprintf ( bufferBcc + offset , bt_len - offset , " %s@%s, " , addr - > mailbox , addr - > host ) ;
2002-07-03 03:29:15 +08:00
}
addr = addr - > next ;
}
efree ( tempMailTo ) ;
2002-11-28 02:52:31 +08:00
if ( offset > 0 ) {
bufferBcc [ offset - 1 ] = 0 ;
}
2002-07-03 03:29:15 +08:00
}
2002-12-07 14:05:06 +08:00
if ( headers & & * headers ) {
2007-01-18 22:03:38 +08:00
strlcat ( bufferHeader , headers , bufferLen + 1 ) ;
2002-12-07 14:05:06 +08:00
}
2002-07-03 03:29:15 +08:00
2005-08-08 06:06:29 +08:00
if ( TSendMail ( INI_STR ( " SMTP " ) , & tsm_err , & tsm_errmsg , bufferHeader , subject , bufferTo , message , bufferCc , bufferBcc , rpath TSRMLS_CC ) ! = SUCCESS ) {
2002-07-03 07:45:32 +08:00
if ( tsm_errmsg ) {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " %s " , tsm_errmsg ) ;
2002-07-03 07:45:32 +08:00
efree ( tsm_errmsg ) ;
} else {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " %s " , GetSMErrorText ( tsm_err ) ) ;
2002-07-03 07:45:32 +08:00
}
2004-05-13 04:17:19 +08:00
PHP_IMAP_CLEAN ;
2000-04-02 00:49:39 +08:00
return 0 ;
}
2004-05-13 04:17:19 +08:00
PHP_IMAP_CLEAN ;
2000-04-02 00:49:39 +08:00
# else
if ( ! INI_STR ( " sendmail_path " ) ) {
return 0 ;
}
sendmail = popen ( INI_STR ( " sendmail_path " ) , " w " ) ;
if ( sendmail ) {
if ( rpath & & rpath [ 0 ] ) fprintf ( sendmail , " From: %s \n " , rpath ) ;
fprintf ( sendmail , " To: %s \n " , to ) ;
if ( cc & & cc [ 0 ] ) fprintf ( sendmail , " Cc: %s \n " , cc ) ;
if ( bcc & & bcc [ 0 ] ) fprintf ( sendmail , " Bcc: %s \n " , bcc ) ;
fprintf ( sendmail , " Subject: %s \n " , subject ) ;
if ( headers ! = NULL ) {
fprintf ( sendmail , " %s \n " , headers ) ;
}
fprintf ( sendmail , " \n %s \n " , message ) ;
ret = pclose ( sendmail ) ;
if ( ret = = - 1 ) {
return 0 ;
} else {
return 1 ;
}
} else {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Could not execute mail delivery program " ) ;
2000-04-02 00:49:39 +08:00
return 0 ;
}
# endif
return 1 ;
}
2001-06-06 21:06:12 +08:00
/* }}} */
2000-07-21 23:50:37 +08:00
2003-06-16 21:39:56 +08:00
/* {{{ proto bool imap_mail(string to, string subject, string message [, string additional_headers [, string cc [, string bcc [, string rpath]]]])
2000-04-02 00:49:39 +08:00
Send an email message */
PHP_FUNCTION ( imap_mail )
{
2001-08-08 10:55:07 +08:00
zval * * argv [ 7 ] ;
2000-04-02 00:49:39 +08:00
char * to = NULL , * message = NULL , * headers = NULL , * subject = NULL , * cc = NULL , * bcc = NULL , * rpath = NULL ;
2001-08-08 10:55:07 +08:00
int argc = ZEND_NUM_ARGS ( ) ;
if ( argc < 3 | | argc > 7 | | zend_get_parameters_array_ex ( argc , argv ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 00:18:05 +08:00
2000-04-02 00:49:39 +08:00
/* To: */
2001-08-08 10:55:07 +08:00
convert_to_string_ex ( argv [ 0 ] ) ;
if ( Z_STRVAL_PP ( argv [ 0 ] ) ) {
to = Z_STRVAL_PP ( argv [ 0 ] ) ;
2000-04-02 00:49:39 +08:00
} else {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " No to field in mail command " ) ;
2000-04-02 00:49:39 +08:00
RETURN_FALSE ;
}
/* Subject: */
2001-08-08 10:55:07 +08:00
convert_to_string_ex ( argv [ 1 ] ) ;
if ( Z_STRVAL_PP ( argv [ 1 ] ) ) {
subject = Z_STRVAL_PP ( argv [ 1 ] ) ;
2000-04-02 00:49:39 +08:00
} else {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " No subject field in mail command " ) ;
2000-04-02 00:49:39 +08:00
RETURN_FALSE ;
}
/* message body */
2001-08-08 10:55:07 +08:00
convert_to_string_ex ( argv [ 2 ] ) ;
if ( Z_STRVAL_PP ( argv [ 2 ] ) ) {
message = Z_STRVAL_PP ( argv [ 2 ] ) ;
2000-04-02 00:49:39 +08:00
} else {
/* this is not really an error, so it is allowed. */
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " No message string in mail command " ) ;
2000-04-02 00:49:39 +08:00
message = NULL ;
}
/* other headers */
if ( argc > 3 ) {
2001-08-08 10:55:07 +08:00
convert_to_string_ex ( argv [ 3 ] ) ;
headers = Z_STRVAL_PP ( argv [ 3 ] ) ;
2000-04-02 00:49:39 +08:00
}
/* cc */
if ( argc > 4 ) {
2001-08-08 10:55:07 +08:00
convert_to_string_ex ( argv [ 4 ] ) ;
cc = Z_STRVAL_PP ( argv [ 4 ] ) ;
2000-04-02 00:49:39 +08:00
}
/* bcc */
if ( argc > 5 ) {
2001-08-08 10:55:07 +08:00
convert_to_string_ex ( argv [ 5 ] ) ;
bcc = Z_STRVAL_PP ( argv [ 5 ] ) ;
2000-04-02 00:49:39 +08:00
}
/* rpath */
if ( argc > 6 ) {
2001-08-08 10:55:07 +08:00
convert_to_string_ex ( argv [ 6 ] ) ;
rpath = Z_STRVAL_PP ( argv [ 6 ] ) ;
2000-04-02 00:49:39 +08:00
}
2002-06-28 22:35:20 +08:00
if ( _php_imap_mail ( to , subject , message , headers , cc , bcc , rpath TSRMLS_CC ) ) {
2000-04-02 00:49:39 +08:00
RETURN_TRUE ;
} else {
RETURN_FALSE ;
}
}
/* }}} */
2003-06-13 03:46:44 +08:00
/* {{{ proto array imap_search(resource stream_id, string criteria [, int options [, string charset]])
2000-04-04 08:51:38 +08:00
Return a list of messages matching the given criteria */
2000-04-02 00:49:39 +08:00
PHP_FUNCTION ( imap_search )
{
2003-06-13 03:46:44 +08:00
zval * * streamind , * * criteria , * * search_flags , * * charset ;
2000-04-02 00:49:39 +08:00
pils * imap_le_struct ;
long flags ;
2001-08-08 00:18:05 +08:00
char * search_criteria ;
2000-04-02 00:49:39 +08:00
MESSAGELIST * cur ;
2001-08-08 10:55:07 +08:00
int argc = ZEND_NUM_ARGS ( ) ;
2003-06-13 03:46:44 +08:00
if ( argc < 2 | | argc > 4 | | zend_get_parameters_ex ( argc , & streamind , & criteria , & search_flags , & charset ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2000-04-20 22:23:35 +08:00
convert_to_string_ex ( criteria ) ;
2001-08-08 00:18:05 +08:00
search_criteria = estrndup ( Z_STRVAL_PP ( criteria ) , Z_STRLEN_PP ( criteria ) ) ;
2000-04-02 00:49:39 +08:00
2001-08-08 10:55:07 +08:00
if ( argc = = 2 ) {
2000-04-02 00:49:39 +08:00
flags = SE_FREE ;
} else {
2000-04-20 22:23:35 +08:00
convert_to_long_ex ( search_flags ) ;
2000-04-20 22:52:54 +08:00
flags = Z_LVAL_PP ( search_flags ) ;
2003-06-13 03:46:44 +08:00
if ( argc = = 4 ) {
convert_to_string_ex ( charset ) ;
}
2000-04-02 00:49:39 +08:00
}
2001-08-17 04:13:27 +08:00
IMAPG ( imap_messages ) = IMAPG ( imap_messages_tail ) = NIL ;
2003-06-13 03:46:44 +08:00
mail_search_full ( imap_le_struct - > imap_stream , ( argc = = 4 ? Z_STRVAL_PP ( charset ) : NIL ) , mail_criteria ( search_criteria ) , flags ) ;
2000-04-02 00:49:39 +08:00
if ( IMAPG ( imap_messages ) = = NIL ) {
2001-04-24 05:58:44 +08:00
efree ( search_criteria ) ;
2000-04-02 00:49:39 +08:00
RETURN_FALSE ;
}
array_init ( return_value ) ;
2001-08-08 10:55:07 +08:00
2000-04-02 00:49:39 +08:00
cur = IMAPG ( imap_messages ) ;
while ( cur ! = NIL ) {
add_next_index_long ( return_value , cur - > msgid ) ;
cur = cur - > next ;
}
2001-08-17 04:13:27 +08:00
mail_free_messagelist ( & IMAPG ( imap_messages ) , & IMAPG ( imap_messages_tail ) ) ;
2001-04-24 05:58:44 +08:00
efree ( search_criteria ) ;
2000-04-02 00:49:39 +08:00
}
/* }}} */
/* {{{ proto array imap_alerts(void)
2000-04-04 08:51:38 +08:00
Returns an array of all IMAP alerts that have been generated since the last page load or since the last imap_alerts ( ) call , whichever came last . The alert stack is cleared after imap_alerts ( ) is called . */
2000-04-02 00:49:39 +08:00
/* Author: CJH */
PHP_FUNCTION ( imap_alerts )
{
STRINGLIST * cur = NIL ;
2002-08-17 07:25:53 +08:00
2008-03-11 06:15:36 +08:00
if ( zend_parse_parameters_none ( ) = = FAILURE ) {
return ;
2000-04-04 08:51:38 +08:00
}
2000-04-02 00:49:39 +08:00
if ( IMAPG ( imap_alertstack ) = = NIL ) {
RETURN_FALSE ;
}
array_init ( return_value ) ;
2001-08-08 10:55:07 +08:00
2000-04-02 00:49:39 +08:00
cur = IMAPG ( imap_alertstack ) ;
while ( cur ! = NIL ) {
2000-04-20 22:23:35 +08:00
add_next_index_string ( return_value , cur - > LTEXT , 1 ) ;
2000-04-02 00:49:39 +08:00
cur = cur - > next ;
}
mail_free_stringlist ( & IMAPG ( imap_alertstack ) ) ;
IMAPG ( imap_alertstack ) = NIL ;
}
/* }}} */
/* {{{ proto array imap_errors(void)
2001-08-08 00:18:05 +08:00
Returns an array of all IMAP errors generated since the last page load , or since the last imap_errors ( ) call , whichever came last . The error stack is cleared after imap_errors ( ) is called . */
2000-04-02 00:49:39 +08:00
/* Author: CJH */
PHP_FUNCTION ( imap_errors )
{
ERRORLIST * cur = NIL ;
2002-08-17 07:25:53 +08:00
2008-03-11 06:15:36 +08:00
if ( zend_parse_parameters_none ( ) = = FAILURE ) {
return ;
2001-08-08 10:55:07 +08:00
}
2000-04-02 00:49:39 +08:00
if ( IMAPG ( imap_errorstack ) = = NIL ) {
RETURN_FALSE ;
}
array_init ( return_value ) ;
2001-08-08 10:55:07 +08:00
2000-04-02 00:49:39 +08:00
cur = IMAPG ( imap_errorstack ) ;
while ( cur ! = NIL ) {
2000-04-20 22:23:35 +08:00
add_next_index_string ( return_value , cur - > LTEXT , 1 ) ;
2000-04-02 00:49:39 +08:00
cur = cur - > next ;
}
mail_free_errorlist ( & IMAPG ( imap_errorstack ) ) ;
IMAPG ( imap_errorstack ) = NIL ;
}
/* }}} */
/* {{{ proto string imap_last_error(void)
Returns the last error that was generated by an IMAP function . The error stack is NOT cleared after this call . */
/* Author: CJH */
PHP_FUNCTION ( imap_last_error )
{
ERRORLIST * cur = NIL ;
2002-08-17 07:25:53 +08:00
2008-03-11 06:15:36 +08:00
if ( zend_parse_parameters_none ( ) = = FAILURE ) {
return ;
2001-08-08 10:55:07 +08:00
}
2000-04-02 00:49:39 +08:00
if ( IMAPG ( imap_errorstack ) = = NIL ) {
RETURN_FALSE ;
}
cur = IMAPG ( imap_errorstack ) ;
while ( cur ! = NIL ) {
if ( cur - > next = = NIL ) {
RETURN_STRING ( cur - > LTEXT , 1 ) ;
}
cur = cur - > next ;
}
}
/* }}} */
2000-04-04 08:51:38 +08:00
/* {{{ proto array imap_mime_header_decode(string str)
Decode mime header element in accordance with RFC 2047 and return array of objects containing ' charset ' encoding and decoded ' text ' */
PHP_FUNCTION ( imap_mime_header_decode )
{
2000-04-28 22:24:38 +08:00
/* Author: Ted Parnefors <ted@mtv.se> */
2000-04-20 22:23:35 +08:00
zval * * str , * myobject ;
char * string , * charset , encoding , * text , * decode ;
long charset_token , encoding_token , end_token , end , offset = 0 , i ;
2000-04-04 08:51:38 +08:00
unsigned long newlength ;
2000-04-19 21:15:57 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & str ) = = FAILURE ) {
2000-04-20 22:23:35 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-04-04 08:51:38 +08:00
}
convert_to_string_ex ( str ) ;
2003-01-18 00:07:39 +08:00
array_init ( return_value ) ;
2000-04-04 08:51:38 +08:00
2001-08-08 10:55:07 +08:00
string = Z_STRVAL_PP ( str ) ;
end = Z_STRLEN_PP ( str ) ;
2000-04-04 08:51:38 +08:00
2003-08-12 08:58:52 +08:00
charset = ( char * ) safe_emalloc ( ( end + 1 ) , 2 , 0 ) ;
2003-01-21 03:41:58 +08:00
text = & charset [ end + 1 ] ;
while ( offset < end ) { /* Reached end of the string? */
if ( ( charset_token = ( long ) php_memnstr ( & string [ offset ] , " =? " , 2 , string + end ) ) ) { /* Is there anything encoded in the string? */
charset_token - = ( long ) string ;
if ( offset ! = charset_token ) { /* Is there anything before the encoded data? */
/* Retrieve unencoded data that is found before encoded data */
memcpy ( text , & string [ offset ] , charset_token - offset ) ;
text [ charset_token - offset ] = 0x00 ;
MAKE_STD_ZVAL ( myobject ) ;
object_init ( myobject ) ;
add_property_string ( myobject , " charset " , " default " , 1 ) ;
add_property_string ( myobject , " text " , text , 1 ) ;
zend_hash_next_index_insert ( Z_ARRVAL_P ( return_value ) , ( void * ) & myobject , sizeof ( zval * ) , NULL ) ;
}
if ( ( encoding_token = ( long ) php_memnstr ( & string [ charset_token + 2 ] , " ? " , 1 , string + end ) ) ) { /* Find token for encoding */
encoding_token - = ( long ) string ;
if ( ( end_token = ( long ) php_memnstr ( & string [ encoding_token + 3 ] , " ?= " , 2 , string + end ) ) ) { /* Find token for end of encoded data */
end_token - = ( long ) string ;
memcpy ( charset , & string [ charset_token + 2 ] , encoding_token - ( charset_token + 2 ) ) ; /* Extract charset encoding */
charset [ encoding_token - ( charset_token + 2 ) ] = 0x00 ;
encoding = string [ encoding_token + 1 ] ; /* Extract encoding from string */
memcpy ( text , & string [ encoding_token + 3 ] , end_token - ( encoding_token + 3 ) ) ; /* Extract text */
text [ end_token - ( encoding_token + 3 ) ] = 0x00 ;
decode = text ;
if ( encoding = = ' q ' | | encoding = = ' Q ' ) { /* Decode 'q' encoded data */
for ( i = 0 ; text [ i ] ! = 0x00 ; i + + ) if ( text [ i ] = = ' _ ' ) text [ i ] = ' ' ; /* Replace all *_' with space. */
decode = ( char * ) rfc822_qprint ( ( unsigned char * ) text , strlen ( text ) , & newlength ) ;
} else if ( encoding = = ' b ' | | encoding = = ' B ' ) {
decode = ( char * ) rfc822_base64 ( ( unsigned char * ) text , strlen ( text ) , & newlength ) ; /* Decode 'B' encoded data */
}
if ( decode = = NULL ) {
efree ( charset ) ;
zval_dtor ( return_value ) ;
RETURN_FALSE ;
}
2000-04-04 08:51:38 +08:00
MAKE_STD_ZVAL ( myobject ) ;
object_init ( myobject ) ;
2003-01-21 03:41:58 +08:00
add_property_string ( myobject , " charset " , charset , 1 ) ;
add_property_string ( myobject , " text " , decode , 1 ) ;
2001-09-26 05:58:48 +08:00
zend_hash_next_index_insert ( Z_ARRVAL_P ( return_value ) , ( void * ) & myobject , sizeof ( zval * ) , NULL ) ;
2004-01-15 08:35:04 +08:00
/* only free decode if it was allocated by rfc822_qprint or rfc822_base64 */
if ( decode ! = text ) {
fs_give ( ( void * * ) & decode ) ;
}
2003-01-21 03:41:58 +08:00
offset = end_token + 2 ;
for ( i = 0 ; ( string [ offset + i ] = = ' ' ) | | ( string [ offset + i ] = = 0x0a ) | | ( string [ offset + i ] = = 0x0d ) ; i + + ) ;
if ( ( string [ offset + i ] = = ' = ' ) & & ( string [ offset + i + 1 ] = = ' ? ' ) & & ( offset + i < end ) ) {
offset + = i ;
2000-04-04 08:51:38 +08:00
}
2003-01-21 03:41:58 +08:00
continue ; /*/ Iterate the loop again please. */
2000-04-04 08:51:38 +08:00
}
}
2003-01-21 03:41:58 +08:00
} else {
/* Just some tweaking to optimize the code, and get the end statements work in a general manner.
* If we end up here we didn ' t find a position for " charset_token " ,
* so we need to set it to the start of the yet unextracted data .
*/
charset_token = offset ;
2000-04-04 08:51:38 +08:00
}
2003-01-21 03:41:58 +08:00
/* Return the rest of the data as unencoded, as it was either unencoded or was missing separators
which rendered the the remainder of the string impossible for us to decode . */
memcpy ( text , & string [ charset_token ] , end - charset_token ) ; /* Extract unencoded text from string */
text [ end - charset_token ] = 0x00 ;
MAKE_STD_ZVAL ( myobject ) ;
object_init ( myobject ) ;
add_property_string ( myobject , " charset " , " default " , 1 ) ;
add_property_string ( myobject , " text " , text , 1 ) ;
zend_hash_next_index_insert ( Z_ARRVAL_P ( return_value ) , ( void * ) & myobject , sizeof ( zval * ) , NULL ) ;
offset = end ; /* We have reached the end of the string. */
2000-04-04 08:51:38 +08:00
}
2003-01-21 03:41:58 +08:00
efree ( charset ) ;
2000-04-04 08:51:38 +08:00
}
/* }}} */
2003-02-12 06:57:22 +08:00
/* {{{ _php_rfc822_len
* Calculate string length based on imap ' s rfc822_cat function .
*/
static int _php_rfc822_len ( char * str )
{
int len ;
char * p ;
if ( ! str | | ! * str ) {
return 0 ;
}
/* strings with special characters will need to be quoted, as a safety measure we
* add 2 bytes for the quotes just in case .
*/
len = strlen ( str ) + 2 ;
p = str ;
/* rfc822_cat() will escape all " and \ characters, therefor we need to increase
* our buffer length to account for these characters .
*/
while ( ( p = strpbrk ( p , " \\ \" " ) ) ) {
p + + ;
len + + ;
}
return len ;
}
/* }}} */
2000-04-02 00:49:39 +08:00
/* Support Functions */
2002-06-28 06:16:53 +08:00
/* {{{ _php_imap_get_address_size
*/
static int _php_imap_address_size ( ADDRESS * addresslist )
{
ADDRESS * tmp ;
2002-10-09 04:07:52 +08:00
int ret = 0 , num_ent = 0 ;
2002-06-28 06:16:53 +08:00
tmp = addresslist ;
if ( tmp ) do {
2003-02-12 06:57:22 +08:00
ret + = _php_rfc822_len ( tmp - > personal ) ;
ret + = _php_rfc822_len ( tmp - > adl ) ;
ret + = _php_rfc822_len ( tmp - > mailbox ) ;
ret + = _php_rfc822_len ( tmp - > host ) ;
2002-10-09 04:07:52 +08:00
num_ent + + ;
2002-06-28 06:16:53 +08:00
} while ( ( tmp = tmp - > next ) ) ;
2002-10-09 04:07:52 +08:00
/*
* rfc822_write_address_full ( ) needs some extra space for ' < > , ' , etc .
* for this perpouse we allocate additional PHP_IMAP_ADDRESS_SIZE_BUF bytes
* by default this buffer is 10 bytes long
*/
ret + = ( ret ) ? num_ent * PHP_IMAP_ADDRESS_SIZE_BUF : 0 ;
2002-06-28 06:16:53 +08:00
return ret ;
}
/* }}} */
2001-06-06 21:06:12 +08:00
/* {{{ _php_imap_parse_address
*/
2002-06-28 06:16:53 +08:00
static void _php_imap_parse_address ( ADDRESS * addresslist , char * * fulladdress , zval * paddress TSRMLS_DC )
2000-04-02 00:49:39 +08:00
{
2002-06-28 06:16:53 +08:00
ADDRESS * addresstmp ;
2000-04-20 22:23:35 +08:00
zval * tmpvals ;
2002-06-28 06:16:53 +08:00
char * tmpstr ;
int len = 0 ;
2000-04-02 00:49:39 +08:00
addresstmp = addresslist ;
2002-06-28 06:16:53 +08:00
if ( ( len = _php_imap_address_size ( addresstmp ) ) ) {
2007-03-12 02:42:19 +08:00
tmpstr = ( char * ) pemalloc ( len + 1 , 1 ) ;
2002-06-28 06:16:53 +08:00
tmpstr [ 0 ] = ' \0 ' ;
rfc822_write_address ( tmpstr , addresstmp ) ;
* fulladdress = tmpstr ;
2003-04-16 08:58:30 +08:00
} else {
* fulladdress = NULL ;
2000-04-02 00:49:39 +08:00
}
addresstmp = addresslist ;
do {
MAKE_STD_ZVAL ( tmpvals ) ;
object_init ( tmpvals ) ;
if ( addresstmp - > personal ) add_property_string ( tmpvals , " personal " , addresstmp - > personal , 1 ) ;
if ( addresstmp - > adl ) add_property_string ( tmpvals , " adl " , addresstmp - > adl , 1 ) ;
if ( addresstmp - > mailbox ) add_property_string ( tmpvals , " mailbox " , addresstmp - > mailbox , 1 ) ;
if ( addresstmp - > host ) add_property_string ( tmpvals , " host " , addresstmp - > host , 1 ) ;
2003-01-05 04:06:32 +08:00
add_next_index_object ( paddress , tmpvals TSRMLS_CC ) ;
2000-04-02 00:49:39 +08:00
} while ( ( addresstmp = addresstmp - > next ) ) ;
}
2001-06-06 21:06:12 +08:00
/* }}} */
2000-04-02 00:49:39 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ _php_make_header_object
*/
2001-08-08 01:40:10 +08:00
static void _php_make_header_object ( zval * myzvalue , ENVELOPE * en TSRMLS_DC )
2000-04-02 00:49:39 +08:00
{
zval * paddress ;
2002-06-28 06:16:53 +08:00
char * fulladdress = NULL ;
2000-04-02 00:49:39 +08:00
object_init ( myzvalue ) ;
2001-08-08 00:18:05 +08:00
if ( en - > remail ) add_property_string ( myzvalue , " remail " , en - > remail , 1 ) ;
if ( en - > date ) add_property_string ( myzvalue , " date " , en - > date , 1 ) ;
if ( en - > date ) add_property_string ( myzvalue , " Date " , en - > date , 1 ) ;
if ( en - > subject ) add_property_string ( myzvalue , " subject " , en - > subject , 1 ) ;
if ( en - > subject ) add_property_string ( myzvalue , " Subject " , en - > subject , 1 ) ;
if ( en - > in_reply_to ) add_property_string ( myzvalue , " in_reply_to " , en - > in_reply_to , 1 ) ;
if ( en - > message_id ) add_property_string ( myzvalue , " message_id " , en - > message_id , 1 ) ;
if ( en - > newsgroups ) add_property_string ( myzvalue , " newsgroups " , en - > newsgroups , 1 ) ;
if ( en - > followup_to ) add_property_string ( myzvalue , " followup_to " , en - > followup_to , 1 ) ;
if ( en - > references ) add_property_string ( myzvalue , " references " , en - > references , 1 ) ;
2000-04-02 00:49:39 +08:00
if ( en - > to ) {
MAKE_STD_ZVAL ( paddress ) ;
array_init ( paddress ) ;
2002-06-28 06:16:53 +08:00
_php_imap_parse_address ( en - > to , & fulladdress , paddress TSRMLS_CC ) ;
if ( fulladdress ) {
add_property_string ( myzvalue , " toaddress " , fulladdress , 1 ) ;
free ( fulladdress ) ;
}
2003-01-05 04:06:32 +08:00
add_assoc_object ( myzvalue , " to " , paddress TSRMLS_CC ) ;
2000-04-02 00:49:39 +08:00
}
if ( en - > from ) {
MAKE_STD_ZVAL ( paddress ) ;
array_init ( paddress ) ;
2002-06-28 06:16:53 +08:00
_php_imap_parse_address ( en - > from , & fulladdress , paddress TSRMLS_CC ) ;
if ( fulladdress ) {
add_property_string ( myzvalue , " fromaddress " , fulladdress , 1 ) ;
free ( fulladdress ) ;
}
2003-01-05 04:06:32 +08:00
add_assoc_object ( myzvalue , " from " , paddress TSRMLS_CC ) ;
2000-04-02 00:49:39 +08:00
}
if ( en - > cc ) {
MAKE_STD_ZVAL ( paddress ) ;
array_init ( paddress ) ;
2002-06-28 06:16:53 +08:00
_php_imap_parse_address ( en - > cc , & fulladdress , paddress TSRMLS_CC ) ;
if ( fulladdress ) {
add_property_string ( myzvalue , " ccaddress " , fulladdress , 1 ) ;
free ( fulladdress ) ;
}
2003-01-05 04:06:32 +08:00
add_assoc_object ( myzvalue , " cc " , paddress TSRMLS_CC ) ;
2000-04-02 00:49:39 +08:00
}
if ( en - > bcc ) {
MAKE_STD_ZVAL ( paddress ) ;
array_init ( paddress ) ;
2002-06-28 06:16:53 +08:00
_php_imap_parse_address ( en - > bcc , & fulladdress , paddress TSRMLS_CC ) ;
if ( fulladdress ) {
add_property_string ( myzvalue , " bccaddress " , fulladdress , 1 ) ;
free ( fulladdress ) ;
}
2003-01-05 04:06:32 +08:00
add_assoc_object ( myzvalue , " bcc " , paddress TSRMLS_CC ) ;
2000-04-02 00:49:39 +08:00
}
if ( en - > reply_to ) {
MAKE_STD_ZVAL ( paddress ) ;
array_init ( paddress ) ;
2002-06-28 06:16:53 +08:00
_php_imap_parse_address ( en - > reply_to , & fulladdress , paddress TSRMLS_CC ) ;
if ( fulladdress ) {
add_property_string ( myzvalue , " reply_toaddress " , fulladdress , 1 ) ;
free ( fulladdress ) ;
}
2003-01-05 04:06:32 +08:00
add_assoc_object ( myzvalue , " reply_to " , paddress TSRMLS_CC ) ;
2000-04-02 00:49:39 +08:00
}
if ( en - > sender ) {
MAKE_STD_ZVAL ( paddress ) ;
array_init ( paddress ) ;
2002-06-28 06:16:53 +08:00
_php_imap_parse_address ( en - > sender , & fulladdress , paddress TSRMLS_CC ) ;
if ( fulladdress ) {
add_property_string ( myzvalue , " senderaddress " , fulladdress , 1 ) ;
free ( fulladdress ) ;
}
2003-01-05 04:06:32 +08:00
add_assoc_object ( myzvalue , " sender " , paddress TSRMLS_CC ) ;
2000-04-02 00:49:39 +08:00
}
if ( en - > return_path ) {
MAKE_STD_ZVAL ( paddress ) ;
array_init ( paddress ) ;
2002-06-28 06:16:53 +08:00
_php_imap_parse_address ( en - > return_path , & fulladdress , paddress TSRMLS_CC ) ;
if ( fulladdress ) {
add_property_string ( myzvalue , " return_pathaddress " , fulladdress , 1 ) ;
free ( fulladdress ) ;
}
2003-01-05 04:06:32 +08:00
add_assoc_object ( myzvalue , " return_path " , paddress TSRMLS_CC ) ;
2000-04-02 00:49:39 +08:00
}
}
2001-06-06 21:06:12 +08:00
/* }}} */
2000-04-02 00:49:39 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ _php_imap_add_body
*/
2001-08-08 01:40:10 +08:00
void _php_imap_add_body ( zval * arg , BODY * body TSRMLS_DC )
2000-04-02 00:49:39 +08:00
{
2000-04-20 22:23:35 +08:00
zval * parametres , * param , * dparametres , * dparam ;
2000-04-02 00:49:39 +08:00
PARAMETER * par , * dpar ;
PART * part ;
2002-06-27 09:47:36 +08:00
if ( body - > type < = TYPEMAX ) {
add_property_long ( arg , " type " , body - > type ) ;
2000-04-19 03:42:22 +08:00
}
2001-08-08 10:55:07 +08:00
2001-05-15 02:24:27 +08:00
if ( body - > encoding < = ENCMAX ) {
2000-04-19 03:42:22 +08:00
add_property_long ( arg , " encoding " , body - > encoding ) ;
}
2000-04-02 00:49:39 +08:00
2000-04-19 03:42:22 +08:00
if ( body - > subtype ) {
add_property_long ( arg , " ifsubtype " , 1 ) ;
add_property_string ( arg , " subtype " , body - > subtype , 1 ) ;
2000-04-02 00:49:39 +08:00
} else {
2000-04-19 03:42:22 +08:00
add_property_long ( arg , " ifsubtype " , 0 ) ;
2000-04-02 00:49:39 +08:00
}
2000-04-19 03:42:22 +08:00
if ( body - > description ) {
add_property_long ( arg , " ifdescription " , 1 ) ;
add_property_string ( arg , " description " , body - > description , 1 ) ;
2000-04-02 00:49:39 +08:00
} else {
2000-04-19 03:42:22 +08:00
add_property_long ( arg , " ifdescription " , 0 ) ;
2000-04-02 00:49:39 +08:00
}
2001-08-08 10:55:07 +08:00
2000-04-19 03:42:22 +08:00
if ( body - > id ) {
add_property_long ( arg , " ifid " , 1 ) ;
add_property_string ( arg , " id " , body - > id , 1 ) ;
2000-04-02 00:49:39 +08:00
} else {
2000-04-19 03:42:22 +08:00
add_property_long ( arg , " ifid " , 0 ) ;
2000-04-02 00:49:39 +08:00
}
2000-04-19 03:42:22 +08:00
if ( body - > size . lines ) {
add_property_long ( arg , " lines " , body - > size . lines ) ;
}
2001-08-08 10:55:07 +08:00
2000-04-19 03:42:22 +08:00
if ( body - > size . bytes ) {
add_property_long ( arg , " bytes " , body - > size . bytes ) ;
}
2001-08-08 10:55:07 +08:00
2000-04-02 00:49:39 +08:00
# ifdef IMAP41
2002-06-27 09:47:36 +08:00
if ( body - > disposition . type ) {
2000-04-19 03:42:22 +08:00
add_property_long ( arg , " ifdisposition " , 1 ) ;
2002-06-27 09:47:36 +08:00
add_property_string ( arg , " disposition " , body - > disposition . type , 1 ) ;
2000-04-02 00:49:39 +08:00
} else {
2000-04-19 03:42:22 +08:00
add_property_long ( arg , " ifdisposition " , 0 ) ;
2000-04-02 00:49:39 +08:00
}
if ( body - > disposition . parameter ) {
dpar = body - > disposition . parameter ;
2000-04-19 03:42:22 +08:00
add_property_long ( arg , " ifdparameters " , 1 ) ;
2000-04-02 00:49:39 +08:00
MAKE_STD_ZVAL ( dparametres ) ;
array_init ( dparametres ) ;
do {
MAKE_STD_ZVAL ( dparam ) ;
object_init ( dparam ) ;
add_property_string ( dparam , " attribute " , dpar - > attribute , 1 ) ;
add_property_string ( dparam , " value " , dpar - > value , 1 ) ;
2003-01-05 04:06:32 +08:00
add_next_index_object ( dparametres , dparam TSRMLS_CC ) ;
2002-08-17 07:25:53 +08:00
} while ( ( dpar = dpar - > next ) ) ;
2003-01-05 04:06:32 +08:00
add_assoc_object ( arg , " dparameters " , dparametres TSRMLS_CC ) ;
2000-04-02 00:49:39 +08:00
} else {
2000-04-19 03:42:22 +08:00
add_property_long ( arg , " ifdparameters " , 0 ) ;
2000-04-02 00:49:39 +08:00
}
# endif
if ( ( par = body - > parameter ) ) {
2000-04-19 03:42:22 +08:00
add_property_long ( arg , " ifparameters " , 1 ) ;
2000-04-02 00:49:39 +08:00
MAKE_STD_ZVAL ( parametres ) ;
array_init ( parametres ) ;
do {
MAKE_STD_ZVAL ( param ) ;
object_init ( param ) ;
2000-04-19 03:42:22 +08:00
if ( par - > attribute ) {
add_property_string ( param , " attribute " , par - > attribute , 1 ) ;
}
if ( par - > value ) {
add_property_string ( param , " value " , par - > value , 1 ) ;
}
2000-04-02 00:49:39 +08:00
2003-01-05 04:06:32 +08:00
add_next_index_object ( parametres , param TSRMLS_CC ) ;
2000-04-19 03:42:22 +08:00
} while ( ( par = par - > next ) ) ;
2000-04-02 00:49:39 +08:00
} else {
MAKE_STD_ZVAL ( parametres ) ;
object_init ( parametres ) ;
2000-04-19 03:42:22 +08:00
add_property_long ( arg , " ifparameters " , 0 ) ;
2000-04-02 00:49:39 +08:00
}
2003-01-05 04:06:32 +08:00
add_assoc_object ( arg , " parameters " , parametres TSRMLS_CC ) ;
2000-04-02 00:49:39 +08:00
/* multipart message ? */
2002-06-27 09:47:36 +08:00
if ( body - > type = = TYPEMULTIPART ) {
2000-04-02 00:49:39 +08:00
MAKE_STD_ZVAL ( parametres ) ;
array_init ( parametres ) ;
for ( part = body - > CONTENT_PART ; part ; part = part - > next ) {
MAKE_STD_ZVAL ( param ) ;
object_init ( param ) ;
2001-08-08 01:40:10 +08:00
_php_imap_add_body ( param , & part - > body TSRMLS_CC ) ;
2003-01-05 04:06:32 +08:00
add_next_index_object ( parametres , param TSRMLS_CC ) ;
2000-04-02 00:49:39 +08:00
}
2003-01-05 04:06:32 +08:00
add_assoc_object ( arg , " parts " , parametres TSRMLS_CC ) ;
2000-04-02 00:49:39 +08:00
}
/* encapsulated message ? */
2002-06-27 09:47:36 +08:00
if ( ( body - > type = = TYPEMESSAGE ) & & ( ! strcasecmp ( body - > subtype , " rfc822 " ) ) ) {
2000-04-02 00:49:39 +08:00
body = body - > CONTENT_MSG_BODY ;
MAKE_STD_ZVAL ( parametres ) ;
array_init ( parametres ) ;
MAKE_STD_ZVAL ( param ) ;
object_init ( param ) ;
2001-08-08 01:40:10 +08:00
_php_imap_add_body ( param , body TSRMLS_CC ) ;
2003-01-05 04:06:32 +08:00
add_next_index_object ( parametres , param TSRMLS_CC ) ;
add_assoc_object ( arg , " parts " , parametres TSRMLS_CC ) ;
2000-04-02 00:49:39 +08:00
}
}
2001-06-06 21:06:12 +08:00
/* }}} */
2000-04-02 00:49:39 +08:00
2001-08-08 00:18:05 +08:00
/* imap_thread, stealing this from header cclient -rjs3 */
/* {{{ build_thread_tree_helper
*/
static void build_thread_tree_helper ( THREADNODE * cur , zval * tree , long * numNodes , char * buf )
{
unsigned long thisNode = * numNodes ;
/* define "#.num" */
2001-08-12 00:39:07 +08:00
snprintf ( buf , 25 , " %ld.num " , thisNode ) ;
2001-08-08 00:18:05 +08:00
2001-08-12 00:39:07 +08:00
add_assoc_long ( tree , buf , cur - > num ) ;
2001-08-08 00:18:05 +08:00
2001-08-12 00:39:07 +08:00
snprintf ( buf , 25 , " %ld.next " , thisNode ) ;
2001-08-08 00:18:05 +08:00
if ( cur - > next ) {
2002-08-17 07:25:53 +08:00
( * numNodes ) + + ;
add_assoc_long ( tree , buf , * numNodes ) ;
build_thread_tree_helper ( cur - > next , tree , numNodes , buf ) ;
2001-08-08 00:18:05 +08:00
} else { /* "null pointer" */
2002-08-17 07:25:53 +08:00
add_assoc_long ( tree , buf , 0 ) ;
2001-08-08 00:18:05 +08:00
}
2001-08-12 00:39:07 +08:00
snprintf ( buf , 25 , " %ld.branch " , thisNode ) ;
2001-08-08 00:18:05 +08:00
if ( cur - > branch ) {
2002-08-17 07:25:53 +08:00
( * numNodes ) + + ;
add_assoc_long ( tree , buf , * numNodes ) ;
build_thread_tree_helper ( cur - > branch , tree , numNodes , buf ) ;
2001-08-08 00:18:05 +08:00
} else { /* "null pointer" */
2002-08-17 07:25:53 +08:00
add_assoc_long ( tree , buf , 0 ) ;
2001-08-08 00:18:05 +08:00
}
}
/* }}} */
/* {{{ build_thread_tree
*/
static int build_thread_tree ( THREADNODE * top , zval * * tree )
{
long numNodes = 0 ;
char buf [ 25 ] ;
2003-01-18 00:07:39 +08:00
array_init ( * tree ) ;
2001-08-08 00:18:05 +08:00
build_thread_tree_helper ( top , * tree , & numNodes , buf ) ;
return SUCCESS ;
}
/* }}} */
2002-10-09 17:20:46 +08:00
/* {{{ proto array imap_thread(resource stream_id [, int options])
2001-08-08 00:18:05 +08:00
Return threaded by REFERENCES tree */
2003-06-13 23:01:18 +08:00
PHP_FUNCTION ( imap_thread )
2001-08-08 00:18:05 +08:00
{
2001-08-08 10:55:07 +08:00
zval * * streamind , * * search_flags ;
2001-08-08 00:18:05 +08:00
pils * imap_le_struct ;
long flags ;
char criteria [ ] = " ALL " ;
THREADNODE * top ;
2001-08-08 10:55:07 +08:00
int argc = ZEND_NUM_ARGS ( ) ;
2001-08-08 00:18:05 +08:00
2001-08-08 10:55:07 +08:00
if ( argc < 1 | | argc > 2 | | zend_get_parameters_ex ( argc , & streamind , & search_flags ) = = FAILURE ) {
2001-08-08 00:18:05 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
}
2001-08-08 10:55:07 +08:00
ZEND_FETCH_RESOURCE ( imap_le_struct , pils * , streamind , - 1 , " imap " , le_imap ) ;
2001-08-08 00:18:05 +08:00
2001-08-08 10:55:07 +08:00
if ( argc = = 1 ) {
2001-08-08 00:18:05 +08:00
flags = SE_FREE ;
} else {
2001-08-08 10:55:07 +08:00
convert_to_long_ex ( search_flags ) ;
flags = Z_LVAL_PP ( search_flags ) ;
2001-08-08 00:18:05 +08:00
}
top = mail_thread ( imap_le_struct - > imap_stream , " REFERENCES " , NIL , mail_criteria ( criteria ) , flags ) ;
if ( top = = NIL ) {
2003-01-21 03:41:58 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Function returned an empty tree " ) ;
2001-08-08 00:18:05 +08:00
RETURN_FALSE ;
}
/* Populate our return value data structure here. */
2001-08-08 10:55:07 +08:00
if ( build_thread_tree ( top , & return_value ) = = FAILURE ) {
2002-08-17 07:25:53 +08:00
mail_free_threadnode ( & top ) ;
2001-08-08 10:55:07 +08:00
RETURN_FALSE ;
2001-08-08 00:18:05 +08:00
}
mail_free_threadnode ( & top ) ;
}
/* }}} */
2003-06-13 22:56:07 +08:00
/* {{{ proto mixed imap_timeout(int timeout_type [, int timeout])
Set or fetch imap timeout */
2003-06-13 23:01:18 +08:00
PHP_FUNCTION ( imap_timeout )
2003-06-13 22:39:22 +08:00
{
long ttype , timeout = - 1 ;
int timeout_type ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " l|l " , & ttype , & timeout ) = = FAILURE ) {
RETURN_FALSE ;
}
if ( timeout = = - 1 ) {
switch ( ttype ) {
case 1 :
timeout_type = GET_OPENTIMEOUT ;
break ;
case 2 :
timeout_type = GET_READTIMEOUT ;
break ;
case 3 :
timeout_type = GET_WRITETIMEOUT ;
break ;
case 4 :
timeout_type = GET_CLOSETIMEOUT ;
break ;
default :
RETURN_FALSE ;
break ;
}
timeout = ( long ) mail_parameters ( NIL , timeout_type , NIL ) ;
RETURN_LONG ( timeout ) ;
} else if ( timeout > = 0 ) {
switch ( ttype ) {
case 1 :
timeout_type = SET_OPENTIMEOUT ;
break ;
case 2 :
timeout_type = SET_READTIMEOUT ;
break ;
case 3 :
timeout_type = SET_WRITETIMEOUT ;
break ;
case 4 :
timeout_type = SET_CLOSETIMEOUT ;
break ;
default :
RETURN_FALSE ;
break ;
}
timeout = ( long ) mail_parameters ( NIL , timeout_type , ( void * ) timeout ) ;
RETURN_TRUE ;
} else {
RETURN_FALSE ;
}
}
2003-06-13 22:56:07 +08:00
/* }}} */
2001-08-08 00:18:05 +08:00
2006-01-28 03:46:11 +08:00
# define GETS_FETCH_SIZE 8196LU
/* {{{ php_mail_gets */
static char * php_mail_gets ( readfn_t f , void * stream , unsigned long size , GETS_DATA * md )
{
TSRMLS_FETCH ( ) ;
/* write to the gets stream if it is set,
otherwise forward to c - clients gets */
if ( IMAPG ( gets_stream ) ) {
char buf [ GETS_FETCH_SIZE ] ;
while ( size ) {
unsigned long read ;
if ( size > GETS_FETCH_SIZE ) {
read = GETS_FETCH_SIZE ;
size - = GETS_FETCH_SIZE ;
} else {
read = size ;
size = 0 ;
}
if ( ! f ( stream , read , buf ) ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Failed to read from socket " ) ;
break ;
} else if ( read ! = php_stream_write ( IMAPG ( gets_stream ) , buf , read ) ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Failed to write to stream " ) ;
break ;
}
}
return NULL ;
} else {
2007-03-12 02:42:19 +08:00
char * buf = pemalloc ( size + 1 , 1 ) ;
2006-01-28 04:18:03 +08:00
if ( f ( stream , size , buf ) ) {
buf [ size ] = ' \0 ' ;
} else {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Failed to read from socket " ) ;
2006-01-28 16:07:20 +08:00
free ( buf ) ;
2006-01-28 04:18:03 +08:00
buf = NULL ;
}
return buf ;
2006-01-28 03:46:11 +08:00
}
}
/* }}} */
2001-08-08 00:18:05 +08:00
/* {{{ Interfaces to C-client
*/
2008-02-01 02:46:03 +08:00
PHP_IMAP_EXPORT void mm_searched ( MAILSTREAM * stream , unsigned long number )
2000-04-02 00:49:39 +08:00
{
MESSAGELIST * cur = NIL ;
2001-07-28 19:36:37 +08:00
TSRMLS_FETCH ( ) ;
2001-08-17 04:13:27 +08:00
2000-04-02 00:49:39 +08:00
if ( IMAPG ( imap_messages ) = = NIL ) {
IMAPG ( imap_messages ) = mail_newmessagelist ( ) ;
IMAPG ( imap_messages ) - > msgid = number ;
IMAPG ( imap_messages ) - > next = NIL ;
2001-08-17 04:13:27 +08:00
IMAPG ( imap_messages_tail ) = IMAPG ( imap_messages ) ;
2000-04-02 00:49:39 +08:00
} else {
2001-08-17 04:13:27 +08:00
cur = IMAPG ( imap_messages_tail ) ;
2000-04-02 00:49:39 +08:00
cur - > next = mail_newmessagelist ( ) ;
cur = cur - > next ;
cur - > msgid = number ;
cur - > next = NIL ;
2001-08-17 04:13:27 +08:00
IMAPG ( imap_messages_tail ) = cur ;
2000-04-02 00:49:39 +08:00
}
}
2008-02-01 02:46:03 +08:00
PHP_IMAP_EXPORT void mm_exists ( MAILSTREAM * stream , unsigned long number )
2000-04-02 00:49:39 +08:00
{
}
2008-02-01 02:46:03 +08:00
PHP_IMAP_EXPORT void mm_expunged ( MAILSTREAM * stream , unsigned long number )
2000-04-02 00:49:39 +08:00
{
}
2008-02-01 02:46:03 +08:00
PHP_IMAP_EXPORT void mm_flags ( MAILSTREAM * stream , unsigned long number )
2000-04-02 00:49:39 +08:00
{
}
/* Author: CJH */
2008-02-01 02:46:03 +08:00
PHP_IMAP_EXPORT void mm_notify ( MAILSTREAM * stream , char * str , long errflg )
2000-04-02 00:49:39 +08:00
{
STRINGLIST * cur = NIL ;
2001-07-28 19:36:37 +08:00
TSRMLS_FETCH ( ) ;
2000-04-02 00:49:39 +08:00
if ( strncmp ( str , " [ALERT] " , 8 ) = = 0 ) {
if ( IMAPG ( imap_alertstack ) = = NIL ) {
IMAPG ( imap_alertstack ) = mail_newstringlist ( ) ;
IMAPG ( imap_alertstack ) - > LSIZE = strlen ( IMAPG ( imap_alertstack ) - > LTEXT = cpystr ( str ) ) ;
IMAPG ( imap_alertstack ) - > next = NIL ;
} else {
cur = IMAPG ( imap_alertstack ) ;
2000-04-19 03:42:22 +08:00
while ( cur - > next ! = NIL ) {
2000-04-02 00:49:39 +08:00
cur = cur - > next ;
}
cur - > next = mail_newstringlist ( ) ;
cur = cur - > next ;
cur - > LSIZE = strlen ( cur - > LTEXT = cpystr ( str ) ) ;
cur - > next = NIL ;
}
}
}
2008-02-01 02:46:03 +08:00
PHP_IMAP_EXPORT void mm_list ( MAILSTREAM * stream , DTYPE delimiter , char * mailbox , long attributes )
2000-04-02 00:49:39 +08:00
{
STRINGLIST * cur = NIL ;
FOBJECTLIST * ocur = NIL ;
2001-07-28 19:36:37 +08:00
TSRMLS_FETCH ( ) ;
2000-04-02 00:49:39 +08:00
if ( IMAPG ( folderlist_style ) = = FLIST_OBJECT ) {
/* build up a the new array of objects */
/* Author: CJH */
if ( IMAPG ( imap_folder_objects ) = = NIL ) {
IMAPG ( imap_folder_objects ) = mail_newfolderobjectlist ( ) ;
IMAPG ( imap_folder_objects ) - > LSIZE = strlen ( IMAPG ( imap_folder_objects ) - > LTEXT = cpystr ( mailbox ) ) ;
IMAPG ( imap_folder_objects ) - > delimiter = delimiter ;
IMAPG ( imap_folder_objects ) - > attributes = attributes ;
IMAPG ( imap_folder_objects ) - > next = NIL ;
2002-05-13 04:53:25 +08:00
IMAPG ( imap_folder_objects_tail ) = IMAPG ( imap_folder_objects ) ;
2000-04-02 00:49:39 +08:00
} else {
2002-05-13 04:53:25 +08:00
ocur = IMAPG ( imap_folder_objects_tail ) ;
2000-04-02 00:49:39 +08:00
ocur - > next = mail_newfolderobjectlist ( ) ;
ocur = ocur - > next ;
ocur - > LSIZE = strlen ( ocur - > LTEXT = cpystr ( mailbox ) ) ;
ocur - > delimiter = delimiter ;
ocur - > attributes = attributes ;
ocur - > next = NIL ;
2002-05-13 04:53:25 +08:00
IMAPG ( imap_folder_objects_tail ) = ocur ;
2000-04-02 00:49:39 +08:00
}
} else {
/* build the old IMAPG(imap_folders) variable to allow old imap_listmailbox() to work */
if ( ! ( attributes & LATT_NOSELECT ) ) {
if ( IMAPG ( imap_folders ) = = NIL ) {
IMAPG ( imap_folders ) = mail_newstringlist ( ) ;
IMAPG ( imap_folders ) - > LSIZE = strlen ( IMAPG ( imap_folders ) - > LTEXT = cpystr ( mailbox ) ) ;
IMAPG ( imap_folders ) - > next = NIL ;
2002-05-13 04:53:25 +08:00
IMAPG ( imap_folders_tail ) = IMAPG ( imap_folders ) ;
2000-04-02 00:49:39 +08:00
} else {
2002-05-13 04:53:25 +08:00
cur = IMAPG ( imap_folders_tail ) ;
2000-04-02 00:49:39 +08:00
cur - > next = mail_newstringlist ( ) ;
cur = cur - > next ;
cur - > LSIZE = strlen ( cur - > LTEXT = cpystr ( mailbox ) ) ;
cur - > next = NIL ;
2002-05-13 04:53:25 +08:00
IMAPG ( imap_folders_tail ) = cur ;
2000-04-02 00:49:39 +08:00
}
}
}
}
2008-02-01 02:46:03 +08:00
PHP_IMAP_EXPORT void mm_lsub ( MAILSTREAM * stream , DTYPE delimiter , char * mailbox , long attributes )
2000-04-02 00:49:39 +08:00
{
STRINGLIST * cur = NIL ;
FOBJECTLIST * ocur = NIL ;
2001-07-28 19:36:37 +08:00
TSRMLS_FETCH ( ) ;
2000-04-02 00:49:39 +08:00
if ( IMAPG ( folderlist_style ) = = FLIST_OBJECT ) {
/* build the array of objects */
/* Author: CJH */
if ( IMAPG ( imap_sfolder_objects ) = = NIL ) {
IMAPG ( imap_sfolder_objects ) = mail_newfolderobjectlist ( ) ;
IMAPG ( imap_sfolder_objects ) - > LSIZE = strlen ( IMAPG ( imap_sfolder_objects ) - > LTEXT = cpystr ( mailbox ) ) ;
IMAPG ( imap_sfolder_objects ) - > delimiter = delimiter ;
IMAPG ( imap_sfolder_objects ) - > attributes = attributes ;
IMAPG ( imap_sfolder_objects ) - > next = NIL ;
2002-05-13 04:53:25 +08:00
IMAPG ( imap_sfolder_objects_tail ) = IMAPG ( imap_sfolder_objects ) ;
2000-04-02 00:49:39 +08:00
} else {
2002-05-13 04:53:25 +08:00
ocur = IMAPG ( imap_sfolder_objects_tail ) ;
2000-04-02 00:49:39 +08:00
ocur - > next = mail_newfolderobjectlist ( ) ;
ocur = ocur - > next ;
ocur - > LSIZE = strlen ( ocur - > LTEXT = cpystr ( mailbox ) ) ;
ocur - > delimiter = delimiter ;
ocur - > attributes = attributes ;
ocur - > next = NIL ;
2002-05-13 04:53:25 +08:00
IMAPG ( imap_sfolder_objects_tail ) = ocur ;
2000-04-02 00:49:39 +08:00
}
} else {
/* build the old simple array for imap_listsubscribed() */
if ( IMAPG ( imap_sfolders ) = = NIL ) {
IMAPG ( imap_sfolders ) = mail_newstringlist ( ) ;
IMAPG ( imap_sfolders ) - > LSIZE = strlen ( IMAPG ( imap_sfolders ) - > LTEXT = cpystr ( mailbox ) ) ;
IMAPG ( imap_sfolders ) - > next = NIL ;
2002-05-13 04:53:25 +08:00
IMAPG ( imap_sfolders_tail ) = IMAPG ( imap_sfolders ) ;
2000-04-02 00:49:39 +08:00
} else {
2002-05-13 04:53:25 +08:00
cur = IMAPG ( imap_sfolders_tail ) ;
2000-04-02 00:49:39 +08:00
cur - > next = mail_newstringlist ( ) ;
cur = cur - > next ;
cur - > LSIZE = strlen ( cur - > LTEXT = cpystr ( mailbox ) ) ;
cur - > next = NIL ;
2002-05-13 04:53:25 +08:00
IMAPG ( imap_sfolders_tail ) = cur ;
2000-04-02 00:49:39 +08:00
}
}
}
2008-02-01 02:46:03 +08:00
PHP_IMAP_EXPORT void mm_status ( MAILSTREAM * stream , char * mailbox , MAILSTATUS * status )
2000-04-02 00:49:39 +08:00
{
2001-07-28 19:36:37 +08:00
TSRMLS_FETCH ( ) ;
2000-04-02 00:49:39 +08:00
IMAPG ( status_flags ) = status - > flags ;
if ( IMAPG ( status_flags ) & SA_MESSAGES ) {
IMAPG ( status_messages ) = status - > messages ;
}
if ( IMAPG ( status_flags ) & SA_RECENT ) {
IMAPG ( status_recent ) = status - > recent ;
}
if ( IMAPG ( status_flags ) & SA_UNSEEN ) {
IMAPG ( status_unseen ) = status - > unseen ;
}
if ( IMAPG ( status_flags ) & SA_UIDNEXT ) {
IMAPG ( status_uidnext ) = status - > uidnext ;
}
if ( IMAPG ( status_flags ) & SA_UIDVALIDITY ) {
IMAPG ( status_uidvalidity ) = status - > uidvalidity ;
}
}
2008-02-01 02:46:03 +08:00
PHP_IMAP_EXPORT void mm_log ( char * str , long errflg )
2000-04-02 00:49:39 +08:00
{
ERRORLIST * cur = NIL ;
2001-07-28 19:36:37 +08:00
TSRMLS_FETCH ( ) ;
2000-04-02 00:49:39 +08:00
/* Author: CJH */
if ( errflg ! = NIL ) { /* CJH: maybe put these into a more comprehensive log for debugging purposes? */
if ( IMAPG ( imap_errorstack ) = = NIL ) {
IMAPG ( imap_errorstack ) = mail_newerrorlist ( ) ;
IMAPG ( imap_errorstack ) - > LSIZE = strlen ( IMAPG ( imap_errorstack ) - > LTEXT = cpystr ( str ) ) ;
IMAPG ( imap_errorstack ) - > errflg = errflg ;
IMAPG ( imap_errorstack ) - > next = NIL ;
} else {
cur = IMAPG ( imap_errorstack ) ;
2000-04-19 03:42:22 +08:00
while ( cur - > next ! = NIL ) {
2000-04-02 00:49:39 +08:00
cur = cur - > next ;
}
2000-04-19 03:42:22 +08:00
cur - > next = mail_newerrorlist ( ) ;
2000-04-02 00:49:39 +08:00
cur = cur - > next ;
cur - > LSIZE = strlen ( cur - > LTEXT = cpystr ( str ) ) ;
cur - > errflg = errflg ;
cur - > next = NIL ;
}
}
}
2008-02-01 02:46:03 +08:00
PHP_IMAP_EXPORT void mm_dlog ( char * str )
2000-04-02 00:49:39 +08:00
{
/* CJH: this is for debugging; it might be useful to allow setting
the stream to debug mode and capturing this somewhere - syslog ?
php debugger ? */
}
2008-02-01 02:46:03 +08:00
PHP_IMAP_EXPORT void mm_login ( NETMBX * mb , char * user , char * pwd , long trial )
2000-04-02 00:49:39 +08:00
{
2001-07-28 19:36:37 +08:00
TSRMLS_FETCH ( ) ;
2000-04-02 00:49:39 +08:00
2001-05-04 03:32:49 +08:00
if ( * mb - > user ) {
2001-08-12 00:39:07 +08:00
strlcpy ( user , mb - > user , MAILTMPLEN ) ;
2000-04-02 00:49:39 +08:00
} else {
2001-05-04 03:32:49 +08:00
strlcpy ( user , IMAPG ( imap_user ) , MAILTMPLEN ) ;
2000-04-02 00:49:39 +08:00
}
2001-05-04 03:32:49 +08:00
strlcpy ( pwd , IMAPG ( imap_password ) , MAILTMPLEN ) ;
2000-04-02 00:49:39 +08:00
}
2008-02-01 02:46:03 +08:00
PHP_IMAP_EXPORT void mm_critical ( MAILSTREAM * stream )
2000-04-02 00:49:39 +08:00
{
}
2008-02-01 02:46:03 +08:00
PHP_IMAP_EXPORT void mm_nocritical ( MAILSTREAM * stream )
2000-04-02 00:49:39 +08:00
{
}
2008-02-01 02:46:03 +08:00
PHP_IMAP_EXPORT long mm_diskerror ( MAILSTREAM * stream , long errcode , long serious )
2000-04-02 00:49:39 +08:00
{
return 1 ;
}
2008-02-01 02:46:03 +08:00
PHP_IMAP_EXPORT void mm_fatal ( char * str )
2000-04-02 00:49:39 +08:00
{
}
2001-05-29 23:34:18 +08:00
/* }}} */
2001-06-05 21:12:10 +08:00
2001-06-06 21:06:12 +08:00
/*
* Local variables :
* tab - width : 4
* c - basic - offset : 4
* End :
2001-09-09 21:29:31 +08:00
* vim600 : sw = 4 ts = 4 fdm = marker
* vim < 600 : sw = 4 ts = 4
2001-06-06 21:06:12 +08:00
*/