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

📄 php_imap.c

📁 php-4.4.7学习linux时下载的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	}		_php_imap_add_body(return_value, body TSRMLS_CC);}/* }}} *//* {{{ proto string imap_fetchbody(resource stream_id, int msg_no, string section [, int options])   Get a specific body section */PHP_FUNCTION(imap_fetchbody){	zval **streamind, **msgno, **sec, **flags;	pils *imap_le_struct;	char *body;	unsigned long len;	int myargc=ZEND_NUM_ARGS();	if (myargc < 3 || myargc > 4 || zend_get_parameters_ex(myargc, &streamind, &msgno, &sec, &flags) == FAILURE) {		ZEND_WRONG_PARAM_COUNT();	}	ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);	convert_to_long_ex(msgno);	convert_to_string_ex(sec);	if (myargc == 4) {		convert_to_long_ex(flags);	}	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));	}	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);	if (!body) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "No body information available");		RETURN_FALSE;	}	RETVAL_STRINGL(body, len, 1);}/* }}} *//* {{{ proto string imap_base64(string text)   Decode BASE64 encoded text */PHP_FUNCTION(imap_base64){	zval **text;	char *decode;	unsigned long newlength;	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &text) == FAILURE) {		ZEND_WRONG_PARAM_COUNT();	}	convert_to_string_ex(text);	decode = (char *) rfc822_base64((unsigned char *) Z_STRVAL_PP(text), Z_STRLEN_PP(text), &newlength);	if (decode == NULL) {		RETURN_FALSE;	}	RETVAL_STRINGL(decode, newlength, 1);	fs_give((void**) &decode);}/* }}} *//* {{{ proto string imap_qprint(string text)   Convert a quoted-printable string to an 8-bit string */PHP_FUNCTION(imap_qprint){	zval **text;	char *decode;	unsigned long newlength;	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &text) == FAILURE) {		ZEND_WRONG_PARAM_COUNT();	}	convert_to_string_ex(text);	decode = (char *) rfc822_qprint((unsigned char *) Z_STRVAL_PP(text), Z_STRLEN_PP(text), &newlength);	if (decode == NULL) {		RETURN_FALSE;	}	RETVAL_STRINGL(decode, newlength, 1);	fs_give((void**) &decode);}/* }}} *//* {{{ proto string imap_8bit(string text)   Convert an 8-bit string to a quoted-printable string */PHP_FUNCTION(imap_8bit){	zval **text;	char *decode;	unsigned long newlength;	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &text) == FAILURE) {		ZEND_WRONG_PARAM_COUNT();	}	convert_to_string_ex(text);	decode = (char *) rfc822_8bit((unsigned char *) Z_STRVAL_PP(text), Z_STRLEN_PP(text), &newlength);	if (decode == NULL) {		RETURN_FALSE;	}	RETVAL_STRINGL(decode, newlength, 1);	fs_give((void**) &decode);}/* }}} *//* {{{ proto string imap_binary(string text)   Convert an 8bit string to a base64 string */PHP_FUNCTION(imap_binary){	zval **text;	char *decode;	unsigned long newlength;	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &text) == FAILURE) {		ZEND_WRONG_PARAM_COUNT();	}	convert_to_string_ex(text);	decode = rfc822_binary(Z_STRVAL_PP(text), Z_STRLEN_PP(text), &newlength);	if (decode == NULL) {		RETURN_FALSE;	}	RETVAL_STRINGL(decode, newlength, 1);	fs_give((void**) &decode);}/* }}} *//* {{{ proto object imap_mailboxmsginfo(resource stream_id)   Returns info about the current mailbox */PHP_FUNCTION(imap_mailboxmsginfo){	zval **streamind;	pils *imap_le_struct;	char date[100];	unsigned int msgno, unreadmsg, deletedmsg, msize;	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);	/* Initialize return object */	object_init(return_value);	unreadmsg = 0;	deletedmsg = 0;	msize = 0;	for (msgno = 1; msgno <= imap_le_struct->imap_stream->nmsgs; msgno++) {		MESSAGECACHE * cache = mail_elt (imap_le_struct->imap_stream, msgno);		mail_fetchstructure (imap_le_struct->imap_stream, msgno, NIL);		if (!cache->seen || cache->recent) {			unreadmsg++;		}		if (cache->deleted) {			deletedmsg++;		}		msize = msize + cache->rfc822_size;	}	add_property_long(return_value, "Unread", unreadmsg);	add_property_long(return_value, "Deleted", deletedmsg);	add_property_long(return_value, "Nmsgs", imap_le_struct->imap_stream->nmsgs);	add_property_long(return_value, "Size", msize);	rfc822_date(date);	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);}/* }}} *//* {{{ 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){	zval **mailbox, **host, **personal;	ADDRESS *addr;	char string[MAILTMPLEN];	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &mailbox, &host, &personal) == FAILURE) {		ZEND_WRONG_PARAM_COUNT();	}	convert_to_string_ex(mailbox);	convert_to_string_ex(host);	convert_to_string_ex(personal);	addr=mail_newaddr();	if (mailbox) {		addr->mailbox = cpystr(Z_STRVAL_PP(mailbox));	}	if (host) {		addr->host = cpystr(Z_STRVAL_PP(host));	}	if (personal) {		addr->personal = cpystr(Z_STRVAL_PP(personal));	}	addr->next=NIL;	addr->error=NIL;	addr->adl=NIL;	if (_php_imap_address_size(addr) >= MAILTMPLEN) {		RETURN_FALSE;	}	string[0]='\0';	rfc822_write_address(string, addr);	RETVAL_STRING(string, 1);}/* }}} *//* {{{ proto array imap_rfc822_parse_adrlist(string address_string, string default_host)   Parses an address string */PHP_FUNCTION(imap_rfc822_parse_adrlist){	zval **str, **defaulthost, *tovals;	ADDRESS *addresstmp;	ENVELOPE *env;		if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &str, &defaulthost) == FAILURE) {		ZEND_WRONG_PARAM_COUNT();	}	SEPARATE_ZVAL(str);	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));	array_init(return_value);	addresstmp = env->to;	if (addresstmp) do {		MAKE_STD_ZVAL(tovals);		object_init(tovals);		if (addresstmp->mailbox) {			add_property_string(tovals, "mailbox", addresstmp->mailbox, 1);		}		if (addresstmp->host) {			add_property_string(tovals, "host", addresstmp->host, 1);		}		if (addresstmp->personal) {			add_property_string(tovals, "personal", addresstmp->personal, 1);		}		if (addresstmp->adl) {			add_property_string(tovals, "adl", addresstmp->adl, 1);		}		add_next_index_object(return_value, tovals);	} while ((addresstmp = addresstmp->next));}/* }}} *//* {{{ proto string imap_utf8(string mime_encoded_text)   Convert a mime-encoded text to UTF-8 */PHP_FUNCTION(imap_utf8){	zval **str;	SIZEDTEXT src, dest;		if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) {		ZEND_WRONG_PARAM_COUNT();	}	convert_to_string_ex(str);		src.data  = NULL;	src.size  = 0;	dest.data = NULL;	dest.size = 0;	cpytxt(&src, Z_STRVAL_PP(str), Z_STRLEN_PP(str));#ifndef HAVE_NEW_MIME2TEXT	utf8_mime2text(&src, &dest);#else	utf8_mime2text(&src, &dest, U8T_CANONICAL);#endif	RETURN_STRINGL(dest.data, strlen(dest.data), 1);}/* }}} *//* {{{ macros for the modified utf7 conversion functions  * * author: Andrew Skalski <askalski@chek.com>  *//* tests `c' and returns true if it is a special character */#define SPECIAL(c) ((c) <= 0x1f || (c) >= 0x7f)/* validate a modified-base64 character */#define B64CHAR(c) (isalnum(c) || (c) == '+' || (c) == ',')/* map the low 64 bits of `n' to the modified-base64 characters */#define B64(n)  ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" \                "abcdefghijklmnopqrstuvwxyz0123456789+,"[(n) & 0x3f])/* 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)/* }}} *//* {{{ proto string imap_utf7_decode(string buf)   Decode a modified UTF-7 string */PHP_FUNCTION(imap_utf7_decode){	/* author: Andrew Skalski <askalski@chek.com> */	zval **arg;	const unsigned char *in, *inp, *endp;	unsigned char *out, *outp;	unsigned char c;	int inlen, outlen;	enum {		ST_NORMAL,	/* printable text */		ST_DECODE0,	/* encoded text rotation... */		ST_DECODE1,		ST_DECODE2,		ST_DECODE3	} state;	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {		ZEND_WRONG_PARAM_COUNT();	}		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() */	in = (const unsigned char *) Z_STRVAL_PP(arg);	inlen = Z_STRLEN_PP(arg);		/* 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)) {				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid modified UTF-7 character: `%c'", *inp);				RETURN_FALSE;			} else if (*inp != '&') {				outlen++;			} else if (inp + 1 == endp) {				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unexpected end of string");				RETURN_FALSE;			} else if (inp[1] != '-') {				state = ST_DECODE0;			} else {				outlen++;				inp++;			}		} else if (*inp == '-') {			/* return to NORMAL mode */			if (state == ST_DECODE1) {				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Stray modified base64 character: `%c'", *--inp);				RETURN_FALSE;			}			state = ST_NORMAL;		} else if (!B64CHAR(*inp)) {			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid modified base64 character: `%c'", *inp);			RETURN_FALSE;		} else {			switch (state) {				case ST_DECODE3:					outlen++;					state = ST_DECODE0;					break;				case ST_DECODE2:				case ST_DECODE1:					outlen++;				case ST_DECODE0:					state++;				case ST_NORMAL:					break;			}		}	}	/* enforce end state */	if (state != ST_NORMAL) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unexpected end of string");		RETURN_FALSE;	}	/* allocate output buffer */	out = emalloc(outlen + 1);	/* 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);				c = outp[1] >> 4;				*outp++ |= c;				*outp <<= 4;				state = ST_DECODE2;				break

⌨️ 快捷键说明

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