⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 php_imap.c

📁 php-4.4.7学习linux时下载的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/*   +----------------------------------------------------------------------+   | PHP Version 4                                                        |   +----------------------------------------------------------------------+   | Copyright (c) 1997-2007 The PHP Group                                |   +----------------------------------------------------------------------+   | This source file is subject to version 3.01 of the PHP license,      |   | that is bundled with this package in the file LICENSE, and is        |   | available through the world-wide-web at the following url:           |   | http://www.php.net/license/3_01.txt                                  |   | 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>                    |   |          Rasmus Lerdorf      <rasmus@php.net>                        |   |          Chuck Hagenbuch     <chuck@horde.org>                       |   |          Andrew Skalski      <askalski@chekinc.com>                  |   |          Hartmut Holzgraefe  <hholzgra@php.net>                      |   |          Jani Taskinen       <sniper@iki.fi>                         |   |          Daniel R. Kalowsky  <kalowsky@php.net>                      |   | PHP 4.0 updates:  Zeev Suraski <zeev@zend.com>                       |   +----------------------------------------------------------------------+ *//* $Id: php_imap.c,v 1.142.2.44.2.12 2007/03/22 00:08:55 edink Exp $ */#define IMAP41#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "php.h"#include "php_ini.h"#include "ext/standard/php_string.h"#include "ext/standard/info.h"#include "ext/standard/file.h"#ifdef ERROR#undef ERROR#endif#include "php_imap.h"#include <time.h>#include <stdio.h>#include <ctype.h>#include <signal.h>#ifdef PHP_WIN32#include <winsock.h>#include <stdlib.h>#include "win32/sendmail.h"MAILSTREAM DEFAULTPROTO;#endif#define CRLF	 "\015\012"#define CRLF_LEN sizeof("\015\012") - 1#define PHP_EXPUNGE 32768#define PHP_IMAP_ADDRESS_SIZE_BUF 10#ifndef SENDBUFLEN#define SENDBUFLEN 16385#endifstatic void _php_make_header_object(zval *myzvalue, ENVELOPE *en TSRMLS_DC);static void _php_imap_add_body(zval *arg, BODY *body TSRMLS_DC);static void _php_imap_parse_address(ADDRESS *addresslist, char **fulladdress, zval *paddress TSRMLS_DC);static int _php_imap_address_size(ADDRESS *addresslist);/* 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);#ifndef HAVE_NEW_MIME2TEXTlong utf8_mime2text(SIZEDTEXT *src, SIZEDTEXT *dst);#elselong utf8_mime2text (SIZEDTEXT *src, SIZEDTEXT *dst, long flags);#endifunsigned long find_rightmost_bit(unsigned long *valptr);void fs_give(void **block);void *fs_get(size_t size);/* {{{ imap_functions[] */function_entry imap_functions[] = {	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)	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)	PHP_FE(imap_utf8,								NULL)	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)	PHP_FE(imap_timeout,							NULL)#if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)	PHP_FE(imap_get_quota,							NULL)	PHP_FE(imap_get_quotaroot,						NULL)	PHP_FE(imap_set_quota,							NULL) 	PHP_FE(imap_setacl,								NULL)#endif	PHP_FE(imap_mail,								NULL)	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)	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)	{NULL, NULL, NULL}};/* }}} *//* {{{ imap_module_entry */zend_module_entry imap_module_entry = {	STANDARD_MODULE_HEADER,	"imap",	imap_functions,	PHP_MINIT(imap),	NULL,	PHP_RINIT(imap),	PHP_RSHUTDOWN(imap),	PHP_MINFO(imap),	NO_VERSION_YET,	STANDARD_MODULE_PROPERTIES};/* }}} */ZEND_DECLARE_MODULE_GLOBALS(imap)#ifdef COMPILE_DL_IMAPZEND_GET_MODULE(imap)#endif/* True globals, no need for thread safety */static int le_imap;#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;	\	}	\/* {{{ mail_close_it */static void mail_close_it(zend_rsrc_list_entry *rsrc TSRMLS_DC){	pils *imap_le_struct = (pils *)rsrc->ptr;	mail_close_full(imap_le_struct->imap_stream, imap_le_struct->flags);	if (IMAPG(imap_user)) {		efree(IMAPG(imap_user));		IMAPG(imap_user) = 0;	}	if (IMAPG(imap_password)) {		efree(IMAPG(imap_password));		IMAPG(imap_password) = 0;	}	efree(imap_le_struct);}/* }}} *//* {{{ add_assoc_object */static int add_assoc_object(zval *arg, char *key, zval *tmp){	HashTable *symtable;		if (Z_TYPE_P(arg) == IS_OBJECT) {		symtable = Z_OBJPROP_P(arg);	} else {		symtable = Z_ARRVAL_P(arg);	}	return zend_hash_update(symtable, key, strlen(key)+1, (void *) &tmp, sizeof(zval *), NULL);}/* }}} *//* {{{ add_next_index_object */static inline int add_next_index_object(zval *arg, zval *tmp){	HashTable *symtable;		if (Z_TYPE_P(arg) == IS_OBJECT) {		symtable = Z_OBJPROP_P(arg);	} else {		symtable = Z_ARRVAL_P(arg);	}	return zend_hash_next_index_insert(symtable, (void *) &tmp, sizeof(zval *), NULL); }/* }}} *//* {{{ mail_newfolderobjectlist * * Mail instantiate FOBJECTLIST * Returns: new FOBJECTLIST list * Author: CJH */FOBJECTLIST *mail_newfolderobjectlist(void){  return (FOBJECTLIST *) memset(fs_get(sizeof(FOBJECTLIST)), 0, sizeof(FOBJECTLIST));}/* }}} *//* {{{ mail_free_foblist * * Mail garbage collect FOBJECTLIST * Accepts: pointer to FOBJECTLIST pointer * Author: CJH */void mail_free_foblist(FOBJECTLIST **foblist, FOBJECTLIST **tail){	FOBJECTLIST *cur, *next;	for (cur=*foblist, next=cur->next; cur; cur=next) {		next = cur->next;		if(cur->text.data)			fs_give((void **)&(cur->text.data));		fs_give((void **)&cur);	}	*tail = NIL;	*foblist = NIL;}/* }}} *//* {{{ mail_newerrorlist * * Mail instantiate ERRORLIST * Returns: new ERRORLIST list * Author: CJH */ERRORLIST *mail_newerrorlist(void){	return (ERRORLIST *) memset(fs_get(sizeof(ERRORLIST)), 0, sizeof(ERRORLIST));}/* }}} *//* {{{ mail_free_errorlist * * Mail garbage collect FOBJECTLIST * Accepts: pointer to FOBJECTLIST pointer * Author: CJH */void mail_free_errorlist(ERRORLIST **errlist){	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 */	}}/* }}} *//* {{{ mail_newmessagelist *  * Mail instantiate MESSAGELIST * Returns: new MESSAGELIST list * Author: CJH */MESSAGELIST *mail_newmessagelist(void){	return (MESSAGELIST *) memset(fs_get(sizeof(MESSAGELIST)), 0, sizeof(MESSAGELIST));}/* }}} *//* {{{ mail_free_messagelist * * Mail garbage collect MESSAGELIST * Accepts: pointer to MESSAGELIST pointer * Author: CJH */void mail_free_messagelist(MESSAGELIST **msglist, MESSAGELIST **tail){	MESSAGELIST *cur, *next;	for (cur = *msglist, next = cur->next; cur; cur = next) {		next = cur->next;		fs_give((void **)&cur);	}	*tail = NIL;	*msglist = NIL;}/* }}} */#if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001) /* {{{ mail_getquota  * * Mail GET_QUOTA callback * Called via the mail_parameter function in c-client:src/c-client/mail.c * Author DRK */void mail_getquota(MAILSTREAM *stream, char *qroot, QUOTALIST *qlist){	zval *t_map, *return_value;	TSRMLS_FETCH();		return_value = *IMAPG(quota_return);/* put parsing code here */	for(; qlist; qlist = qlist->next) {		MAKE_STD_ZVAL(t_map);		array_init(t_map);		if (strncmp(qlist->name, "STORAGE", 7) == 0)		{			/* this is to add backwards compatibility */			add_assoc_long_ex(return_value, "usage", sizeof("usage"), qlist->usage);			add_assoc_long_ex(return_value, "limit", sizeof("limit"), qlist->limit);		}		add_assoc_long_ex(t_map, "usage", sizeof("usage"), qlist->usage);		add_assoc_long_ex(t_map, "limit", sizeof("limit"), qlist->limit);		add_assoc_zval_ex(return_value, qlist->name, strlen(qlist->name)+1, t_map);	}}/* }}} */#endif/* {{{ php_imap_init_globals */static void php_imap_init_globals(zend_imap_globals *imap_globals){	imap_globals->imap_user = NIL;	imap_globals->imap_password = NIL;	imap_globals->imap_alertstack = NIL;	imap_globals->imap_errorstack = NIL;	imap_globals->imap_folders = NIL;	imap_globals->imap_folders_tail = NIL;	imap_globals->imap_sfolders = NIL;	imap_globals->imap_sfolders_tail = NIL;	imap_globals->imap_messages = NIL;	imap_globals->imap_messages_tail = NIL;	imap_globals->imap_folder_objects = NIL;	imap_globals->imap_folder_objects_tail = NIL;	imap_globals->imap_sfolder_objects = NIL;	imap_globals->imap_sfolder_objects_tail = NIL;	imap_globals->folderlist_style = FLIST_ARRAY;#if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)	imap_globals->quota_return = NULL;#endif}/* }}} *//* {{{ PHP_MINIT_FUNCTION */PHP_MINIT_FUNCTION(imap){	unsigned long sa_all =	SA_MESSAGES | SA_RECENT | SA_UNSEEN | SA_UIDNEXT | SA_UIDVALIDITY;	ZEND_INIT_MODULE_GLOBALS(imap, php_imap_init_globals, NULL)#ifndef PHP_WIN32	mail_link(&unixdriver);		/* link in the unix driver */	mail_link(&mhdriver);		/* link in the mh driver */	/* mail_link(&mxdriver); */	/* According to c-client docs (internal.txt) this shouldn't be used. */	mail_link(&mmdfdriver);		/* link in the mmdf driver */	mail_link(&newsdriver);		/* link in the news driver */	mail_link(&philedriver);	/* link in the phile driver */#endif	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 */	mail_link(&dummydriver);	/* link in the dummy driver */#ifndef PHP_WIN32	auth_link(&auth_log);		/* link in the log authenticator */	auth_link(&auth_md5);       /* link in the cram-md5 authenticator */ #if HAVE_IMAP_KRB && defined(HAVE_IMAP_AUTH_GSS)	auth_link(&auth_gss);		/* link in the gss authenticator */#endif#endif#ifdef HAVE_IMAP_SSL

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -