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

📄 php_imap.c

📁 php-4.4.7学习linux时下载的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	/* set flag for new, improved array of objects mailbox list */	IMAPG(folderlist_style) = FLIST_OBJECT;		IMAPG(imap_folder_objects) = IMAPG(imap_folder_objects_tail) = NIL;	mail_list(imap_le_struct->imap_stream, Z_STRVAL_PP(ref), Z_STRVAL_PP(pat));	if (IMAPG(imap_folder_objects) == NIL) {		RETURN_FALSE;	}		array_init(return_value);	delim = safe_emalloc(2, sizeof(char), 0);	cur=IMAPG(imap_folder_objects);	while (cur != NIL) {		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		add_next_index_object(return_value, mboxob);		cur=cur->next;	}	mail_free_foblist(&IMAPG(imap_folder_objects), &IMAPG(imap_folder_objects_tail));	efree(delim);	IMAPG(folderlist_style) = FLIST_ARRAY;		/* reset to default */}/* }}} *//* {{{ proto array imap_scan(resource stream_id, string ref, string pattern, string content)   Read list of mailboxes containing a certain string */PHP_FUNCTION(imap_listscan){	zval **streamind, **ref, **pat, **content;	pils *imap_le_struct;	STRINGLIST *cur=NIL;	if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &streamind, &ref, &pat, &content) == FAILURE) {		ZEND_WRONG_PARAM_COUNT();	}	ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);	convert_to_string_ex(ref);	convert_to_string_ex(pat);	convert_to_string_ex(content);	IMAPG(imap_folders) = NIL;	mail_scan(imap_le_struct->imap_stream, Z_STRVAL_PP(ref), Z_STRVAL_PP(pat), Z_STRVAL_PP(content));	if (IMAPG(imap_folders) == NIL) {		RETURN_FALSE;	}	array_init(return_value);	cur=IMAPG(imap_folders);	while (cur != NIL) {		add_next_index_string(return_value, cur->LTEXT, 1);		cur=cur->next;	}	mail_free_stringlist (&IMAPG(imap_folders));	IMAPG(imap_folders) = IMAPG(imap_folders_tail) = NIL;}/* }}} *//* {{{ proto object imap_check(resource stream_id)   Get mailbox properties */PHP_FUNCTION(imap_check){	zval **streamind;	pils *imap_le_struct;	char date[100];	if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &streamind) == FAILURE) {		ZEND_WRONG_PARAM_COUNT();	}	ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);	if (mail_ping (imap_le_struct->imap_stream) == NIL) {		RETURN_FALSE;	}	if (imap_le_struct->imap_stream && imap_le_struct->imap_stream->mailbox) {		rfc822_date(date);		object_init(return_value);		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);	} else {		RETURN_FALSE;	}}/* }}} *//* {{{ proto bool imap_delete(resource stream_id, int msg_no [, int options])   Mark a message for deletion */PHP_FUNCTION(imap_delete){	zval **streamind, **sequence, **flags;	pils *imap_le_struct;	int myargc=ZEND_NUM_ARGS();		if (myargc < 2 || myargc > 3 || zend_get_parameters_ex(myargc, &streamind, &sequence, &flags) == FAILURE) {		ZEND_WRONG_PARAM_COUNT();	}		ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);	convert_to_string_ex(sequence);	if (myargc == 3) {		convert_to_long_ex(flags);	}		mail_setflag_full(imap_le_struct->imap_stream, Z_STRVAL_PP(sequence), "\\DELETED", myargc==3 ? Z_LVAL_PP(flags) : NIL);	RETVAL_TRUE;}/* }}} *//* {{{ proto bool imap_undelete(resource stream_id, int msg_no)   Remove the delete flag from a message */PHP_FUNCTION(imap_undelete){	zval **streamind, **sequence, **flags;	pils *imap_le_struct;	int myargc=ZEND_NUM_ARGS();	if (myargc < 2 || myargc > 3 || zend_get_parameters_ex(myargc, &streamind, &sequence, &flags) == FAILURE) {		ZEND_WRONG_PARAM_COUNT();	}		ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);		convert_to_string_ex(sequence);	if (myargc == 3) {		convert_to_long_ex(flags);	}	mail_clearflag_full(imap_le_struct->imap_stream, Z_STRVAL_PP(sequence), "\\DELETED", myargc==3 ? Z_LVAL_PP(flags) : NIL);	RETVAL_TRUE;}/* }}} *//* {{{ proto object imap_headerinfo(resource stream_id, int msg_no [, int from_length [, int subject_length [, string default_host]]])   Read the headers of the message */PHP_FUNCTION(imap_headerinfo){	zval **streamind, **msgno, **fromlength, **subjectlength, **defaulthost;	pils *imap_le_struct;	MESSAGECACHE *cache;	ENVELOPE *en;	char dummy[2000], fulladdress[MAILTMPLEN];	int myargc = ZEND_NUM_ARGS();		if (myargc < 2 || myargc > 5 || zend_get_parameters_ex(myargc, &streamind, &msgno, &fromlength, &subjectlength, &defaulthost) == FAILURE) {		ZEND_WRONG_PARAM_COUNT();	}		ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);	convert_to_long_ex(msgno);	if (myargc >= 3) {		convert_to_long_ex(fromlength);		if (Z_LVAL_PP(fromlength) < 0) {			php_error_docref(NULL TSRMLS_CC, E_WARNING, "From length has to be greater than or equal to 0");			RETURN_FALSE;		}	} else {		fromlength = 0x00;	}	if (myargc >= 4) {		convert_to_long_ex(subjectlength);		if (Z_LVAL_PP(subjectlength) < 0) {			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Subject length has to be greater than or equal to 0");			RETURN_FALSE;		}	} else {		subjectlength = 0x00;	}	if (myargc == 5) {		convert_to_string_ex(defaulthost);	}		PHP_IMAP_CHECK_MSGNO(Z_LVAL_PP(msgno));	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));	} else {		RETURN_FALSE;	}		en = mail_fetchenvelope(imap_le_struct->imap_stream, Z_LVAL_PP(msgno));	/* call a function to parse all the text, so that we can use the	   same function to parse text from other sources */	_php_make_header_object(return_value, en TSRMLS_CC);		/* now run through properties that are only going to be returned	   from a server, not text headers */	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);		sprintf(dummy, "%4ld", cache->msgno);	add_property_string(return_value, "Msgno", dummy, 1);		mail_date(dummy, cache);	add_property_string(return_value, "MailDate", dummy, 1);		sprintf(dummy, "%ld", cache->rfc822_size); 	add_property_string(return_value, "Size", dummy, 1);		add_property_long(return_value, "udate", mail_longdate(cache));		if (en->from && fromlength) {		fulladdress[0] = 0x00;		mail_fetchfrom(fulladdress, imap_le_struct->imap_stream, Z_LVAL_PP(msgno), Z_LVAL_PP(fromlength));		add_property_string(return_value, "fetchfrom", fulladdress, 1);	}	if (en->subject && subjectlength) {		fulladdress[0] = 0x00;		mail_fetchsubject(fulladdress, imap_le_struct->imap_stream, Z_LVAL_PP(msgno), Z_LVAL_PP(subjectlength));		add_property_string(return_value, "fetchsubject", fulladdress, 1);	}}/* }}} *//* {{{ proto object imap_rfc822_parse_headers(string headers [, string default_host])   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;	int myargc = ZEND_NUM_ARGS();	if (myargc < 1 || myargc > 2 || zend_get_parameters_ex(myargc, &headers, &defaulthost) == FAILURE) {		ZEND_WRONG_PARAM_COUNT();	}		convert_to_string_ex(headers);	if (myargc == 2) {		convert_to_string_ex(defaulthost);	}		if (myargc == 2) {		rfc822_parse_msg(&en, NULL, Z_STRVAL_PP(headers), Z_STRLEN_PP(headers), NULL, Z_STRVAL_PP(defaulthost), NIL);	} else {		rfc822_parse_msg(&en, NULL, Z_STRVAL_PP(headers), Z_STRLEN_PP(headers), NULL, "UNKNOWN", NIL);	}		/* call a function to parse all the text, so that we can use the	   same function no matter where the headers are from */	_php_make_header_object(return_value, en TSRMLS_CC);	mail_free_envelope(&en);}/* }}} *//* KMLANG *//* {{{ proto array imap_lsub(resource stream_id, string ref, string pattern)   Return a list of subscribed mailboxes */PHP_FUNCTION(imap_lsub){	zval **streamind, **ref, **pat;	pils *imap_le_struct;	STRINGLIST *cur=NIL;		if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &streamind, &ref, &pat) == FAILURE) {		ZEND_WRONG_PARAM_COUNT();	}		ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);		convert_to_string_ex(ref);	convert_to_string_ex(pat);	/* set flag for normal, old mailbox list */	IMAPG(folderlist_style) = FLIST_ARRAY;		IMAPG(imap_sfolders) = NIL;	mail_lsub(imap_le_struct->imap_stream, Z_STRVAL_PP(ref), Z_STRVAL_PP(pat));	if (IMAPG(imap_sfolders) == NIL) {		RETURN_FALSE;	}	array_init(return_value);	cur=IMAPG(imap_sfolders);	while (cur != NIL) {		add_next_index_string(return_value, cur->LTEXT, 1);		cur=cur->next;	}	mail_free_stringlist (&IMAPG(imap_sfolders));	IMAPG(imap_sfolders) = IMAPG(imap_sfolders_tail) = NIL;}/* }}} *//* {{{ proto array imap_getsubscribed(resource stream_id, string ref, string pattern)   Return a list of subscribed mailboxes, in the same format as imap_getmailboxes() *//* Author: CJH */PHP_FUNCTION(imap_lsub_full){	zval **streamind, **ref, **pat, *mboxob;	pils *imap_le_struct;	FOBJECTLIST *cur=NIL;	char *delim=NIL;		if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &streamind, &ref, &pat) == FAILURE) {		ZEND_WRONG_PARAM_COUNT();	}		ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);	convert_to_string_ex(ref);	convert_to_string_ex(pat);	/* set flag for new, improved array of objects list */	IMAPG(folderlist_style) = FLIST_OBJECT;		IMAPG(imap_sfolder_objects) = IMAPG(imap_sfolder_objects_tail) = NIL;	mail_lsub(imap_le_struct->imap_stream, Z_STRVAL_PP(ref), Z_STRVAL_PP(pat));	if (IMAPG(imap_sfolder_objects) == NIL) {		RETURN_FALSE;	}		array_init(return_value);	delim = safe_emalloc(2, sizeof(char), 0);	cur=IMAPG(imap_sfolder_objects);	while (cur != NIL) {		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		add_next_index_object(return_value, mboxob);		cur=cur->next;	}	mail_free_foblist (&IMAPG(imap_sfolder_objects), &IMAPG(imap_sfolder_objects_tail));	efree(delim);	IMAPG(folderlist_style) = FLIST_ARRAY; /* reset to default */}/* }}} *//* {{{ proto bool imap_subscribe(resource stream_id, string mailbox)   Subscribe to a mailbox */PHP_FUNCTION(imap_subscribe){	zval **streamind, **folder;	pils *imap_le_struct;	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &streamind, &folder) == FAILURE) {		ZEND_WRONG_PARAM_COUNT();	}		ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);	convert_to_string_ex(folder);	if (mail_subscribe(imap_le_struct->imap_stream, Z_STRVAL_PP(folder))==T) {		RETURN_TRUE;	} else {		RETURN_FALSE;	}}/* }}} *//* {{{ proto bool imap_unsubscribe(resource stream_id, string mailbox)   Unsubscribe from a mailbox */PHP_FUNCTION(imap_unsubscribe){	zval **streamind, **folder;	pils *imap_le_struct;	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &streamind, &folder) == FAILURE) {		ZEND_WRONG_PARAM_COUNT();	}	ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);	convert_to_string_ex(folder);	if (mail_unsubscribe(imap_le_struct->imap_stream, Z_STRVAL_PP(folder))==T) {		RETURN_TRUE;	} else {		RETURN_FALSE;	}}/* }}} *//* {{{ proto object imap_fetchstructure(resource stream_id, int msg_no [, int options])   Read the full structure of a message */PHP_FUNCTION(imap_fetchstructure){	zval **streamind, **msgno, **flags;	pils *imap_le_struct;	BODY *body;	int msgindex, myargc=ZEND_NUM_ARGS();	if (myargc < 2  || myargc > 3 || zend_get_parameters_ex(myargc, &streamind, &msgno, &flags) == FAILURE) {		ZEND_WRONG_PARAM_COUNT();	}		ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);	convert_to_long_ex(msgno);	if (Z_LVAL_PP(msgno) < 1) {		RETURN_FALSE;	}	if (myargc == 3) {		convert_to_long_ex(flags);	}	object_init(return_value);	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);	}	PHP_IMAP_CHECK_MSGNO(msgindex);	mail_fetchstructure_full(imap_le_struct->imap_stream, Z_LVAL_PP(msgno), &body , myargc == 3 ? Z_LVAL_PP(flags) : NIL);		if (!body) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "No body information available");		RETURN_FALSE;

⌨️ 快捷键说明

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