/ext/imap/php_imap.c
C | 5095 lines | 3811 code | 702 blank | 582 comment | 869 complexity | 19aaaebfa2eb11f6332dff5a49519ba6 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- /*
- +----------------------------------------------------------------------+
- | PHP Version 5 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2011 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 <jani.taskinen@iki.fi> |
- | Daniel R. Kalowsky <kalowsky@php.net> |
- | PHP 4.0 updates: Zeev Suraski <zeev@zend.com> |
- +----------------------------------------------------------------------+
- */
- /* $Id: php_imap.c 307691 2011-01-24 03:52:00Z stas $ */
- #define IMAP41
- #ifdef HAVE_CONFIG_H
- #include "config.h"
- #endif
- #include "php.h"
- #include "php_ini.h"
- #include "php_streams.h"
- #include "ext/standard/php_string.h"
- #include "ext/standard/info.h"
- #include "ext/standard/file.h"
- #include "ext/standard/php_smart_str.h"
- #include "ext/pcre/php_pcre.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 <winsock2.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
- #endif
- #if defined(__GNUC__) && __GNUC__ >= 4
- # define PHP_IMAP_EXPORT __attribute__ ((visibility("default")))
- #else
- # define PHP_IMAP_EXPORT
- #endif
- static void _php_make_header_object(zval *myzvalue, ENVELOPE *en TSRMLS_DC);
- static void _php_imap_add_body(zval *arg, BODY *body TSRMLS_DC);
- static char* _php_imap_parse_address(ADDRESS *addresslist, zval *paddress TSRMLS_DC);
- static char* _php_rfc822_write_address(ADDRESS *addresslist TSRMLS_DC);
- /* the gets we use */
- static char *php_mail_gets(readfn_t f, void *stream, unsigned long size, GETS_DATA *md);
- /* 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_MIME2TEXT
- long utf8_mime2text(SIZEDTEXT *src, SIZEDTEXT *dst);
- #else
- long utf8_mime2text (SIZEDTEXT *src, SIZEDTEXT *dst, long flags);
- #endif
- unsigned long find_rightmost_bit(unsigned long *valptr);
- void fs_give(void **block);
- void *fs_get(size_t size);
- ZEND_DECLARE_MODULE_GLOBALS(imap)
- static PHP_GINIT_FUNCTION(imap);
- /* {{{ arginfo */
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_open, 0, 0, 3)
- ZEND_ARG_INFO(0, mailbox)
- ZEND_ARG_INFO(0, user)
- ZEND_ARG_INFO(0, password)
- ZEND_ARG_INFO(0, options)
- ZEND_ARG_INFO(0, n_retries)
- ZEND_ARG_INFO(0, params)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_reopen, 0, 0, 2)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, mailbox)
- ZEND_ARG_INFO(0, options)
- ZEND_ARG_INFO(0, n_retries)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_append, 0, 0, 3)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, folder)
- ZEND_ARG_INFO(0, message)
- ZEND_ARG_INFO(0, options)
- ZEND_ARG_INFO(0, date)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_num_msg, 0, 0, 1)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_ping, 0, 0, 1)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_num_recent, 0, 0, 1)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_END_ARG_INFO()
- #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_get_quota, 0, 0, 2)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, qroot)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_get_quotaroot, 0, 0, 2)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, mbox)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_set_quota, 0, 0, 3)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, qroot)
- ZEND_ARG_INFO(0, mailbox_size)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_setacl, 0, 0, 4)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, mailbox)
- ZEND_ARG_INFO(0, id)
- ZEND_ARG_INFO(0, rights)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_getacl, 0, 0, 2)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, mailbox)
- ZEND_END_ARG_INFO()
- #endif
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_expunge, 0, 0, 1)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_gc, 0, 0, 1)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, flags)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_close, 0, 0, 1)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, options)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_headers, 0, 0, 1)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_body, 0, 0, 2)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, msg_no)
- ZEND_ARG_INFO(0, options)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_mail_copy, 0, 0, 3)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, msglist)
- ZEND_ARG_INFO(0, mailbox)
- ZEND_ARG_INFO(0, options)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_mail_move, 0, 0, 3)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, sequence)
- ZEND_ARG_INFO(0, mailbox)
- ZEND_ARG_INFO(0, options)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_createmailbox, 0, 0, 2)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, mailbox)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_renamemailbox, 0, 0, 3)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, old_name)
- ZEND_ARG_INFO(0, new_name)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_deletemailbox, 0, 0, 2)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, mailbox)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_list, 0, 0, 3)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, ref)
- ZEND_ARG_INFO(0, pattern)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_getmailboxes, 0, 0, 3)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, ref)
- ZEND_ARG_INFO(0, pattern)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_listscan, 0, 0, 4)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, ref)
- ZEND_ARG_INFO(0, pattern)
- ZEND_ARG_INFO(0, content)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_check, 0, 0, 1)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_delete, 0, 0, 2)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, msg_no)
- ZEND_ARG_INFO(0, options)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_undelete, 0, 0, 2)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, msg_no)
- ZEND_ARG_INFO(0, flags)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_headerinfo, 0, 0, 2)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, msg_no)
- ZEND_ARG_INFO(0, from_length)
- ZEND_ARG_INFO(0, subject_length)
- ZEND_ARG_INFO(0, default_host)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_rfc822_parse_headers, 0, 0, 1)
- ZEND_ARG_INFO(0, headers)
- ZEND_ARG_INFO(0, default_host)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_lsub, 0, 0, 3)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, ref)
- ZEND_ARG_INFO(0, pattern)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_getsubscribed, 0, 0, 3)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, ref)
- ZEND_ARG_INFO(0, pattern)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_subscribe, 0, 0, 2)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, mailbox)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_unsubscribe, 0, 0, 2)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, mailbox)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_fetchstructure, 0, 0, 2)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, msg_no)
- ZEND_ARG_INFO(0, options)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_fetchbody, 0, 0, 3)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, msg_no)
- ZEND_ARG_INFO(0, section)
- ZEND_ARG_INFO(0, options)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_savebody, 0, 0, 3)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, file)
- ZEND_ARG_INFO(0, msg_no)
- ZEND_ARG_INFO(0, section)
- ZEND_ARG_INFO(0, options)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_base64, 0, 0, 1)
- ZEND_ARG_INFO(0, text)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_qprint, 0, 0, 1)
- ZEND_ARG_INFO(0, text)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_8bit, 0, 0, 1)
- ZEND_ARG_INFO(0, text)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_binary, 0, 0, 1)
- ZEND_ARG_INFO(0, text)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_mailboxmsginfo, 0, 0, 1)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_rfc822_write_address, 0, 0, 3)
- ZEND_ARG_INFO(0, mailbox)
- ZEND_ARG_INFO(0, host)
- ZEND_ARG_INFO(0, personal)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_rfc822_parse_adrlist, 0, 0, 2)
- ZEND_ARG_INFO(0, address_string)
- ZEND_ARG_INFO(0, default_host)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_utf8, 0, 0, 1)
- ZEND_ARG_INFO(0, mime_encoded_text)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_utf7_decode, 0, 0, 1)
- ZEND_ARG_INFO(0, buf)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_utf7_encode, 0, 0, 1)
- ZEND_ARG_INFO(0, buf)
- ZEND_END_ARG_INFO()
- #ifdef HAVE_IMAP_MUTF7
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_utf8_to_mutf7, 0, 0, 1)
- ZEND_ARG_INFO(0, in)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_mutf7_to_utf8, 0, 0, 1)
- ZEND_ARG_INFO(0, in)
- ZEND_END_ARG_INFO()
- #endif
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_setflag_full, 0, 0, 3)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, sequence)
- ZEND_ARG_INFO(0, flag)
- ZEND_ARG_INFO(0, options)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_clearflag_full, 0, 0, 3)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, sequence)
- ZEND_ARG_INFO(0, flag)
- ZEND_ARG_INFO(0, options)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_sort, 0, 0, 3)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, criteria)
- ZEND_ARG_INFO(0, reverse)
- ZEND_ARG_INFO(0, options)
- ZEND_ARG_INFO(0, search_criteria)
- ZEND_ARG_INFO(0, charset)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_fetchheader, 0, 0, 2)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, msg_no)
- ZEND_ARG_INFO(0, options)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_uid, 0, 0, 2)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, msg_no)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_msgno, 0, 0, 2)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, unique_msg_id)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_status, 0, 0, 3)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, mailbox)
- ZEND_ARG_INFO(0, options)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_bodystruct, 0, 0, 3)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, msg_no)
- ZEND_ARG_INFO(0, section)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_fetch_overview, 0, 0, 2)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, sequence)
- ZEND_ARG_INFO(0, options)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_mail_compose, 0, 0, 2)
- ZEND_ARG_INFO(0, envelope)
- ZEND_ARG_INFO(0, body)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_mail, 0, 0, 3)
- ZEND_ARG_INFO(0, to)
- ZEND_ARG_INFO(0, subject)
- ZEND_ARG_INFO(0, message)
- ZEND_ARG_INFO(0, additional_headers)
- ZEND_ARG_INFO(0, cc)
- ZEND_ARG_INFO(0, bcc)
- ZEND_ARG_INFO(0, rpath)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_search, 0, 0, 2)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, criteria)
- ZEND_ARG_INFO(0, options)
- ZEND_ARG_INFO(0, charset)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_imap_alerts, 0)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_imap_errors, 0)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_imap_last_error, 0)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_mime_header_decode, 0, 0, 1)
- ZEND_ARG_INFO(0, str)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_thread, 0, 0, 1)
- ZEND_ARG_INFO(0, stream_id)
- ZEND_ARG_INFO(0, options)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_timeout, 0, 0, 1)
- ZEND_ARG_INFO(0, timeout_type)
- ZEND_ARG_INFO(0, timeout)
- ZEND_END_ARG_INFO()
- /* }}} */
- /* {{{ imap_functions[]
- */
- const zend_function_entry imap_functions[] = {
- PHP_FE(imap_open, arginfo_imap_open)
- PHP_FE(imap_reopen, arginfo_imap_reopen)
- PHP_FE(imap_close, arginfo_imap_close)
- PHP_FE(imap_num_msg, arginfo_imap_num_msg)
- PHP_FE(imap_num_recent, arginfo_imap_num_recent)
- PHP_FE(imap_headers, arginfo_imap_headers)
- PHP_FE(imap_headerinfo, arginfo_imap_headerinfo)
- PHP_FE(imap_rfc822_parse_headers, arginfo_imap_rfc822_parse_headers)
- PHP_FE(imap_rfc822_write_address, arginfo_imap_rfc822_write_address)
- PHP_FE(imap_rfc822_parse_adrlist, arginfo_imap_rfc822_parse_adrlist)
- PHP_FE(imap_body, arginfo_imap_body)
- PHP_FE(imap_bodystruct, arginfo_imap_bodystruct)
- PHP_FE(imap_fetchbody, arginfo_imap_fetchbody)
- PHP_FE(imap_fetchmime, arginfo_imap_fetchbody)
- PHP_FE(imap_savebody, arginfo_imap_savebody)
- PHP_FE(imap_fetchheader, arginfo_imap_fetchheader)
- PHP_FE(imap_fetchstructure, arginfo_imap_fetchstructure)
- PHP_FE(imap_gc, arginfo_imap_gc)
- PHP_FE(imap_expunge, arginfo_imap_expunge)
- PHP_FE(imap_delete, arginfo_imap_delete)
- PHP_FE(imap_undelete, arginfo_imap_undelete)
- PHP_FE(imap_check, arginfo_imap_check)
- PHP_FE(imap_listscan, arginfo_imap_listscan)
- PHP_FE(imap_mail_copy, arginfo_imap_mail_copy)
- PHP_FE(imap_mail_move, arginfo_imap_mail_move)
- PHP_FE(imap_mail_compose, arginfo_imap_mail_compose)
- PHP_FE(imap_createmailbox, arginfo_imap_createmailbox)
- PHP_FE(imap_renamemailbox, arginfo_imap_renamemailbox)
- PHP_FE(imap_deletemailbox, arginfo_imap_deletemailbox)
- PHP_FE(imap_subscribe, arginfo_imap_subscribe)
- PHP_FE(imap_unsubscribe, arginfo_imap_unsubscribe)
- PHP_FE(imap_append, arginfo_imap_append)
- PHP_FE(imap_ping, arginfo_imap_ping)
- PHP_FE(imap_base64, arginfo_imap_base64)
- PHP_FE(imap_qprint, arginfo_imap_qprint)
- PHP_FE(imap_8bit, arginfo_imap_8bit)
- PHP_FE(imap_binary, arginfo_imap_binary)
- PHP_FE(imap_utf8, arginfo_imap_utf8)
- PHP_FE(imap_status, arginfo_imap_status)
- PHP_FE(imap_mailboxmsginfo, arginfo_imap_mailboxmsginfo)
- PHP_FE(imap_setflag_full, arginfo_imap_setflag_full)
- PHP_FE(imap_clearflag_full, arginfo_imap_clearflag_full)
- PHP_FE(imap_sort, arginfo_imap_sort)
- PHP_FE(imap_uid, arginfo_imap_uid)
- PHP_FE(imap_msgno, arginfo_imap_msgno)
- PHP_FE(imap_list, arginfo_imap_list)
- PHP_FE(imap_lsub, arginfo_imap_lsub)
- PHP_FE(imap_fetch_overview, arginfo_imap_fetch_overview)
- PHP_FE(imap_alerts, arginfo_imap_alerts)
- PHP_FE(imap_errors, arginfo_imap_errors)
- PHP_FE(imap_last_error, arginfo_imap_last_error)
- PHP_FE(imap_search, arginfo_imap_search)
- PHP_FE(imap_utf7_decode, arginfo_imap_utf7_decode)
- PHP_FE(imap_utf7_encode, arginfo_imap_utf7_encode)
- #ifdef HAVE_IMAP_MUTF7
- PHP_FE(imap_utf8_to_mutf7, arginfo_imap_utf8_to_mutf7)
- PHP_FE(imap_mutf7_to_utf8, arginfo_imap_mutf7_to_utf8)
- #endif
- PHP_FE(imap_mime_header_decode, arginfo_imap_mime_header_decode)
- PHP_FE(imap_thread, arginfo_imap_thread)
- PHP_FE(imap_timeout, arginfo_imap_timeout)
- #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
- PHP_FE(imap_get_quota, arginfo_imap_get_quota)
- PHP_FE(imap_get_quotaroot, arginfo_imap_get_quotaroot)
- PHP_FE(imap_set_quota, arginfo_imap_set_quota)
- PHP_FE(imap_setacl, arginfo_imap_setacl)
- PHP_FE(imap_getacl, arginfo_imap_getacl)
- #endif
- PHP_FE(imap_mail, arginfo_imap_mail)
- PHP_FALIAS(imap_header, imap_headerinfo, arginfo_imap_headerinfo)
- PHP_FALIAS(imap_listmailbox, imap_list, arginfo_imap_list)
- PHP_FALIAS(imap_getmailboxes, imap_list_full, arginfo_imap_getmailboxes)
- PHP_FALIAS(imap_scanmailbox, imap_listscan, arginfo_imap_listscan)
- PHP_FALIAS(imap_listsubscribed, imap_lsub, arginfo_imap_lsub)
- PHP_FALIAS(imap_getsubscribed, imap_lsub_full, arginfo_imap_getsubscribed)
- PHP_FALIAS(imap_fetchtext, imap_body, arginfo_imap_body)
- PHP_FALIAS(imap_scan, imap_listscan, arginfo_imap_listscan)
- PHP_FALIAS(imap_create, imap_createmailbox, arginfo_imap_createmailbox)
- PHP_FALIAS(imap_rename, imap_renamemailbox, arginfo_imap_renamemailbox)
- {NULL, NULL, NULL}
- };
- /* }}} */
- /* {{{ imap dependencies */
- static const zend_module_dep imap_deps[] = {
- ZEND_MOD_REQUIRED("standard")
- {NULL, NULL, NULL}
- };
- /* }}} */
- /* {{{ imap_module_entry
- */
- zend_module_entry imap_module_entry = {
- STANDARD_MODULE_HEADER_EX, NULL,
- imap_deps,
- "imap",
- imap_functions,
- PHP_MINIT(imap),
- NULL,
- PHP_RINIT(imap),
- PHP_RSHUTDOWN(imap),
- PHP_MINFO(imap),
- NO_VERSION_YET,
- PHP_MODULE_GLOBALS(imap),
- PHP_GINIT(imap),
- NULL,
- NULL,
- STANDARD_MODULE_PROPERTIES_EX
- };
- /* }}} */
- #ifdef COMPILE_DL_IMAP
- ZEND_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;
- /* Do not try to close prototype streams */
- if (!(imap_le_struct->flags & OP_PROTOTYPE)) {
- 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 TSRMLS_DC)
- {
- 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 TSRMLS_DC)
- {
- 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);
- }
- }
- /* }}} */
- /* {{{ 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);
- }
- }
- /* }}} */
- #endif
- /* {{{ PHP_GINIT_FUNCTION
- */
- static PHP_GINIT_FUNCTION(imap)
- {
- 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 = NIL;
- imap_globals->imap_acl_list = NIL;
- #endif
- imap_globals->gets_stream = NIL;
- }
- /* }}} */
- /* {{{ PHP_MINIT_FUNCTION
- */
- PHP_MINIT_FUNCTION(imap)
- {
- unsigned long sa_all = SA_MESSAGES | SA_RECENT | SA_UNSEEN | SA_UIDNEXT | SA_UIDVALIDITY;
- #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
- auth_link(&auth_pla); /* link in the plain authenticator */
- #endif
- #ifdef HAVE_IMAP_SSL
- ssl_onceonlyinit ();
- #endif
- /* lets allow NIL */
- REGISTER_LONG_CONSTANT("NIL", NIL, CONST_PERSISTENT | CONST_CS);
- /* plug in our gets */
- mail_parameters(NIL, SET_GETS, (void *) NIL);
- /* 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);
- /* Open Options */
- REGISTER_LONG_CONSTANT("OP_DEBUG", OP_DEBUG, CONST_PERSISTENT | CONST_CS);
- /* debug protocol negotiations */
- REGISTER_LONG_CONSTANT("OP_READONLY", OP_READONLY, CONST_PERSISTENT | CONST_CS);
- /* read-only open */
- REGISTER_LONG_CONSTANT("OP_ANONYMOUS", OP_ANONYMOUS, CONST_PERSISTENT | CONST_CS);
- /* anonymous open of newsgroup */
- REGISTER_LONG_CONSTANT("OP_SHORTCACHE", OP_SHORTCACHE, CONST_PERSISTENT | CONST_CS);
- /* short (elt-only) caching */
- REGISTER_LONG_CONSTANT("OP_SILENT", OP_SILENT, CONST_PERSISTENT | CONST_CS);
- /* don't pass up events (internal use) */
- REGISTER_LONG_CONSTANT("OP_PROTOTYPE", OP_PROTOTYPE, CONST_PERSISTENT | CONST_CS);
- /* return driver prototype */
- REGISTER_LONG_CONSTANT("OP_HALFOPEN", OP_HALFOPEN, CONST_PERSISTENT | CONST_CS);
- /* half-open (IMAP connect but no select) */
- REGISTER_LONG_CONSTANT("OP_EXPUNGE", OP_EXPUNGE, CONST_PERSISTENT | CONST_CS);
- /* silently expunge recycle stream */
- REGISTER_LONG_CONSTANT("OP_SECURE", OP_SECURE, CONST_PERSISTENT | CONST_CS);
- /* 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
- */
- REGISTER_LONG_CONSTANT("CL_EXPUNGE", PHP_EXPUNGE, CONST_PERSISTENT | CONST_CS);
- /* expunge silently */
- /* Fetch options */
- REGISTER_LONG_CONSTANT("FT_UID", FT_UID, CONST_PERSISTENT | CONST_CS);
- /* argument is a UID */
- REGISTER_LONG_CONSTANT("FT_PEEK", FT_PEEK, CONST_PERSISTENT | CONST_CS);
- /* peek at data */
- REGISTER_LONG_CONSTANT("FT_NOT", FT_NOT, CONST_PERSISTENT | CONST_CS);
- /* NOT flag for header lines fetch */
- REGISTER_LONG_CONSTANT("FT_INTERNAL", FT_INTERNAL, CONST_PERSISTENT | CONST_CS);
- /* text can be internal strings */
- REGISTER_LONG_CONSTANT("FT_PREFETCHTEXT", FT_PREFETCHTEXT, CONST_PERSISTENT | CONST_CS);
- /* IMAP prefetch text when fetching header */
- /* Flagging options */
- REGISTER_LONG_CONSTANT("ST_UID", ST_UID, CONST_PERSISTENT | CONST_CS);
- /* argument is a UID sequence */
- REGISTER_LONG_CONSTANT("ST_SILENT", ST_SILENT, CONST_PERSISTENT | CONST_CS);
- /* don't return results */
- REGISTER_LONG_CONSTANT("ST_SET", ST_SET, CONST_PERSISTENT | CONST_CS);
- /* set vs. clear */
- /* Copy options */
- REGISTER_LONG_CONSTANT("CP_UID", CP_UID, CONST_PERSISTENT | CONST_CS);
- /* argument is a UID sequence */
- REGISTER_LONG_CONSTANT("CP_MOVE", CP_MOVE, CONST_PERSISTENT | CONST_CS);
- /* delete from source after copying */
- /* Search/sort options */
- REGISTER_LONG_CONSTANT("SE_UID", SE_UID, CONST_PERSISTENT | CONST_CS);
- /* return UID */
- REGISTER_LONG_CONSTANT("SE_FREE", SE_FREE, CONST_PERSISTENT | CONST_CS);
- /* free search program after finished */
- REGISTER_LONG_CONSTANT("SE_NOPREFETCH", SE_NOPREFETCH, CONST_PERSISTENT | CONST_CS);
- /* no search prefetching */
- REGISTER_LONG_CONSTANT("SO_FREE", SO_FREE, CONST_PERSISTENT | CONST_CS);
- /* free sort program after finished */
- REGISTER_LONG_CONSTANT("SO_NOSERVER", SO_NOSERVER, CONST_PERSISTENT | CONST_CS);
- /* don't do server-based sort */
- /* Status options */
- REGISTER_LONG_CONSTANT("SA_MESSAGES", SA_MESSAGES , CONST_PERSISTENT | CONST_CS);
- /* number of messages */
- REGISTER_LONG_CONSTANT("SA_RECENT", SA_RECENT, CONST_PERSISTENT | CONST_CS);
- /* number of recent messages */
- REGISTER_LONG_CONSTANT("SA_UNSEEN", SA_UNSEEN , CONST_PERSISTENT | CONST_CS);
- /* number of unseen messages */
- REGISTER_LONG_CONSTANT("SA_UIDNEXT", SA_UIDNEXT, CONST_PERSISTENT | CONST_CS);
- /* next UID to be assigned */
- REGISTER_LONG_CONSTANT("SA_UIDVALIDITY", SA_UIDVALIDITY , CONST_PERSISTENT | CONST_CS);
- /* UID validity value */
- REGISTER_LONG_CONSTANT("SA_ALL", sa_all, CONST_PERSISTENT | CONST_CS);
- /* get all status information */
- /* Bits for mm_list() and mm_lsub() */
- 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);
- #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
- /* Sort functions */
- REGISTER_LONG_CONSTANT("SORTDATE", SORTDATE , CONST_PERSISTENT | CONST_CS);
- /* date */
- REGISTER_LONG_CONSTANT("SORTARRIVAL", SORTARRIVAL , CONST_PERSISTENT | CONST_CS);
- /* arrival date */
- REGISTER_LONG_CONSTANT("SORTFROM", SORTFROM , CONST_PERSISTENT | CONST_CS);
- /* from */
- REGISTER_LONG_CONSTANT("SORTSUBJECT", SORTSUBJECT , CONST_PERSISTENT | CONST_CS);
- /* subject */
- REGISTER_LONG_CONSTANT("SORTTO", SORTTO , CONST_PERSISTENT | CONST_CS);
- /* to */
- REGISTER_LONG_CONSTANT("SORTCC", SORTCC , CONST_PERSISTENT | CONST_CS);
- /* cc */
- REGISTER_LONG_CONSTANT("SORTSIZE", SORTSIZE , CONST_PERSISTENT | CONST_CS);
- /* size */
- 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);
- REGISTER_LONG_CONSTANT("TYPEMODEL", TYPEMODEL , CONST_PERSISTENT | CONST_CS);
- REGISTER_LONG_CONSTANT("TYPEOTHER", TYPEOTHER , CONST_PERSISTENT | CONST_CS);
- /*
- TYPETEXT unformatted text
- TYPEMULTIPART multiple part
- TYPEMESSAGE encapsulated message
- TYPEAPPLICATION application data
- TYPEAUDIO audio
- TYPEIMAGE static image (GIF, JPEG, etc.)
- TYPEVIDEO video
- TYPEMODEL model
- TYPEOTHER unknown
- */
- 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);
- /*
- 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
- */
- REGISTER_LONG_CONSTANT("IMAP_GC_ELT", GC_ELT , CONST_PERSISTENT | CONST_CS);
- REGISTER_LONG_CONSTANT("IMAP_GC_ENV", GC_ENV , CONST_PERSISTENT | CONST_CS);
- REGISTER_LONG_CONSTANT("IMAP_GC_TEXTS", GC_TEXTS , CONST_PERSISTENT | CONST_CS);
- /*
- GC_ELT message cache elements
- GC_ENV ENVELOPEs and BODYs
- GC_TEXTS texts
- */
- le_imap = zend_register_list_destructors_ex(mail_close_it, NULL, "imap", module_number);
- return SUCCESS;
- }
- /* }}} */
- /* {{{ PHP_RINIT_FUNCTION
- */
- PHP_RINIT_FUNCTION(imap)
- {
- IMAPG(imap_errorstack) = NIL;
- IMAPG(imap_alertstack) = NIL;
- IMAPG(gets_stream) = NIL;
- 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 */
- if (EG(error_reporting) & E_NOTICE) {
- ecur = IMAPG(imap_errorstack);
- while (ecur != NIL) {
- php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s (errflg=%ld)", ecur->LTEXT, ecur->errflg);
- ecur = ecur->next;
- }
- }
- mail_free_errorlist(&IMAPG(imap_errorstack));
- }
- if (IMAPG(imap_alertstack) != NIL) {
- /* output any remaining alerts at E_NOTICE level */
- if (EG(error_reporting) & E_NOTICE) {
- acur = IMAPG(imap_alertstack);
- while (acur != NIL) {
- php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s", acur->LTEXT);
- acur = acur->next;
- }
- }
- mail_free_stringlist(&IMAPG(imap_alertstack));
- IMAPG(imap_alertstack) = NIL;
- }
- return SUCCESS;
- }
- /* }}} */
- #if !defined(CCLIENTVERSION)
- #if HAVE_IMAP2007e
- #define CCLIENTVERSION "2007e"
- #elif HAVE_IMAP2007d
- #define CCLIENTVERSION "2007d"
- #elif HAVE_IMAP2007b
- #define CCLIENTVERSION "2007b"
- #elif HAVE_IMAP2007a
- #define CCLIENTVERSION "2007a"
- #elif HAVE_IMAP2004
- #define CCLIENTVERSION "2004"
- #elif HAVE_IMAP2001
- #define CCLIENTVERSION "2001"
- #elif HAVE_IMAP2000
- #define CCLIENTVERSION "2000"
- #elif defined(IMAP41)
- #define CCLIENTVERSION "4.1"
- #else
- #define CCLIENTVERSION "4.0"
- #endif
- #endif
- /* {{{ PHP_MINFO_FUNCTION
- */
- PHP_MINFO_FUNCTION(imap)
- {
- php_info_print_table_start();
- php_info_print_table_row(2, "IMAP c-Client Version", CCLIENTVERSION);
- #if HAVE_IMAP_SSL
- php_info_print_table_row(2, "SSL Support", "enabled");
- #endif
- #if HAVE_IMAP_KRB && HAVE_IMAP_AUTH_GSS
- php_info_print_table_row(2, "Kerberos Support", "enabled");
- #endif
- php_info_print_table_end();
- }
- /* }}} */
- /* {{{ imap_do_open
- */
- static void php_imap_do_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
- {
- char *mailbox, *user, *passwd;
- int mailbox_len, user_len, passwd_len;
- long retries = 0, flags = NIL, cl_flags = NIL;
- MAILSTREAM *imap_stream;
- pils *imap_le_struct;
- zval *params = NULL;
- int argc = ZEND_NUM_ARGS();
- if (zend_parse_parameters(argc TSRMLS_CC, "sss|lla", &mailbox, &mailbox_len, &user, &user_len,
- &passwd, &passwd_len, &flags, &retries, ¶ms) == FAILURE) {
- return;
- }
- if (argc >= 4) {
- if (flags & PHP_EXPUNGE) {
- cl_flags = CL_EXPUNGE;
- flags ^= PHP_EXPUNGE;
- }
- if (flags & OP_PROTOTYPE) {
- cl_flags |= OP_PROTOTYPE;
- }
- }
- if (params) {
- zval **disabled_auth_method;
- if (zend_hash_find(HASH_OF(params), "DISABLE_AUTHENTICATOR", sizeof("DISABLE_AUTHENTICATOR"), (void **)&disabled_auth_method) == SUCCESS) {
- switch (Z_TYPE_PP(disabled_auth_method)) {
- case IS_STRING:
- if (Z_STRLEN_PP(disabled_auth_method) > 1) {
- mail_parameters (NIL, DISABLE_AUTHENTICATOR, (void *)Z_STRVAL_PP(disabled_auth_method));
- }
- break;
- case IS_ARRAY:
- {
- zval **z_auth_method;
- int i;
- int nelems = zend_hash_num_elements(Z_ARRVAL_PP(disabled_auth_method));
- if (nelems == 0 ) {
- break;
- }
- for (i = 0; i < nelems; i++) {
- if (zend_hash_index_find(Z_ARRVAL_PP(disabled_auth_method), i, (void **) &z_auth_method) == SUCCESS) {
- if (Z_TYPE_PP(z_auth_method) == IS_STRING) {
- if (Z_STRLEN_PP(z_auth_method) > 1) {
- mail_parameters (NIL, DISABLE_AUTHENTICATOR, (void *)Z_STRVAL_PP(disabled_auth_method));
- }
- } else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid argument, expect string or array of strings");
- }
- }
- }
- }
- break;
- case IS_LONG:
- default:
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid argument, expect string or array of strings");
- break;
- }
- }
- }
- if (IMAPG(imap_user)) {
- efree(IMAPG(imap_user));
- IMAPG(imap_user) = 0;
- }
- if (IMAPG(imap_password)) {
- efree(IMAPG(imap_password));
- IMAPG(imap_password) = 0;
- }
- /* local filename, need to perform open_basedir and safe_mode checks */
- if (mailbox[0] != '{') {
- if (strlen(mailbox) != mailbox_len) {
- RETURN_FALSE;
- }
- if (php_check_open_basedir(mailbox TSRMLS_CC)) {
- RETURN_FALSE;
- }
- }
- IMAPG(imap_user) = estrndup(user, user_len);
- IMAPG(imap_password) = estrndup(passwd, passwd_len);
- #ifdef SET_MAXLOGINTRIALS
- if (argc == 5) {
- if (retries < 0) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING ,"Retries must be greater or equal to 0");
- } else {
- mail_parameters(NIL, SET_MAXLOGINTRIALS, (void *) retries);
- }
- }
- #endif
- imap_stream = mail_open(NIL, mailbox, flags);
- if (imap_stream == NIL) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't open stream %s", mailbox);
- efree(IMAPG(imap_user)); IMAPG(imap_user) = 0;
- efree(IMAPG(imap_password)); IMAPG(imap_password) = 0;
- RETURN_FALSE;
- }
- 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);
- }
- /* }}} */
- /* {{{ proto resource imap_open(string mailbox, string user, string password [, int options [, int n_retries]])
- Open an IMAP stream to a mailbox */
- PHP_FUNCTION(imap_open)
- {
- php_imap_do_open(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
- }
- /* }}} */
- /* {{{ proto bool imap_reopen(resource stream_id, string mailbox [, int options [, int n_retries]])
- Reopen an IMAP stream to a new mailbox */
- PHP_FUNCTION(imap_reopen)
- {
- zval *streamind;
- char *mailbox;
- int mailbox_len;
- long options = 0, retries = 0;
- pils *imap_le_struct;
- MAILSTREAM *imap_stream;
- long flags=NIL;
- long cl_flags=NIL;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|ll", &streamind, &mailbox, &mailbox_len, &options, &retries) == FAILURE) {
- return;
- }
- ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
- if (options) {
- flags = options;
- if (flags & PHP_EXPUNGE) {
- cl_flags = CL_EXPUNGE;
- flags ^= PHP_EXPUNGE;
- }
- imap_le_struct->flags = cl_flags;
- }
- #ifdef SET_MAXLOGINTRIALS
- if (retries) {
- mail_parameters(NIL, SET_MAXLOGINTRIALS, (void *) retries);
- }
- #endif
- /* local filename, need to perform open_basedir and safe_mode checks */
- if (mailbox[0] != '{' && php_check_open_basedir(mailbox TSRMLS_CC)) {
- RETURN_FALSE;
- }
- imap_stream = mail_open(imap_le_struct->imap_stream, mailbox, flags);
- if (imap_stream == NIL) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't re-open stream");
- RETURN_FALSE;
- }
- imap_le_struct->imap_stream = imap_stream;
- RETURN_TRUE;
- }
- /* }}} */
- /* {{{ proto bool imap_append(resource stream_id, string folder, string message [, string options [, string internal_date]])
- Append a new message to a specified mailbox */
- PHP_FUNCTION(imap_append)
- {
- zval *streamind;
- char *folder, *message, *internal_date = NULL, *flags = NULL;
- int folder_len, message_len, internal_date_len = 0, flags_len = 0;
- pils *imap_le_struct;
- STRING st;
- char* regex = "/[0-3][0-9]-((Jan)|(Feb)|(Mar)|(Apr)|(May)|(Jun)|(Jul)|(Aug)|(Sep)|(Oct)|(Nov)|(Dec))-[0-9]{4} [0-2][0-9]:[0-5][0-9]:[0-5][0-9] [+-][0-9]{4}/";
- const int regex_len = strlen(regex);
- pcre_cache_entry *pce; /* Compiled regex */
- zval *subpats = NULL; /* Parts (not used) */
- long regex_flags = 0; /* Flags (not used) */
- long start_offset = 0; /* Start offset (not used) */
- int global = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss|ss", &streamind, &folder, &folder_len, &message, &message_len, &flags, &flags_len, &internal_date, &internal_date_len) == FAILURE) {
- return;
- }
- if (internal_date) {
- /* Make sure the given internal_date string matches the RFC specifiedformat */
- if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC))== NULL) {
- RETURN_FALSE;
- }
- php_pcre_match_impl(pce, internal_date, internal_date_len, return_value, subpats, global,
- 0, regex_flags, start_offset TSRMLS_CC);
- if (!Z_LVAL_P(return_value)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "internal date not correctly formatted");
- internal_date = NULL;
- }
- }
- ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
- INIT (&st, mail_string, (void *) message, message_len);
- if (mail_append_full(imap_le_struct->imap_stream, folder, (flags ? flags : NIL), (internal_date ? internal_date : NIL), &st)) {
- RETURN_TRUE;
- } else {
- RETURN_FALSE;
- }
- }
- /* }}} */
- /* {{{ proto int imap_num_msg(resource stream_id)
- Gives the number of messages in the current mailbox */
- PHP_FUNCTION(imap_num_msg)
- {
- zval *streamind;
- pils *imap_le_struct;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &streamind) == FAILURE) {
- return;
- }
- ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
- RETURN_LONG(imap_le_struct->imap_stream->nmsgs);
- }
- /* }}} */
- /* {{{ proto bool imap_ping(resource stream_id)
- Check if the IMAP stream is still active */
- PHP_FUNCTION(imap_ping)
- {
- zval *streamind;
- pils *imap_le_struct;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &streamind) == FAILURE) {
- return;
- }
- ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
- RETURN_BOOL(mail_ping(imap_le_struct->imap_stream));
- }
- /* }}} */
- /* {{{ proto int imap_num_recent(resource stream_id)
- Gives the number of recent messages in current mailbox */
- PHP_FUNCTION(imap_num_recent)
- {
- zval *streamind;
- pils *imap_le_struct;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &streamind) == FAILURE) {
- return;
- }
- ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
- RETURN_LONG(imap_le_struct->imap_stream->recent);
- }
- /* }}} */
- #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
- /* {{{ proto array imap_get_quota(resource stream_id, string qroot)
- Returns the quota set to the mailbox account qroot */
- PHP_FUNCTION(imap_get_quota)
- {
- zval *streamind;
- char *qroot;
- int qroot_len;
- pils *imap_le_struct;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &streamind, &qroot, &qroot_len) == FAILURE) {
- return;
- }
- ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
- array_init(return_value);
- IMAPG(quota_return) = &return_value;
- /* set the callback for the GET_QUOTA function */
- mail_parameters(NIL, SET_QUOTA, (void *) mail_getquota);
- if (!imap_getquota(imap_le_struct->imap_stream, qroot)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "c-client imap_getquota failed");
- zval_dtor(return_value);
- RETURN_FALSE;
- }
- }
- /* }}} */
- /* {{{ proto array imap_get_quotaroot(resource stream_id, string mbox)
- Returns the quota set to the mailbox account mbox */
- PHP_FUNCTION(imap_get_quotaroot)
- {
- zval *streamind;
- char *mbox;
- int mbox_len;
- pils *imap_le_struct;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &streamind, &mbox, &mbox_len) == FAILURE) {
- return;
- }
- ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
- array_init(return_value);
- IMAPG(quota_return) = &return_value;
- /* set the callback for the GET_QUOTAROOT function */
- mail_parameters(NIL, SET_QUOTA, (void *) mail_getquota);
- if (!imap_getquotaroot(imap_le_struct->imap_stream, mbox)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "c-client imap_getquotaroot failed");
- zval_dtor(return_value);
- RETURN_FALSE;
- }
- }
- /* }}} */
- /* {{{ proto bool imap_set_quota(resource stream_id, string qroot, int mailbox_size)
- Will set the quota for qroot mailbox */
- PHP_FUNCTION(imap_set_quota)
- {
- zval *streamind;
- char *qroot;
- int qroot_len;
- long mailbox_size;
- pils *imap_le_struct;
- STRINGLIST limits;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsl", &streamind, &qroot, &qroot_len, &mailbox_size) == FAILURE) {
- return;
- }
- ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
- limits.text.data = "STORAGE";
- limits.text.size = mailbox_size;
- limits.next = NIL;
- RETURN_BOOL(imap_setquota(imap_le_struct->imap_stream, qroot, &limits));
- }
- /* }}} */
- /* {{{ proto bool imap_setacl(resource stream_id, string mailbox, string id, string rights)
- Sets the ACL for a given mailbox */
- PHP_FUNCTION(imap_setacl)
- {
- zval *streamind;
- char *mailbox, *id, *rights;
- int mailbox_len, id_len, rights_len;
- pils *imap_le_struct;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsss", &streamind, &mailbox, &mailbox_len, &id, &id_len, &rights, &rights_len) == FAILURE) {
- return;
- }
- ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
- RETURN_BOOL(imap_setacl(imap_le_struct->imap_stream, mailbox, id, rights));
- }
- /* }}} */
- /* {{{ proto array imap_getacl(resource stream_id, string mailbox)
- Gets the ACL for a given mailbox */
- PHP_FUNCTION(imap_getacl)
- {
- zval *streamind;
- char *mailbox;
- int mailbox_len;
- pils *imap_le_struct;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &streamind, &mailbox, &mailbox_len) == FAILURE) {
- return;
- }
- ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
- /* 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, mailbox)) {
- php_error(E_WARNING, "c-client imap_getacl failed");
- zval_dtor(return_value);
- RETURN_FALSE;
- }
- IMAPG(imap_acl_list) = NIL;
- }
- /* }}} */
- #endif /* HAVE_IMAP2000 || HAVE_IMAP2001 */
- /* {{{ proto bool imap_expunge(resource stream_id)
- Permanently delete all messages marked for deletion */
- PHP_FUNCTION(imap_expunge)
- {
- zval *streamind;
- pils *imap_le_struct;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &streamind) == FAILURE) {
- return;
- }
- ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
- mail_expunge (imap_le_struct->imap_stream);
- RETURN_TRUE;
- }
- /* }}} */
- /* {{{ proto bool imap_gc(resource stream_id, int flags)
- This function garbage collects (purges) the cache of entries of a specific type. */
- PHP_FUNCTION(imap_gc)
- {
- zval *streamind;
- pils *imap_le_struct;
- long flags;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &streamind, &flags) == FAILURE) {
- return;
- }
- if (flags && ((flags & ~(GC_TEXTS | GC_ELT | GC_ENV)) != 0)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid value for the flags parameter");
- RETURN_FALSE;
- }
- ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
- mail_gc(imap_le_struct->imap_stream, flags);
- RETURN_TRUE;
- }
- /* }}} */
- /* {{{ proto bool imap_close(resource stream_id [, int options])
- Close an IMAP stream */
- PHP_FUNCTION(imap_close)
- {
- zval *streamind;
- pils *imap_le_struct=NULL;
- long options = 0, flags = NIL;
- int argc = ZEND_NUM_ARGS();
- if (zend_parse_parameters(argc TSRMLS_CC, "r|l", &streamind, &options) == FAILURE) {
- return;
- }
- ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
- if (argc == 2) {
- flags = options;
- /* Check that flags is exactly equal to PHP_EXPUNGE or zero */
- if (flags && ((flags & ~PHP_EXPUNGE) != 0)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid value for the flags parameter");
- RETURN_FALSE;
- }
- /* Do the translation from PHP's internal PHP_EXPUNGE define to c-client's CL_EXPUNGE */
- if (flags & PHP_EXPUNGE) {
- flags ^= PHP_EXPUNGE;
- flags |= CL_EXPUNGE;
- }
- imap_le_struct->flags = flags;
- }
- zend_list_delete(Z_RESVAL_P(streamind));
- RETURN_TRUE;
- }
- /* }}} */
- /* {{{ proto array imap_headers(resource stream_id)
- Returns headers for all messages in a mailbox */
- PHP_FUNCTION(imap_headers)
- {
- zval *streamind;
- pils *imap_le_struct;
- unsigned long i;
- char *t;
- unsigned int msgno;
- char tmp[MAILTMPLEN];
- if (ze…
Large files files are truncated, but you can click here to view the full file