diff --git a/Makefile.in b/Makefile.in index d3f2c042da8..7b4b46c8082 100644 --- a/Makefile.in +++ b/Makefile.in @@ -68,17 +68,15 @@ OBJS = main.o internal_functions.o snprintf.o php3_sprintf.o \ safe_mode.o fopen-wrappers.o php3_realpath.o alloca.o output.o \ php_ini.o -FUNCTIONS_SOURCE = functions/fhttpd.c \ - functions/imap.c functions/mime.c \ +FUNCTIONS_SOURCE = functions/fhttpd.c functions/mime.c \ functions/pgsql.c functions/post.c functions/sybase.c \ - functions/sybase-ct.c functions/xml.c \ - functions/ldap.c functions/zlib.c \ + functions/sybase-ct.c functions/xml.c functions/zlib.c \ functions/pdf.c functions/snmp.c functions/interbase.c \ functions/sysvsem.c functions/sysvshm.c FUNCTIONS = $(FUNCTIONS_SOURCE:.c=.o) PHPLIBS = -L@top_srcdir@/libzend -lzend -L@top_srcdir@/ext -lphpext -LIBS = $(PHPLIBS) $(EXTRA_LIBS) @SYBASE_CT_LFLAGS@ @SYBASE_CT_LIBS@ @FHTTPD_LIB@ @REGEX_LIB@ @DBM_LIB@ @SYBASE_LFLAGS@ @SYBASE_LIBS@ @SYBASE_CT_LFLAGS@ @SYBASE_CT_LIBS@ @PGSQL_LFLAGS@ @PGSQL_LIBS@ @LDAP_LFLAGS@ @LDAP_LIBS@ @IMAP_LIBS@ @ZLIB_LIBS@ @PDFLIB_LIBS@ @SNMP_LFLAGS@ @SNMP_LIBS@ @IBASE_LFLAGS@ @IBASE_LIBS@ @XML_LIBS@ @LIBS@ +LIBS = $(PHPLIBS) $(EXTRA_LIBS) @SYBASE_CT_LFLAGS@ @SYBASE_CT_LIBS@ @FHTTPD_LIB@ @REGEX_LIB@ @DBM_LIB@ @SYBASE_LFLAGS@ @SYBASE_LIBS@ @SYBASE_CT_LFLAGS@ @SYBASE_CT_LIBS@ @PGSQL_LFLAGS@ @PGSQL_LIBS@ @ZLIB_LIBS@ @PDFLIB_LIBS@ @SNMP_LFLAGS@ @SNMP_LIBS@ @IBASE_LFLAGS@ @IBASE_LIBS@ @XML_LIBS@ @LIBS@ all: $(BINNAME) diff --git a/acconfig.h.in b/acconfig.h.in index 645c3c32665..7303be1acbc 100644 --- a/acconfig.h.in +++ b/acconfig.h.in @@ -58,18 +58,9 @@ #define REGEX 0 #define HSREGEX 0 -/* Define if you have the crypt() function */ -#define HAVE_CRYPT 1 - -/* Define if you want the LDAP directory interface */ -#define HAVE_LDAP 0 - /* Define if you want the SNMP interface */ #define HAVE_SNMP 0 -/* Define if you want the IMAP directory interface */ -#define HAVE_IMAP 0 - /* Define if you have libdl (used for dynamic linking) */ #define HAVE_LIBDL 0 diff --git a/configure.in.in b/configure.in.in index a8aaed39eb7..0ab3f949d0a 100644 --- a/configure.in.in +++ b/configure.in.in @@ -792,45 +792,6 @@ AC_SUBST(EXTRA_LIBS) # reading config stubs esyscmd(./scripts/config-stubs) -AC_MSG_CHECKING(for IMAP support) -AC_ARG_WITH(imap, -[ --with-imap[=DIR] Include IMAP support (DIR is the IMAP include dir and c-client.a dir).], -[ - if test "$withval" != "no"; then - if test "$withval" = "yes"; then - IMAP_DIR=/usr/local - else - IMAP_DIR=$withval - fi - if test ! -f $IMAP_DIR/include/mail.h; then - AC_MSG_ERROR(could not find mail.h in $IMAP_DIR/include !) - fi - if test ! -f $IMAP_DIR/include/rfc822.h; then - AC_MSG_ERROR(could not find rfc822.h in $IMAP_DIR/include !) - fi - if test ! -f $IMAP_DIR/include/linkage.h; then - AC_MSG_ERROR(could not find linkage.h in $IMAP_DIR/include !) - fi - if test ! -f $IMAP_DIR/lib/c-client.a; then - AC_MSG_ERROR(could not find c-client.a in $IMAP_DIR/lib !) - fi - IMAP_INCLUDE="-I$IMAP_DIR/include/" - IMAP_LIBS="$IMAP_DIR/lib/c-client.a" - -dnl## AC_SUBST(IMAP_INCLUDE) - INCLUDES="$INCLUDES $IMAP_INCLUDE" - AC_SUBST(IMAP_LIBS) - LIBS="$LIBS $IMAP_LIBS" - AC_DEFINE(HAVE_IMAP) - AC_MSG_RESULT(yes) - else - AC_MSG_ERROR(could not find imap library!) - fi -],[ - AC_MSG_RESULT(no) -]) - - AC_MSG_CHECKING(for Sybase support) AC_ARG_WITH(sybase, [ --with-sybase[=DIR] Include Sybase-DB support. DIR is the Sybase home @@ -942,38 +903,6 @@ dnl## AC_SUBST(PGSQL_INCLUDE) INCLUDES="$INCLUDES $PGSQL_INCLUDE" -AC_MSG_CHECKING(for LDAP support) -AC_ARG_WITH(ldap, -[ --with-ldap[=DIR] Include LDAP support. DIR is the LDAP base - install directory, defaults to /usr/local/ldap], -[ - if test "$withval" != "no"; then - if test "$withval" = "yes"; then - LDAP_INCDIR=/usr/local/ldap/include - LDAP_LIBDIR=/usr/local/ldap/lib - else - LDAP_INCDIR=$withval/include - LDAP_LIBDIR=$withval/lib - fi - LDAP_INCLUDE=-I$LDAP_INCDIR - LDAP_LFLAGS="-L$LDAP_LIBDIR ${ld_runpath_switch}$LDAP_LIBDIR" - LDAP_LIBS="-lldap -llber" - - AC_DEFINE(HAVE_LDAP) - - AC_MSG_RESULT(yes) - else - AC_MSG_RESULT(no) - fi -],[ - AC_MSG_RESULT(no) -]) -AC_SUBST(LDAP_LIBS) -AC_SUBST(LDAP_LFLAGS) -dnl## AC_SUBST(LDAP_INCLUDE) -INCLUDES="$INCLUDES $LDAP_INCLUDE" - - AC_MSG_CHECKING(for SNMP support) AC_ARG_WITH(snmp, [ --with-snmp[=DIR] Include SNMP support. DIR is the SNMP base diff --git a/ext/imap/Makefile.am b/ext/imap/Makefile.am new file mode 100644 index 00000000000..51e26414645 --- /dev/null +++ b/ext/imap/Makefile.am @@ -0,0 +1,6 @@ +# $Id$ + +INCLUDES=@INCLUDES@ -I@top_srcdir@ -I@top_srcdir@/libzend +noinst_LIBRARIES=libphpext_imap.a +libphpext_imap_a_SOURCES=imap.c + diff --git a/ext/imap/Makefile.in b/ext/imap/Makefile.in new file mode 100644 index 00000000000..d9d006134b0 --- /dev/null +++ b/ext/imap/Makefile.in @@ -0,0 +1,283 @@ +# Makefile.in generated automatically by automake 1.3 from Makefile.am + +# Copyright (C) 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +# $Id$ + + +SHELL = /bin/sh + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +bindir = @bindir@ +sbindir = @sbindir@ +libexecdir = @libexecdir@ +datadir = @datadir@ +sysconfdir = @sysconfdir@ +sharedstatedir = @sharedstatedir@ +localstatedir = @localstatedir@ +libdir = @libdir@ +infodir = @infodir@ +mandir = @mandir@ +includedir = @includedir@ +oldincludedir = /usr/include + +DISTDIR = + +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ + +top_builddir = ../.. + +ACLOCAL = @ACLOCAL@ +AUTOCONF = @AUTOCONF@ +AUTOMAKE = @AUTOMAKE@ +AUTOHEADER = @AUTOHEADER@ + +INSTALL = @INSTALL@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +transform = @program_transform_name@ + +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +APACHE_INCLUDE = @APACHE_INCLUDE@ +APACHE_TARGET = @APACHE_TARGET@ +APXS = @APXS@ +APXS_LDFLAGS = @APXS_LDFLAGS@ +BINNAME = @BINNAME@ +CC = @CC@ +CFLAGS = @CFLAGS@ +CFLAGS_SHLIB = @CFLAGS_SHLIB@ +DEBUG_CFLAGS = @DEBUG_CFLAGS@ +EXTINFO_DEPS = @EXTINFO_DEPS@ +EXTRA_LIBS = @EXTRA_LIBS@ +EXT_LIBS = @EXT_LIBS@ +EXT_SUBDIRS = @EXT_SUBDIRS@ +FHTTPD_LIB = @FHTTPD_LIB@ +FHTTPD_TARGET = @FHTTPD_TARGET@ +HSREGEX = @HSREGEX@ +IBASE_LFLAGS = @IBASE_LFLAGS@ +IBASE_LIBS = @IBASE_LIBS@ +INSTALL_IT = @INSTALL_IT@ +LDFLAGS_SHLIB = @LDFLAGS_SHLIB@ +LDFLAGS_SHLIB_EXPORT = @LDFLAGS_SHLIB_EXPORT@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +PACKAGE = @PACKAGE@ +PDFLIB_LIBS = @PDFLIB_LIBS@ +PERL_PATH = @PERL_PATH@ +PGSQL_LFLAGS = @PGSQL_LFLAGS@ +PGSQL_LIBS = @PGSQL_LIBS@ +PHP_BUILD_DATE = @PHP_BUILD_DATE@ +PHP_DEBUG = @PHP_DEBUG@ +PHP_LIBS = @PHP_LIBS@ +PHP_VERSION = @PHP_VERSION@ +PROG_SENDMAIL = @PROG_SENDMAIL@ +RANLIB = @RANLIB@ +RDYNAMIC_LFLAGS = @RDYNAMIC_LFLAGS@ +REGEX_LIB = @REGEX_LIB@ +SNMP_LFLAGS = @SNMP_LFLAGS@ +SNMP_LIBS = @SNMP_LIBS@ +STRONGHOLD = @STRONGHOLD@ +SYBASE_CT_LFLAGS = @SYBASE_CT_LFLAGS@ +SYBASE_CT_LIBS = @SYBASE_CT_LIBS@ +SYBASE_LFLAGS = @SYBASE_LFLAGS@ +SYBASE_LIBS = @SYBASE_LIBS@ +VERSION = @VERSION@ +WARNING_LEVEL = @WARNING_LEVEL@ +XML_LIBS = @XML_LIBS@ +YACC = @YACC@ +ZLIB_LIBS = @ZLIB_LIBS@ + +INCLUDES=@INCLUDES@ -I@top_srcdir@ -I@top_srcdir@/libzend +noinst_LIBRARIES=libphpext_imap.a +libphpext_imap_a_SOURCES=imap.c +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = ../../config.h +CONFIG_CLEAN_FILES = +LIBRARIES = $(noinst_LIBRARIES) + + +DEFS = @DEFS@ -I. -I$(srcdir) -I../.. +CPPFLAGS = @CPPFLAGS@ +LDFLAGS = @LDFLAGS@ +LIBS = @LIBS@ +libphpext_imap_a_LIBADD = +libphpext_imap_a_OBJECTS = imap.o +AR = ar +COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) +LINK = $(CC) $(CFLAGS) $(LDFLAGS) -o $@ +DIST_COMMON = Makefile.am Makefile.in + + +DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) + +TAR = tar +GZIP = --best +SOURCES = $(libphpext_imap_a_SOURCES) +OBJECTS = $(libphpext_imap_a_OBJECTS) + +all: Makefile $(LIBRARIES) + +.SUFFIXES: +.SUFFIXES: .S .c .o .s +$(srcdir)/Makefile.in: @MAINT@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps ext/imap/Makefile + +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + cd $(top_builddir) \ + && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status + + +mostlyclean-noinstLIBRARIES: + +clean-noinstLIBRARIES: + -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) + +distclean-noinstLIBRARIES: + +maintainer-clean-noinstLIBRARIES: + +.c.o: + $(COMPILE) -c $< + +.s.o: + $(COMPILE) -c $< + +.S.o: + $(COMPILE) -c $< + +mostlyclean-compile: + -rm -f *.o core *.core + +clean-compile: + +distclean-compile: + -rm -f *.tab.c + +maintainer-clean-compile: + +libphpext_imap.a: $(libphpext_imap_a_OBJECTS) $(libphpext_imap_a_DEPENDENCIES) + -rm -f libphpext_imap.a + $(AR) cru libphpext_imap.a $(libphpext_imap_a_OBJECTS) $(libphpext_imap_a_LIBADD) + $(RANLIB) libphpext_imap.a + +tags: TAGS + +ID: $(HEADERS) $(SOURCES) $(LISP) + here=`pwd` && cd $(srcdir) \ + && mkid -f$$here/ID $(SOURCES) $(HEADERS) $(LISP) + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \ + || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS) + +mostlyclean-tags: + +clean-tags: + +distclean-tags: + -rm -f TAGS ID + +maintainer-clean-tags: + +distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) + +subdir = ext/imap + +distdir: $(DISTFILES) + @for file in $(DISTFILES); do \ + d=$(srcdir); \ + test -f $(distdir)/$$file \ + || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ + || cp -p $$d/$$file $(distdir)/$$file; \ + done +info: +dvi: +check: all + $(MAKE) +installcheck: +install-exec: + @$(NORMAL_INSTALL) + +install-data: + @$(NORMAL_INSTALL) + +install: install-exec install-data all + @: + +uninstall: + +install-strip: + $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' INSTALL_SCRIPT='$(INSTALL_PROGRAM)' install +installdirs: + + +mostlyclean-generic: + -test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES) + +clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) + +distclean-generic: + -rm -f Makefile $(DISTCLEANFILES) + -rm -f config.cache config.log stamp-h stamp-h[0-9]* + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) + -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) +mostlyclean: mostlyclean-noinstLIBRARIES mostlyclean-compile \ + mostlyclean-tags mostlyclean-generic + +clean: clean-noinstLIBRARIES clean-compile clean-tags clean-generic \ + mostlyclean + +distclean: distclean-noinstLIBRARIES distclean-compile distclean-tags \ + distclean-generic clean + -rm -f config.status + +maintainer-clean: maintainer-clean-noinstLIBRARIES \ + maintainer-clean-compile maintainer-clean-tags \ + maintainer-clean-generic distclean + @echo "This command is intended for maintainers to use;" + @echo "it deletes files that may require special tools to rebuild." + +.PHONY: mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \ +clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \ +mostlyclean-compile distclean-compile clean-compile \ +maintainer-clean-compile tags mostlyclean-tags distclean-tags \ +clean-tags maintainer-clean-tags distdir info dvi installcheck \ +install-exec install-data install uninstall all installdirs \ +mostlyclean-generic distclean-generic clean-generic \ +maintainer-clean-generic clean mostlyclean distclean maintainer-clean + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/ext/imap/config.h.stub b/ext/imap/config.h.stub new file mode 100644 index 00000000000..d225ffa0924 --- /dev/null +++ b/ext/imap/config.h.stub @@ -0,0 +1,2 @@ +/* Define if you want the IMAP extension */ +#define HAVE_IMAP 0 diff --git a/ext/imap/config.m4 b/ext/imap/config.m4 new file mode 100644 index 00000000000..e94df1bfd50 --- /dev/null +++ b/ext/imap/config.m4 @@ -0,0 +1,43 @@ +dnl $Id$ + +AC_MSG_CHECKING(for IMAP support) +AC_ARG_WITH(imap, +[ --with-imap[=DIR] Include IMAP support (DIR is the IMAP include dir and c-client.a dir).], +[ + if test "$withval" != "no"; then + if test "$withval" = "yes"; then + IMAP_DIR=/usr/local + else + IMAP_DIR=$withval + fi + if test ! -f $IMAP_DIR/include/mail.h; then + AC_MSG_ERROR(could not find mail.h in $IMAP_DIR/include !) + fi + if test ! -f $IMAP_DIR/include/rfc822.h; then + AC_MSG_ERROR(could not find rfc822.h in $IMAP_DIR/include !) + fi + if test ! -f $IMAP_DIR/include/linkage.h; then + AC_MSG_ERROR(could not find linkage.h in $IMAP_DIR/include !) + fi + if test ! -f $IMAP_DIR/lib/c-client.a; then + AC_MSG_ERROR(could not find c-client.a in $IMAP_DIR/lib !) + fi + IMAP_INCLUDE="-I$IMAP_DIR/include/" + IMAP_LIBS="$IMAP_DIR/lib/c-client.a" + +dnl## AC_SUBST(IMAP_INCLUDE) + INCLUDES="$INCLUDES $IMAP_INCLUDE" + AC_SUBST(IMAP_LIBS) + LIBS="$LIBS $IMAP_LIBS" + AC_DEFINE(HAVE_IMAP) + AC_MSG_RESULT(yes) + PHP_EXTENSION(imap) + else + AC_MSG_ERROR(could not find imap library!) + fi +],[ + AC_MSG_RESULT(no) +]) + + + diff --git a/ext/imap/imap.c b/ext/imap/imap.c new file mode 100644 index 00000000000..cabdeb7549e --- /dev/null +++ b/ext/imap/imap.c @@ -0,0 +1,2668 @@ +/* + +----------------------------------------------------------------------+ + | PHP HTML Embedded Scripting Language Version 3.0 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | + +----------------------------------------------------------------------+ + | This program is free software; you can redistribute it and/or modify | + | it under the terms of one of the following licenses: | + | | + | A) the GNU General Public License as published by the Free Software | + | Foundation; either version 2 of the License, or (at your option) | + | any later version. | + | | + | B) the PHP License as published by the PHP Development Team and | + | included in the distribution in the file: LICENSE | + | | + | This program is distributed in the hope that it will be useful, | + | but WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | + | GNU General Public License for more details. | + | | + | You should have received a copy of both licenses referred to here. | + | If you did not, or have any questions about PHP licensing, please | + | contact core@php.net. | + +----------------------------------------------------------------------+ + | Authors: Rex Logan | + | Mark Musone | + | Brian Wang | + | Kaj-Michael Lang | + | Antoni Pamies Olive | + | Rasmus Lerdorf | + +----------------------------------------------------------------------+ + */ +/* $Id$ */ + +#define IMAP41 + +#ifdef ERROR +#undef ERROR +#endif + +#if !(WIN32|WINNT) +#include "config.h" +#endif +#include "php.h" + +#if COMPILE_DL +#include "dl/phpdl.h" +#endif + +#if HAVE_IMAP + +#include +#include +#include +#include +#include "imap.h" +#include "mail.h" +#include "rfc822.h" +#include "modules.h" +#if (WIN32|WINNT) +#include "winsock.h" +#endif + +#ifdef IMAP41 +#define LSIZE text.size +#define LTEXT text.data +#define DTYPE int +#define CONTENT_PART nested.part +#define CONTENT_MSG_BODY nested.msg->body +#define IMAPVER "Imap 4R1" +#else +#define LSIZE size +#define LTEXT text +#define DTYPE char +#define CONTENT_PART contents.part +#define CONTENT_MSG_BODY contents.msg.body +#define IMAPVER "Imap 4" +#endif + +#define PHP_EXPUNGE 32768 + +/* + * this array should be set up as: + * {"PHPScriptFunctionName",dllFunctionName,1} + */ + +/* type casts left out, put here to remove warnings in + msvc +*/ +extern void rfc822_date(char *date); +extern char *cpystr(const char *string); +extern unsigned long find_rightmost_bit (unsigned long *valptr); +extern void fs_give (void **block); +extern void *fs_get (size_t size); +int add_assoc_object(pval *arg, char *key, pval tmp); +int add_next_index_object(pval *arg, pval tmp); +void imap_add_body( pval *arg, BODY *body ); + +typedef struct php3_imap_le_struct { + MAILSTREAM *imap_stream; + long flags; +} pils; + +MAILSTREAM *mail_close_it (pils *imap_le_struct); + +function_entry imap_functions[] = { + {"imap_open", php3_imap_open, NULL}, + {"imap_reopen", php3_imap_reopen, NULL}, + {"imap_num_msg", php3_imap_num_msg, NULL}, + {"imap_num_recent", php3_imap_num_recent, NULL}, + {"imap_headers", php3_imap_headers, NULL}, + {"imap_header", php3_imap_headerinfo, NULL}, + {"imap_headerinfo", php3_imap_headerinfo, NULL}, + {"imap_body", php3_imap_body, NULL}, + {"imap_fetchstructure", php3_imap_fetchstructure, NULL}, + {"imap_fetchbody", php3_imap_fetchbody, NULL}, + {"imap_expunge", php3_imap_expunge, NULL}, + {"imap_delete", php3_imap_delete, NULL}, + {"imap_undelete", php3_imap_undelete, NULL}, + {"imap_check", php3_imap_check, NULL}, + {"imap_close", php3_imap_close, NULL}, + {"imap_mail_copy", php3_imap_mail_copy, NULL}, + {"imap_mail_move", php3_imap_mail_move, NULL}, + {"imap_createmailbox", php3_imap_createmailbox, NULL}, + {"imap_renamemailbox", php3_imap_renamemailbox, NULL}, + {"imap_deletemailbox", php3_imap_deletemailbox, NULL}, + {"imap_listmailbox", php3_imap_list, NULL}, + {"imap_scanmailbox", php3_imap_listscan, NULL}, + {"imap_listsubscribed", php3_imap_lsub, NULL}, + {"imap_subscribe", php3_imap_subscribe, NULL}, + {"imap_unsubscribe", php3_imap_unsubscribe, NULL}, + {"imap_append", php3_imap_append, NULL}, + {"imap_ping", php3_imap_ping, NULL}, + {"imap_base64", php3_imap_base64, NULL}, + {"imap_qprint", php3_imap_qprint, NULL}, + {"imap_8bit", php3_imap_8bit, NULL}, + {"imap_binary", php3_imap_binary, NULL}, + {"imap_mailboxmsginfo", php3_imap_mailboxmsginfo, NULL}, + {"imap_rfc822_write_address", php3_imap_rfc822_write_address, NULL}, + {"imap_rfc822_parse_adrlist", php3_imap_rfc822_parse_adrlist, NULL}, + {"imap_setflag_full", php3_imap_setflag_full, NULL}, + {"imap_clearflag_full", php3_imap_clearflag_full, NULL}, + {"imap_sort", php3_imap_sort, NULL}, + {"imap_fetchheader", php3_imap_fetchheader, NULL}, + {"imap_fetchtext", php3_imap_body, NULL}, + {"imap_uid", php3_imap_uid, NULL}, + {"imap_msgno",php3_imap_msgno, NULL}, + {"imap_list", php3_imap_list, NULL}, + {"imap_scan", php3_imap_listscan, NULL}, + {"imap_lsub", php3_imap_lsub, NULL}, + {"imap_create", php3_imap_createmailbox, NULL}, + {"imap_rename", php3_imap_renamemailbox, NULL}, + {"imap_status", php3_imap_status, NULL}, + {"imap_bodystruct", php3_imap_bodystruct, NULL}, + {"imap_fetch_overview", php3_imap_fetch_overview, NULL}, + {"imap_mail_compose", php3_imap_mail_compose, NULL}, + {NULL, NULL, NULL} +}; + + +php3_module_entry php3_imap_module_entry = { + IMAPVER, imap_functions, imap_init, NULL, NULL, NULL,imap_info, 0, 0, 0, NULL +}; + + +#if COMPILE_DL +DLEXPORT php3_module_entry *get_module(void) { return &php3_imap_module_entry; } +#endif + +/* + I beleive since this global is used ONLY within this module, + and nothing will link to this module, we can use the simple + thread local storage +*/ +int le_imap; +char imap_user[80]=""; +char imap_password[80]=""; +STRINGLIST *imap_folders=NIL; +STRINGLIST *imap_sfolders=NIL; +long status_flags; +unsigned long status_messages; +unsigned long status_recent; +unsigned long status_unseen; +unsigned long status_uidnext; +unsigned long status_uidvalidity; + +MAILSTREAM *mail_close_it (pils *imap_le_struct) +{ + MAILSTREAM *ret; + ret = mail_close_full (imap_le_struct->imap_stream,imap_le_struct->flags); + efree(imap_le_struct); + return ret; +} + +inline int add_assoc_object(pval *arg, char *key, pval tmp) +{ + return _php3_hash_update(arg->value.ht, key, strlen(key)+1, (void *) &tmp, sizeof(pval), NULL); +} + +inline int add_next_index_object(pval *arg, pval tmp) +{ + return _php3_hash_next_index_insert( arg->value.ht, (void *) &tmp, sizeof(pval), NULL); +} + + +void imap_info(void) +{ + php3_printf("Imap Support enabled
"); + php3_printf(""); + php3_printf(""); +#ifdef IMAP41 + php3_printf(""); +#else + php3_printf(""); +#endif + php3_printf("
Imap c-client Version:Imap 4.1Imap 4.0
"); +} + +int imap_init(INIT_FUNC_ARGS) +{ +#if !(WIN32|WINNT) + mail_link(&unixdriver); /* link in the unix 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 */ +#if !(WIN32|WINNT) + mail_link (&mhdriver); /* link in the mh driver */ + mail_link (&mxdriver); /* link in the mx driver */ +#endif + mail_link (&mbxdriver); /* link in the mbx driver */ + mail_link (&tenexdriver); /* link in the tenex driver */ + mail_link (&mtxdriver); /* link in the mtx driver */ +#if !(WIN32|WINNT) + 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 (&dummydriver); /* link in the dummy driver */ + auth_link (&auth_log); /* link in the log authenticator */ + /* lets allow NIL */ + + REGISTER_MAIN_LONG_CONSTANT("NIL", NIL, CONST_PERSISTENT | CONST_CS); + + + /* Open Options */ + + REGISTER_MAIN_LONG_CONSTANT("OP_DEBUG", OP_DEBUG, CONST_PERSISTENT | CONST_CS); +/* debug protocol negotiations */ + + REGISTER_MAIN_LONG_CONSTANT("OP_READONLY", OP_READONLY, CONST_PERSISTENT | CONST_CS); +/* read-only open */ + + REGISTER_MAIN_LONG_CONSTANT("OP_ANONYMOUS", OP_ANONYMOUS, CONST_PERSISTENT | CONST_CS); + /* anonymous open of newsgroup */ + + REGISTER_MAIN_LONG_CONSTANT("OP_SHORTCACHE", OP_SHORTCACHE, CONST_PERSISTENT | CONST_CS); + +/* short (elt-only) caching */ + + REGISTER_MAIN_LONG_CONSTANT("OP_SILENT", OP_SILENT, CONST_PERSISTENT | CONST_CS); +/* don't pass up events (internal use) */ + REGISTER_MAIN_LONG_CONSTANT("OP_PROTOTYPE", OP_PROTOTYPE, CONST_PERSISTENT | CONST_CS); +/* return driver prototype */ + REGISTER_MAIN_LONG_CONSTANT("OP_HALFOPEN", OP_HALFOPEN, CONST_PERSISTENT | CONST_CS); +/* half-open (IMAP connect but no select) */ + + REGISTER_MAIN_LONG_CONSTANT("OP_EXPUNGE", OP_EXPUNGE, CONST_PERSISTENT | CONST_CS); + /* silently expunge recycle stream */ + + REGISTER_MAIN_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_MAIN_LONG_CONSTANT("CL_EXPUNGE", PHP_EXPUNGE, CONST_PERSISTENT | CONST_CS); + /* expunge silently */ + + + /* Fetch options */ + + REGISTER_MAIN_LONG_CONSTANT("FT_UID", FT_UID, CONST_PERSISTENT | CONST_CS); + /* argument is a UID */ + REGISTER_MAIN_LONG_CONSTANT("FT_PEEK", FT_PEEK, CONST_PERSISTENT | CONST_CS); + /* peek at data */ + REGISTER_MAIN_LONG_CONSTANT("FT_NOT", FT_NOT, CONST_PERSISTENT | CONST_CS); + /* NOT flag for header lines fetch */ + REGISTER_MAIN_LONG_CONSTANT("FT_INTERNAL", FT_INTERNAL, CONST_PERSISTENT | CONST_CS); + /* text can be internal strings */ + REGISTER_MAIN_LONG_CONSTANT("FT_PREFETCHTEXT", FT_PREFETCHTEXT, CONST_PERSISTENT | CONST_CS); + /* IMAP prefetch text when fetching header */ + + + /* Flagging options */ + + REGISTER_MAIN_LONG_CONSTANT("ST_UID", ST_UID, CONST_PERSISTENT | CONST_CS); + /* argument is a UID sequence */ + REGISTER_MAIN_LONG_CONSTANT("ST_SILENT", ST_SILENT, CONST_PERSISTENT | CONST_CS); + /* don't return results */ + REGISTER_MAIN_LONG_CONSTANT("ST_SET", ST_SET, CONST_PERSISTENT | CONST_CS); + /* set vs. clear */ + + /* Copy options */ + + REGISTER_MAIN_LONG_CONSTANT("CP_UID", CP_UID, CONST_PERSISTENT | CONST_CS); + /* argument is a UID sequence */ + REGISTER_MAIN_LONG_CONSTANT("CP_MOVE", CP_MOVE, CONST_PERSISTENT | CONST_CS); + /* delete from source after copying */ + + + /* Search/sort options */ + + REGISTER_MAIN_LONG_CONSTANT("SE_UID", SE_UID, CONST_PERSISTENT | CONST_CS); + /* return UID */ + REGISTER_MAIN_LONG_CONSTANT("SE_FREE", SE_FREE, CONST_PERSISTENT | CONST_CS); + /* free search program after finished */ + REGISTER_MAIN_LONG_CONSTANT("SE_NOPREFETCH", SE_NOPREFETCH, CONST_PERSISTENT | CONST_CS); + /* no search prefetching */ + REGISTER_MAIN_LONG_CONSTANT("SO_FREE", SO_FREE, CONST_PERSISTENT | CONST_CS); + /* free sort program after finished */ + REGISTER_MAIN_LONG_CONSTANT("SO_NOSERVER", SO_NOSERVER, CONST_PERSISTENT | CONST_CS); + /* don't do server-based sort */ + + /* Status options */ + + REGISTER_MAIN_LONG_CONSTANT("SA_MESSAGES",SA_MESSAGES , CONST_PERSISTENT | CONST_CS); + /* number of messages */ + REGISTER_MAIN_LONG_CONSTANT("SA_RECENT", SA_RECENT, CONST_PERSISTENT | CONST_CS); + /* number of recent messages */ + REGISTER_MAIN_LONG_CONSTANT("SA_UNSEEN",SA_UNSEEN , CONST_PERSISTENT | CONST_CS); + /* number of unseen messages */ + REGISTER_MAIN_LONG_CONSTANT("SA_UIDNEXT", SA_UIDNEXT, CONST_PERSISTENT | CONST_CS); + /* next UID to be assigned */ + REGISTER_MAIN_LONG_CONSTANT("SA_UIDVALIDITY",SA_UIDVALIDITY , CONST_PERSISTENT | CONST_CS); + /* UID validity value */ + + + /* Bits for mm_list() and mm_lsub() */ + + REGISTER_MAIN_LONG_CONSTANT("LATT_NOINFERIORS",LATT_NOINFERIORS , CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("LATT_NOSELECT", LATT_NOSELECT, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("LATT_MARKED", LATT_MARKED, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("LATT_UNMARKED",LATT_UNMARKED , CONST_PERSISTENT | CONST_CS); + + + /* Sort functions */ + + REGISTER_MAIN_LONG_CONSTANT("SORTDATE",SORTDATE , CONST_PERSISTENT | CONST_CS); + /* date */ + REGISTER_MAIN_LONG_CONSTANT("SORTARRIVAL",SORTARRIVAL , CONST_PERSISTENT | CONST_CS); + /* arrival date */ + REGISTER_MAIN_LONG_CONSTANT("SORTFROM",SORTFROM , CONST_PERSISTENT | CONST_CS); + /* from */ + REGISTER_MAIN_LONG_CONSTANT("SORTSUBJECT",SORTSUBJECT , CONST_PERSISTENT | CONST_CS); + /* subject */ + REGISTER_MAIN_LONG_CONSTANT("SORTTO",SORTTO , CONST_PERSISTENT | CONST_CS); + /* to */ + REGISTER_MAIN_LONG_CONSTANT("SORTCC",SORTCC , CONST_PERSISTENT | CONST_CS); + /* cc */ + REGISTER_MAIN_LONG_CONSTANT("SORTSIZE",SORTSIZE , CONST_PERSISTENT | CONST_CS); + /* size */ + + REGISTER_MAIN_LONG_CONSTANT("TYPETEXT",TYPETEXT , CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("TYPEMULTIPART",TYPEMULTIPART , CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("TYPEMESSAGE",TYPEMESSAGE , CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("TYPEAPPLICATION",TYPEAPPLICATION , CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("TYPEAUDIO",TYPEAUDIO , CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("TYPEIMAGE",TYPEIMAGE , CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("TYPEVIDEO",TYPEVIDEO , CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_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 + TYPEOTHER unknown + */ + REGISTER_MAIN_LONG_CONSTANT("ENC7BIT",ENC7BIT , CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("ENC8BIT",ENC8BIT , CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("ENCBINARY",ENCBINARY , CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("ENCBASE64",ENCBASE64, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("ENCQUOTEDPRINTABLE",ENCQUOTEDPRINTABLE , CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_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 + */ + + le_imap = register_list_destructors(mail_close_it,NULL); + return SUCCESS; +} + +/* {{{ proto int imap_open(string mailbox, string user, string password [, int options]) + Open an IMAP stream to a mailbox */ +void php3_imap_open(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *mailbox; + pval *user; + pval *passwd; + pval *options; + MAILSTREAM *imap_stream; + pils *imap_le_struct; + long flags=NIL; + long cl_flags=NIL; + + int ind; + int myargc=ARG_COUNT(ht); + + if (myargc <3 || myargc >4 || getParameters(ht, myargc, &mailbox,&user,&passwd,&options) == FAILURE) { + WRONG_PARAM_COUNT; + } else { + convert_to_string(mailbox); + convert_to_string(user); + convert_to_string(passwd); + if(myargc ==4) { + convert_to_long(options); + flags = options->value.lval; + if(flags & PHP_EXPUNGE) { + cl_flags = CL_EXPUNGE; + flags ^= PHP_EXPUNGE; + } + } + strcpy(imap_user,user->value.str.val); + strcpy(imap_password,passwd->value.str.val); + imap_stream = NIL; + imap_stream = mail_open(imap_stream,mailbox->value.str.val,flags); + + if (imap_stream == NIL){ + php3_error(E_WARNING,"Couldn't open stream %s\n",mailbox->value.str.val); + RETURN_FALSE; + } + /* Note that if we ever come up with a persistent imap stream, the persistent version of this + struct needs to be malloc'ed and not emalloc'ed */ + imap_le_struct = emalloc(sizeof(pils)); + imap_le_struct->imap_stream = imap_stream; + imap_le_struct->flags = cl_flags; + ind = php3_list_insert(imap_le_struct, le_imap); + + RETURN_LONG(ind); + } + return; +} +/* }}} */ + +/* {{{ proto int imap_reopen(int stream_id, string mailbox [, int options]) + Reopen IMAP stream to new mailbox */ +void php3_imap_reopen(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind; + pval *mailbox; + pval *options; + MAILSTREAM *imap_stream; + pils *imap_le_struct; + int ind, ind_type; + long flags=NIL; + long cl_flags=NIL; + int myargc=ARG_COUNT(ht); + + if (myargc<2 || myargc>3 || getParameters(ht,myargc,&streamind, &mailbox, &options) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + ind = streamind->value.lval; + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + + convert_to_string(mailbox); + if(myargc == 3) { + convert_to_long(options); + flags = options->value.lval; + if(flags & PHP_EXPUNGE) { + cl_flags = CL_EXPUNGE; + flags ^= PHP_EXPUNGE; + } + imap_le_struct->flags = cl_flags; + } + imap_stream = mail_open(imap_le_struct->imap_stream, mailbox->value.str.val, flags); + if (imap_stream == NIL) { + php3_error(E_WARNING,"Couldn't re-open stream\n"); + RETURN_FALSE; + } + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto int imap_append(int stream_id, string folder, string message [, string flags]) + Append a string message to a specified mailbox */ +void php3_imap_append(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind,*folder, *message,*flags; + int ind, ind_type; + pils *imap_le_struct; + STRING st; + int myargc=ARG_COUNT(ht); + + if ( myargc < 3 || myargc > 4 || getParameters( ht, myargc, &streamind, &folder, &message,&flags) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_string(folder); + convert_to_string(message); + if (myargc == 4) convert_to_string(flags); + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find( ind, &ind_type ); + + if ( !imap_le_struct || ind_type != le_imap ) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + INIT (&st,mail_string,(void *) message->value.str.val,message->value.str.len); + if(mail_append_full(imap_le_struct->imap_stream, folder->value.str.val,myargc==4?flags->value.str.val:NIL,NIL,&st)) + { + RETURN_TRUE; + } + else + { + RETURN_FALSE; + } +} +/* }}} */ + +/* {{{ proto imap_num_msg(int stream_id) + Gives the number of messages in the current mailbox */ +void php3_imap_num_msg(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind; + int ind, ind_type; + pils *imap_le_struct; + + if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &streamind) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + + RETURN_LONG(imap_le_struct->imap_stream->nmsgs); +} +/* }}} */ + +/* {{{ proto int imap_ping(int stream_id) + Check if the IMAP stream is still active */ +void php3_imap_ping(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind; + int ind, ind_type; + pils *imap_le_struct; + + if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &streamind) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long( streamind ); + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find( ind, &ind_type ); + if ( !imap_le_struct || ind_type != le_imap ) { + php3_error( E_WARNING, "Unable to find stream pointer" ); + RETURN_FALSE; + } + RETURN_LONG( mail_ping( imap_le_struct->imap_stream ) ); +} +/* }}} */ + +/* {{{ proto int imap_num_recent(int stream_id) + Gives the number of recent messages in current mailbox */ +void php3_imap_num_recent(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind; + int ind, ind_type; + pils *imap_le_struct; + if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &streamind) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(streamind); + ind = streamind->value.lval; + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + RETURN_LONG(imap_le_struct->imap_stream->recent); +} +/* }}} */ + +/* {{{ proto int imap_expunge(int stream_id) + Delete all messages marked for deletion */ +void php3_imap_expunge(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind; + int ind, ind_type; + pils *imap_le_struct; + + if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &streamind) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + + mail_expunge (imap_le_struct->imap_stream); + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto int imap_close(int stream_id [, int options]) + Close an IMAP stream */ +void php3_imap_close(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *options, *streamind; + int ind, ind_type; + pils *imap_le_struct=NULL; + int myargcount=ARG_COUNT(ht); + long flags = NIL; + + if (myargcount < 1 || myargcount > 2 || getParameters(ht, myargcount, &streamind, &options) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(streamind); + ind = streamind->value.lval; + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + if(myargcount==2) { + convert_to_long(options); + flags = options->value.lval; + /* 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; + } + php3_list_delete(ind); + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto array imap_headers(int stream_id) + Returns headers for all messages in a mailbox */ +void php3_imap_headers(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind; + int ind, ind_type; + unsigned long i; + char *t; + unsigned int msgno; + pils *imap_le_struct; + char tmp[MAILTMPLEN]; + + if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &streamind) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + + /* Initialize return array */ + if (array_init(return_value) == FAILURE) { + RETURN_FALSE; + } + + 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); + 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' : ' '; + sprintf (tmp+5,"%4ld) ",cache->msgno); + mail_date (tmp+11,cache); + tmp[17] = ' '; + tmp[18] = '\0'; + mail_fetchfrom (tmp+18,imap_le_struct->imap_stream,msgno,(long) 20); + strcat (tmp," "); + if ((i = cache->user_flags)) { + strcat (tmp,"{"); + while (i) { + strcat (tmp,imap_le_struct->imap_stream->user_flags[find_rightmost_bit (&i)]); + if (i) strcat (tmp," "); + } + strcat (tmp,"} "); + } + mail_fetchsubject(t=tmp+strlen(tmp),imap_le_struct->imap_stream,msgno,(long)25); + sprintf (t+=strlen(t)," (%ld chars)",cache->rfc822_size); + add_next_index_string(return_value,tmp,1); + } +} +/* }}} */ + +/* {{{ proto imap_body(int stream_id, int msg_no [, int options]) + Read the message body */ +void php3_imap_body(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind, * msgno, *flags; + int ind, ind_type; + pils *imap_le_struct; + int myargc=ARG_COUNT(ht); + if (myargc <2 || myargc > 3 || getParameters(ht,myargc,&streamind,&msgno,&flags) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_long(msgno); + if(myargc == 3) convert_to_long(flags); + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + RETVAL_STRING(mail_fetchtext_full (imap_le_struct->imap_stream,msgno->value.lval,NIL,myargc == 3 ? flags->value.lval : NIL),1); +} +/* }}} */ + +/* v--- add proto here when this function is done */ +/* {{{ string imap_fetchtext_full(int stream_id, int msg_no [, int options]) + Read the body of a message*/ +void php3_imap_fetchtext_full(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind, * msgno, *flags; + int ind, ind_type; + pils *imap_le_struct; + int myargcount = ARG_COUNT(ht); + if (myargcount >3 || myargcount <2 || getParameters(ht,myargcount,&streamind,&msgno,&flags) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_long(msgno); + if (myargcount == 3) convert_to_long(flags); + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + RETVAL_STRING(mail_fetchtext_full (imap_le_struct->imap_stream,msgno->value.lval,NIL,myargcount==3?flags->value.lval:NIL),1); +} +/* }}} */ + +/* {{{ proto int imap_mail_copy(int stream_id, int msg_no, string mailbox [, int options]) + Copy specified message to a mailbox */ +void php3_imap_mail_copy(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind,*seq, *folder, *options; + int ind, ind_type; + pils *imap_le_struct; + int myargcount = ARG_COUNT(ht); + if (myargcount > 4 || myargcount < 3 + || getParameters(ht,myargcount,&streamind,&seq,&folder,&options) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_string(seq); + convert_to_string(folder); + if(myargcount == 4) convert_to_long(options); + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + if ( mail_copy_full(imap_le_struct->imap_stream,seq->value.str.val,folder->value.str.val,myargcount == 4 ? options->value.lval : NIL)==T ) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } +} +/* }}} */ + +/* {{{ proto imap_mail_move(int stream_id, int msg_no, string mailbox) + Move specified message to a mailbox */ +void php3_imap_mail_move(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind,*seq, *folder; + int ind, ind_type; + pils *imap_le_struct; + + if (ARG_COUNT(ht)!=3 + || getParameters(ht,3,&streamind,&seq,&folder) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_string(seq); + convert_to_string(folder); + + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + if ( mail_move(imap_le_struct->imap_stream,seq->value.str.val,folder->value.str.val)==T ) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } +} +/* }}} */ + +/* {{{ proto int imap_createmailbox(int stream_id, string mailbox) + Create a new mailbox */ +void php3_imap_createmailbox(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind, *folder; + int ind, ind_type; + pils *imap_le_struct; + + if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&streamind,&folder) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_string(folder); + + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + if ( mail_create(imap_le_struct->imap_stream,folder->value.str.val)==T ) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } +} +/* }}} */ + +/* {{{ proto int imap_renamemailbox(int stream_id, string old_name, string new_name) + Rename a mailbox */ +void php3_imap_renamemailbox(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind, *old, *new; + int ind, ind_type; + pils *imap_le_struct; + + if (ARG_COUNT(ht)!=3 || getParameters(ht,3,&streamind,&old,&new)==FAILURE){ + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_string(old); + convert_to_string(new); + + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + if ( mail_rename(imap_le_struct->imap_stream,old->value.str.val,new->value.str.val)==T ) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } +} +/* }}} */ + +/* {{{ proto imap_deletemailbox(int stream_id, string mailbox) + Delete a mailbox */ +void php3_imap_deletemailbox(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind, *folder; + int ind, ind_type; + pils *imap_le_struct; + + if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&streamind,&folder) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_string(folder); + + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + if ( mail_delete(imap_le_struct->imap_stream,folder->value.str.val)==T ) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } +} +/* }}} */ + +/* {{{ proto array imap_list(int stream_id, string ref, string pattern) + Read the list of mailboxes */ +void php3_imap_list(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind, *ref, *pat; + int ind, ind_type; + pils *imap_le_struct; + STRINGLIST *cur=NIL; + + if (ARG_COUNT(ht)!=3 + || getParameters(ht,3,&streamind,&ref,&pat) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_string(ref); + convert_to_string(pat); + + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + imap_folders = NIL; + mail_list(imap_le_struct->imap_stream,ref->value.str.val,pat->value.str.val); + if (imap_folders == NIL) { + RETURN_FALSE; + } + array_init(return_value); + cur=imap_folders; + while (cur != NIL ) { + add_next_index_string(return_value,cur->LTEXT,1); + cur=cur->next; + } + mail_free_stringlist (&imap_folders); +} +/* }}} */ + +/* {{{ proto imap_scan(int stream_id, string ref, string pattern, string content) + Read list of mailboxes containing a certain string */ +void php3_imap_listscan(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind, *ref, *pat, *content; + int ind, ind_type; + pils *imap_le_struct; + STRINGLIST *cur=NIL; + + if (ARG_COUNT(ht)!=4 || getParameters(ht,4,&streamind,&ref,&pat,&content) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_string(ref); + convert_to_string(pat); + convert_to_string(content); + + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + imap_folders = NIL; + mail_scan(imap_le_struct->imap_stream,ref->value.str.val,pat->value.str.val,content->value.str.val); + if (imap_folders == NIL) { + RETURN_FALSE; + } + array_init(return_value); + cur=imap_folders; + while (cur != NIL ) { + add_next_index_string(return_value,cur->LTEXT,1); + cur=cur->next; + } + mail_free_stringlist (&imap_folders); +} +/* }}} */ + +/* {{{ proto object imap_check(int stream_id) + Get mailbox properties */ +void php3_imap_check(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind; + int ind, ind_type; + pils *imap_le_struct; + char date[50]; + + if (ARG_COUNT(ht)!=1 || getParameters(ht,1,&streamind) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + + 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 int imap_delete(int stream_id, int msg_no) + Mark a message for deletion */ +void php3_imap_delete(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind, * msgno; + int ind, ind_type; + pils *imap_le_struct; + + if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&streamind,&msgno) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_string(msgno); + + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + + mail_setflag(imap_le_struct->imap_stream,msgno->value.str.val,"\\DELETED"); + RETVAL_TRUE; +} +/* }}} */ + +/* {{{ proto int imap_undelete(int stream_id, int msg_no) + Remove the delete flag from a message */ +void php3_imap_undelete(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind, * msgno; + int ind, ind_type; + pils *imap_le_struct; + + if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&streamind,&msgno) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_string(msgno); + + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + + mail_clearflag (imap_le_struct->imap_stream,msgno->value.str.val,"\\DELETED"); + RETVAL_TRUE; +} +/* }}} */ + +/* {{{ proto object imap_header(int stream_id, int msg_no [, int from_length [, int subject_length [, string default_host]]]) + Read the header of the message */ +void php3_imap_headerinfo(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind, * msgno,to,tovals,from,fromvals,reply_to,reply_tovals,sender; + pval *fromlength; + pval *subjectlength; + pval sendervals,return_path,return_pathvals; + pval cc,ccvals,bcc,bccvals; + pval *defaulthost; + int ind, ind_type; + unsigned long length; + pils *imap_le_struct; + MESSAGECACHE * cache; + char *mystring; + char dummy[2000]; + char fulladdress[MAILTMPLEN],tempaddress[MAILTMPLEN]; + ENVELOPE *en; + ADDRESS *addresstmp,*addresstmp2; + int myargc; + myargc=ARG_COUNT(ht); + if (myargc<2 || myargc>5 || getParameters(ht,myargc,&streamind,&msgno,&fromlength,&subjectlength,&defaulthost)==FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(streamind); + convert_to_long(msgno); + if(myargc >= 3) convert_to_long(fromlength); else fromlength=0x00;; + if(myargc >= 4) convert_to_long(subjectlength); else subjectlength=0x00; + if(myargc == 5) convert_to_string(defaulthost); + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + + if(msgno->value.lval && msgno->value.lval <= imap_le_struct->imap_stream->nmsgs && mail_fetchstructure (imap_le_struct->imap_stream,msgno->value.lval,NIL)) + cache = mail_elt (imap_le_struct->imap_stream,msgno->value.lval); + else + RETURN_FALSE; + object_init(return_value); + + + mystring=mail_fetchheader_full(imap_le_struct->imap_stream,msgno->value.lval,NIL,&length,NIL); +if(myargc ==5) +rfc822_parse_msg (&en,NULL,mystring,length,NULL,defaulthost->value.str.val,NIL); +else +rfc822_parse_msg (&en,NULL,mystring,length,NULL,"UNKNOWN",NIL); + + if(en->remail) add_property_string(return_value,"remail",en->remail,1); + if(en->date) add_property_string(return_value,"date",en->date,1); + if(en->date) add_property_string(return_value,"Date",en->date,1); + if(en->subject)add_property_string(return_value,"subject",en->subject,1); + if(en->subject)add_property_string(return_value,"Subject",en->subject,1); + if(en->in_reply_to)add_property_string(return_value,"in_reply_to",en->in_reply_to,1); + if(en->message_id)add_property_string(return_value,"message_id",en->message_id,1); + if(en->newsgroups)add_property_string(return_value,"newsgroups",en->newsgroups,1); + if(en->followup_to)add_property_string(return_value,"followup_to",en->followup_to,1); + if(en->references)add_property_string(return_value,"references",en->references,1); + +if(en->to) +{ + int ok=1; + addresstmp=en->to; + fulladdress[0]=0x00; + + while(ok && addresstmp) /* while length < 1000 and we are not at the end of the list */ + { + addresstmp2=addresstmp->next; /* save the pointer to the next address */ + addresstmp->next=NULL; /* make this address the only one now. */ + tempaddress[0]=0x00; /* reset tempaddress buffer */ + rfc822_write_address(tempaddress,addresstmp); /* ok, write the address into tempaddress string */ + if((strlen(tempaddress) + strlen(fulladdress)) < 1000) /* is the new address + total address < 1000 */ + { /* yes */ + if(strlen(fulladdress)) strcat(fulladdress,","); /* put in a comma */ + strcat(fulladdress,tempaddress); /* put in the new address */ + } + else /* no */ + { + ok=0; /* stop looping */ + strcat(fulladdress,", ..."); + } + addresstmp=addresstmp2; /* reset the pointer to the next address first! */ + } + + if(fulladdress) add_property_string( return_value, "toaddress", fulladdress, 1); + addresstmp=en->to; + array_init( &to ); + do { + object_init( &tovals); + if(addresstmp->personal) add_property_string( &tovals, "personal", addresstmp->personal, 1); + if(addresstmp->adl) add_property_string( &tovals, "adl", addresstmp->adl, 1); + if(addresstmp->mailbox) add_property_string( &tovals, "mailbox", addresstmp->mailbox, 1); + if(addresstmp->host) add_property_string( &tovals, "host", addresstmp->host, 1); + add_next_index_object( &to, tovals ); + } while ( (addresstmp = addresstmp->next) ); + add_assoc_object( return_value, "to", to ); +} + +if(en->from) +{ + int ok=1; + addresstmp=en->from; + fulladdress[0]=0x00; + + while(ok && addresstmp) /* while length < 1000 and we are not at the end of the list */ + { + addresstmp2=addresstmp->next; /* save the pointer to the next address */ + addresstmp->next=NULL; /* make this address the only one now. */ + tempaddress[0]=0x00; /* reset tempaddress buffer */ + rfc822_write_address(tempaddress,addresstmp); /* ok, write the address into tempaddress string */ + if((strlen(tempaddress) + strlen(fulladdress)) < 1000) /* is the new address + total address < 1000 */ + { /* yes */ + if(strlen(fulladdress)) strcat(fulladdress,","); /* put in a comma */ + strcat(fulladdress,tempaddress); /* put in the new address */ + } + else /* no */ + { + ok=0; /* stop looping */ + strcat(fulladdress,", ..."); + } + addresstmp=addresstmp2; /* reset the pointer to the next address first! */ + } + + if(fulladdress) add_property_string( return_value, "fromaddress", fulladdress, 1); + addresstmp=en->from; + array_init( &from ); + do { + object_init( &fromvals); + if(addresstmp->personal) add_property_string( &fromvals, "personal", addresstmp->personal, 1); + if(addresstmp->adl) add_property_string( &fromvals, "adl", addresstmp->adl, 1); + if(addresstmp->mailbox) add_property_string( &fromvals, "mailbox", addresstmp->mailbox, 1); + if(addresstmp->host) add_property_string( &fromvals, "host", addresstmp->host, 1); + add_next_index_object( &from, fromvals ); + } while ( (addresstmp = addresstmp->next) ); + add_assoc_object( return_value, "from", from ); +} + +if(en->cc) +{ + int ok=1; + addresstmp=en->cc; + fulladdress[0]=0x00; + + while(ok && addresstmp) /* while length < 1000 and we are not at the end of the list */ + { + addresstmp2=addresstmp->next; /* save the pointer to the next address */ + addresstmp->next=NULL; /* make this address the only one now. */ + tempaddress[0]=0x00; /* reset tempaddress buffer */ + rfc822_write_address(tempaddress,addresstmp); /* ok, write the address into tempaddress string */ + if((strlen(tempaddress) + strlen(fulladdress)) < 1000) /* is the new address + total address < 1000 */ + { /* yes */ + if(strlen(fulladdress)) strcat(fulladdress,","); /* put in a comma */ + strcat(fulladdress,tempaddress); /* put in the new address */ + } + else /* no */ + { + ok=0; /* stop looping */ + strcat(fulladdress,", ..."); + } + addresstmp=addresstmp2; /* reset the pointer to the next address first! */ + } + + if(fulladdress) add_property_string( return_value, "ccaddress", fulladdress, 1); + addresstmp=en->cc; + array_init( &cc ); + do { + object_init( &ccvals); + if(addresstmp->personal) add_property_string( &ccvals, "personal", addresstmp->personal, 1); + if(addresstmp->adl) add_property_string( &ccvals, "adl", addresstmp->adl, 1); + if(addresstmp->mailbox) add_property_string( &ccvals, "mailbox", addresstmp->mailbox, 1); + if(addresstmp->host) add_property_string( &ccvals, "host", addresstmp->host, 1); + add_next_index_object( &cc, ccvals ); + } while ( (addresstmp = addresstmp->next) ); + add_assoc_object( return_value, "cc", cc ); +} + +if(en->bcc) +{ + int ok=1; + addresstmp=en->bcc; + fulladdress[0]=0x00; + while(ok && addresstmp) /* while length < 1000 and we are not at the end of the list */ + { + addresstmp2=addresstmp->next; /* save the pointer to the next address */ + addresstmp->next=NULL; /* make this address the only one now. */ + tempaddress[0]=0x00; /* reset tempaddress buffer */ + rfc822_write_address(tempaddress,addresstmp); /* ok, write the address into tempaddress string */ + if((strlen(tempaddress) + strlen(fulladdress)) < 1000) /* is the new address + total address < 1000 */ + { /* yes */ + if(strlen(fulladdress)) strcat(fulladdress,","); /* put in a comma */ + strcat(fulladdress,tempaddress); /* put in the new address */ + } + else /* no */ + { + ok=0; /* stop looping */ + strcat(fulladdress,", ..."); + } + addresstmp=addresstmp2; /* reset the pointer to the next address first! */ + } + + if(fulladdress) add_property_string( return_value, "bccaddress", fulladdress, 1); + addresstmp=en->bcc; + array_init( &bcc ); + do { + object_init( &bccvals); + if(addresstmp->personal) add_property_string( &bccvals, "personal", addresstmp->personal, 1); + if(addresstmp->adl) add_property_string( &bccvals, "adl", addresstmp->adl, 1); + if(addresstmp->mailbox) add_property_string( &bccvals, "mailbox", addresstmp->mailbox, 1); + if(addresstmp->host) add_property_string( &bccvals, "host", addresstmp->host, 1); + add_next_index_object( &bcc, bccvals ); + } while ( (addresstmp = addresstmp->next) ); + add_assoc_object( return_value, "bcc", bcc ); +} + +if(en->reply_to) +{ + int ok=1; + addresstmp=en->reply_to; + fulladdress[0]=0x00; + while(ok && addresstmp) /* while length < 1000 and we are not at the end of the list */ + { + addresstmp2=addresstmp->next; /* save the pointer to the next address */ + addresstmp->next=NULL; /* make this address the only one now. */ + tempaddress[0]=0x00; /* reset tempaddress buffer */ + rfc822_write_address(tempaddress,addresstmp); /* ok, write the address into tempaddress string */ + if((strlen(tempaddress) + strlen(fulladdress)) < 1000) /* is the new address + total address < 1000 */ + { /* yes */ + if(strlen(fulladdress)) strcat(fulladdress,","); /* put in a comma */ + strcat(fulladdress,tempaddress); /* put in the new address */ + } + else /* no */ + { + ok=0; /* stop looping */ + strcat(fulladdress,", ..."); + } + addresstmp=addresstmp2; /* reset the pointer to the next address first! */ + } + + if(fulladdress) add_property_string( return_value, "reply_toaddress", fulladdress, 1); + addresstmp=en->reply_to; + array_init( &reply_to ); + do { + object_init( &reply_tovals); + if(addresstmp->personal) add_property_string( &reply_tovals, "personal", addresstmp->personal, 1); + if(addresstmp->adl) add_property_string( &reply_tovals, "adl", addresstmp->adl, 1); + if(addresstmp->mailbox) add_property_string( &reply_tovals, "mailbox", addresstmp->mailbox, 1); + if(addresstmp->host) add_property_string( &reply_tovals, "host", addresstmp->host, 1); + add_next_index_object( &reply_to, reply_tovals ); + } while ( (addresstmp = addresstmp->next) ); + add_assoc_object( return_value, "reply_to", reply_to ); +} + +if(en->sender) +{ + int ok=1; + addresstmp=en->sender; + fulladdress[0]=0x00; + while(ok && addresstmp) /* while length < 1000 and we are not at the end of the list */ + { + addresstmp2=addresstmp->next; /* save the pointer to the next address */ + addresstmp->next=NULL; /* make this address the only one now. */ + tempaddress[0]=0x00; /* reset tempaddress buffer */ + rfc822_write_address(tempaddress,addresstmp); /* ok, write the address into tempaddress string */ + if((strlen(tempaddress) + strlen(fulladdress)) < 1000) /* is the new address + total address < 1000 */ + { /* yes */ + if(strlen(fulladdress)) strcat(fulladdress,","); /* put in a comma */ + strcat(fulladdress,tempaddress); /* put in the new address */ + } + else /* no */ + { + ok=0; /* stop looping */ + strcat(fulladdress,", ..."); + } + addresstmp=addresstmp2; /* reset the pointer to the next address first! */ + } + + if(fulladdress) add_property_string( return_value, "senderaddress", fulladdress, 1); + addresstmp=en->sender; + array_init( &sender ); + do { + object_init( &sendervals); + if(addresstmp->personal) add_property_string( &sendervals, "personal", addresstmp->personal, 1); + if(addresstmp->adl) add_property_string( &sendervals, "adl", addresstmp->adl, 1); + if(addresstmp->mailbox) add_property_string( &sendervals, "mailbox", addresstmp->mailbox, 1); + if(addresstmp->host) add_property_string( &sendervals, "host", addresstmp->host, 1); + add_next_index_object( &sender, sendervals ); + } while ( (addresstmp = addresstmp->next) ); + add_assoc_object( return_value, "sender", sender ); +} + +if(en->return_path) +{ + int ok=1; + addresstmp=en->return_path; + fulladdress[0]=0x00; + while(ok && addresstmp) /* while length < 1000 and we are not at the end of the list */ + { + addresstmp2=addresstmp->next; /* save the pointer to the next address */ + addresstmp->next=NULL; /* make this address the only one now. */ + tempaddress[0]=0x00; /* reset tempaddress buffer */ + rfc822_write_address(tempaddress,addresstmp); /* ok, write the address into tempaddress string */ + if((strlen(tempaddress) + strlen(fulladdress)) < 1000) /* is the new address + total address < 1000 */ + { /* yes */ + if(strlen(fulladdress)) strcat(fulladdress,","); /* put in a comma */ + strcat(fulladdress,tempaddress); /* put in the new address */ + } + else /* no */ + { + ok=0; /* stop looping */ + strcat(fulladdress,", ..."); + } + addresstmp=addresstmp2; /* reset the pointer to the next address first! */ + } + + if(fulladdress) add_property_string( return_value, "return_pathaddress", fulladdress, 1); + addresstmp=en->return_path; + array_init( &return_path ); + do { + object_init( &return_pathvals); + if(addresstmp->personal) add_property_string( &return_pathvals, "personal", addresstmp->personal, 1); + if(addresstmp->adl) add_property_string( &return_pathvals, "adl", addresstmp->adl, 1); + if(addresstmp->mailbox) add_property_string( &return_pathvals, "mailbox", addresstmp->mailbox, 1); + if(addresstmp->host) add_property_string( &return_pathvals, "host", addresstmp->host, 1); + add_next_index_object( &return_path, return_pathvals ); + } while ( (addresstmp = addresstmp->next) ); + add_assoc_object( return_value, "return_path", return_path ); +} + 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); + 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,msgno->value.lval,fromlength->value.lval); +add_property_string(return_value,"fetchfrom",fulladdress,1); +} +if(en->subject && subjectlength) +{ +fulladdress[0]=0x00; +mail_fetchsubject(fulladdress,imap_le_struct->imap_stream,msgno->value.lval,subjectlength->value.lval); +add_property_string(return_value,"fetchsubject",fulladdress,1); +} +} +/* }}} */ + +/* KMLANG */ +/* {{{ proto array imap_lsub(int stream_id, string ref, string pattern) + Return a list of subscribed mailboxes */ +void php3_imap_lsub(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind, *ref, *pat; + int ind, ind_type; + pils *imap_le_struct; + STRINGLIST *cur=NIL; + + if (ARG_COUNT(ht)!=3 || getParameters(ht,3,&streamind,&ref,&pat) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_string(ref); + convert_to_string(pat); + + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + imap_sfolders = NIL; + mail_lsub(imap_le_struct->imap_stream,ref->value.str.val,pat->value.str.val); + if (imap_sfolders == NIL) { + RETURN_FALSE; + } + array_init(return_value); + cur=imap_sfolders; + while (cur != NIL ) { + add_next_index_string(return_value,cur->LTEXT,1); + cur=cur->next; + } + mail_free_stringlist (&imap_sfolders); +} +/* }}} */ + +/* {{{ proto int imap_subscribe(int stream_id, string mailbox) + Subscribe to a mailbox */ +void php3_imap_subscribe(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind, *folder; + int ind, ind_type; + pils *imap_le_struct; + + if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&streamind,&folder) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_string(folder); + + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + if ( mail_subscribe(imap_le_struct->imap_stream,folder->value.str.val)==T ) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } +} +/* }}} */ + +/* {{{ proto int imap_unsubscribe(int stream_id, string mailbox) + Unsubscribe from a mailbox */ +void php3_imap_unsubscribe(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind, *folder; + int ind, ind_type; + pils *imap_le_struct; + int myargc=ARG_COUNT(ht); + if (myargc !=2 || getParameters(ht,myargc,&streamind,&folder) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_string(folder); + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + if ( mail_unsubscribe(imap_le_struct->imap_stream,folder->value.str.val)==T ) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } +} +/* }}} */ + +void imap_add_body( pval *arg, BODY *body ) +{ + pval parametres, param, dparametres, dparam; + PARAMETER *par, *dpar; + PART *part; + + if(body->type) add_property_long( arg, "type", body->type ); + if(body->encoding) add_property_long( arg, "encoding", body->encoding ); + + if ( body->subtype ){ + add_property_long( arg, "ifsubtype", 1 ); + add_property_string( arg, "subtype", body->subtype, 1 ); + } else { + add_property_long( arg, "ifsubtype", 0 ); + } + + if ( body->description ){ + add_property_long( arg, "ifdescription", 1 ); + add_property_string( arg, "description", body->description, 1 ); + } else { + add_property_long( arg, "ifdescription", 0 ); + } + if ( body->id ){ + add_property_long( arg, "ifid", 1 ); + if(body->description) add_property_string( arg, "id", body->description, 1 ); + } else { + add_property_long( arg, "ifid", 0 ); + } + + if(body->size.lines) add_property_long( arg, "lines", body->size.lines ); + if(body->size.bytes) add_property_long( arg, "bytes", body->size.bytes ); +#ifdef IMAP41 + if ( body->disposition.type ){ + add_property_long( arg, "ifdisposition", 1); + add_property_string( arg, "disposition", body->disposition.type, 1); + } else { + add_property_long( arg, "ifdisposition", 0); + } + + if ( body->disposition.parameter ) { + dpar = body->disposition.parameter; + add_property_long( arg, "ifdparameters", 1); + array_init( &dparametres ); + do { + object_init( &dparam ); + add_property_string( &dparam, "attribute", dpar->attribute, 1); + add_property_string( &dparam, "value", dpar->value, 1); + add_next_index_object( &dparametres, dparam ); + } while ( (dpar = dpar->next) ); + add_assoc_object( arg, "dparameters", dparametres ); + } else { + add_property_long( arg, "ifdparameters", 0); + } +#endif + + if ( (par = body->parameter) ) { + add_property_long( arg, "ifparameters", 1 ); + + array_init( ¶metres ); + do { + object_init( ¶m ); + if(par->attribute) add_property_string( ¶m, "attribute", par->attribute, 1 ); + if(par->value) add_property_string( ¶m, "value", par->value, 1 ); + + add_next_index_object( ¶metres, param ); + } while ( (par = par->next) ); + } else { + object_init(¶metres); + add_property_long( arg, "ifparameters", 0 ); + } + add_assoc_object( arg, "parameters", parametres ); + + /* multipart message ? */ + + if ( body->type == TYPEMULTIPART ) { + array_init( ¶metres ); + for ( part = body->CONTENT_PART; part; part = part->next ) { + object_init( ¶m ); + imap_add_body( ¶m, &part->body ); + add_next_index_object( ¶metres, param ); + } + add_assoc_object( arg, "parts", parametres ); + } + + /* encapsulated message ? */ + + if ( ( body->type == TYPEMESSAGE ) && (!strncasecmp(body->subtype, "rfc822", 6))) { + body=body->CONTENT_MSG_BODY; + array_init(¶metres); + object_init( ¶m ); + imap_add_body( ¶m, body ); + add_next_index_object(¶metres, param ); + add_assoc_object( arg, "parts", parametres ); + } +} + +/* {{{ proto object imap_fetchstructure(int stream_id, int msg_no [, int options]) + Read the full structure of a message */ +void php3_imap_fetchstructure(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind, *msgno,*flags; + int ind, ind_type; + pils *imap_le_struct; + BODY *body; + int myargc=ARG_COUNT(ht); + if ( myargc < 2 || myargc > 3 || getParameters( ht, myargc, &streamind, &msgno ,&flags) == FAILURE ) { + WRONG_PARAM_COUNT; + } + + convert_to_long( streamind ); + convert_to_long( msgno ); + if(myargc == 3) convert_to_long(flags); + object_init(return_value); + + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find( ind, &ind_type ); + + if ( !imap_le_struct || ind_type != le_imap ) { + php3_error( E_WARNING, "Unable to find stream pointer" ); + RETURN_FALSE; + } + + mail_fetchstructure_full( imap_le_struct->imap_stream, msgno->value.lval, &body ,myargc == 3 ? flags->value.lval : NIL); + + if ( !body ) { + php3_error( E_WARNING, "No body information available" ); + RETURN_FALSE; + } + + imap_add_body( return_value, body ); +} +/* }}} */ + +/* {{{ proto string imap_fetchbody(int stream_id, int msg_no, int section [, int options]) + Get a specific body section */ +void php3_imap_fetchbody(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind, *msgno, *sec,*flags; + int ind, ind_type; + pils *imap_le_struct; + char *body; + unsigned long len; + int myargc=ARG_COUNT(ht); + if(myargc < 3 || myargc >4 || getParameters( ht, myargc, &streamind, &msgno, &sec,&flags ) == FAILURE ) { + WRONG_PARAM_COUNT; + } + + convert_to_long( streamind ); + convert_to_long( msgno ); + convert_to_string( sec ); + if(myargc == 4) convert_to_long(flags); + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find( ind, &ind_type ); + + if ( !imap_le_struct || ind_type != le_imap ) { + php3_error( E_WARNING, "Unable to find stream pointer" ); + RETURN_FALSE; + } + + body = mail_fetchbody_full( imap_le_struct->imap_stream, msgno->value.lval, sec->value.str.val, &len,myargc == 4 ? flags->value.lval : NIL ); + + if ( !body ) { + php3_error( E_WARNING, "No body information available" ); + RETURN_FALSE; + } + RETVAL_STRINGL( body ,len,1); +} +/* }}} */ + +/* {{{ proto string imap_base64(string text) + Decode BASE64 encoded text */ +void php3_imap_base64(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *text; + char *decode; + unsigned long newlength; + if ( ARG_COUNT(ht) != 1 || getParameters( ht, 1, &text) == FAILURE ) { + WRONG_PARAM_COUNT; + } + + convert_to_string( text ); + object_init(return_value); + + decode = (char *) rfc822_base64((unsigned char *) text->value.str.val, text->value.str.len,&newlength); + RETVAL_STRINGL(decode,newlength,1); +} +/* }}} */ + +/* {{{ proto string imap_qprint(string text) + Convert a quoted-printable string to an 8-bit string */ +void php3_imap_qprint(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *text; + char *decode; + unsigned long newlength; + if ( ARG_COUNT(ht) != 1 || getParameters( ht, 1, &text) == FAILURE ) { + WRONG_PARAM_COUNT; + } + + convert_to_string( text ); + object_init(return_value); + + decode = (char *) rfc822_qprint((unsigned char *) text->value.str.val, text->value.str.len,&newlength); + RETVAL_STRINGL(decode,newlength,1); +} +/* }}} */ + +/* {{{ proto string imap_8bit(string text) + Convert an 8-bit string to a quoted-printable string */ +void php3_imap_8bit(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *text; + char *decode; + unsigned long newlength; + if ( ARG_COUNT(ht) != 1 || getParameters( ht, 1, &text) == FAILURE ) { + WRONG_PARAM_COUNT; + } + + convert_to_string( text ); + object_init(return_value); + + decode = (char *) rfc822_8bit((unsigned char *) text->value.str.val, text->value.str.len,&newlength); + RETVAL_STRINGL(decode,newlength,1); +} +/* }}} */ + +/* {{{ proto string imap_binary(string text) + Convert an 8bit string to a base64 string */ +void php3_imap_binary(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *text; + unsigned long len; + if ( ARG_COUNT(ht) != 1 || getParameters( ht, 1, &text) == FAILURE ) { + WRONG_PARAM_COUNT; + } + convert_to_string(text); + RETVAL_STRINGL(rfc822_binary(text->value.str.val,text->value.str.len,&len),len,1); +} +/* }}} */ + +/* {{{ proto array imap_mailboxmsginfo(int stream_id) + Returns info about the current mailbox in an associative array */ +void php3_imap_mailboxmsginfo(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind; + char date[50]; + int ind, ind_type; + unsigned int msgno; + pils *imap_le_struct; + unsigned unreadmsg,msize; + + if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &streamind) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + + if(!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + + /* Initialize return array */ + if(object_init(return_value) == FAILURE) { + RETURN_FALSE; + } + + unreadmsg = 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); + unreadmsg = cache->recent ? (cache->seen ? unreadmsg : unreadmsg++) : unreadmsg; + unreadmsg = (cache->recent | cache->seen) ? unreadmsg : unreadmsg++; + msize = msize + cache->rfc822_size; + } + add_property_long(return_value,"Unread",unreadmsg); + 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 */ +void php3_imap_rfc822_write_address(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *mailbox,*host,*personal; + ADDRESS *addr; + char string[MAILTMPLEN]; + int argc; + argc=ARG_COUNT(ht); + if ( argc != 3 || getParameters( ht, argc, &mailbox,&host,&personal) == FAILURE ) { + WRONG_PARAM_COUNT; + } + convert_to_string(mailbox); + convert_to_string(host); + convert_to_string(personal); + addr=mail_newaddr(); + if(mailbox) addr->mailbox = cpystr(mailbox->value.str.val); + if(host) addr->host = cpystr(host->value.str.val); + if(personal) addr->personal = cpystr(personal->value.str.val); + addr->next=NIL; + addr->error=NIL; + addr->adl=NIL; + string[0]=0x00; + + 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 */ +void php3_imap_rfc822_parse_adrlist(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *string,*defaulthost,tovals; + ADDRESS *addresstmp; + ENVELOPE *env; + int argc; + + env=mail_newenvelope(); + argc=ARG_COUNT(ht); + if ( argc != 2 || getParameters( ht, argc, &string,&defaulthost) == FAILURE ) { + WRONG_PARAM_COUNT; + } + convert_to_string(string); + convert_to_string(defaulthost); + rfc822_parse_adrlist(&env->to,string->value.str.val,defaulthost->value.str.val); + if(array_init(return_value) == FAILURE) { + RETURN_FALSE; + } + addresstmp=env->to; + if(addresstmp) do { + 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 int imap_setflag_full(int stream_id, string sequence, string flag [, int options]) + Sets flags on messages */ +void php3_imap_setflag_full(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind; + pval *sequence; + pval *flag; + pval *flags; + int ind,ind_type; + pils *imap_le_struct; + int myargc=ARG_COUNT(ht); + + if (myargc < 3 || myargc > 4 || getParameters(ht, myargc, &streamind,&sequence,&flag,&flags) ==FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(streamind); + convert_to_string(sequence); + convert_to_string(flag); + if(myargc==4) convert_to_long(flags); + + ind = streamind->value.lval; + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if(!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + mail_setflag_full(imap_le_struct->imap_stream,sequence->value.str.val,flag->value.str.val,myargc == 4 ? flags->value.lval : NIL); + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto imap_clearflag_full(int stream_id, string sequence, string flag [, int options]) + Clears flags on messages */ +void php3_imap_clearflag_full(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind; + pval *sequence; + pval *flag; + pval *flags; + int ind,ind_type; + pils *imap_le_struct; + int myargc=ARG_COUNT(ht); + if (myargc < 3 || myargc > 4 || getParameters(ht, myargc, &streamind,&sequence,&flag,&flags) ==FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(streamind); + convert_to_string(sequence); + convert_to_string(flag); + if(myargc==4) convert_to_long(flags); + ind = streamind->value.lval; + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if(!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + mail_clearflag_full(imap_le_struct->imap_stream,sequence->value.str.val,flag->value.str.val,myargc == 4 ? flags->value.lval : NIL); +} +/* }}} */ + +/* {{{ proto array imap_sort(int stream_id, int criteria, int reverse [, int options]) + Sort an array of message headers */ +void php3_imap_sort(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind; + pval *pgm; + pval *rev; + pval *flags; + int ind,ind_type; + unsigned long *slst,*sl; + SORTPGM *mypgm=NIL; + SEARCHPGM *spg=NIL; + pils *imap_le_struct; + int myargc=ARG_COUNT(ht); + if (myargc < 3 || myargc > 4 || getParameters(ht, myargc, &streamind,&pgm,&rev,&flags) ==FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(streamind); + convert_to_long(rev); + convert_to_long(pgm); + if(pgm->value.lval>SORTSIZE) { + php3_error(E_WARNING, "Unrecognized sort criteria"); + RETURN_FALSE; + } + if(myargc==4) convert_to_long(flags); + + ind = streamind->value.lval; + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if(!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + spg = mail_newsearchpgm(); + mypgm=mail_newsortpgm(); + mypgm->reverse=rev->value.lval; + mypgm->function=pgm->value.lval; + mypgm->next=NIL; + + array_init(return_value); + slst=mail_sort(imap_le_struct->imap_stream,NIL,spg,mypgm,myargc == 4 ? flags->value.lval:NIL); + + + for (sl = slst; *sl; sl++) { + add_next_index_long(return_value,*sl); + } + fs_give ((void **) &slst); + +} +/* }}} */ + +/* {{{ proto string imap_fetchheader(int stream_id, int msg_no [, int options]) + Get the full unfiltered header for a message */ +void php3_imap_fetchheader(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind, * msgno, * flags; + int ind, ind_type; + pils *imap_le_struct; + int myargc = ARG_COUNT(ht); + if (myargc < 2 || myargc > 3 || getParameters(ht,myargc,&streamind,&msgno,&flags) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_long(msgno); + if(myargc == 3) convert_to_long(flags); + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + RETVAL_STRING(mail_fetchheader_full (imap_le_struct->imap_stream,msgno->value.lval,NIL,NIL,myargc == 3 ? flags->value.lval : NIL),1); + +} +/* }}} */ + +/* {{{ proto int imap_uid(int stream_id, int msg_no) + Get the unique message id associated with a standard sequential message number */ +void php3_imap_uid(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind, *msgno; + int ind, ind_type; + pils *imap_le_struct; + + if (ARG_COUNT(ht) != 2 || getParameters(ht,2,&streamind,&msgno) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_long(msgno); + + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + + RETURN_LONG(mail_uid(imap_le_struct->imap_stream, msgno->value.lval)); +} +/* }}} */ + +/* {{{ proto int imap_msgno(int stream_id, int unique_msg_id) + Get the sequence number associated with a UID */ +void php3_imap_msgno(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind, *msgno; + int ind, ind_type; + pils *imap_le_struct; + + if (ARG_COUNT(ht) != 2 || getParameters(ht,2,&streamind,&msgno) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_long(msgno); + + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + + RETURN_LONG(mail_msgno(imap_le_struct->imap_stream, msgno->value.lval)); +} +/* }}} */ + +/* {{{ proto object imap_status(int stream_id, string mailbox, int options) + Get status info from a mailbox */ +void php3_imap_status(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind, *mbx, *flags; + int ind, ind_type; + pils *imap_le_struct; + int myargc=ARG_COUNT(ht); + if (myargc != 3 || getParameters(ht,myargc,&streamind,&mbx,&flags) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_string(mbx); + convert_to_long(flags); + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + + if(object_init(return_value) == FAILURE){ + RETURN_FALSE; + } + if(mail_status(imap_le_struct->imap_stream, mbx->value.str.val, flags->value.lval)) + { + add_property_long(return_value,"flags",status_flags); + if(status_flags & SA_MESSAGES) add_property_long(return_value,"messages",status_messages); + if(status_flags & SA_RECENT) add_property_long(return_value,"recent",status_recent); + if(status_flags & SA_UNSEEN) add_property_long(return_value,"unseen",status_unseen); + if(status_flags & SA_UIDNEXT) add_property_long(return_value,"uidnext",status_uidnext); + if(status_flags & SA_UIDVALIDITY) add_property_long(return_value,"uidvalidity",status_uidvalidity); + } + else + { + RETURN_FALSE; + } +} +/* }}} */ + +/* {{{ proto object imap_bodystruct(int stream_id, int msg_no, int section) + Read the structure of a specified body section of a specific message */ +void php3_imap_bodystruct(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind, *msg, *section; + int ind, ind_type; + pils *imap_le_struct; + pval parametres, param, dparametres, dparam; + PARAMETER *par, *dpar; + BODY *body; + int myargc=ARG_COUNT(ht); + if (myargc != 3 || getParameters(ht,myargc,&streamind,&msg,§ion) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_long(msg); + convert_to_string(section); + ind = streamind->value.lval; + + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + + if(object_init(return_value) == FAILURE){ + RETURN_FALSE; + } + + body=mail_body(imap_le_struct->imap_stream, msg->value.lval, section->value.str.val); + if(body->type) add_property_long( return_value, "type", body->type ); + if(body->encoding) add_property_long( return_value, "encoding", body->encoding ); + + if ( body->subtype ){ + add_property_long( return_value, "ifsubtype", 1 ); + add_property_string( return_value, "subtype", body->subtype, 1 ); + } else { + add_property_long( return_value, "ifsubtype", 0 ); + } + + if ( body->description ){ + add_property_long( return_value, "ifdescription", 1 ); + add_property_string( return_value, "description", body->description, 1 ); + } else { + add_property_long( return_value, "ifdescription", 0 ); + } + if ( body->id ){ + add_property_long( return_value, "ifid", 1 ); + if(body->description) add_property_string( return_value, "id", body->description, 1 ); + } else { + add_property_long( return_value, "ifid", 0 ); + } + + 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 ); +#ifdef IMAP41 + if ( body->disposition.type ){ + add_property_long( return_value, "ifdisposition", 1); + add_property_string( return_value, "disposition", body->disposition.type, 1); + } else { + add_property_long( return_value, "ifdisposition", 0); + } + + if ( body->disposition.parameter ) { + dpar = body->disposition.parameter; + add_property_long( return_value, "ifdparameters", 1); + array_init( &dparametres ); + do { + object_init( &dparam ); + add_property_string( &dparam, "attribute", dpar->attribute, 1); + add_property_string( &dparam, "value", dpar->value, 1); + add_next_index_object( &dparametres, dparam ); + } while ( (dpar = dpar->next) ); + add_assoc_object( return_value, "dparameters", dparametres ); + } else { + add_property_long( return_value, "ifdparameters", 0); + } +#endif + + if ( (par = body->parameter) ) { + add_property_long( return_value, "ifparameters", 1 ); + + array_init( ¶metres ); + do { + object_init( ¶m ); + if(par->attribute) add_property_string( ¶m, "attribute", par->attribute, 1 ); + if(par->value) add_property_string( ¶m, "value", par->value, 1 ); + + add_next_index_object( ¶metres, param ); + } while ( (par = par->next) ); + } else { + object_init(¶metres); + add_property_long( return_value, "ifparameters", 0 ); + } + add_assoc_object( return_value, "parameters", parametres ); +} +/* }}} */ + +/* {{{ proto array imap_fetch_overview(int stream_id, int msg_no) + Read an overview of the information in the headers of the given message */ +void php3_imap_fetch_overview(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind, *sequence; + int ind, ind_type; + pils *imap_le_struct; + pval myoverview; + char address[MAILTMPLEN]; + int myargc=ARG_COUNT(ht); + if (myargc != 2 || getParameters(ht,myargc,&streamind,&sequence) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_string(sequence); + + ind = streamind->value.lval; + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + + if (!imap_le_struct || ind_type != le_imap) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + array_init(return_value); + if (mail_uid_sequence (imap_le_struct->imap_stream,(char *)sequence)) { + MESSAGECACHE *elt; + ENVELOPE *env; + unsigned long i; + for (i = 1; i <= imap_le_struct->imap_stream->nmsgs; i++) + if (((elt = mail_elt (imap_le_struct->imap_stream,i))->sequence) && + (env = mail_fetch_structure (imap_le_struct->imap_stream,i,NIL,NIL))) { + object_init(&myoverview); + add_property_string(&myoverview,"subject",env->subject,1); + env->from->next=NULL; + rfc822_write_address(address,env->from); + add_property_string(&myoverview,"from",address,1); + add_property_string(&myoverview,"date",env->date,1); + add_property_string(&myoverview,"message_id",env->message_id,1); + add_property_string(&myoverview,"references",env->references,1); + 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_next_index_object(return_value,myoverview); + } + } +} +/* }}} */ + +/* {{{ proto string imap_mail_compose(array envelope, array body) + Create a MIME message based on given envelope and body sections */ +void php3_imap_mail_compose(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *envelope, *body; + char *key; + pval *data,*pvalue; + ulong ind; + char *cookie = NIL; + ENVELOPE *env; + BODY *bod=NULL,*topbod=NULL; + PART *mypart=NULL,*toppart=NULL,*part; + PARAMETER *param; + char tmp[8*MAILTMPLEN],*mystring=NULL,*t,*tempstring; + int myargc=ARG_COUNT(ht); + if (myargc != 2 || getParameters(ht,myargc,&envelope,&body) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_array(envelope); + convert_to_array(body); + env=mail_newenvelope(); + if(_php3_hash_find(envelope->value.ht,"remail",sizeof("remail"),(void **) &pvalue)== SUCCESS){ + convert_to_string(pvalue); + env->remail=cpystr(pvalue->value.str.val); + } + + if(_php3_hash_find(envelope->value.ht,"return_path",sizeof("return_path"),(void **) &pvalue)== SUCCESS){ + convert_to_string(pvalue); + rfc822_parse_adrlist (&env->return_path,pvalue->value.str.val,"NO HOST"); + } + if(_php3_hash_find(envelope->value.ht,"date",sizeof("date"),(void **) &pvalue)== SUCCESS){ + convert_to_string(pvalue); + env->date=cpystr(pvalue->value.str.val); + } + if(_php3_hash_find(envelope->value.ht,"from",sizeof("from"),(void **) &pvalue)== SUCCESS){ + convert_to_string(pvalue); + rfc822_parse_adrlist (&env->from,pvalue->value.str.val,"NO HOST"); + } + if(_php3_hash_find(envelope->value.ht,"reply_to",sizeof("reply_to"),(void **) &pvalue)== SUCCESS){ + convert_to_string(pvalue); + rfc822_parse_adrlist (&env->reply_to,pvalue->value.str.val,"NO HOST"); + } + if(_php3_hash_find(envelope->value.ht,"to",sizeof("to"),(void **) &pvalue)== SUCCESS){ + convert_to_string(pvalue); + rfc822_parse_adrlist (&env->to,pvalue->value.str.val,"NO HOST"); + } + if(_php3_hash_find(envelope->value.ht,"cc",sizeof("cc"),(void **) &pvalue)== SUCCESS){ + convert_to_string(pvalue); + rfc822_parse_adrlist (&env->cc,pvalue->value.str.val,"NO HOST"); + } + if(_php3_hash_find(envelope->value.ht,"bcc",sizeof("bcc"),(void **) &pvalue)== SUCCESS){ + convert_to_string(pvalue); + rfc822_parse_adrlist (&env->bcc,pvalue->value.str.val,"NO HOST"); + } + if(_php3_hash_find(envelope->value.ht,"message_id",sizeof("message_id"),(void **) &pvalue)== SUCCESS){ + convert_to_string(pvalue); + env->message_id=cpystr(pvalue->value.str.val); + } + + _php3_hash_internal_pointer_reset(body->value.ht); + _php3_hash_get_current_key(body->value.ht, &key, &ind); + _php3_hash_get_current_data(body->value.ht, (void **) &data); + if(data->type == IS_ARRAY) + { + bod=mail_newbody(); + topbod=bod; + if(_php3_hash_find(data->value.ht,"type",sizeof("type"),(void **) &pvalue)== SUCCESS){ + convert_to_long(pvalue); + bod->type=pvalue->value.lval; + } + if(_php3_hash_find(data->value.ht,"encoding",sizeof("encoding"),(void **) &pvalue)== SUCCESS){ + convert_to_long(pvalue); + bod->encoding=pvalue->value.lval; + } + if(_php3_hash_find(data->value.ht,"subtype",sizeof("subtype"),(void **) &pvalue)== SUCCESS){ + convert_to_string(pvalue); + bod->subtype=cpystr(pvalue->value.str.val); + } + if(_php3_hash_find(data->value.ht,"id",sizeof("id"),(void **) &pvalue)== SUCCESS){ + convert_to_string(pvalue); + bod->id=cpystr(pvalue->value.str.val); + } + if(_php3_hash_find(data->value.ht,"contents.data",sizeof("contents.data"),(void **) &pvalue)== SUCCESS){ + convert_to_string(pvalue); + bod->contents.text.data=(char *)fs_get(pvalue->value.str.len); + memcpy(bod->contents.text.data,pvalue->value.str.val,pvalue->value.str.len+1); + bod->contents.text.size=pvalue->value.str.len; + } + if(_php3_hash_find(data->value.ht,"lines",sizeof("lines"),(void **) &pvalue)== SUCCESS){ + convert_to_long(pvalue); + bod->size.lines=pvalue->value.lval; + } + if(_php3_hash_find(data->value.ht,"bytes",sizeof("bytes"),(void **) &pvalue)== SUCCESS){ + convert_to_long(pvalue); + bod->size.bytes=pvalue->value.lval; + } + if(_php3_hash_find(data->value.ht,"md5",sizeof("md5"),(void **) &pvalue)== SUCCESS){ + convert_to_string(pvalue); + bod->md5=cpystr(pvalue->value.str.val); + } + } + _php3_hash_move_forward(body->value.ht); + while(_php3_hash_get_current_data(body->value.ht, (void **) &data)==SUCCESS) + { + _php3_hash_get_current_key(body->value.ht, &key, &ind); + if(data->type == IS_ARRAY) + { + if(!toppart) + { + bod->nested.part=mail_newbody_part(); + mypart=bod->nested.part; + toppart=mypart; + bod=&mypart->body; + } + else + { + mypart->next=mail_newbody_part(); + mypart=mypart->next; + bod=&mypart->body; + } + if(_php3_hash_find(data->value.ht,"type",sizeof("type"),(void **) &pvalue)== SUCCESS){ + convert_to_long(pvalue); + bod->type=pvalue->value.lval; + } + if(_php3_hash_find(data->value.ht,"encoding",sizeof("encoding"),(void **) &pvalue)== SUCCESS){ + convert_to_long(pvalue); + bod->encoding=pvalue->value.lval; + } + if(_php3_hash_find(data->value.ht,"subtype",sizeof("subtype"),(void **) &pvalue)== SUCCESS){ + convert_to_string(pvalue); + bod->subtype=cpystr(pvalue->value.str.val); + } + if(_php3_hash_find(data->value.ht,"id",sizeof("id"),(void **) &pvalue)== SUCCESS){ + convert_to_string(pvalue); + bod->id=cpystr(pvalue->value.str.val); + } + if(_php3_hash_find(data->value.ht,"contents.data",sizeof("contents.data"),(void **) &pvalue)== SUCCESS){ + convert_to_string(pvalue); + bod->contents.text.data=(char *)fs_get(pvalue->value.str.len); + memcpy(bod->contents.text.data,pvalue->value.str.val,pvalue->value.str.len+1); + bod->contents.text.size=pvalue->value.str.len; + } + if(_php3_hash_find(data->value.ht,"lines",sizeof("lines"),(void **) &pvalue)== SUCCESS){ + convert_to_long(pvalue); + bod->size.lines=pvalue->value.lval; + } + if(_php3_hash_find(data->value.ht,"bytes",sizeof("bytes"),(void **) &pvalue)== SUCCESS){ + convert_to_long(pvalue); + bod->size.bytes=pvalue->value.lval; + } + if(_php3_hash_find(data->value.ht,"md5",sizeof("md5"),(void **) &pvalue)== SUCCESS){ + convert_to_string(pvalue); + bod->md5=cpystr(pvalue->value.str.val); + } + _php3_hash_move_forward(body->value.ht); + } + } + + rfc822_encode_body_7bit (env,topbod); + rfc822_header (tmp,env,topbod); + mystring=emalloc(strlen(tmp)+1); + strcpy(mystring,tmp); + + bod=topbod; + switch (bod->type) { + case TYPEMULTIPART: /* multipart gets special handling */ + part = bod->nested.part; /* first body part */ + /* find cookie */ + for (param = bod->parameter; param && !cookie; param = param->next) + if (!strcmp (param->attribute,"BOUNDARY")) cookie = param->value; + if (!cookie) cookie = "-"; /* yucky default */ + do { /* for each part */ + /* build cookie */ + sprintf (t=tmp,"--%s\015\012",cookie); + /* append mini-header */ + rfc822_write_body_header (&t,&part->body); + strcat (t,"\015\012"); /* write terminating blank line */ + /* output cookie, mini-header, and contents */ + tempstring=emalloc(strlen(mystring)+strlen(tmp)+1); + strcpy(tempstring,mystring); + efree(mystring); + mystring=tempstring; + strcat(mystring,tmp); + + bod=&part->body; + + tempstring=emalloc(strlen(bod->contents.text.data)+strlen(mystring)+1); + strcpy(tempstring,mystring); + efree(mystring); + mystring=tempstring; + strcat(mystring,bod->contents.text.data); + + } while ((part = part->next));/* until done */ + /* output trailing cookie */ + + sprintf(tmp,"--%s--",cookie); + tempstring=emalloc(strlen(tmp)+strlen(mystring)+1); + strcpy(tempstring,mystring); + efree(mystring); + mystring=tempstring; + strcat(mystring,tmp); + break; + default: /* all else is text now */ + tempstring=emalloc(strlen(bod->contents.text.data)+strlen(mystring)+1); + strcpy(tempstring,mystring); + efree(mystring); + mystring=tempstring; + strcat(mystring,bod->contents.text.data); + break; + } + + RETURN_STRINGL(mystring,strlen(mystring),1); +} +/* }}} */ + + + +/* Interfaces to C-client */ + + +void mm_searched (MAILSTREAM *stream,unsigned long number) +{ +} + + +void mm_exists (MAILSTREAM *stream,unsigned long number) +{ +} + + +void mm_expunged (MAILSTREAM *stream,unsigned long number) +{ +} + + +void mm_flags (MAILSTREAM *stream,unsigned long number) +{ +} + + +void mm_notify (MAILSTREAM *stream,char *string,long errflg) +{ +} + +void mm_list (MAILSTREAM *stream,DTYPE delimiter,char *mailbox,long attributes) +{ + STRINGLIST *cur=NIL; + if(!(attributes & LATT_NOSELECT)) { + if (imap_folders == NIL) { + imap_folders=mail_newstringlist(); + imap_folders->LSIZE=strlen(imap_folders->LTEXT=cpystr(mailbox)); + imap_folders->next=NIL; + } else { + cur=imap_folders; + while (cur->next != NIL ) { + cur=cur->next; + } + cur->next=mail_newstringlist (); + cur=cur->next; + cur->LSIZE = strlen (cur->LTEXT = cpystr (mailbox)); + cur->next = NIL; + } + } +} + +void mm_lsub (MAILSTREAM *stream,DTYPE delimiter,char *mailbox,long attributes) +{ + STRINGLIST *cur=NIL; + if (imap_sfolders == NIL) { + imap_sfolders=mail_newstringlist(); + imap_sfolders->LSIZE=strlen(imap_sfolders->LTEXT=cpystr(mailbox)); + imap_sfolders->next=NIL; + } else { + cur=imap_sfolders; + while (cur->next != NIL ) { + cur=cur->next; + } + cur->next=mail_newstringlist (); + cur=cur->next; + cur->LSIZE = strlen (cur->LTEXT = cpystr (mailbox)); + cur->next = NIL; + } +} + +void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status) +{ +status_flags=status->flags; + if(status_flags & SA_MESSAGES) status_messages=status->messages; + if(status_flags & SA_RECENT) status_recent=status->recent; + if(status_flags & SA_UNSEEN) status_unseen=status->unseen; + if(status_flags & SA_UIDNEXT) status_uidnext=status->uidnext; + if(status_flags & SA_UIDVALIDITY) status_uidvalidity=status->uidvalidity; + +} + +void mm_log (char *string,long errflg) +{ + switch ((short) errflg) { + case NIL: + /* php3_error(E_NOTICE,string); messages */ + break; + case PARSE: + case WARN: + php3_error(E_WARNING,string); /* warnings */ + break; + case ERROR: + php3_error(E_NOTICE,string); /* errors */ + break; + } +} + +void mm_dlog (char *string) +{ + php3_error(E_NOTICE,string); +} + +void mm_login (NETMBX *mb,char *user,char *pwd,long trial) +{ + if (*mb->user) { + strcpy (user,mb->user); + } else { + strcpy (user,imap_user); + } + strcpy (pwd,imap_password); +} + + +void mm_critical (MAILSTREAM *stream) +{ +} + + +void mm_nocritical (MAILSTREAM *stream) +{ +} + + +long mm_diskerror (MAILSTREAM *stream,long errcode,long serious) +{ + return 1; +} + + +void mm_fatal (char *string) +{ +} + +#endif diff --git a/ext/imap/imap.h b/ext/imap/imap.h new file mode 100644 index 00000000000..421ca5e76ed --- /dev/null +++ b/ext/imap/imap.h @@ -0,0 +1,89 @@ +#ifndef _INCLUDED_IMAP_H +#define _INCLUDED_IMAP_H + +#if COMPILE_DL +#undef HAVE_IMAP +#define HAVE_IMAP 1 +#endif + +#if HAVE_IMAP + +#ifdef THREAD_SAFE +#include "tls.h" +#endif +#ifndef MSVC5 +#include "build-defs.h" +#endif + +/* Functions accessable to PHP */ +extern php3_module_entry php3_imap_module_entry; +#define php3_imap_module_ptr &php3_imap_module_entry + +extern int imap_init(INIT_FUNC_ARGS); +extern void imap_info(void); +void php3_imap_open(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_reopen(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_close(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_num_msg(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_headers(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_body(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_expunge(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_delete(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_undelete(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_check(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_headerinfo(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_mail_copy(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_mail_move(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_createmailbox(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_renamemailbox(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_deletemailbox(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_list(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_listscan(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_lsub(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_subscribe(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_unsubscribe(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_num_recent(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_fetchstructure(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_fetchbody(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_append(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_ping(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_base64(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_qprint(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_8bit(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_binary(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_mailboxmsginfo(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_rfc822_write_address(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_rfc822_parse_adrlist(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_setflag_full(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_clearflag_full(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_sort(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_fetchtext(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_fetchheader(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_uid(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_msgno(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_fetchtext_full(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_status(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_bodystruct(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_fetch_overview(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_mail_compose(INTERNAL_FUNCTION_PARAMETERS); + +#else +#define php3_imap_module_ptr NULL +#endif /* HAVE_IMAP */ + +#endif + + + + + + + + + + + + + + + diff --git a/ext/imap/setup.stub b/ext/imap/setup.stub new file mode 100644 index 00000000000..afc77dd90e9 --- /dev/null +++ b/ext/imap/setup.stub @@ -0,0 +1,7 @@ +# $Source$ +# $Id$ + +define_option with-imap 'IMAP support?' yesnodir \ + 'no /usr/local/imap IMAP base install' \ +' Whether to build with IMAP (Internet Message Access Protocol)\n + support.\n' diff --git a/ext/ldap/Makefile.am b/ext/ldap/Makefile.am new file mode 100644 index 00000000000..ca395117577 --- /dev/null +++ b/ext/ldap/Makefile.am @@ -0,0 +1,6 @@ +# $Id$ + +INCLUDES=@INCLUDES@ -I@top_srcdir@ -I@top_srcdir@/libzend +noinst_LIBRARIES=libphpext_ldap.a +libphpext_ldap_a_SOURCES=ldap.c + diff --git a/ext/ldap/config.h.stub b/ext/ldap/config.h.stub new file mode 100644 index 00000000000..f0da3f0d5cc --- /dev/null +++ b/ext/ldap/config.h.stub @@ -0,0 +1,2 @@ +/* Define if you want the LDAP directory interface */ +#define HAVE_LDAP 0 diff --git a/ext/ldap/config.m4 b/ext/ldap/config.m4 new file mode 100644 index 00000000000..876c739b97f --- /dev/null +++ b/ext/ldap/config.m4 @@ -0,0 +1,31 @@ +dnl $Id$ + +AC_MSG_CHECKING(for LDAP support) +AC_ARG_WITH(ldap, +[ --with-ldap[=DIR] Include LDAP support. DIR is the LDAP base + install directory, defaults to /usr/local/ldap], +[ + if test "$withval" != "no"; then + if test "$withval" = "yes"; then + LDAP_INCDIR=/usr/local/ldap/include + LDAP_LIBDIR=/usr/local/ldap/lib + else + LDAP_INCDIR=$withval/include + LDAP_LIBDIR=$withval/lib + fi + LDAP_INCLUDE=-I$LDAP_INCDIR + LDAP_LFLAGS="-L$LDAP_LIBDIR ${ld_runpath_switch}$LDAP_LIBDIR" + LDAP_LIBS="-lldap -llber" + INCLUDES="$INCLUDES $LDAP_INCLUDE" + EXTRA_LIBS="$EXTRA_LIBS $LDAP_LFLAGS $LDAP_LIBS" + + AC_DEFINE(HAVE_LDAP) + + AC_MSG_RESULT(yes) + PHP_EXTENSION(ldap) + else + AC_MSG_RESULT(no) + fi +],[ + AC_MSG_RESULT(no) +]) diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c new file mode 100644 index 00000000000..b4bc182982d --- /dev/null +++ b/ext/ldap/ldap.c @@ -0,0 +1,1275 @@ +/* + +----------------------------------------------------------------------+ + | PHP HTML Embedded Scripting Language Version 3.0 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | + +----------------------------------------------------------------------+ + | This program is free software; you can redistribute it and/or modify | + | it under the terms of one of the following licenses: | + | | + | A) the GNU General Public License as published by the Free Software | + | Foundation; either version 2 of the License, or (at your option) | + | any later version. | + | | + | B) the PHP License as published by the PHP Development Team and | + | included in the distribution in the file: LICENSE | + | | + | This program is distributed in the hope that it will be useful, | + | but WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | + | GNU General Public License for more details. | + | | + | You should have received a copy of both licenses referred to here. | + | If you did not, or have any questions about PHP licensing, please | + | contact core@php.net. | + +----------------------------------------------------------------------+ + | Authors: Amitay Isaacs | + | Eric Warnke | + | Rasmus Lerdorf | + +----------------------------------------------------------------------+ + */ + + +/* $Id$ */ +#define IS_EXT_MODULE +#if !PHP_31 && defined(THREAD_SAFE) +#undef THREAD_SAFE +#endif +#ifdef THREAD_SAFE +#include "tls.h" +DWORD ldapTLS; +static int numthreads=0; +void *ldap_mutex; +#endif + +#if !(WIN32|WINNT) +#include "config.h" +#endif +#include "php.h" + +#if HAVE_LDAP + +#if COMPILE_DL +#if PHP_31 +#include "ext/phpdl.h" +#include "ext/standard/dl.h" +#else +#include "dl/phpdl.h" +#include "functions/dl.h" +#endif +#endif +#include "php3_ldap.h" + +#if WIN32|WINNT +#include +#if HAVE_NSLDAP +#include +#endif +#define strdup _strdup +#undef WINDOWS +#undef strcasecmp +#undef strncasecmp +#define WINSOCK 1 +#define __STDC__ 1 +#endif + +#if PHP_31 +#include "ext/standard/php3_string.h" +#else +#include "functions/php3_string.h" +#endif + + +#if THREAD_SAFE & HAVE_NSLDAP +#include "php3_threads.h" +/* Structure for LDAP error values */ +#define LDAP_TLS_VARS ldap_module *PHP3_TLS_GET(ldapTLS,php3_ldap_module) +#define LDAP_GLOBAL(a) php3_ldap_module->a +#else +#define LDAP_TLS_VARS +#define LDAP_GLOBAL(a) php3_ldap_module.a +ldap_module php3_ldap_module; +#endif + + + +/* + This is just a small subset of the functionality provided by the LDAP library. All the + operations are synchronous. Referrals are not handled automatically. +*/ + +function_entry ldap_functions[] = { + {"ldap_connect", php3_ldap_connect, NULL}, + {"ldap_close", php3_ldap_unbind, NULL}, + {"ldap_bind", php3_ldap_bind, NULL}, + {"ldap_unbind", php3_ldap_unbind, NULL}, + {"ldap_read", php3_ldap_read, NULL}, + {"ldap_list", php3_ldap_list, NULL}, + {"ldap_search", php3_ldap_search, NULL}, + {"ldap_free_result", php3_ldap_free_result, NULL}, + {"ldap_count_entries", php3_ldap_count_entries, NULL}, + {"ldap_first_entry", php3_ldap_first_entry, NULL}, + {"ldap_next_entry", php3_ldap_next_entry, NULL}, + {"ldap_get_entries", php3_ldap_get_entries, NULL}, + {"ldap_first_attribute", php3_ldap_first_attribute, NULL}, + {"ldap_next_attribute", php3_ldap_next_attribute, NULL}, + {"ldap_get_attributes", php3_ldap_get_attributes, NULL}, + {"ldap_get_values", php3_ldap_get_values, NULL}, + {"ldap_get_dn", php3_ldap_get_dn, NULL}, + {"ldap_explode_dn", php3_ldap_explode_dn, NULL}, + {"ldap_dn2ufn", php3_ldap_dn2ufn, NULL}, + {"ldap_add", php3_ldap_add, NULL}, + {"ldap_delete", php3_ldap_delete, NULL}, + {"ldap_modify", php3_ldap_modify, NULL}, + {NULL, NULL, NULL} +}; + + +php3_module_entry ldap_module_entry = { + "LDAP", ldap_functions, php3_minit_ldap, php3_mshutdown_ldap, NULL, NULL, php3_info_ldap, STANDARD_MODULE_PROPERTIES +}; + + + +#if COMPILE_DL +DLEXPORT php3_module_entry *get_module(void ) { return &ldap_module_entry; } +#endif + + +#if 0 /* see my note in php3_ldap.h. smc */ +/* Function for setting thread-specific LDAP error values */ +static void php3_ldap_set_ld_error( int err, char *matched, char *errmsg, void *dummy ) +{ + LDAP_TLS_VARS; + + /* Set the error code returned by the LDAP operation */ + LDAP_GLOBAL(le_errno) = err; + /* Specify the components of the DN that matched (if + an "NO_SUCH_OBJECT" error occurred */ + if ( LDAP_GLOBAL(le_matched) != NULL ) { + ldap_memfree( LDAP_GLOBAL(le_matched) ); + } + LDAP_GLOBAL(le_matched) = matched; + /* Specify the error message corresponding to the error code */ + if ( LDAP_GLOBAL(le_errmsg) != NULL ) { + ldap_memfree( LDAP_GLOBAL(le_errmsg) ); + } + LDAP_GLOBAL(le_errmsg) = errmsg; +} + +/* Function for getting the thread-specific LDAP error values */ +static int php3_ldap_get_ld_error( char **matched, char **errmsg, void *dummy ) +{ + LDAP_TLS_VARS; + /* Retrieve the error values */ + if ( matched != NULL ) { + *matched = LDAP_GLOBAL(le_matched); + } + if ( errmsg != NULL ) { + *errmsg = LDAP_GLOBAL(le_errmsg); + } + return( LDAP_GLOBAL(le_errno) ); +} + +/* Function for setting the value of the errno variable */ +static void php3_ldap_set_errno( int err ) +{ + errno = err; +} + +/* Function for getting the value of the errno variable */ +static int php3_ldap_get_errno( void ) +{ + return( errno ); +} +#endif /* THREAD_SAFE && NSLDAP */ + +static void _close_ldap_link(LDAP *ld) +{ + LDAP_TLS_VARS; + ldap_unbind_s(ld); + /* php3_printf("Freeing ldap connection");*/ + LDAP_GLOBAL(num_links)--; +} + + +static void _free_ldap_result(LDAPMessage *result) +{ + ldap_msgfree(result); +} + +int php3_minit_ldap(INIT_FUNC_ARGS) +{ +#if defined(THREAD_SAFE) + ldap_module *php3_ldap_module; + PHP3_MUTEX_ALLOC(ldap_mutex); + PHP3_MUTEX_LOCK(ldap_mutex); + numthreads++; + if (numthreads==1){ + if (!PHP3_TLS_PROC_STARTUP(ldapTLS)){ + PHP3_MUTEX_UNLOCK(ldap_mutex); + PHP3_MUTEX_FREE(ldap_mutex); + return 0; + } + } + PHP3_MUTEX_UNLOCK(ldap_mutex); + if(!PHP3_TLS_THREAD_INIT(ldapTLS,php3_ldap_module,ldap_module)) + return 0; +#if 0 /*HAVE_NSLDAP*/ + /* Set up the ldap_thread_fns structure with pointers + to the functions that you want called */ + memset( &LDAP_GLOBAL(tfns), '\0', sizeof(struct ldap_thread_fns) ); + /* Specify the functions that you want called */ + /* Call the my_mutex_alloc() function whenever mutexes + need to be allocated */ + LDAP_GLOBAL(tfns).ltf_mutex_alloc = (void *(*)(void)) php3_mutex_alloc; + /* Call the my_mutex_free() function whenever mutexes + need to be destroyed */ + LDAP_GLOBAL(tfns).ltf_mutex_free = (void (*)(void *)) php3_mutex_free; + /* Call the pthread_mutex_lock() function whenever a + thread needs to lock a mutex. */ + LDAP_GLOBAL(tfns).ltf_mutex_lock = (int (*)(void *)) php3_mutex_lock; + /* Call the pthread_mutex_unlock() function whenever a + thread needs to unlock a mutex. */ + LDAP_GLOBAL(tfns).ltf_mutex_unlock = (int (*)(void *)) php3_mutex_unlock; + /* Call the get_errno() function to get the value of errno */ + LDAP_GLOBAL(tfns).ltf_get_errno = php3_ldap_get_errno; + /* Call the set_errno() function to set the value of errno */ + LDAP_GLOBAL(tfns).ltf_set_errno = php3_ldap_set_errno; + /* Call the get_ld_error() function to get error values from + calls to functions in the libldap library */ + LDAP_GLOBAL(tfns).ltf_get_lderrno = php3_ldap_get_ld_error; + /* Call the set_ld_error() function to set error values for + calls to functions in the libldap library */ + LDAP_GLOBAL(tfns).ltf_set_lderrno = php3_ldap_set_ld_error; + /* Don't pass any extra parameter to the functions for + getting and setting libldap function call errors */ + LDAP_GLOBAL(tfns).ltf_lderrno_arg = NULL; +/* Set the session option that specifies the functions to call for multi-threaded clients */ + if (ldap_set_option( ld, LDAP_OPT_THREAD_FN_PTRS, (void *) &LDAP_GLOBAL(tfns))!= 0) { + ldap_perror( ld, "ldap_set_option: thread pointers" ); + } +#endif +#endif + if (cfg_get_long("ldap.max_links", &LDAP_GLOBAL(max_links)) == FAILURE) { + LDAP_GLOBAL(max_links) = -1; + } + + if (cfg_get_string("ldap.base_dn", &LDAP_GLOBAL(base_dn)) == FAILURE) { + LDAP_GLOBAL(base_dn) = NULL; + } + + LDAP_GLOBAL(le_result) = register_list_destructors(_free_ldap_result, NULL); + LDAP_GLOBAL(le_link) = register_list_destructors(_close_ldap_link, NULL); + + /*FIXME is this safe in threaded environment? if so, please comment*/ + ldap_module_entry.type = type; + + return SUCCESS; +} + +int php3_mshutdown_ldap(void){ +#ifdef THREAD_SAFE + LDAP_TLS_VARS; + PHP3_TLS_THREAD_FREE(php3_ldap_module); + PHP3_MUTEX_LOCK(ldap_mutex); + numthreads--; + if (!numthreads) { + PHP3_TLS_PROC_SHUTDOWN(ldapTLS); + } + PHP3_MUTEX_UNLOCK(ldap_mutex); + PHP3_MUTEX_FREE(ldap_mutex); +#endif + return SUCCESS; +} + +void php3_info_ldap(void) +{ + char maxl[16]; +#if HAVE_NSLDAP + LDAPVersion ver; + double SDKVersion; + /* Print version information */ + SDKVersion = ldap_version( &ver ); +#endif + LDAP_TLS_VARS; + + if (LDAP_GLOBAL(max_links) == -1) { + strcpy(maxl, "Unlimited"); + } else { + snprintf(maxl, 15, "%ld", LDAP_GLOBAL(max_links)); + maxl[15] = 0; + } + + php3_printf("" + "\n" + "\n" +#if HAVE_NSLDAP + "" + "" + "" +#endif + ,LDAP_GLOBAL(num_links),maxl +#if HAVE_NSLDAP + ,SDKVersion/100.0,ver.protocol_version/100.0,ver.SSL_version/100.0 +#endif + ); +#if HAVE_NSLDAP + if ( ver.security_level != LDAP_SECURITY_NONE ) { + php3_printf( "\n", ver.security_level ); + } else { + php3_printf( "\n" ); + } +#endif + php3_printf("
Total links:%d/%s
RCS Version:$Id$
SDK Version:%f
Highest LDAP Protocol Supported:%f
SSL Level Supported:%f
Level of encryption:%d bits
SSL not enabled.
\n"); + +} + +/* {{{ proto int ldap_connect([string host [, int port]]) + Connect to an LDAP server */ +void php3_ldap_connect(INTERNAL_FUNCTION_PARAMETERS) +{ + char *host; + int port; + /* char *hashed_details; + int hashed_details_length;*/ + LDAP *ldap; + LDAP_TLS_VARS; + + switch(ARG_COUNT(ht)) { + case 0: + host = NULL; + port = 0; + /* hashed_details = estrndup("ldap_", 5); + hashed_details_length = 4+1; */ + break; + + case 1: { + pval *yyhost; + + if (getParameters(ht, 1, &yyhost) == FAILURE) { + RETURN_FALSE; + } + + convert_to_string(yyhost); + host = yyhost->value.str.val; + port = 389; /* Default port */ + + /* hashed_details_length = yyhost->value.str.len+4+1; + hashed_details = emalloc(hashed_details_length+1); + sprintf(hashed_details, "ldap_%s", yyhost->value.str.val);*/ + } + break; + + case 2: { + pval *yyhost, *yyport; + + if (getParameters(ht, 2, &yyhost, &yyport) == FAILURE) { + RETURN_FALSE; + } + + convert_to_string(yyhost); + host = yyhost->value.str.val; + convert_to_long(yyport); + port = yyport->value.lval; + + /* Do we need to take care of hosts running multiple LDAP servers ? */ + /* hashed_details_length = yyhost->value.str.len+4+1; + hashed_details = emalloc(hashed_details_length+1); + sprintf(hashed_details, "ldap_%s", yyhost->value.str.val);*/ + } + break; + + default: + WRONG_PARAM_COUNT; + break; + } + + if (LDAP_GLOBAL(max_links)!=-1 && LDAP_GLOBAL(num_links)>=LDAP_GLOBAL(max_links)) { + php3_error(E_WARNING, "LDAP: Too many open links (%d)", LDAP_GLOBAL(num_links)); + RETURN_FALSE; + } + + ldap = ldap_open(host,port); + if ( ldap == NULL ) { + RETURN_FALSE; + } else { + RETURN_LONG(php3_list_insert((void*)ldap,LDAP_GLOBAL(le_link))); + } + +} +/* }}} */ + + +static LDAP * _get_ldap_link(pval *link, HashTable *list) +{ + LDAP *ldap; + int type; + LDAP_TLS_VARS; + + convert_to_long(link); + ldap = (LDAP *) php3_list_find(link->value.lval, &type); + + if (!ldap || !(type == LDAP_GLOBAL(le_link))) { + php3_error(E_WARNING, "%d is not a LDAP link index", link->value.lval); + return NULL; + } + return ldap; +} + + +static LDAPMessage * _get_ldap_result(pval *result, HashTable *list) +{ + LDAPMessage *ldap_result; + int type; + LDAP_TLS_VARS; + + convert_to_long(result); + ldap_result = (LDAPMessage *) php3_list_find(result->value.lval, &type); + + if (!ldap_result || type != LDAP_GLOBAL(le_result)) { + php3_error(E_WARNING, "%d is not a LDAP result index", result->value.lval); + return NULL; + } + + return ldap_result; +} + + +static LDAPMessage * _get_ldap_result_entry(pval *result, HashTable *list) +{ + LDAPMessage *ldap_result_entry; + int type; + LDAP_TLS_VARS; + + convert_to_long(result); + ldap_result_entry = (LDAPMessage *) php3_list_find(result->value.lval, &type); + + if (!ldap_result_entry || type != LDAP_GLOBAL(le_result_entry)) { + php3_error(E_WARNING, "%d is not a LDAP result entry index", result->value.lval); + return NULL; + } + + return ldap_result_entry; +} + + +static BerElement * _get_ber_entry(pval *berp, HashTable *list) +{ + BerElement *ber; + int type; + LDAP_TLS_VARS; + + convert_to_long(berp); + ber = (BerElement *) php3_list_find(berp->value.lval, &type); + + if ( type != LDAP_GLOBAL(le_ber_entry)) { + php3_error(E_WARNING, "%d is not a BerElement index", berp->value.lval); + return NULL; + } + + return ber; +} + +#if 0 +void php3_ber_free(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *berp; + + if ( getParameters(ht,1,&berp) == FAILURE ) RETURN_FALSE; + + php3_list_delete(berp->value.lval); + RETURN_TRUE; +} +#endif + +/* {{{ proto int ldap_bind(int link [, string dn, string password]) + Bind to LDAP directory */ +void php3_ldap_bind(INTERNAL_FUNCTION_PARAMETERS) +{ +pval *link, *bind_rdn, *bind_pw; +char *ldap_bind_rdn, *ldap_bind_pw; +LDAP *ldap; + + switch(ARG_COUNT(ht)) { + case 1: /* Anonymous Bind */ + if (getParameters(ht, 1, &link) == FAILURE) { + RETURN_FALSE; + } + + ldap_bind_rdn = NULL; + ldap_bind_pw = NULL; + + break; + + case 3 : + if (getParameters(ht, 3, &link, &bind_rdn, &bind_pw) == FAILURE) { + RETURN_FALSE; + } + + convert_to_string(bind_rdn); + convert_to_string(bind_pw); + + ldap_bind_rdn = bind_rdn->value.str.val; + ldap_bind_pw = bind_pw->value.str.val; + + break; + + default: + WRONG_PARAM_COUNT; + break; + } + + ldap = _get_ldap_link(link, list); + if (ldap == NULL) RETURN_FALSE; + + if (ldap_bind_s(ldap, ldap_bind_rdn, ldap_bind_pw, LDAP_AUTH_SIMPLE) != LDAP_SUCCESS) { +#if !HAVE_NSLDAP +#if LDAP_API_VERSION > 2000 + /* New versions of OpenLDAP do it this way */ + php3_error(E_WARNING,"LDAP: Unable to bind to server: %s",ldap_err2string(ldap_get_lderrno(ldap,NULL,NULL))); +#else + php3_error(E_WARNING,"LDAP: Unable to bind to server: %s",ldap_err2string(ldap->ld_errno)); +#endif +#endif + RETURN_FALSE; + } else { + RETURN_TRUE; + } +} +/* }}} */ + +/* {{{ proto int ldap_unbind(int link) + Unbind from LDAP directory */ +void php3_ldap_unbind(INTERNAL_FUNCTION_PARAMETERS) +{ +pval *link; +LDAP *ldap; + + if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &link) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(link); + + ldap = _get_ldap_link(link, list); + if (ldap == NULL) RETURN_FALSE; + + php3_list_delete(link->value.lval); + RETURN_TRUE; +} +/* }}} */ + + +static void php3_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) +{ + pval *link, *base_dn, *filter, *attrs, *attr; + char *ldap_base_dn, *ldap_filter; + LDAP *ldap; + char **ldap_attrs = NULL; + int attrsonly; + LDAPMessage *ldap_result; + int num_attribs=0, i; + LDAP_TLS_VARS; + + switch(ARG_COUNT(ht)) { + case 3 : + if (getParameters(ht, 3, &link, &base_dn, &filter) == FAILURE) { + RETURN_FALSE; + } + + convert_to_string(base_dn); + convert_to_string(filter); + + ldap_base_dn = base_dn->value.str.val; + ldap_filter = filter->value.str.val; + + break; + + case 4 : + if (getParameters(ht, 4, &link, &base_dn, &filter, &attrs) == FAILURE) { + RETURN_FALSE; + } + + if (attrs->type != IS_ARRAY) { + php3_error(E_WARNING, "LDAP: Expected Array as last element"); + RETURN_FALSE; + } + + convert_to_string(base_dn); + convert_to_string(filter); + + ldap_base_dn = base_dn->value.str.val; + ldap_filter = filter->value.str.val; + + num_attribs = _php3_hash_num_elements(attrs->value.ht); + if ((ldap_attrs = emalloc((num_attribs+1) * sizeof(char *))) == NULL) { + php3_error(E_WARNING, "LDAP: Could not allocate memory"); + RETURN_FALSE; + return; + } + + for(i=0; ivalue.ht, i, (void **) &attr) == FAILURE) { + php3_error(E_WARNING, "LDAP: Array initialization wrong"); + RETURN_FALSE; + return; + } + convert_to_string(attr); + ldap_attrs[i] = attr->value.str.val; + } + ldap_attrs[num_attribs] = NULL; + + break; + + default: + WRONG_PARAM_COUNT; + break; + } + + /* fix to make null base_dn's work */ + if ( strlen(ldap_base_dn) < 1 ) { + ldap_base_dn = NULL; + } + + ldap = _get_ldap_link(link, list); + if (ldap == NULL) RETURN_FALSE; + + /* Is it useful to only get the attributes ? */ + attrsonly = 0; + + /* We can possibly add the timeout value also */ + + if (ldap_search_s(ldap, ldap_base_dn, scope, ldap_filter, ldap_attrs, attrsonly, &ldap_result) != LDAP_SUCCESS) { +#if !HAVE_NSLDAP +#if LDAP_API_VERSION > 2000 + php3_error(E_WARNING,"LDAP: Unable to perform the search: %s",ldap_err2string(ldap_get_lderrno(ldap,NULL,NULL))); +#else + php3_error(E_WARNING, "LDAP: Unable to perform the search: %s", ldap_err2string(ldap->ld_errno)); +#endif +#endif + RETVAL_FALSE; + } else { + RETVAL_LONG(php3_list_insert(ldap_result, LDAP_GLOBAL(le_result))); + } + + if (ldap_attrs != NULL) { + /* for(i=0; ivalue.lval); /* Delete list entry and call registered destructor function */ + RETVAL_TRUE; + } + return; +} +/* }}} */ + +/* {{{ proto int ldap_count_entries(int link, int result) + Count the number of entries in a search result */ +void php3_ldap_count_entries(INTERNAL_FUNCTION_PARAMETERS) +{ +pval *result, *link; +LDAP *ldap; +LDAPMessage *ldap_result; + + if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &link, &result) == FAILURE) { + WRONG_PARAM_COUNT; + } + + ldap = _get_ldap_link(link, list); + if (ldap == NULL) RETURN_FALSE; + + ldap_result = _get_ldap_result(result, list); + if (ldap_result == NULL) RETURN_FALSE; + + RETURN_LONG(ldap_count_entries(ldap, ldap_result)); +} +/* }}} */ + +/* {{{ proto int ldap_first_entry(int link, int result) + Return first result id */ +void php3_ldap_first_entry(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *result, *link; + LDAP *ldap; + LDAPMessage *ldap_result; + LDAPMessage *ldap_result_entry; + LDAP_TLS_VARS; + + if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &link, &result) == FAILURE) { + WRONG_PARAM_COUNT; + } + + ldap = _get_ldap_link(link, list); + if (ldap == NULL) RETURN_FALSE; + + ldap_result = _get_ldap_result(result, list); + if (ldap_result == NULL) RETURN_FALSE; + + if ((ldap_result_entry = ldap_first_entry(ldap, ldap_result)) == NULL) { + RETURN_FALSE; + } else { + RETURN_LONG(php3_list_insert(ldap_result_entry, LDAP_GLOBAL(le_result_entry))); + } +} +/* }}} */ + +/* {{{ proto int ldap_next_entry(int link, int entry) + Get next result entry */ +void php3_ldap_next_entry(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *result_entry, *link; + LDAP *ldap; + LDAPMessage *ldap_result_entry, *ldap_result_entry_next; + LDAP_TLS_VARS; + + if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &link, &result_entry) == FAILURE) { + WRONG_PARAM_COUNT; + } + + ldap = _get_ldap_link(link, list); + if (ldap == NULL) RETURN_FALSE; + + ldap_result_entry = _get_ldap_result_entry(result_entry, list); + if (ldap_result_entry == NULL) RETURN_FALSE; + + if ((ldap_result_entry_next = ldap_next_entry(ldap, ldap_result_entry)) == NULL) { + RETURN_FALSE; + } else { + RETURN_LONG(php3_list_insert(ldap_result_entry_next, LDAP_GLOBAL(le_result_entry))); + } +} +/* }}} */ + +/* {{{ proto array ldap_get_entries(int link, int result) + Get all result entries */ +void php3_ldap_get_entries(INTERNAL_FUNCTION_PARAMETERS) +{ +pval *link, *result; +LDAPMessage *ldap_result, *ldap_result_entry; +pval tmp1, tmp2; +LDAP *ldap; +int num_entries, num_attrib, num_values, i; +int attr_count, entry_count; +BerElement *ber; +char *attribute; +char **ldap_value; +char *dn; + + if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &link, &result) == FAILURE) { + WRONG_PARAM_COUNT; + } + + ldap = _get_ldap_link(link, list); + if (ldap == NULL) RETURN_FALSE; + + ldap_result = _get_ldap_result(result, list); + if (ldap_result == NULL) RETURN_FALSE; + + num_entries = ldap_count_entries(ldap, ldap_result); + + array_init(return_value); + add_assoc_long(return_value, "count", num_entries); + + if (num_entries == 0) return; + + ldap_result_entry = ldap_first_entry(ldap, ldap_result); + if (ldap_result_entry == NULL) RETURN_FALSE; + + entry_count = 0; + + while(ldap_result_entry != NULL) { + + num_attrib = 0; + attribute = ldap_first_attribute(ldap, ldap_result_entry, &ber); + if (attribute == NULL) RETURN_FALSE; + while (attribute != NULL) { + num_attrib++; + attribute = ldap_next_attribute(ldap, ldap_result_entry, ber); + } + + array_init(&tmp1); + + attr_count = 0; + attribute = ldap_first_attribute(ldap, ldap_result_entry, &ber); + while (attribute != NULL) { + ldap_value = ldap_get_values(ldap, ldap_result_entry, attribute); + num_values = ldap_count_values(ldap_value); + + array_init(&tmp2); + add_assoc_long(&tmp2, "count", num_values); + for(i=0; ivalue.ht, entry_count, (void *) &tmp1, sizeof(pval), NULL); + + entry_count++; + ldap_result_entry = ldap_next_entry(ldap, ldap_result_entry); + } + + add_assoc_long(return_value, "count", num_entries); +} +/* }}} */ + +/* {{{ proto string ldap_first_attribute(int link, int result, int ber) + Return first attribute */ +void php3_ldap_first_attribute(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *result,*link,*berp; + LDAP *ldap; + LDAPMessage *ldap_result_entry; + BerElement *ber; + char *attribute; + LDAP_TLS_VARS; + + if (ARG_COUNT(ht) != 3 || getParameters(ht, 3, &link, &result,&berp) == FAILURE || ParameterPassedByReference(ht,3)==0 ) { + WRONG_PARAM_COUNT; + } + + ldap = _get_ldap_link(link,list); + if (ldap == NULL) RETURN_FALSE; + + ldap_result_entry = _get_ldap_result_entry(result,list); + if (ldap_result_entry == NULL) RETURN_FALSE; + + if ((attribute = ldap_first_attribute(ldap, ldap_result_entry, &ber)) == NULL) { + RETURN_FALSE; + } else { + /* brep is passed by ref so we do not have to account for memory */ + berp->type=IS_LONG; + berp->value.lval=php3_list_insert(ber, LDAP_GLOBAL(le_ber_entry)); + + RETVAL_STRING(attribute,1); +#ifdef WINDOWS + ldap_memfree(attribute); +#endif + } +} +/* }}} */ + +/* {{{ proto string ldap_next_attribute(int link, int result, int ber) + Get the next attribute in result */ +void php3_ldap_next_attribute(INTERNAL_FUNCTION_PARAMETERS) +{ +pval *result,*link,*berp; +LDAP *ldap; +LDAPMessage *ldap_result_entry; +BerElement *ber; +char *attribute; + + if (ARG_COUNT(ht) != 3 || getParameters(ht, 3, &link, &result,&berp) == FAILURE ) { + WRONG_PARAM_COUNT; + } + + ldap = _get_ldap_link(link,list); + if (ldap == NULL) RETURN_FALSE; + + ldap_result_entry = _get_ldap_result_entry(result,list); + if (ldap_result_entry == NULL) RETURN_FALSE; + + ber = _get_ber_entry(berp,list); + + if ((attribute = ldap_next_attribute(ldap, ldap_result_entry, ber)) == NULL) { + RETURN_FALSE; + } else { + RETVAL_STRING(attribute,1); +#ifdef WINDOWS + ldap_memfree(attribute); +#endif + } +} +/* }}} */ + +/* {{{ proto array ldap_get_attributes(int link, int result) + Get attributes from a search result entry */ +void php3_ldap_get_attributes(INTERNAL_FUNCTION_PARAMETERS) +{ +pval *link, *result_entry; +pval tmp; +LDAP *ldap; +LDAPMessage *ldap_result_entry; +char *attribute; +char **ldap_value; +int i, count, num_values, num_attrib; +BerElement *ber; + + if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &link, &result_entry) == FAILURE) { + WRONG_PARAM_COUNT; + } + + ldap = _get_ldap_link(link, list); + if (ldap == NULL) RETURN_FALSE; + + ldap_result_entry = _get_ldap_result_entry(result_entry, list); + if (ldap_result_entry == NULL) RETURN_FALSE; + + num_attrib = 0; + attribute = ldap_first_attribute(ldap, ldap_result_entry, &ber); + if (attribute == NULL) RETURN_FALSE; + while (attribute != NULL) { + num_attrib++; + attribute = ldap_next_attribute(ldap, ldap_result_entry, ber); + } + + array_init(return_value); + + count=0; + attribute = ldap_first_attribute(ldap, ldap_result_entry, &ber); + while (attribute != NULL) { + ldap_value = ldap_get_values(ldap, ldap_result_entry, attribute); + num_values = ldap_count_values(ldap_value); + + array_init(&tmp); + add_assoc_long(&tmp, "count", num_values); + for(i=0; ivalue.ht, attribute, strlen(attribute)+1, (void *) &tmp, sizeof(pval), NULL); + add_index_string(return_value, count, attribute, 1); + + count++; + attribute = ldap_next_attribute(ldap, ldap_result_entry, ber); + } + + add_assoc_long(return_value, "count", num_attrib); +} +/* }}} */ + +/* {{{ proto array ldap_get_values(int link, int result, string attribute) + Get all values from a result entry */ +void php3_ldap_get_values(INTERNAL_FUNCTION_PARAMETERS) +{ +pval *link, *result_entry, *attr; +LDAP *ldap; +LDAPMessage *ldap_result_entry; +char *attribute; +char **ldap_value; +int i, num_values; + + if (ARG_COUNT(ht) != 3 || getParameters(ht, 3, &link, &result_entry, &attr) == FAILURE) { + WRONG_PARAM_COUNT; + } + + ldap = _get_ldap_link(link, list); + if (ldap == NULL) RETURN_FALSE; + + ldap_result_entry = _get_ldap_result_entry(result_entry, list); + if (ldap_result_entry == NULL) RETURN_FALSE; + + convert_to_string(attr); + attribute = attr->value.str.val; + + if ((ldap_value = ldap_get_values(ldap, ldap_result_entry, attribute)) == NULL) { +#if !HAVE_NSLDAP +#if LDAP_API_VERSION > 2000 + php3_error(E_WARNING, "LDAP: Cannot get the value(s) of attribute %s", ldap_err2string(ldap_get_lderrno(ldap,NULL,NULL))); +#else + php3_error(E_WARNING, "LDAP: Cannot get the value(s) of attribute %s", ldap_err2string(ldap->ld_errno)); +#endif +#endif + RETURN_FALSE; + } + + num_values = ldap_count_values(ldap_value); + + if (array_init(return_value) == FAILURE) { + RETURN_FALSE; + } + + for(i=0; ivalue.str.val, with_attrib->value.lval); + + i=0; + while(ldap_value[i] != NULL) i++; + count = i; + + if (array_init(return_value) == FAILURE) { + RETURN_FALSE; + } + + add_assoc_long(return_value, "count", count); + for(i=0; ivalue.str.val); + + if (ufn !=NULL) { + RETVAL_STRING(ufn,1); +#ifdef WINDOWS + ldap_memfree(ufn); +#endif + } else { + RETURN_FALSE; + } +} +/* }}} */ + + +static void php3_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper) +{ +pval *link, *dn, *entry, *value, *ivalue; +LDAP *ldap; +char *ldap_dn; +LDAPMod **ldap_mods; +int i, j, num_attribs, num_values; +char *attribute; +ulong index; + + if (ARG_COUNT(ht) != 3 || getParameters(ht, 3, &link, &dn, &entry) == FAILURE) { + WRONG_PARAM_COUNT; + } + + if (entry->type != IS_ARRAY) { + php3_error(E_WARNING, "LDAP: Expected Array as the last element"); + RETURN_FALSE; + } + + ldap = _get_ldap_link(link, list); + if (ldap == NULL) RETURN_FALSE; + + convert_to_string(dn); + ldap_dn = dn->value.str.val; + + num_attribs = _php3_hash_num_elements(entry->value.ht); + + ldap_mods = emalloc((num_attribs+1) * sizeof(LDAPMod *)); + + _php3_hash_internal_pointer_reset(entry->value.ht); + + for(i=0; imod_op = oper; + + if (_php3_hash_get_current_key(entry->value.ht, &attribute, &index) == HASH_KEY_IS_STRING) { + ldap_mods[i]->mod_type = estrdup(attribute); + efree(attribute); + } else { + php3_error(E_WARNING, "LDAP: Unknown Attribute in the data"); + } + + _php3_hash_get_current_data(entry->value.ht, (void **) &value); + + if (value->type != IS_ARRAY) { + num_values = 1; + } else { + num_values = _php3_hash_num_elements(value->value.ht); + } + + ldap_mods[i]->mod_values = emalloc((num_values+1) * sizeof(char *)); + + if (num_values == 1) { + convert_to_string(value); + ldap_mods[i]->mod_values[0] = value->value.str.val; + } else { + for(j=0; jvalue.ht, j, (void **) &ivalue); + convert_to_string(ivalue); + ldap_mods[i]->mod_values[j] = ivalue->value.str.val; + } + } + ldap_mods[i]->mod_values[num_values] = NULL; + + _php3_hash_move_forward(entry->value.ht); + } + ldap_mods[num_attribs] = NULL; + + if (oper == LDAP_MOD_ADD) { + if (ldap_add_s(ldap, ldap_dn, ldap_mods) != LDAP_SUCCESS) { + ldap_perror(ldap, "LDAP"); + php3_error(E_WARNING, "LDAP: add operation could not be completed."); + RETVAL_FALSE; + } else RETVAL_TRUE; + } else { + if (ldap_modify_s(ldap, ldap_dn, ldap_mods) != LDAP_SUCCESS) { + php3_error(E_WARNING, "LDAP: modify operation could not be completed."); + RETVAL_FALSE; + } else RETVAL_TRUE; + } + + for(i=0; imod_type); + efree(ldap_mods[i]->mod_values); + efree(ldap_mods[i]); + } + efree(ldap_mods); + + return; +} + +/* {{{ proto int ldap_add(int link, string dn, array entry) + Add entries to LDAP directory */ +void php3_ldap_add(INTERNAL_FUNCTION_PARAMETERS) +{ + php3_ldap_do_modify(INTERNAL_FUNCTION_PARAM_PASSTHRU, LDAP_MOD_ADD); +} +/* }}} */ + + +/* {{{ proto int ldap_modify(int link, string dn, array entry) + Modify an LDAP entry */ +void php3_ldap_modify(INTERNAL_FUNCTION_PARAMETERS) +{ + php3_ldap_do_modify(INTERNAL_FUNCTION_PARAM_PASSTHRU, LDAP_MOD_REPLACE); +} +/* }}} */ + +/* {{{ proto int ldap_delete(int link, string dn) + Delete an entry from a directory */ +void php3_ldap_delete(INTERNAL_FUNCTION_PARAMETERS) +{ +pval *link, *dn; +LDAP *ldap; +char *ldap_dn; + + if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &link, &dn) == FAILURE) { + WRONG_PARAM_COUNT; + } + + ldap = _get_ldap_link(link, list); + if (ldap == NULL) RETURN_FALSE; + + convert_to_string(dn); + ldap_dn = dn->value.str.val; + + if (ldap_delete_s(ldap, ldap_dn) != LDAP_SUCCESS) { + ldap_perror(ldap, "LDAP"); + RETURN_FALSE; + } + + RETURN_TRUE; +} +/* }}} */ + +#endif diff --git a/ext/ldap/php3_ldap.h b/ext/ldap/php3_ldap.h new file mode 100644 index 00000000000..1440df17f53 --- /dev/null +++ b/ext/ldap/php3_ldap.h @@ -0,0 +1,121 @@ +/* + +----------------------------------------------------------------------+ + | PHP HTML Embedded Scripting Language Version 3.0 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | + +----------------------------------------------------------------------+ + | This program is free software; you can redistribute it and/or modify | + | it under the terms of one of the following licenses: | + | | + | A) the GNU General Public License as published by the Free Software | + | Foundation; either version 2 of the License, or (at your option) | + | any later version. | + | | + | B) the PHP License as published by the PHP Development Team and | + | included in the distribution in the file: LICENSE | + | | + | This program is distributed in the hope that it will be useful, | + | but WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | + | GNU General Public License for more details. | + | | + | You should have received a copy of both licenses referred to here. | + | If you did not, or have any questions about PHP licensing, please | + | contact core@php.net. | + +----------------------------------------------------------------------+ + | Authors: Amitay Isaacs | + | Eric Warnke | + +----------------------------------------------------------------------+ + */ + + +/* $Id$ */ + +#ifndef _PHP3_LDAP_H +#define _PHP3_LDAP_H + +#if COMPILE_DL +#undef HAVE_LDAP +#define HAVE_LDAP 1 +#endif + +#if HAVE_LDAP +#include +#include + +extern php3_module_entry ldap_module_entry; +#define ldap_module_ptr &ldap_module_entry + +/* LDAP functions */ +extern int php3_minit_ldap(INIT_FUNC_ARGS); +extern int php3_mshutdown_ldap(SHUTDOWN_FUNC_ARGS); + +extern void php3_info_ldap(void); + +extern void php3_ldap_connect(INTERNAL_FUNCTION_PARAMETERS); + +extern void php3_ldap_bind(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_ldap_unbind(INTERNAL_FUNCTION_PARAMETERS); + +extern void php3_ldap_read(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_ldap_list(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_ldap_search(INTERNAL_FUNCTION_PARAMETERS); + +extern void php3_ldap_free_result(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_ldap_count_entries(INTERNAL_FUNCTION_PARAMETERS); + +extern void php3_ldap_first_entry(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_ldap_next_entry(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_ldap_get_entries(INTERNAL_FUNCTION_PARAMETERS); +#if 0 +extern void php3_ldap_free_entry(INTERNAL_FUNCTION_PARAMETERS); +#endif +extern void php3_ldap_first_attribute(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_ldap_next_attribute(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_ldap_get_attributes(INTERNAL_FUNCTION_PARAMETERS); + +extern void php3_ldap_get_values(INTERNAL_FUNCTION_PARAMETERS); + +extern void php3_ber_free(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_ldap_get_dn(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_ldap_explode_dn(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_ldap_dn2ufn(INTERNAL_FUNCTION_PARAMETERS); + +extern void php3_ldap_add(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_ldap_delete(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_ldap_modify(INTERNAL_FUNCTION_PARAMETERS); + +typedef struct { + long default_link; + long num_links, max_links; + char *base_dn; + int le_result, le_result_entry, le_ber_entry; + int le_link; + + /* I just found out that the thread safe features + of the netscape ldap library are only required if + multiple threads are accessing the same LDAP + structure. Since we are not doing that, we do + not need to use this feature. I am leaving the + code here anyway just in case. smc + */ +#if 0 + struct ldap_thread_fns tfns; + int le_errno; /* Corresponds to the LDAP error code */ + char *le_matched; /* Matching components of the DN, + if an NO_SUCH_OBJECT error occurred */ + char *le_errmsg; /* Error message */ +#endif +} ldap_module; + +#ifndef THREAD_SAFE +extern ldap_module php3_ldap_module; +#endif + +#else + +#define ldap_module_ptr NULL + +#endif + +#endif /* _PHP3_LDAP_H */ diff --git a/ext/ldap/setup.stub b/ext/ldap/setup.stub new file mode 100644 index 00000000000..72182a28ef8 --- /dev/null +++ b/ext/ldap/setup.stub @@ -0,0 +1,8 @@ +# $Source$ +# $Id$ + +define_option with-ldap 'LDAP support?' yesnodir \ + 'no /usr/local/ldap LDAP base install' \ +' Whether to build with LDAP (Lightweight Directory Access Protocol)\n + support.\n + More information about LDAP can be found in RFC1777 and RFC1778.' diff --git a/ext/standard/config.h.stub b/ext/standard/config.h.stub new file mode 100644 index 00000000000..50703755eb5 --- /dev/null +++ b/ext/standard/config.h.stub @@ -0,0 +1,2 @@ +/* Define if you have the crypt() function */ +#define HAVE_CRYPT 1 diff --git a/internal_functions.c b/internal_functions.c index a935289c479..747d1aec845 100644 --- a/internal_functions.c +++ b/internal_functions.c @@ -47,7 +47,7 @@ #include "ext/gettext/php3_gettext.h" #include "ext/informix/php3_ifx.h" -#include "functions/php3_ldap.h" +#include "ext/ldap/php3_ldap.h" #include "ext/mysql/php3_mysql.h" #include "ext/bcmath/php3_bcmath.h" #include "ext/msql/php3_msql.h" @@ -56,7 +56,7 @@ #include "functions/php3_pgsql.h" #include "functions/php3_sybase.h" #include "functions/php3_sybase-ct.h" -#include "functions/imap.h" +#include "ext/imap/imap.h" #include "ext/standard/head.h" #include "functions/post.h" #include "ext/hyperwave/hw.h" diff --git a/setup b/setup index 224f501eb07..18a1673f5ea 100644 --- a/setup +++ b/setup @@ -266,18 +266,6 @@ define_option with-interbase 'InterBase support?' yesnodir \ ' Whether to build PHP with InterBase support. More\n information about InterBase can be found at http://www.interbase.com/.' -define_option with-ldap 'LDAP support?' yesnodir \ - 'no /usr/local/ldap LDAP base install' \ -' Whether to build with LDAP (Lightweight Directory Access Protocol)\n - support.\n - More information about LDAP can be found in RFC1777 and RFC1778.' - -define_option with-imap 'IMAP support?' yesnodir \ - 'no /usr/local/imap IMAP base install' \ -' Whether to build with IMAP (Internet Message Access Protocol)\n - support.\n - More information about LDAP can be found in RFC1777 and RFC1778.' - define_option with-pdflib 'pdflib 0.6 support? ' yesnodir \ 'no /usr/local pdflib install' \ ' Whether to use the pdflib support to write .pdf-files.\n