├── .github
└── workflows
│ └── ci.yml
├── .gitignore
├── CREDITS
├── LICENSE
├── README.rst
├── config.m4
├── config.w32
├── package.xml
├── php_imap.c
├── php_imap.h
├── php_imap.stub.php
├── php_imap_arginfo.h
└── tests
├── README.md
├── bug31142_1.phpt
├── bug31142_2.phpt
├── bug32589.phpt
├── bug35669.phpt
├── bug40854.phpt
├── bug44098.phpt
├── bug45705_1.phpt
├── bug45705_2.phpt
├── bug46918.phpt
├── bug53377.phpt
├── bug63126.phpt
├── bug64076.phpt
├── bug75774.phpt
├── bug77020.phpt
├── bug77153.phpt
├── bug80213.phpt
├── bug80215.phpt
├── bug80216.phpt
├── bug80220.phpt
├── bug80223.phpt
├── bug80226.phpt
├── bug80242.phpt
├── bug80438.phpt
├── bug80710_1.phpt
├── bug80710_2.phpt
├── bug80800.phpt
├── gh9309.phpt
├── imap_8bit_basic.phpt
├── imap_append_basic.phpt
├── imap_base64_basic.phpt
├── imap_binary_basic.phpt
├── imap_body_basic.phpt
├── imap_body_errors.phpt
├── imap_body_uid.phpt
├── imap_bodystruct_basic.phpt
├── imap_clearflag_full_basic.phpt
├── imap_clearflag_full_uid.phpt
├── imap_close_basic.phpt
├── imap_close_variation4.phpt
├── imap_constructor.phpt
├── imap_createmailbox_basic.phpt
├── imap_delete_uid.phpt
├── imap_errors_basic.phpt
├── imap_fetch_overview_basic.phpt
├── imap_fetch_overview_uid.phpt
├── imap_fetch_overview_variation5.phpt
├── imap_fetch_overview_variation6.phpt
├── imap_fetchbody_basic.phpt
├── imap_fetchbody_errors.phpt
├── imap_fetchbody_uid.phpt
├── imap_fetchbody_variation6.phpt
├── imap_fetchheader_basic.phpt
├── imap_fetchheader_errors.phpt
├── imap_fetchheader_uid.phpt
├── imap_fetchheader_variation5.phpt
├── imap_fetchmime_errors.phpt
├── imap_fetchmime_uid.phpt
├── imap_fetchstructure_basic.phpt
├── imap_fetchstructure_errors.phpt
├── imap_fetchstructure_uid.phpt
├── imap_final.phpt
├── imap_gc_error.phpt
├── imap_getsubscribed_basic.phpt
├── imap_headerinfo_basic.phpt
├── imap_is_open.phpt
├── imap_list_basic.phpt
├── imap_lsub_basic.phpt
├── imap_mail_copy_basic.phpt
├── imap_mail_move_basic.phpt
├── imap_mutf7_to_utf8.phpt
├── imap_open_error.phpt
├── imap_open_with_cl_expunge.phpt
├── imap_renamemailbox_basic.phpt
├── imap_reopen_with_cl_expunge.phpt
├── imap_rfc822_parse_headers_basic.phpt
├── imap_rfc822_write_address_basic.phpt
├── imap_savebody_basic.phpt
├── imap_savebody_errors.phpt
├── imap_savebody_uid.phpt
├── imap_search_basic.phpt
├── imap_setflag_full_basic.phpt
├── imap_setflag_full_uid.phpt
├── imap_sort_uid.phpt
├── imap_timeout_basic.phpt
├── imap_undelete_basic.phpt
├── imap_undelete_uid.phpt
├── imap_utf8.phpt
├── imap_utf8_to_mutf7_basic.phpt
├── nil_constant.phpt
└── setup
├── clean.inc
├── dovecot.conf
├── dovecotpass
├── imap_include.inc
├── setup.sh
└── skipif.inc
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: Build
2 | on: [push, pull_request]
3 | jobs:
4 | ubuntu:
5 | strategy:
6 | matrix:
7 | version: ['8.4']
8 | runs-on: ubuntu-22.04
9 | steps:
10 | - name: git checkout
11 | uses: actions/checkout@v4
12 | - name: Install depencies
13 | run: |
14 | sudo apt-get update -y | true
15 | sudo apt-get install -y \
16 | libkrb5-dev \
17 | libgssapi-krb5-2 \
18 | libc-client-dev
19 | - name: Setup PHP
20 | uses: shivammathur/setup-php@v2
21 | with:
22 | php-version: ${{matrix.version}}
23 | - name: phpize
24 | run: phpize
25 | - name: configure
26 | run: ./configure --with-imap --with-kerberos --with-imap-ssl
27 | - name: make
28 | run: make
29 | windows:
30 | defaults:
31 | run:
32 | shell: cmd
33 | strategy:
34 | matrix:
35 | version: ['8.4']
36 | arch: [x64]
37 | ts: [ts]
38 | runs-on: windows-2022
39 | steps:
40 | - name: Checkout imap
41 | uses: actions/checkout@v4
42 | - name: Setup PHP
43 | id: setup-php
44 | uses: php/setup-php-sdk@v0.9
45 | with:
46 | version: ${{matrix.version}}
47 | arch: ${{matrix.arch}}
48 | ts: ${{matrix.ts}}
49 | - name: Fetch dependencies
50 | run: |
51 | curl -LO https://downloads.php.net/~windows/pecl/deps/c-client-2007f-1-vs16-${{matrix.arch}}.zip
52 | 7z x c-client-2007f-1-vs16-${{matrix.arch}}.zip -o..\deps
53 | - name: Enable Developer Command Prompt
54 | uses: ilammy/msvc-dev-cmd@v1
55 | with:
56 | arch: ${{matrix.arch}}
57 | toolset: ${{steps.setup-php.outputs.toolset}}
58 | - name: phpize
59 | run: phpize
60 | - name: configure
61 | run: configure --with-imap --with-prefix=${{steps.setup-php.outputs.prefix}}
62 | - name: make
63 | run: nmake
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | Makefile.global
2 | acinclude.m4
3 | aclocal.m4
4 | autom4te.cache
5 | build
6 | config.guess
7 | config.h.in
8 | config.sub
9 | configure
10 | configure.in
11 | install-sh
12 | ltmain.sh
13 | missing
14 | mkinstalldirs
15 | run-tests.php
16 | .deps
17 | Makefile
18 | Makefile.fragments
19 | Makefile.objects
20 | config.h
21 | config.log
22 | config.nice
23 | config.status
24 | libtool
25 | .idea
26 | CMakeLists.txt
27 | .libs
28 | /*~
29 | configure.ac
30 | php_test_*
31 | imap.la
32 | modules/
33 | php_imap.dep
34 | php_imap.lo
35 | imap*tgz
36 |
--------------------------------------------------------------------------------
/CREDITS:
--------------------------------------------------------------------------------
1 | IMAP
2 | Rex Logan, Mark Musone, Brian Wang, Kaj-Michael Lang, Antoni Pamies Olive, Rasmus Lerdorf, Andrew Skalski, Chuck Hagenbuch, Daniel R Kalowsky
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | --------------------------------------------------------------------
2 | The PHP License, version 3.01
3 | Copyright (c) 1999 - 2023 The PHP Group. All rights reserved.
4 | --------------------------------------------------------------------
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, is permitted provided that the following conditions
8 | are met:
9 |
10 | 1. Redistributions of source code must retain the above copyright
11 | notice, this list of conditions and the following disclaimer.
12 |
13 | 2. Redistributions in binary form must reproduce the above copyright
14 | notice, this list of conditions and the following disclaimer in
15 | the documentation and/or other materials provided with the
16 | distribution.
17 |
18 | 3. The name "PHP" must not be used to endorse or promote products
19 | derived from this software without prior written permission. For
20 | written permission, please contact group@php.net.
21 |
22 | 4. Products derived from this software may not be called "PHP", nor
23 | may "PHP" appear in their name, without prior written permission
24 | from group@php.net. You may indicate that your software works in
25 | conjunction with PHP by saying "Foo for PHP" instead of calling
26 | it "PHP Foo" or "phpfoo"
27 |
28 | 5. The PHP Group may publish revised and/or new versions of the
29 | license from time to time. Each version will be given a
30 | distinguishing version number.
31 | Once covered code has been published under a particular version
32 | of the license, you may always continue to use it under the terms
33 | of that version. You may also choose to use such covered code
34 | under the terms of any subsequent version of the license
35 | published by the PHP Group. No one other than the PHP Group has
36 | the right to modify the terms applicable to covered code created
37 | under this License.
38 |
39 | 6. Redistributions of any form whatsoever must retain the following
40 | acknowledgment:
41 | "This product includes PHP software, freely available from
42 | ".
43 |
44 | THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND
45 | ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
46 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
47 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PHP
48 | DEVELOPMENT TEAM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
49 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
50 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
51 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55 | OF THE POSSIBILITY OF SUCH DAMAGE.
56 |
57 | --------------------------------------------------------------------
58 |
59 | This software consists of voluntary contributions made by many
60 | individuals on behalf of the PHP Group.
61 |
62 | The PHP Group can be contacted via Email at group@php.net.
63 |
64 | For more information on the PHP Group and the PHP project,
65 | please see .
66 |
67 | PHP includes the Zend Engine, freely available at
68 | .
69 |
--------------------------------------------------------------------------------
/README.rst:
--------------------------------------------------------------------------------
1 | ====
2 | IMAP
3 | ====
4 |
5 | This is the IMAP extension extracted from the PHP source distribution.
6 | PHP versions after PHP 8.3 no longer bundle this extension.
7 |
8 | This extension is no longer actively maintained or supported, and this
9 | repository serves as an archive for it.
10 |
11 | The documentation is still available as part of the `PHP Documentation
12 | `_.
13 |
14 | Installation Issues
15 | -------------------
16 |
17 | In order for this extension to compile, you need to have the ``c-client``
18 | installed.
19 |
20 | Debian
21 | ~~~~~~
22 |
23 | On Debian based systems, you can do that with ``apt-get``. As this
24 | distribution installed library is compiled with Kerberos and SSL support, you
25 | need to make sure to have these development libraries installed too.
26 |
27 | You can install all of these with::
28 |
29 | apt-get install libc-client-dev libkrb5-dev libssl-dev
30 |
31 | When running PECL, you may not disable either Kerberos or SSL support, as the
32 | system installed c-client requires it.
33 |
--------------------------------------------------------------------------------
/config.m4:
--------------------------------------------------------------------------------
1 | AC_DEFUN([IMAP_INC_CHK],[if test -r "$i$1/c-client.h"; then
2 | AC_DEFINE(HAVE_IMAP2000, 1, [ ])
3 | IMAP_DIR=$i
4 | IMAP_INC_DIR=$i$1
5 | break
6 | elif test -r "$i$1/rfc822.h"; then
7 | IMAP_DIR=$i;
8 | IMAP_INC_DIR=$i$1
9 | break
10 | ])
11 |
12 | AC_DEFUN([IMAP_LIB_CHK],[
13 | str="$IMAP_DIR/$1/lib$lib.*"
14 | for i in `echo $str`; do
15 | test -r $i && IMAP_LIBDIR=$IMAP_DIR/$1 && break 2
16 | done
17 | ])
18 |
19 | dnl PHP_IMAP_TEST_BUILD(function, action-if-ok, action-if-not-ok, extra-libs)
20 | dnl
21 | dnl The UW-IMAP c-client library was not originally designed to be a
22 | dnl shared library. The mm_foo functions are callbacks, and are required
23 | dnl to be implemented by the program that is linking to c-client. This
24 | dnl macro does the work of defining them all to no-ops for you. Note
25 | dnl that this is a link test; the undefined symbols will only
26 | dnl cause problems if you actually try to link with c-client. For
27 | dnl example, if your test is trivial enough to be optimized out, and if
28 | dnl you link with --as-needed, the test/library may be omitted entirely
29 | dnl from the final executable. In that case linking will of course
30 | dnl succeed, but your luck won't necessarily apply at lower optimization
31 | dnl levels or systems where --as-needed is not used.
32 | AC_DEFUN([PHP_IMAP_TEST_BUILD], [
33 | old_LIBS=$LIBS
34 | LIBS="$4 $LIBS"
35 | AC_LINK_IFELSE([AC_LANG_SOURCE([
36 | #if defined(__GNUC__) && __GNUC__ >= 4
37 | # define PHP_IMAP_EXPORT __attribute__ ((visibility("default")))
38 | #else
39 | # define PHP_IMAP_EXPORT
40 | #endif
41 |
42 | PHP_IMAP_EXPORT void mm_log(void){}
43 | PHP_IMAP_EXPORT void mm_dlog(void){}
44 | PHP_IMAP_EXPORT void mm_flags(void){}
45 | PHP_IMAP_EXPORT void mm_fatal(void){}
46 | PHP_IMAP_EXPORT void mm_critical(void){}
47 | PHP_IMAP_EXPORT void mm_nocritical(void){}
48 | PHP_IMAP_EXPORT void mm_notify(void){}
49 | PHP_IMAP_EXPORT void mm_login(void){}
50 | PHP_IMAP_EXPORT void mm_diskerror(void){}
51 | PHP_IMAP_EXPORT void mm_status(void){}
52 | PHP_IMAP_EXPORT void mm_lsub(void){}
53 | PHP_IMAP_EXPORT void mm_list(void){}
54 | PHP_IMAP_EXPORT void mm_exists(void){}
55 | PHP_IMAP_EXPORT void mm_searched(void){}
56 | PHP_IMAP_EXPORT void mm_expunged(void){}
57 |
58 | char $1(void);
59 | int main(void) {
60 | $1();
61 | return 0;
62 | }
63 | ])],[
64 | LIBS=$old_LIBS
65 | $2
66 | ],[
67 | LIBS=$old_LIBS
68 | $3
69 | ])
70 | ])
71 |
72 | AC_DEFUN([PHP_IMAP_KRB_CHK], [
73 | if test "$PHP_KERBEROS" != "no"; then
74 | PKG_CHECK_MODULES([KERBEROS], [krb5-gssapi krb5])
75 |
76 | PHP_EVAL_INCLINE($KERBEROS_CFLAGS)
77 | PHP_EVAL_LIBLINE($KERBEROS_LIBS, IMAP_SHARED_LIBADD)
78 |
79 | AC_DEFINE(HAVE_IMAP_KRB, 1, [Whether IMAP extension has Kerberos support])
80 | else
81 | AC_EGREP_HEADER(auth_gss, $IMAP_INC_DIR/linkage.h, [
82 | AC_MSG_ERROR([This c-client library is built with Kerberos support.
83 |
84 | Add --with-kerberos to your configure line. Check config.log for details.
85 | ])
86 | ])
87 | fi
88 | ])
89 |
90 | AC_DEFUN([PHP_IMAP_SSL_CHK], [
91 | if test "$PHP_IMAP_SSL" != "no"; then
92 | if test "$PHP_OPENSSL" = ""; then
93 | PHP_OPENSSL='no'
94 | fi
95 | PHP_SETUP_OPENSSL([IMAP_SHARED_LIBADD],
96 | [AC_DEFINE([HAVE_IMAP_SSL], [1], [ ])])
97 | elif test -f "$IMAP_INC_DIR/linkage.c"; then
98 | AC_EGREP_HEADER(ssl_onceonlyinit, $IMAP_INC_DIR/linkage.c, [
99 | AC_MSG_ERROR([This c-client library is built with SSL support.
100 |
101 | Add --with-imap-ssl to your configure line. Check config.log for details.
102 | ])
103 | ])
104 | fi
105 | ])
106 |
107 | PHP_ARG_WITH([imap],
108 | [for IMAP support],
109 | [AS_HELP_STRING([[--with-imap[=DIR]]],
110 | [Include IMAP support. DIR is the c-client install prefix])])
111 |
112 | PHP_ARG_WITH([kerberos],
113 | [for IMAP Kerberos support],
114 | [AS_HELP_STRING([--with-kerberos],
115 | [IMAP: Include Kerberos support])],
116 | [no],
117 | [no])
118 |
119 | PHP_ARG_WITH([imap-ssl],
120 | [for IMAP SSL support],
121 | [AS_HELP_STRING([[--with-imap-ssl]],
122 | [IMAP: Include SSL support])],
123 | [no],
124 | [no])
125 |
126 | if test "$PHP_IMAP" != "no"; then
127 | PHP_SUBST(IMAP_SHARED_LIBADD)
128 | PHP_NEW_EXTENSION(imap, php_imap.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
129 | AC_DEFINE(HAVE_IMAP,1,[ ])
130 |
131 | for i in $PHP_IMAP /usr/local /usr; do
132 | IMAP_INC_CHK()
133 | el[]IMAP_INC_CHK(/include/c-client)
134 | el[]IMAP_INC_CHK(/include/imap)
135 | el[]IMAP_INC_CHK(/include)
136 | el[]IMAP_INC_CHK(/imap)
137 | el[]IMAP_INC_CHK(/c-client)
138 | fi
139 | done
140 |
141 | dnl Check for c-client version 2004
142 | AC_EGREP_HEADER(mail_fetch_overview_sequence, $IMAP_INC_DIR/mail.h, [
143 | AC_DEFINE(HAVE_IMAP2004,1,[ ])
144 | ])
145 |
146 | dnl Check for new version of the utf8_mime2text() function
147 | old_CFLAGS=$CFLAGS
148 | CFLAGS="-I$IMAP_INC_DIR"
149 | AC_CACHE_CHECK(for utf8_mime2text signature, ac_cv_utf8_mime2text,
150 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
151 | #include
152 | #include
153 | ]],[[
154 | SIZEDTEXT *src, *dst;
155 | utf8_mime2text(src, dst);
156 | ]])],[
157 | ac_cv_utf8_mime2text=old
158 | ],[
159 | ac_cv_utf8_mime2text=new
160 | ])
161 | )
162 | if test "$ac_cv_utf8_mime2text" = "new"; then
163 | AC_DEFINE(HAVE_NEW_MIME2TEXT, 1, [Whether utf8_mime2text() has new signature])
164 | fi
165 | CFLAGS=$old_CFLAGS
166 |
167 | old_CFLAGS=$CFLAGS
168 | CFLAGS="-I$IMAP_INC_DIR"
169 | AC_CACHE_CHECK(for U8T_DECOMPOSE, ac_cv_u8t_decompose,
170 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
171 | #include
172 | ]],[[
173 | int i = U8T_CANONICAL;
174 | ]])],[
175 | ac_cv_u8t_decompose=yes
176 | ],[
177 | ac_cv_u8t_decompose=no
178 | ])
179 | )
180 | CFLAGS=$old_CFLAGS
181 |
182 | if test "$ac_cv_u8t_decompose" = "no" && test "$ac_cv_utf8_mime2text" = "new"; then
183 | AC_MSG_ERROR([utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.])
184 | fi
185 | if test "$ac_cv_u8t_decompose" = "yes" && test "$ac_cv_utf8_mime2text" = "old"; then
186 | AC_MSG_ERROR([utf8_mime2text() has old signature, but U8T_CANONICAL is present. This should not happen. Check config.log for additional information.])
187 | fi
188 |
189 | dnl Check for c-client version 2001
190 | old_CPPFLAGS=$CPPFLAGS
191 | CPPFLAGS=-I$IMAP_INC_DIR
192 | AC_EGREP_CPP(this_is_true, [
193 | #include "imap4r1.h"
194 | #if defined(IMAPSSLPORT)
195 | this_is_true
196 | #endif
197 | ],[
198 | AC_DEFINE(HAVE_IMAP2001, 1, [ ])
199 | ],[])
200 | CPPFLAGS=$old_CPPFLAGS
201 |
202 | PHP_CHECK_LIBRARY(pam, pam_start,
203 | [
204 | PHP_ADD_LIBRARY(pam,, IMAP_SHARED_LIBADD)
205 | AC_DEFINE(HAVE_LIBPAM,1,[ ])
206 | ])
207 |
208 | PHP_CHECK_LIBRARY(crypt, crypt,
209 | [
210 | PHP_ADD_LIBRARY(crypt,, IMAP_SHARED_LIBADD)
211 | AC_DEFINE(HAVE_LIBCRYPT,1,[ ])
212 | ])
213 |
214 | PHP_EXPAND_PATH($IMAP_DIR, IMAP_DIR)
215 |
216 | if test -z "$IMAP_DIR"; then
217 | AC_MSG_ERROR(Cannot find rfc822.h. Please check your c-client installation.)
218 | fi
219 |
220 | if test ! -r "$IMAP_DIR/c-client/libc-client.a" && test -r "$IMAP_DIR/c-client/c-client.a" ; then
221 | ln -s "$IMAP_DIR/c-client/c-client.a" "$IMAP_DIR/c-client/libc-client.a" >/dev/null 2>&1
222 | elif test ! -r "$IMAP_DIR/$PHP_LIBDIR/libc-client.a" && test -r "$IMAP_DIR/$PHP_LIBDIR/c-client.a"; then
223 | ln -s "$IMAP_DIR/$PHP_LIBDIR/c-client.a" "$IMAP_DIR/$PHP_LIBDIR/libc-client.a" >/dev/null 2>&1
224 | fi
225 |
226 | for lib in c-client4 c-client imap; do
227 | IMAP_LIB=$lib
228 | IMAP_LIB_CHK($PHP_LIBDIR)
229 | IMAP_LIB_CHK(c-client)
230 | done
231 |
232 | if test -z "$IMAP_LIBDIR"; then
233 | AC_MSG_ERROR(Cannot find imap library (libc-client.a). Please check your c-client installation.)
234 | fi
235 |
236 | PHP_ADD_INCLUDE($IMAP_INC_DIR)
237 | PHP_ADD_LIBRARY_DEFER($IMAP_LIB,, IMAP_SHARED_LIBADD)
238 | PHP_ADD_LIBPATH($IMAP_LIBDIR, IMAP_SHARED_LIBADD)
239 | PHP_IMAP_KRB_CHK
240 | PHP_IMAP_SSL_CHK
241 |
242 | dnl Test the build in the end
243 | TST_LIBS="$DLIBS $IMAP_SHARED_LIBADD"
244 |
245 | dnl Check if auth_gss exists
246 | PHP_IMAP_TEST_BUILD([auth_gssapi_valid],
247 | [AC_DEFINE([HAVE_IMAP_AUTH_GSS], [1], [ ])],
248 | [],
249 | [$TST_LIBS])
250 |
251 | dnl Check if utf8_to_mutf7 exists.
252 | old_CPPFLAGS="${CPPFLAGS}"
253 | CPPFLAGS="${CPPFLAGS} -I${IMAP_INC_DIR}"
254 | AC_LANG_PUSH(C)
255 | AC_CACHE_CHECK(for utf8_to_mutf7, ac_cv_utf8_to_mutf7,
256 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]],[[
257 | unsigned char c = '\0';
258 | utf8_to_mutf7(&c);
259 | ]])],[
260 | AC_DEFINE(HAVE_IMAP_MUTF7, 1, [ ])
261 | ac_cv_utf8_to_mutf7=yes
262 | ],[
263 | ac_cv_utf8_to_mutf7=no
264 | ])
265 | )
266 | AC_LANG_POP
267 |
268 |
269 | AC_CACHE_CHECK([whether rfc822_output_address_list function is present],
270 | [php_cv_imap_have_rfc822_output_address_list],
271 | [
272 | old_LIBS=$LIBS
273 | LIBS="$TST_LIBS $LIBS"
274 | AC_LINK_IFELSE([AC_LANG_SOURCE([
275 | #if defined(__GNUC__) && __GNUC__ >= 4
276 | # define PHP_IMAP_EXPORT __attribute__ ((visibility("default")))
277 | #else
278 | # define PHP_IMAP_EXPORT
279 | #endif
280 |
281 | PHP_IMAP_EXPORT void mm_log(void){}
282 | PHP_IMAP_EXPORT void mm_dlog(void){}
283 | PHP_IMAP_EXPORT void mm_flags(void){}
284 | PHP_IMAP_EXPORT void mm_fatal(void){}
285 | PHP_IMAP_EXPORT void mm_critical(void){}
286 | PHP_IMAP_EXPORT void mm_nocritical(void){}
287 | PHP_IMAP_EXPORT void mm_notify(void){}
288 | PHP_IMAP_EXPORT void mm_login(void){}
289 | PHP_IMAP_EXPORT void mm_diskerror(void){}
290 | PHP_IMAP_EXPORT void mm_status(void){}
291 | PHP_IMAP_EXPORT void mm_lsub(void){}
292 | PHP_IMAP_EXPORT void mm_list(void){}
293 | PHP_IMAP_EXPORT void mm_exists(void){}
294 | PHP_IMAP_EXPORT void mm_searched(void){}
295 | PHP_IMAP_EXPORT void mm_expunged(void){}
296 | void rfc822_output_address_list(void);
297 | void (*f)(void);
298 | char foobar () {f = rfc822_output_address_list;}
299 | char foobar(void);
300 | int main(void) {
301 | foobar();
302 | return 0;
303 | }
304 | ])],
305 | [php_cv_imap_have_rfc822_output_address_list=yes],
306 | [php_cv_imap_have_rfc822_output_address_list=no])
307 | LIBS=$old_LIBS
308 | ])
309 | AS_VAR_IF([php_cv_imap_have_rfc822_output_address_list], [yes],
310 | [AC_DEFINE([HAVE_RFC822_OUTPUT_ADDRESS_LIST], [1],
311 | [Define to 1 if C-client has the 'rfc822_output_address_list' function.])])
312 |
313 | AC_MSG_CHECKING(whether build with IMAP works)
314 | PHP_IMAP_TEST_BUILD([mail_newbody],
315 | [AC_MSG_RESULT(yes)], [
316 | AC_MSG_RESULT(no)
317 | AC_MSG_ERROR([build test failed. Please check the config.log for details.])
318 | ], [$TST_LIBS])
319 | fi
320 |
--------------------------------------------------------------------------------
/config.w32:
--------------------------------------------------------------------------------
1 | // vim:ft=javascript
2 |
3 | ARG_WITH("imap", "IMAP Support", "no");
4 |
5 | if (PHP_IMAP == "yes") {
6 | if (CHECK_LIB("cclient_a.lib;cclient.lib", "imap") &&
7 | (CHECK_HEADER_ADD_INCLUDE("c-client.h", "CFLAGS_IMAP")||
8 | CHECK_HEADER_ADD_INCLUDE("c-client/c-client.h", "CFLAGS_IMAP", null, null, true)) ||
9 | (CHECK_HEADER_ADD_INCLUDE("utf8aux.h", "CFLAGS_IMAP")||
10 | CHECK_HEADER_ADD_INCLUDE("c-client/utf8aux.h", "CFLAGS_IMAP", null, null, true))
11 | ) {
12 | CHECK_LIB("winmm.lib", "imap");
13 | CHECK_LIB("ws2_32.lib", "imap");
14 | CHECK_LIB("Secur32.lib", "imap");
15 | CHECK_LIB("crypt32.lib", "imap");
16 | EXTENSION("imap", "php_imap.c", true, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
17 |
18 | ADD_FLAG("CFLAGS_IMAP", "/D HAVE_IMAP2000=1 /D HAVE_IMAP2004=1 /D HAVE_IMAP2007a=1 /D HAVE_IMAP2007b=1 /D HAVE_IMAP_SSL=1");
19 | AC_DEFINE('HAVE_IMAP', 1, 'Have IMAP support', true);
20 | AC_DEFINE('HAVE_RFC822_OUTPUT_ADDRESS_LIST', 1, 'Have rfc822_output_address_list', true);
21 | AC_DEFINE('HAVE_IMAP_MUTF7', 1, 'Have modified utf7 support', true);
22 | AC_DEFINE('HAVE_NEW_MIME2TEXT', 1, 'Whether utf8_mime2text() has new signature');
23 | } else {
24 | WARNING("imap not enabled; libraries and headers not found");
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/package.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 | imap
7 | pecl.php.net
8 | An extension to operate with the IMAP protocol, as well as the NNTP,
9 | POP3, and local mailbox access methods.
10 | An extension to operate with the IMAP protocol, as well as the
11 | NNTP, POP3, and local mailbox access methods.
12 |
13 | Derick Rethans
14 | derick
15 | derick@php.net
16 | yes
17 |
18 | 2024-10-15
19 |
20 |
21 | 1.0.3
22 | 1.0.0
23 |
24 |
25 | stable
26 | stable
27 |
28 | PHP 3.01
29 |
30 | - Build fixes for PHP 8.4.
31 | - Report extension version in phpinfo() output.
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 | 8.3.0
149 |
150 |
151 | 1.4.0b1
152 |
153 |
154 |
155 | imap
156 |
157 |
158 |
159 |
160 |
161 |
--------------------------------------------------------------------------------
/php_imap.h:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Copyright (c) The PHP Group |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | https://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Authors: Rex Logan |
14 | | Mark Musone |
15 | | Brian Wang |
16 | | Kaj-Michael Lang |
17 | | Antoni Pamies Olive |
18 | | Rasmus Lerdorf |
19 | | Chuck Hagenbuch |
20 | | Andrew Skalski |
21 | | Hartmut Holzgraefe |
22 | | Jani Taskinen |
23 | | Daniel R. Kalowsky |
24 | | PHP 4.0 updates: Zeev Suraski |
25 | +----------------------------------------------------------------------+
26 | */
27 |
28 | #ifndef PHP_IMAP_H
29 | #define PHP_IMAP_H
30 |
31 | #ifdef HAVE_IMAP
32 |
33 | #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
34 |
35 | /* For now these appear on Windows, remove this check if it appears outside */
36 | # ifdef PHP_WIN32
37 | /* Undefine these LOG defines to avoid warnings */
38 | # undef LOG_EMERG
39 | # undef LOG_CRIT
40 | # undef LOG_ERR
41 | # undef LOG_WARNING
42 | # undef LOG_NOTICE
43 | # undef LOG_DEBUG
44 |
45 | /* c-client also redefines its own ftruncate */
46 | # undef ftruncate
47 | # endif
48 |
49 | /* these are used for quota support */
50 | ZEND_DIAGNOSTIC_IGNORED_START("-Wstrict-prototypes")
51 | # include "c-client.h" /* includes mail.h and rfc822.h */
52 | ZEND_DIAGNOSTIC_IGNORED_END
53 | # include "imap4r1.h" /* location of c-client quota functions */
54 | #else
55 | # include "mail.h"
56 | # include "rfc822.h"
57 | #endif
58 |
59 | extern zend_module_entry imap_module_entry;
60 | #define imap_module_ptr &imap_module_entry
61 |
62 | #include "php_version.h"
63 | #define PHP_IMAP_VERSION "1.0.3"
64 |
65 | /* Data types */
66 |
67 | #ifdef IMAP41
68 | #define LSIZE text.size
69 | #define LTEXT text.data
70 | #define DTYPE int
71 | #define CONTENT_PART nested.part
72 | #define CONTENT_MSG_BODY nested.msg->body
73 | #define IMAPVER "Imap 4R1"
74 | #else
75 | #define LSIZE size
76 | #define LTEXT text
77 | #define DTYPE char
78 | #define CONTENT_PART contents.part
79 | #define CONTENT_MSG_BODY contents.msg.body
80 | #define IMAPVER "Imap 4"
81 | #endif
82 |
83 |
84 | /* Determines how mm_list() and mm_lsub() are to return their results. */
85 | typedef enum {
86 | FLIST_ARRAY,
87 | FLIST_OBJECT
88 | } folderlist_style_t;
89 |
90 | typedef struct php_imap_mailbox_struct {
91 | SIZEDTEXT text;
92 | DTYPE delimiter;
93 | long attributes;
94 | struct php_imap_mailbox_struct *next;
95 | } FOBJECTLIST;
96 |
97 | typedef struct php_imap_error_struct {
98 | SIZEDTEXT text;
99 | long errflg;
100 | struct php_imap_error_struct *next;
101 | } ERRORLIST;
102 |
103 | typedef struct _php_imap_message_struct {
104 | unsigned long msgid;
105 | struct _php_imap_message_struct *next;
106 | } MESSAGELIST;
107 |
108 |
109 | /* Functions */
110 |
111 | PHP_MINIT_FUNCTION(imap);
112 | PHP_RINIT_FUNCTION(imap);
113 | PHP_RSHUTDOWN_FUNCTION(imap);
114 | PHP_MINFO_FUNCTION(imap);
115 |
116 | ZEND_BEGIN_MODULE_GLOBALS(imap)
117 | char *imap_user;
118 | char *imap_password;
119 |
120 | STRINGLIST *imap_alertstack;
121 | ERRORLIST *imap_errorstack;
122 |
123 | STRINGLIST *imap_folders;
124 | STRINGLIST *imap_folders_tail;
125 | STRINGLIST *imap_sfolders;
126 | STRINGLIST *imap_sfolders_tail;
127 | MESSAGELIST *imap_messages;
128 | MESSAGELIST *imap_messages_tail;
129 | FOBJECTLIST *imap_folder_objects;
130 | FOBJECTLIST *imap_folder_objects_tail;
131 | FOBJECTLIST *imap_sfolder_objects;
132 | FOBJECTLIST *imap_sfolder_objects_tail;
133 |
134 | folderlist_style_t folderlist_style;
135 | long status_flags;
136 | unsigned long status_messages;
137 | unsigned long status_recent;
138 | unsigned long status_unseen;
139 | unsigned long status_uidnext;
140 | unsigned long status_uidvalidity;
141 | #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
142 | zval **quota_return;
143 | zval *imap_acl_list;
144 | #endif
145 | /* php_stream for php_mail_gets() */
146 | php_stream *gets_stream;
147 | bool enable_rsh;
148 | ZEND_END_MODULE_GLOBALS(imap)
149 |
150 | #if defined(ZTS) && defined(COMPILE_DL_IMAP)
151 | ZEND_TSRMLS_CACHE_EXTERN()
152 | #endif
153 |
154 | ZEND_EXTERN_MODULE_GLOBALS(imap)
155 | #define IMAPG(v) ZEND_MODULE_GLOBALS_ACCESSOR(imap, v)
156 |
157 | #else
158 |
159 | #define imap_module_ptr NULL
160 |
161 | #endif
162 |
163 | #define phpext_imap_ptr imap_module_ptr
164 |
165 | #endif /* PHP_IMAP_H */
166 |
--------------------------------------------------------------------------------
/php_imap.stub.php:
--------------------------------------------------------------------------------
1 | ce_flags |= ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES|ZEND_ACC_NOT_SERIALIZABLE;
615 |
616 | return class_entry;
617 | }
618 |
--------------------------------------------------------------------------------
/tests/README.md:
--------------------------------------------------------------------------------
1 | # The imap extension tests
2 |
3 | Many of the tests in this directory require a mail server to be running, if
4 | there is no mail server the test will skip and warn, see skipif.inc for details.
5 |
6 | To make the tests run parameters in the `skipif.inc` and `imap_include.inc`
7 | files will need to be changed to match the local mailserver configuration.
8 |
9 | The tests have been checked using dovecot (on Linux 32 and 64 bit systems) and
10 | hMailServer on Windows. The tests are intended to be mailserver agnostic.
11 |
12 | ## Set-up tests on Ubuntu (checked on Ubuntu 18.04 (Bionic))
13 | The necessary packages can be installed using the following command;
14 | `apt-get install libc-client-dev libkrb5-dev dovecot-core dovecot-pop3d dovecot-imapd sendmail`
15 |
16 | The build of PHP will need to be compiled with the following flags:
17 | ```
18 | --with-imap --with-kerberos --with-imap-ssl
19 | ```
20 |
21 | Then run the set-up script `ext/imap/tests/setup/setup.sh` which will add the `vmail`
22 | group and user which is used by Dovecot for the mailbox. It will also copy the
23 | `ext/imap/tests/setup/dovecot.conf` and `ext/imap/tests/setup/dovecotpass` to the correct
24 | location for Dovecot and restarts it for the new configuration to be enabled.
25 |
--------------------------------------------------------------------------------
/tests/bug31142_1.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #31142 test #1 (imap_mail_compose() generates incorrect output)
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 |
33 | --EXPECTF--
34 | From: joe@example.com
35 | To: foo@example.com
36 | cc: bar@example.com
37 | MIME-Version: 1.0
38 | Content-Type: MULTIPART/mixed; BOUNDARY="%s"
39 |
40 | --%s
41 | Content-Type: APPLICATION/octet-stream
42 | Content-Transfer-Encoding: BASE64
43 | Content-Description: some file
44 |
45 | QUJD
46 |
47 | --%s
48 | Content-Type: TEXT/plain; CHARSET=US-ASCII
49 | Content-Description: description3
50 |
51 | contents.data3
52 |
53 |
54 |
55 | --%s--
56 |
--------------------------------------------------------------------------------
/tests/bug31142_2.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #31142 test #2 (imap_mail_compose() generates incorrect output)
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 |
20 | --EXPECT--
21 | From: host@domain.com
22 | MIME-Version: 1.0
23 | Content-Type: TEXT/plain; CHARSET=iso-8859-2
24 | Content-Transfer-Encoding: QUOTED-PRINTABLE
25 |
26 | asn =C5=99kl
27 |
--------------------------------------------------------------------------------
/tests/bug32589.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #32589 (crash inside imap_mail_compose() function)
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 |
21 | --EXPECTF--
22 | MIME-Version: 1.0
23 | Content-Type: MULTIPART/mixed; BOUNDARY="%s"
24 |
25 | %s
26 | Content-Type: TEXT/plain; CHARSET=ISO-8859-2
27 | Content-Description: text_message
28 |
29 | hello
30 | %s
31 |
--------------------------------------------------------------------------------
/tests/bug35669.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #35669 (imap_mail_compose() crashes with multipart-multiboundary-email)
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 | ';
8 | $envelope["to"] = 'The bad smurf ';
9 | $envelope['date'] = 'Wed, 04 Jan 2006 19:24:43 -0500';
10 |
11 | $multipart["type"] = TYPEMULTIPART;
12 | $multipart["subtype"] = "MIXED";
13 | $body[] = $multipart; //add multipart stuff
14 |
15 | $textpart["type"] = TYPEMULTIPART;
16 | $textpart["subtype"] = "ALTERNATIVE";
17 | $body[] = $textpart; //add body part
18 |
19 | $plain["type"] = TYPETEXT;
20 | $plain["subtype"] = "PLAIN";
21 | $plain["charset"] = "iso-8859-1";
22 | $plain["encoding"] = ENCQUOTEDPRINTABLE;
23 | $plain["description"] = "Plaintype part of message";
24 | $plain['disposition'] = "inline";
25 | $plain["contents.data"] = 'See mom, it will crash';
26 |
27 | $body[] = $plain; //next add plain text part
28 |
29 | $html["type"] = TYPETEXT;
30 | $html["subtype"] = "HTML";
31 | $html["charset"] = "iso-8859-1";
32 | $html["encoding"] = ENCQUOTEDPRINTABLE;
33 | $html["description"] = "HTML part of message";
34 | $html['disposition'] = "inline";
35 | $html["contents.data"] = 'See mom, it will crash';
36 |
37 | $body[] = $html;
38 |
39 | echo imap_mail_compose($envelope, $body);
40 | ?>
41 | --EXPECTF--
42 | Date: Wed, 04 Jan 2006 19:24:43 -0500
43 | From: Santa
44 | To: The bad smurf
45 | MIME-Version: 1.0
46 | Content-Type: MULTIPART/MIXED; BOUNDARY="%s"
47 |
48 | --%s
49 | Content-Type: TEXT/ALTERNATIVE; CHARSET=US-ASCII
50 |
51 |
52 | --%s
53 | Content-Type: TEXT/PLAIN; CHARSET=iso-8859-1
54 | Content-Transfer-Encoding: QUOTED-PRINTABLE
55 | Content-Description: Plaintype part of message
56 |
57 | See mom, it will crash
58 | --%s
59 | Content-Type: TEXT/HTML; CHARSET=iso-8859-1
60 | Content-Transfer-Encoding: QUOTED-PRINTABLE
61 | Content-Description: HTML part of message
62 |
63 | See mom, it will crash
64 | --%s--
65 |
--------------------------------------------------------------------------------
/tests/bug40854.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #40854 (imap_mail_compose() creates an invalid terminator for multipart e-mails)
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 |
31 | --EXPECTF--
32 | From: joe@example.com
33 | To: foo@example.com
34 | cc: bar@example.com
35 | MIME-Version: 1.0
36 | Content-Type: MULTIPART/mixed; BOUNDARY="%s"
37 |
38 | --%s
39 | Content-Type: APPLICATION/octet-stream
40 | Content-Transfer-Encoding: BASE64
41 | Content-Description: a.txt
42 |
43 |
44 |
45 | --%s
46 | Content-Type: TEXT/plain; CHARSET=US-ASCII
47 | Content-Description: description3
48 |
49 | contents.data3
50 |
51 |
52 |
53 | --%s--
54 |
--------------------------------------------------------------------------------
/tests/bug44098.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #44098 (imap_utf8() returns only capital letters)
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 |
12 | --EXPECT--
13 | string(17) "Luzon®14 dot CoM"
14 |
--------------------------------------------------------------------------------
/tests/bug45705_1.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #45705 test #1 (imap rfc822_parse_adrlist() modifies passed address parameter)
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 | ';
9 | var_dump($address);
10 | imap_rfc822_parse_adrlist($address, '');
11 | var_dump($address);
12 |
13 | ?>
14 | --EXPECT--
15 | string(27) "John Doe "
16 | string(27) "John Doe "
17 |
--------------------------------------------------------------------------------
/tests/bug45705_2.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #45705 test #2 (imap rfc822_parse_adrlist() modifies passed address parameter)
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 | 'John Doe ',
9 | 'from' => 'John Doe ',
10 | 'reply_to' => 'John Doe ',
11 | 'to' => 'John Doe ',
12 | 'cc' => 'John Doe ',
13 | 'bcc' => 'John Doe ',
14 | );
15 |
16 | var_dump($envelope);
17 | imap_mail_compose($envelope, [1 => ['cc' => 'Steve Doe ',]]);
18 | var_dump($envelope);
19 |
20 | ?>
21 | --EXPECT--
22 | array(6) {
23 | ["return_path"]=>
24 | string(27) "John Doe "
25 | ["from"]=>
26 | string(27) "John Doe "
27 | ["reply_to"]=>
28 | string(27) "John Doe "
29 | ["to"]=>
30 | string(27) "John Doe "
31 | ["cc"]=>
32 | string(27) "John Doe "
33 | ["bcc"]=>
34 | string(27) "John Doe "
35 | }
36 | array(6) {
37 | ["return_path"]=>
38 | string(27) "John Doe "
39 | ["from"]=>
40 | string(27) "John Doe "
41 | ["reply_to"]=>
42 | string(27) "John Doe "
43 | ["to"]=>
44 | string(27) "John Doe "
45 | ["cc"]=>
46 | string(27) "John Doe "
47 | ["bcc"]=>
48 | string(27) "John Doe "
49 | }
50 |
--------------------------------------------------------------------------------
/tests/bug46918.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #46918 (imap_rfc822_parse_adrlist host part not filled in correctly)
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 | ,
9 | shuf6@example.ac.uk,
10 | blobby,
11 | "ian,eiloart",
12 | <@example.com:foo@example.ac.uk>,
13 | foo@#,
14 | ian@-example.com,
15 | ian@one@two';
16 | $add_arr = imap_rfc822_parse_adrlist($adds, 'example.com');
17 | var_export($add_arr);
18 |
19 | ?>
20 | --EXPECT--
21 | array (
22 | 0 =>
23 | (object) array(
24 | 'mailbox' => 'iane',
25 | 'host' => 'example.ac.uk',
26 | 'personal' => 'ian eiloart',
27 | ),
28 | 1 =>
29 | (object) array(
30 | 'mailbox' => 'shuf6',
31 | 'host' => 'example.ac.uk',
32 | ),
33 | 2 =>
34 | (object) array(
35 | 'mailbox' => 'blobby',
36 | 'host' => 'example.com',
37 | ),
38 | 3 =>
39 | (object) array(
40 | 'mailbox' => 'ian',
41 | 'host' => 'example.ac.uk',
42 | 'personal' => 'ian,eiloart',
43 | ),
44 | 4 =>
45 | (object) array(
46 | 'mailbox' => 'foo',
47 | 'host' => 'example.ac.uk',
48 | 'adl' => '@example.com',
49 | ),
50 | 5 =>
51 | (object) array(
52 | 'mailbox' => 'foo',
53 | 'host' => '#',
54 | ),
55 | 6 =>
56 | (object) array(
57 | 'mailbox' => 'ian',
58 | 'host' => '-example.com',
59 | ),
60 | 7 =>
61 | (object) array(
62 | 'mailbox' => 'ian',
63 | 'host' => 'one',
64 | ),
65 | 8 =>
66 | (object) array(
67 | 'mailbox' => 'UNEXPECTED_DATA_AFTER_ADDRESS',
68 | 'host' => '.SYNTAX-ERROR.',
69 | ),
70 | )
71 | Notice: PHP Request Shutdown: Unexpected characters at end of address: @two (errflg=3) in Unknown on line 0
72 |
--------------------------------------------------------------------------------
/tests/bug53377.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #53377 (imap_mime_header_decode() doesn't ignore \t during long MIME header unfolding)
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 |
12 | --EXPECT--
13 | array(3) {
14 | [0]=>
15 | object(stdClass)#1 (2) {
16 | ["charset"]=>
17 | string(5) "UTF-8"
18 | ["text"]=>
19 | string(3) "€"
20 | }
21 | [1]=>
22 | object(stdClass)#2 (2) {
23 | ["charset"]=>
24 | string(5) "UTF-8"
25 | ["text"]=>
26 | string(3) "€"
27 | }
28 | [2]=>
29 | object(stdClass)#3 (2) {
30 | ["charset"]=>
31 | string(5) "UTF-8"
32 | ["text"]=>
33 | string(3) "€"
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/tests/bug63126.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_open() DISABLE_AUTHENTICATOR ignores array param
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
25 | --CONFLICTS--
26 | defaultmailbox
27 | --FILE--
28 | array('DISABLE_AUTHENTICATOR' => array('GSSAPI','NTLM')),
32 | 'String' => array('DISABLE_AUTHENTICATOR' => 'GSSAPI'),
33 | );
34 | require_once(__DIR__. '/setup/imap_include.inc');
35 | foreach ($tests as $name => $testparams) {
36 | echo "Test for $name\n";
37 | $in = imap_open(IMAP_SERVER_DEBUG, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD, OP_HALFOPEN, 1, $testparams);
38 | if ($in) {
39 | if (is_array($errors = imap_errors())) {
40 | foreach ($errors as $err) {
41 | if (strstr($err, 'GSSAPI') || strstr($err, 'Kerberos')) {
42 | echo "$err\n";
43 | }
44 | }
45 | }
46 | } else {
47 | echo "Can't connect\n";
48 | }
49 | }
50 | echo "Done\n";
51 | ?>
52 | --EXPECT--
53 | Test for Array
54 | Test for String
55 | Done
56 |
--------------------------------------------------------------------------------
/tests/bug64076.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #64076 (imap_sort() does not return FALSE on failure)
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
17 | --CLEAN--
18 |
22 | --EXPECT--
23 | Create a temporary mailbox and add 2 msgs
24 | New mailbox created
25 | bool(false)
26 | bool(true)
27 |
--------------------------------------------------------------------------------
/tests/bug75774.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #75774 imap_append HeapCorruction
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 | getMessage() . "\n";
15 | }
16 |
17 | fclose($var1);
18 | unlink($fn);
19 |
20 | ?>
21 | --EXPECT--
22 | imap_append(): Argument #1 ($imap) must be of type IMAP\Connection, resource given
23 |
--------------------------------------------------------------------------------
/tests/bug77020.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #77020 (null pointer dereference in imap_mail)
3 | --EXTENSIONS--
4 | imap
5 | --INI--
6 | sendmail_path="echo >/dev/null"
7 | --FILE--
8 |
15 | --EXPECTF--
16 | %Adone
17 |
--------------------------------------------------------------------------------
/tests/bug77153.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #77153 (imap_open allows to run arbitrary shell commands via mailbox parameter)
3 | --EXTENSIONS--
4 | imap
5 | --CONFLICTS--
6 | defaultmailbox
7 | --FILE--
8 | " . __DIR__ . '/__bug';
10 | $payloadb64 = base64_encode($payload);
11 | $server = "x -oProxyCommand=echo\t$payloadb64|base64\t-d|sh}";
12 | @imap_open('{'.$server.':143/imap}INBOX', '', '');
13 | // clean
14 | imap_errors();
15 | var_dump(file_exists(__DIR__ . '/__bug'));
16 | ?>
17 | --EXPECT--
18 | bool(false)
19 | --CLEAN--
20 |
23 |
--------------------------------------------------------------------------------
/tests/bug80213.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #80213 (imap_mail_compose() segfaults on certain $bodies)
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 | ['param'],
10 | 'disposition' => ['disp'],
11 | ], [
12 | 'type.parameters' => ['param'],
13 | 'disposition' => ['disp'],
14 | ]];
15 | var_dump(imap_mail_compose($envelope, $body));
16 | echo "done\n";
17 | ?>
18 | --EXPECT--
19 | string(67) "MIME-Version: 1.0
20 | Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
21 |
22 |
23 | "
24 | done
25 |
--------------------------------------------------------------------------------
/tests/bug80215.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #80215 (imap_mail_compose() may modify by-val parameters)
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 | 1,
9 | "to" => 2,
10 | "custom_headers" => [3],
11 | ];
12 | $body = [[
13 | "contents.data" => 4,
14 | "type.parameters" => ['foo' => 5],
15 | "disposition" => ['bar' => 6],
16 | ], [
17 | "contents.data" => 7,
18 | "type.parameters" => ['foo' => 8],
19 | "disposition" => ['bar' => 9],
20 | ]];
21 | imap_mail_compose($envelope, $body);
22 | var_dump($envelope, $body);
23 | ?>
24 | --EXPECT--
25 | array(3) {
26 | ["from"]=>
27 | int(1)
28 | ["to"]=>
29 | int(2)
30 | ["custom_headers"]=>
31 | array(1) {
32 | [0]=>
33 | int(3)
34 | }
35 | }
36 | array(2) {
37 | [0]=>
38 | array(3) {
39 | ["contents.data"]=>
40 | int(4)
41 | ["type.parameters"]=>
42 | array(1) {
43 | ["foo"]=>
44 | int(5)
45 | }
46 | ["disposition"]=>
47 | array(1) {
48 | ["bar"]=>
49 | int(6)
50 | }
51 | }
52 | [1]=>
53 | array(3) {
54 | ["contents.data"]=>
55 | int(7)
56 | ["type.parameters"]=>
57 | array(1) {
58 | ["foo"]=>
59 | int(8)
60 | }
61 | ["disposition"]=>
62 | array(1) {
63 | ["bar"]=>
64 | int(9)
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/tests/bug80216.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #80216 (imap_mail_compose() does not validate types/encodings)
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 | TYPEMULTIPART], []]);
8 | imap_mail_compose([], [['type' => 12]]);
9 | imap_mail_compose([], [['type' => TYPEMULTIPART], ['type' => 12]]);
10 | imap_mail_compose([], [['encoding' => 8]]);
11 | imap_mail_compose([], [['type' => TYPEMULTIPART], ['encoding' => 8]]);
12 | echo "done\n";
13 | ?>
14 | --EXPECT--
15 | done
16 |
--------------------------------------------------------------------------------
/tests/bug80220.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #80220 (imap_mail_compose() may leak memory) - message/rfc822 regression
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 | TYPEMESSAGE,
9 | 'subtype' => 'RFC822',
10 | ], [
11 | 'contents.data' => 'asd',
12 | ]];
13 | var_dump(imap_mail_compose([], $bodies));
14 |
15 | $bodies = [[
16 | 'type' => TYPEMESSAGE,
17 | ], [
18 | 'contents.data' => 'asd',
19 | ]];
20 | var_dump(imap_mail_compose([], $bodies));
21 | ?>
22 | --EXPECT--
23 | string(53) "MIME-Version: 1.0
24 | Content-Type: MESSAGE/RFC822
25 |
26 |
27 | "
28 | string(53) "MIME-Version: 1.0
29 | Content-Type: MESSAGE/RFC822
30 |
31 |
32 | "
33 |
--------------------------------------------------------------------------------
/tests/bug80223.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #80223 (imap_mail_compose() leaks envelope on malformed bodies)
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 | getMessage(), \PHP_EOL;
11 | }
12 | try {
13 | imap_mail_compose([], [1]);
14 | } catch (\TypeError $e) {
15 | echo $e->getMessage(), \PHP_EOL;
16 | }
17 | try {
18 | imap_mail_compose([], [[]]);
19 | } catch (\ValueError $e) {
20 | echo $e->getMessage(), \PHP_EOL;
21 | }
22 | ?>
23 | --EXPECT--
24 | imap_mail_compose(): Argument #2 ($bodies) cannot be empty
25 | imap_mail_compose(): Argument #2 ($bodies) individual body must be of type array, int given
26 | imap_mail_compose(): Argument #2 ($bodies) individual body cannot be empty
27 |
--------------------------------------------------------------------------------
/tests/bug80226.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #80226 (imap_sort() leaks sortpgm memory)
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
18 | --CLEAN--
19 |
23 | --EXPECT--
24 | Create a new mailbox for test
25 | Create a temporary mailbox and add 0 msgs
26 | New mailbox created
27 | array(0) {
28 | }
29 |
--------------------------------------------------------------------------------
/tests/bug80242.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #80242 (imap_mail_compose() segfaults for multipart with rfc822)
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 | TYPEMULTIPART,
9 | ], [
10 | 'type' => TYPETEXT,
11 | 'contents.data' => 'some text',
12 | ], [
13 | 'type' => TYPEMESSAGE,
14 | 'subtype' => 'RFC822',
15 | ]];
16 | imap_mail_compose([], $bodies);
17 | echo "done\n";
18 | ?>
19 | --EXPECT--
20 | done
21 |
--------------------------------------------------------------------------------
/tests/bug80438.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #80438: imap_msgno() incorrectly warns and return false on valid UIDs in PHP 8.0.0
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
32 | --CLEAN--
33 |
37 | --EXPECT--
38 | Create a temporary mailbox and add 10 msgs
39 | New mailbox created
40 | Delete 4 messages for Unique ID generation
41 | array(6) {
42 | [0]=>
43 | int(1)
44 | [1]=>
45 | int(2)
46 | [2]=>
47 | int(7)
48 | [3]=>
49 | int(8)
50 | [4]=>
51 | int(9)
52 | [5]=>
53 | int(10)
54 | }
55 | Unique ID: int(1)
56 | Ordered message number: int(1)
57 | Unique ID: int(2)
58 | Ordered message number: int(2)
59 | Unique ID: int(7)
60 | Ordered message number: int(3)
61 | Unique ID: int(8)
62 | Ordered message number: int(4)
63 | Unique ID: int(9)
64 | Ordered message number: int(5)
65 | Unique ID: int(10)
66 | Ordered message number: int(6)
67 |
--------------------------------------------------------------------------------
/tests/bug80710_1.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #80710 (imap_mail_compose() header injection) - MIME Splitting Attack
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 |
34 | --EXPECTF--
35 | Warning: imap_mail_compose(): header injection attempt in from in %s on line %d
36 |
--------------------------------------------------------------------------------
/tests/bug80710_2.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #80710 (imap_mail_compose() header injection) - Remail
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 |
34 | --EXPECTF--
35 | Warning: imap_mail_compose(): header injection attempt in remail in %s on line %d
36 |
--------------------------------------------------------------------------------
/tests/bug80800.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #80800: imap_open() fails when the flags parameter includes CL_EXPUNGE
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
21 | --EXPECT--
22 | bool(true)
23 | Connected without any issues
24 |
--------------------------------------------------------------------------------
/tests/gh9309.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug GH-9309 (Segfault when connection is used after imap_close())
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 | getMessage(), PHP_EOL;
18 | }
19 | ?>
20 | --CLEAN--
21 |
25 | --EXPECT--
26 | Create a temporary mailbox and add 0 msgs
27 | New mailbox created
28 | IMAP\Connection is already closed
29 |
--------------------------------------------------------------------------------
/tests/imap_8bit_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Test imap_8bit() function : basic functionality
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 |
17 | --EXPECT--
18 | *** Testing imap_8bit() : basic functionality ***
19 | string(28) "String with CRLF at end=20
20 | "
21 | string(25) "String with space at end "
22 | string(33) "String with tabs =09=09 in middle"
23 | string(26) "String with tab at end =09"
24 | string(27) "=00=01=02=03=04=FE=FF=0A=0D"
25 |
--------------------------------------------------------------------------------
/tests/imap_append_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Test imap_append() function : basic functionality
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 | Mailbox
21 | , "From: webmaster@example.com\r\n"
22 | . "To: info@example.com\r\n"
23 | . "Subject: Test message\r\n"
24 | . "\r\n"
25 | . "this is a test message, please ignore\r\n"
26 | ));
27 |
28 | var_dump(imap_append($imap_stream, $mb_details->Mailbox
29 | , "From: webmaster@example.com\r\n"
30 | . "To: info@example.com\r\n"
31 | . "Subject: Another test\r\n"
32 | . "\r\n"
33 | . "this is another test message, please ignore it too!!\r\n"
34 | ));
35 |
36 | $check = imap_check($imap_stream);
37 | echo "Msg Count after append : ". $check->Nmsgs . "\n";
38 |
39 | echo "List the msg headers\n";
40 | var_dump(imap_headers($imap_stream));
41 |
42 | imap_close($imap_stream);
43 | ?>
44 | --CLEAN--
45 |
49 | --EXPECTF--
50 | *** Testing imap_append() : basic functionality ***
51 | Create a new mailbox for test
52 | Create a temporary mailbox and add 0 msgs
53 | New mailbox created
54 | Add a couple of msgs to the new mailbox
55 | bool(true)
56 | bool(true)
57 | Msg Count after append : 2
58 | List the msg headers
59 | array(2) {
60 | [0]=>
61 | string(%d) "%w%s 1)%s webmaster@example.co Test message (%d chars)"
62 | [1]=>
63 | string(%d) "%w%s 2)%s webmaster@example.co Another test (%d chars)"
64 | }
65 |
--------------------------------------------------------------------------------
/tests/imap_base64_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Test imap_base64() function : basic functionality
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 | .<,';
18 | $base64 = base64_encode($str);
19 | if (imap_base64($base64) == $str) {
20 | echo "TEST PASSED\n";
21 | } else {
22 | echo "TEST FAILED";
23 | }
24 |
25 | $hex = 'x00\x01\x02\x03\x04\x05\x06\xFA\xFB\xFC\xFD\xFE\xFF';
26 | $base64 = base64_encode($hex);
27 | if (imap_base64($base64) == $hex) {
28 | echo "TEST PASSED\n";
29 | } else {
30 | echo "TEST FAILED";
31 | }
32 |
33 | ?>
34 | --EXPECT--
35 | *** Testing imap_base64() : basic functionality ***
36 | TEST PASSED
37 | TEST PASSED
38 | TEST PASSED
39 |
--------------------------------------------------------------------------------
/tests/imap_binary_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Test imap_binary() function : basic functionality
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 | .<,';
21 | $base64 = imap_binary($str);
22 | var_dump(bin2hex($base64));
23 |
24 | echo "Encode some hexadecimal data\n";
25 | $hex = 'x00\x01\x02\x03\x04\x05\x06\xFA\xFB\xFC\xFD\xFE\xFF';
26 | $base64 = imap_binary($hex);
27 | var_dump(bin2hex($base64));
28 |
29 | ?>
30 | --EXPECT--
31 | *** Testing imap_binary() : basic functionality ***
32 | Encode as short string
33 | string(136) "5647687063794270637942686269426c654746746347786c49484e30636d6c755a794230627942695a53426959584e6c49445930494756755932396b0d0a5a57513d0d0a"
34 | Encode a string which results in more than 60 charters of output
35 | string(200) "56476870637942706379426849477876626d6367633352796157356e4948647064476767636d567a64577830637942706269427462334a6c4948526f0d0a595734674e6a416759326868636d466a64475679637942765a694276645852776458513d0d0a"
36 | Encode a string with special characters
37 | string(60) "5879737450587464573130374f30422b497a3876506934384c413d3d0d0a"
38 | Encode some hexadecimal data
39 | string(144) "65444177584867774d5678344d444a636544417a584867774e4678344d445663654441325848684751567834526b4a6365455a4458486847524678340d0a526b566365455a470d0a"
40 |
--------------------------------------------------------------------------------
/tests/imap_body_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Test imap_body() function : basic functionality
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 | Nmsgs . "\n";
20 |
21 | // show body for msg 1
22 | var_dump(imap_body($imap_stream, 1));
23 |
24 | //Access via FT_UID
25 | var_dump(imap_body($imap_stream, 1, FT_UID));
26 |
27 | imap_close($imap_stream);
28 | ?>
29 | --CLEAN--
30 |
34 | --EXPECTF--
35 | *** Testing imap_body() : basic functionality ***
36 | Create a new mailbox for test
37 | Create a temporary mailbox and add 1 msgs
38 | New mailbox created
39 | Msg Count in new mailbox: 1
40 | string(%d) "1: this is a test message, please ignore
41 | newline%r\R?%r"
42 | string(%d) "1: this is a test message, please ignore
43 | newline%r\R?%r"
44 |
--------------------------------------------------------------------------------
/tests/imap_body_errors.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_body() errors: ValueError and Warnings
3 | --CREDITS--
4 | Paul Sohier
5 | #phptestfest utrecht
6 | --EXTENSIONS--
7 | imap
8 | --SKIPIF--
9 |
12 | --FILE--
13 | getMessage() . \PHP_EOL;
23 | }
24 | try {
25 | imap_body($imap_mail_box, 1, -1);
26 | } catch (\ValueError $e) {
27 | echo $e->getMessage() . \PHP_EOL;
28 | }
29 |
30 | // Access not existing
31 | var_dump(imap_body($imap_mail_box, 255));
32 | var_dump(imap_body($imap_mail_box, 255, FT_UID));
33 |
34 | imap_close($imap_mail_box);
35 |
36 | ?>
37 | --CLEAN--
38 |
42 | --EXPECTF--
43 | Create a temporary mailbox and add 0 msgs
44 | New mailbox created
45 | imap_body(): Argument #2 ($message_num) must be greater than 0
46 | imap_body(): Argument #3 ($flags) must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL
47 |
48 | Warning: imap_body(): Bad message number in %s on line %d
49 | bool(false)
50 |
51 | Warning: imap_body(): UID does not exist in %s on line %d
52 | bool(false)
53 |
--------------------------------------------------------------------------------
/tests/imap_body_uid.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_body() passing a unique ID
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
21 | --CLEAN--
22 |
26 | --EXPECT--
27 | Create a temporary mailbox and add 10 msgs
28 | New mailbox created
29 | Delete 4 messages for Unique ID generation
30 | bool(true)
31 |
--------------------------------------------------------------------------------
/tests/imap_bodystruct_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Test imap_bodystruct() function : basic functionality
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 | $mf)) {
36 | echo "$mf is 0 or 1\n";
37 | } else {
38 | echo "$mf FAIL\n";
39 | }
40 | }
41 |
42 | if(is_array($m->parameters)) {
43 | echo "parameters is an array\n";
44 | }
45 |
46 | echo "\nTry to get part 4!\n";
47 | var_dump(imap_bodystruct($imap_stream, 1, "4"));
48 |
49 | imap_close($imap_stream);
50 |
51 | ?>
52 | --CLEAN--
53 |
57 | --EXPECT--
58 | *** Testing string imap_bodystruct : basic functionality ***
59 | Create a new mailbox for test and add a multipart msgs
60 | Create a temporary mailbox and add 1 msgs
61 | New mailbox created
62 |
63 | Get and validate structure of body part 1
64 | ifsubtype is 0 or 1
65 | ifdescription is 0 or 1
66 | ifid is 0 or 1
67 | ifdisposition is 0 or 1
68 | ifdparameters is 0 or 1
69 | ifparameters is 0 or 1
70 | parameters is an array
71 |
72 | Try to get part 4!
73 | bool(false)
74 |
--------------------------------------------------------------------------------
/tests/imap_clearflag_full_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Test imap_clearflag_full() function : basic functionality
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 | Nmsgs . "\n";
20 |
21 | echo "Set some flags\n";
22 | var_dump(imap_setflag_full($imap_stream, "1,3", "\\Seen \\Answered"));
23 | var_dump(imap_setflag_full($imap_stream, "2,4", "\\Answered"));
24 | var_dump(imap_setflag_full($imap_stream, "5,7", "\\Flagged \\Deleted"));
25 | var_dump(imap_setflag_full($imap_stream, "6,8", "\\Deleted"));
26 | var_dump(imap_setflag_full($imap_stream, "9,10", "\\Draft \\Flagged"));
27 |
28 | var_dump(imap_search($imap_stream, "SEEN"));
29 | var_dump(imap_search($imap_stream, "ANSWERED"));
30 | var_dump(imap_search($imap_stream, "FLAGGED"));
31 | var_dump(imap_search($imap_stream, "DELETED"));
32 |
33 | var_dump(imap_clearflag_full($imap_stream, "1,4", "\\Answered"));
34 | var_dump(imap_clearflag_full($imap_stream, "5,6,7,8", "\\Deleted"));
35 | var_dump(imap_clearflag_full($imap_stream, "9", "\\Flagged"));
36 |
37 | var_dump(imap_search($imap_stream, "SEEN"));
38 | var_dump(imap_search($imap_stream, "ANSWERED"));
39 | var_dump(imap_search($imap_stream, "FLAGGED"));
40 | var_dump(imap_search($imap_stream, "DELETED"));
41 |
42 | imap_close($imap_stream);
43 | ?>
44 | --CLEAN--
45 |
49 | --EXPECT--
50 | *** Testing imap_clearflag_full() : basic functionality ***
51 | Create a new mailbox for test
52 | Create a temporary mailbox and add 10 msgs
53 | New mailbox created
54 | Initial msg count in new_mailbox : 10
55 | Set some flags
56 | bool(true)
57 | bool(true)
58 | bool(true)
59 | bool(true)
60 | bool(true)
61 | array(2) {
62 | [0]=>
63 | int(1)
64 | [1]=>
65 | int(3)
66 | }
67 | array(4) {
68 | [0]=>
69 | int(1)
70 | [1]=>
71 | int(2)
72 | [2]=>
73 | int(3)
74 | [3]=>
75 | int(4)
76 | }
77 | array(4) {
78 | [0]=>
79 | int(5)
80 | [1]=>
81 | int(7)
82 | [2]=>
83 | int(9)
84 | [3]=>
85 | int(10)
86 | }
87 | array(4) {
88 | [0]=>
89 | int(5)
90 | [1]=>
91 | int(6)
92 | [2]=>
93 | int(7)
94 | [3]=>
95 | int(8)
96 | }
97 | bool(true)
98 | bool(true)
99 | bool(true)
100 | array(2) {
101 | [0]=>
102 | int(1)
103 | [1]=>
104 | int(3)
105 | }
106 | array(2) {
107 | [0]=>
108 | int(2)
109 | [1]=>
110 | int(3)
111 | }
112 | array(3) {
113 | [0]=>
114 | int(5)
115 | [1]=>
116 | int(7)
117 | [2]=>
118 | int(10)
119 | }
120 | bool(false)
121 |
--------------------------------------------------------------------------------
/tests/imap_clearflag_full_uid.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_clearflag_full() passing a unique ID
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
44 | --CLEAN--
45 |
49 | --EXPECT--
50 | Create a temporary mailbox and add 10 msgs
51 | New mailbox created
52 | Delete 4 messages for Unique ID generation
53 | ALL: array(6) {
54 | [0]=>
55 | int(1)
56 | [1]=>
57 | int(2)
58 | [2]=>
59 | int(3)
60 | [3]=>
61 | int(4)
62 | [4]=>
63 | int(5)
64 | [5]=>
65 | int(6)
66 | }
67 | ALL (with UID correspondance): array(6) {
68 | [0]=>
69 | int(1)
70 | [1]=>
71 | int(2)
72 | [2]=>
73 | int(7)
74 | [3]=>
75 | int(8)
76 | [4]=>
77 | int(9)
78 | [5]=>
79 | int(10)
80 | }
81 | ANSWERED: array(1) {
82 | [0]=>
83 | int(4)
84 | }
85 | DELETED: array(1) {
86 | [0]=>
87 | int(3)
88 | }
89 | FLAGGED: array(1) {
90 | [0]=>
91 | int(5)
92 | }
93 |
--------------------------------------------------------------------------------
/tests/imap_close_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Test imap_close() function : basic functionality
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
37 | --CLEAN--
38 |
42 | --EXPECTF--
43 | *** Testing imap_close() : basic functionality ***
44 | Create a temporary mailbox and add 3 msgs
45 | New mailbox created
46 |
47 | -- Call to imap_close() with all possible arguments --
48 | bool(true)
49 | There are now 0 msgs in mailbox '%sINBOX.phpttestimapclosebasic'
50 |
51 | -- Call to imap_close() with mandatory arguments --
52 | bool(true)
53 |
--------------------------------------------------------------------------------
/tests/imap_close_variation4.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Test imap_close() function : usage variations - different ints as $flags arg
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 | getMessage() . \PHP_EOL;
37 | $check = false;
38 | }
39 |
40 | // check that imap_close was successful, if not call imap_close and explicitly set CL_EXPUNGE
41 | if(false === $check) {
42 | imap_close($stream_id, CL_EXPUNGE);
43 | } else {
44 | // if imap_close was successful test whether CL_EXPUNGE was set by doing a message count
45 | $imap_stream = imap_open($mailbox, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD);
46 | $num_msg = imap_num_msg($imap_stream);
47 | if ($num_msg != 0) {
48 | echo "CL_EXPUNGE was not set, $num_msg msgs in mailbox\n";
49 | } else {
50 | echo "CL_EXPUNGE was set\n";
51 | }
52 | // call imap_close with CL_EXPUNGE explicitly set in case mailbox not empty
53 | imap_close($imap_stream, CL_EXPUNGE);
54 | }
55 | $iterator++;
56 |
57 | // get $stream_id for next iteration
58 | $stream_id = imap_open($mailbox, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD);
59 | populate_mailbox($stream_id, $mailbox, 3);
60 |
61 | };
62 | ?>
63 | --CLEAN--
64 |
68 | --EXPECT--
69 | *** Testing imap_close() : usage variations ***
70 | Create a temporary mailbox and add 3 msgs
71 | New mailbox created
72 |
73 | -- Iteration 1 --
74 | bool(true)
75 | CL_EXPUNGE was not set, 3 msgs in mailbox
76 |
77 | -- Iteration 2 --
78 | bool(true)
79 | CL_EXPUNGE was set
80 |
81 | -- Iteration 3 --
82 | imap_close(): Argument #2 ($flags) must be CL_EXPUNGE or 0
83 |
84 | -- Iteration 4 --
85 | imap_close(): Argument #2 ($flags) must be CL_EXPUNGE or 0
86 |
87 | -- Iteration 5 --
88 | imap_close(): Argument #2 ($flags) must be CL_EXPUNGE or 0
89 |
--------------------------------------------------------------------------------
/tests/imap_constructor.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Attempt to instantiate an IMAP\Connection directly
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 | getMessage(), "\n";
12 | }
13 | ?>
14 | --EXPECT--
15 | Exception: Cannot directly construct IMAP\Connection, use imap_open() instead
16 |
--------------------------------------------------------------------------------
/tests/imap_createmailbox_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Test imap_createmailbox() function : basic functionality
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 | messages . "\n";
31 | echo "Recent: " . $status->recent . "\n";
32 | echo "Unseen: " . $status->unseen . "\n";
33 | echo "UIDnext: " . $status->uidnext . "\n";
34 | echo "UIDvalidity: " . $status->uidvalidity . "\n";
35 |
36 | } else {
37 | echo "imap_status on new mailbox failed: " . imap_last_error() . "\n";
38 | }
39 |
40 | if (imap_deletemailbox($imap_stream, $newbox)) {
41 | echo "Mailbox '$newname' removed to restore initial state\n";
42 | } else {
43 | echo "imap_deletemailbox on new mailbox failed: " . implode("\n", imap_errors()) . "\n";
44 | }
45 |
46 | } else {
47 | echo "could not create new mailbox: " . implode("\n", imap_errors()) . "\n";
48 | }
49 |
50 | imap_close($imap_stream);
51 |
52 | ?>
53 | --CLEAN--
54 |
58 | --EXPECTF--
59 | *** Testing imap_createmailbox() : basic functionality ***
60 | Create a temporary mailbox and add 0 msgs
61 | New mailbox created
62 | Newname will be 'phpnewbox'
63 | Add a couple of msgs to 'phpnewbox' mailbox
64 | Your new mailbox 'phpnewbox' has the following status:
65 | Messages: 2
66 | Recent: 2
67 | Unseen: 2
68 | UIDnext: %d
69 | UIDvalidity: %d
70 | Mailbox 'phpnewbox' removed to restore initial state
71 |
--------------------------------------------------------------------------------
/tests/imap_delete_uid.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_delete() passing a unique ID
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
28 | --CLEAN--
29 |
33 | --EXPECT--
34 | Create a temporary mailbox and add 10 msgs
35 | New mailbox created
36 | Delete 4 messages for Unique ID generation
37 | array(1) {
38 | [0]=>
39 | int(9)
40 | }
41 | After expunging: bool(false)
42 | array(5) {
43 | [0]=>
44 | int(1)
45 | [1]=>
46 | int(2)
47 | [2]=>
48 | int(7)
49 | [3]=>
50 | int(8)
51 | [4]=>
52 | int(10)
53 | }
54 |
--------------------------------------------------------------------------------
/tests/imap_errors_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Test imap_errors() function : anonymous user not supported
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
20 | --EXPECTF--
21 | *** Testing imap_errors() : anonymous user not supported ***
22 | List any errors
23 | array(1) {
24 | [0]=>
25 | string(%d) "%s"
26 | }
27 |
--------------------------------------------------------------------------------
/tests/imap_fetch_overview_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Test imap_fetch_overview() function : basic functionality
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 | Object #1\n";
26 | displayOverviewFields($a[0]);
27 |
28 | // Calling imap_fetch_overview() with mandatory arguments
29 | echo "\n-- Mandatory arguments --\n";
30 | $a = imap_fetch_overview($stream_id, '1:2') ;
31 |
32 | //first object in array
33 | echo "\n--> Object #1\n";
34 | displayOverviewFields($a[0]);
35 |
36 | //Second object in array
37 | echo "\n--> Object #2\n";
38 | displayOverviewFields($a[1]);
39 |
40 | imap_close($stream_id);
41 |
42 | ?>
43 | --CLEAN--
44 |
48 | --EXPECTF--
49 | *** Testing imap_fetch_overview() : basic functionality ***
50 | Create a temporary mailbox and add 2 msgs
51 | New mailbox created
52 |
53 | -- All possible arguments --
54 |
55 | --> Object #1
56 | size is %d
57 | uid is %d
58 | msgno is 1
59 | recent is %d
60 | flagged is 0
61 | answered is 0
62 | deleted is 0
63 | seen is 0
64 | draft is 0
65 | udate is OK
66 |
67 | -- Mandatory arguments --
68 |
69 | --> Object #1
70 | size is %d
71 | uid is %d
72 | msgno is 1
73 | recent is %d
74 | flagged is 0
75 | answered is 0
76 | deleted is 0
77 | seen is 0
78 | draft is 0
79 | udate is OK
80 |
81 | --> Object #2
82 | size is %d
83 | uid is %d
84 | msgno is 2
85 | recent is %d
86 | flagged is 0
87 | answered is 0
88 | deleted is 0
89 | seen is 0
90 | draft is 0
91 | udate is OK
92 |
--------------------------------------------------------------------------------
/tests/imap_fetch_overview_uid.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_fetch_overview() passing a unique ID
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
22 | --CLEAN--
23 |
27 | --EXPECT--
28 | Create a temporary mailbox and add 10 msgs
29 | New mailbox created
30 | Delete 4 messages for Unique ID generation
31 | bool(true)
32 |
--------------------------------------------------------------------------------
/tests/imap_fetch_overview_variation5.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Test imap_fetch_overview() function : usage variations - $msg_no argument
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
47 | --CLEAN--
48 |
52 | --EXPECTF--
53 | *** Testing imap_fetch_overview() : usage variations ***
54 | Create a temporary mailbox and add 3 msgs
55 | New mailbox created
56 |
57 | -- $msg_no is 0 --
58 | Sequence out of range
59 |
60 | -- $msg_no is 4 --
61 | Sequence out of range
62 |
63 | -- $msg_no is 4 --
64 | Sequence out of range
65 |
66 | -- $msg_no is 2 --
67 |
68 | size is %d
69 | uid is %d
70 | msgno is 2
71 | recent is %d
72 | flagged is 0
73 | answered is 0
74 | deleted is 0
75 | seen is 0
76 | draft is 0
77 | udate is OK
78 |
79 | -- $msg_no is 1,3 --
80 |
81 | size is %d
82 | uid is %d
83 | msgno is 1
84 | recent is %d
85 | flagged is 0
86 | answered is 0
87 | deleted is 0
88 | seen is 0
89 | draft is 0
90 | udate is OK
91 |
92 | size is %d
93 | uid is %d
94 | msgno is 3
95 | recent is %d
96 | flagged is 0
97 | answered is 0
98 | deleted is 0
99 | seen is 0
100 | draft is 0
101 | udate is OK
102 |
103 | -- $msg_no is 1, 2 --
104 | Syntax error in sequence
105 |
106 | -- $msg_no is 1:3 --
107 |
108 | size is %d
109 | uid is %d
110 | msgno is 1
111 | recent is %d
112 | flagged is 0
113 | answered is 0
114 | deleted is 0
115 | seen is 0
116 | draft is 0
117 | udate is OK
118 |
119 | size is %d
120 | uid is %d
121 | msgno is 2
122 | recent is %d
123 | flagged is 0
124 | answered is 0
125 | deleted is 0
126 | seen is 0
127 | draft is 0
128 | udate is OK
129 |
130 | size is %d
131 | uid is %d
132 | msgno is 3
133 | recent is %d
134 | flagged is 0
135 | answered is 0
136 | deleted is 0
137 | seen is 0
138 | draft is 0
139 | udate is OK
140 |
--------------------------------------------------------------------------------
/tests/imap_fetch_overview_variation6.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Test imap_fetch_overview() function : usage variations - multipart message
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 | Object #1\n";
28 | displayOverviewFields($a[0]);
29 |
30 |
31 |
32 |
33 | /**
34 | * Create a multipart message with subparts
35 | *
36 | * @param resource $imap_stream
37 | * @param string $mailbox
38 | */
39 | function create_multipart_message($imap_stream, $mailbox) {
40 | global $users, $domain;
41 | $envelope["from"]= "foo@anywhere.com";
42 | $envelope["to"] = IMAP_USERS[0] . '@' . IMAP_MAIL_DOMAIN;
43 | $envelope["subject"] = "Test msg 1";
44 |
45 | $part1["type"] = TYPEMULTIPART;
46 | $part1["subtype"] = "mixed";
47 |
48 | $part2["type"] = TYPETEXT;
49 | $part2["subtype"] = "plain";
50 | $part2["description"] = "imap_mail_compose() function";
51 | $part2["contents.data"] = "message 1:xxxxxxxxxxxxxxxxxxxxxxxxxx";
52 |
53 | $part3["type"] = TYPETEXT;
54 | $part3["subtype"] = "plain";
55 | $part3["description"] = "Example";
56 | $part3["contents.data"] = "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy";
57 |
58 | $file_handle = fopen(__FILE__, 'r+');
59 | $file_size = 1;
60 |
61 | $part4["type"] = TYPEAPPLICATION;
62 | $part4["encoding"] = ENCBASE64;
63 | $part4["subtype"] = "octet-stream";
64 | $part4["description"] = 'Test';
65 | $part4['disposition.type'] = 'attachment';
66 | $part4['disposition'] = array ('filename' => 'Test');
67 | $part4['type.parameters'] = array('name' => 'Test');
68 | $part4["contents.data"] = base64_encode(fread($file_handle, 1));
69 |
70 | $body[1] = $part1;
71 | $body[2] = $part2;
72 | $body[3] = $part3;
73 | $body[4] = $part4;
74 |
75 | $msg = imap_mail_compose($envelope, $body);
76 |
77 | if (imap_append($imap_stream, $mailbox, $msg) === false) {
78 | echo imap_last_error() . "\n";
79 | echo "TEST FAILED : could not append new message to mailbox '$mailbox'\n";
80 | exit;
81 | }
82 | }
83 |
84 | ?>
85 | --CLEAN--
86 |
90 | --EXPECTF--
91 | *** Testing imap_fetch_overview() : usage variations ***
92 | Create a temporary mailbox and add 0 msgs
93 | New mailbox created
94 |
95 | --> Object #1
96 | size is %d
97 | uid is %d
98 | msgno is 1
99 | recent is %d
100 | flagged is 0
101 | answered is 0
102 | deleted is 0
103 | seen is 0
104 | draft is 0
105 | udate is OK
106 |
--------------------------------------------------------------------------------
/tests/imap_fetchbody_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Test imap_fetchbody() function : basic functionality
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 | FT_UID, 'FT_PEEK' => FT_PEEK, 'FT_INTERNAL' => FT_INTERNAL);
27 |
28 | // Calling imap_fetchbody() with all possible arguments
29 | echo "\n-- All possible arguments --\n";
30 | foreach ($options as $key => $option) {
31 | echo "-- Option is $key --\n";
32 | switch ($key) {
33 |
34 | case 'FT_UID';
35 | $msg_uid = imap_uid($stream_id, $msg_no);
36 | var_dump( imap_fetchbody($stream_id, $msg_uid, $section, $option) );
37 | break;
38 |
39 | case 'FT_PEEK';
40 | var_dump( imap_fetchbody($stream_id, $msg_no, $section, $option) );
41 | $overview = imap_fetch_overview($stream_id, 1);
42 | echo "Seen Flag: ";
43 | var_dump( $overview[0]->seen );
44 | break;
45 |
46 | case 'FT_INTERNAL';
47 | var_dump( imap_fetchbody($stream_id, $msg_no, $section, $option) );
48 | break;
49 |
50 | }
51 | }
52 |
53 | // Calling imap_fetchbody() with mandatory arguments
54 | echo "\n-- Mandatory arguments --\n";
55 | var_dump( imap_fetchbody($stream_id, $msg_no, $section) );
56 | $overview = imap_fetch_overview($stream_id, 1);
57 | echo "Seen Flag: ";
58 | var_dump( $overview[0]->seen );
59 | ?>
60 | --CLEAN--
61 |
65 | --EXPECTF--
66 | *** Testing imap_fetchbody() : basic functionality ***
67 | Create a temporary mailbox and add 1 msgs
68 | New mailbox created
69 |
70 | -- All possible arguments --
71 | -- Option is FT_UID --
72 | string(36) "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy"
73 | -- Option is FT_PEEK --
74 | string(36) "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy"
75 | Seen Flag: int(%d)
76 | -- Option is FT_INTERNAL --
77 | string(36) "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy"
78 |
79 | -- Mandatory arguments --
80 | string(36) "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy"
81 | Seen Flag: int(%d)
82 |
--------------------------------------------------------------------------------
/tests/imap_fetchbody_errors.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_fetchbody() errors: ValueError and Warnings
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 | getMessage() . \PHP_EOL;
22 | }
23 | try {
24 | imap_fetchbody($imap_mail_box, 1, $section, -1);
25 | } catch (\ValueError $e) {
26 | echo $e->getMessage() . \PHP_EOL;
27 | }
28 |
29 | // Access not existing
30 | var_dump(imap_fetchbody($imap_mail_box, 255, $section));
31 | var_dump(imap_fetchbody($imap_mail_box, 255, $section, FT_UID));
32 |
33 | imap_close($imap_mail_box);
34 |
35 | ?>
36 | --CLEAN--
37 |
41 | --EXPECTF--
42 | Create a temporary mailbox and add 0 msgs
43 | New mailbox created
44 | imap_fetchbody(): Argument #2 ($message_num) must be greater than 0
45 | imap_fetchbody(): Argument #4 ($flags) must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL
46 |
47 | Warning: imap_fetchbody(): Bad message number in %s on line %d
48 | bool(false)
49 |
50 | Warning: imap_fetchbody(): UID does not exist in %s on line %d
51 | bool(false)
52 |
--------------------------------------------------------------------------------
/tests/imap_fetchbody_uid.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_fetchbody() passing a unique ID
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
22 | --CLEAN--
23 |
27 | --EXPECT--
28 | Create a temporary mailbox and add 10 msgs
29 | New mailbox created
30 | Delete 4 messages for Unique ID generation
31 | bool(true)
32 |
--------------------------------------------------------------------------------
/tests/imap_fetchbody_variation6.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Test imap_fetchbody() function : usage variations - $message_num arg
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 | getMessage() . \PHP_EOL;
32 | }
33 | }
34 | ?>
35 | --CLEAN--
36 |
40 | --EXPECTF--
41 | *** Testing imap_fetchbody() : usage variations ***
42 | Create a temporary mailbox and add 3 msgs
43 | New mailbox created
44 |
45 | -- $message_num is 0 --
46 | imap_fetchbody(): Argument #2 ($message_num) must be greater than 0
47 |
48 | -- $message_num is 4 --
49 |
50 | Warning: imap_fetchbody(): Bad message number in %s on line %d
51 | bool(false)
52 |
53 | -- $message_num is 1 --
54 | string(%d) "1: this is a test message, please ignore
55 | newline%r\R?%r"
56 |
--------------------------------------------------------------------------------
/tests/imap_fetchheader_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Test imap_fetchheader() function : basic function
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 | FT_UID, 'FT_INTERNAL' => FT_INTERNAL,
18 | 'FT_PREFETCHTEXT' => FT_PREFETCHTEXT);
19 |
20 | // Calling imap_fetchheader() with all possible arguments
21 | echo "\n-- All possible arguments --\n";
22 | foreach ($options as $key => $option) {
23 | echo "-- Option is $key --\n";
24 | if ($key == 'FT_UID') {
25 | $msg_uid = imap_uid($stream_id, $msg_no);
26 | var_dump(imap_fetchheader($stream_id, $msg_uid, $option));
27 | } else {
28 | var_dump(imap_fetchheader($stream_id, $msg_no, $option));
29 | }
30 | }
31 |
32 | // Calling imap_fetchheader() with mandatory arguments
33 | echo "\n-- Mandatory arguments --\n";
34 | var_dump( imap_fetchheader($stream_id, $msg_no) );
35 | ?>
36 | --CLEAN--
37 |
41 | --EXPECTF--
42 | *** Testing imap_fetchheader() : basic functionality ***
43 | Create a temporary mailbox and add 1 msgs
44 | New mailbox created
45 |
46 | -- All possible arguments --
47 | -- Option is FT_UID --
48 | string(%d) "From: foo@anywhere.com
49 | Subject: Test msg 1
50 | To: %s
51 | MIME-Version: 1.0
52 | Content-Type: %s; %s
53 |
54 | "
55 | -- Option is FT_INTERNAL --
56 | string(%d) "From: foo@anywhere.com
57 | Subject: Test msg 1
58 | To: %s
59 | MIME-Version: 1.0
60 | Content-Type: %s; %s
61 |
62 | "
63 | -- Option is FT_PREFETCHTEXT --
64 | string(%d) "From: foo@anywhere.com
65 | Subject: Test msg 1
66 | To: %s
67 | MIME-Version: 1.0
68 | Content-Type: %s; %s
69 |
70 | "
71 |
72 | -- Mandatory arguments --
73 | string(%d) "From: foo@anywhere.com
74 | Subject: Test msg 1
75 | To: %s
76 | MIME-Version: 1.0
77 | Content-Type: %s; %s
78 |
79 | "
80 |
--------------------------------------------------------------------------------
/tests/imap_fetchheader_errors.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_fetchheader() errors: ValueError and Warnings
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 | getMessage() . \PHP_EOL;
20 | }
21 | try {
22 | imap_fetchheader($imap_mail_box, 1, -1);
23 | } catch (\ValueError $e) {
24 | echo $e->getMessage() . \PHP_EOL;
25 | }
26 |
27 | // Access not existing
28 | var_dump(imap_fetchheader($imap_mail_box, 255));
29 | var_dump(imap_fetchheader($imap_mail_box, 255, FT_UID));
30 |
31 | imap_close($imap_mail_box);
32 |
33 | ?>
34 | --CLEAN--
35 |
39 | --EXPECTF--
40 | Create a temporary mailbox and add 0 msgs
41 | New mailbox created
42 | imap_fetchheader(): Argument #2 ($message_num) must be greater than 0
43 | imap_fetchheader(): Argument #3 ($flags) must be a bitmask of FT_UID, FT_PREFETCHTEXT, and FT_INTERNAL
44 |
45 | Warning: imap_fetchheader(): Bad message number in %s on line %d
46 | bool(false)
47 |
48 | Warning: imap_fetchheader(): UID does not exist in %s on line %d
49 | bool(false)
50 |
--------------------------------------------------------------------------------
/tests/imap_fetchheader_uid.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_fetchheader() passing a unique ID
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
21 | --CLEAN--
22 |
26 | --EXPECT--
27 | Create a temporary mailbox and add 10 msgs
28 | New mailbox created
29 | Delete 4 messages for Unique ID generation
30 | bool(true)
31 |
--------------------------------------------------------------------------------
/tests/imap_fetchheader_variation5.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Test imap_fetchheader() function : usage variations - $message_num argument
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 | getMessage() . \PHP_EOL;
30 | }
31 | }
32 |
33 | // clear error stack
34 | imap_errors();
35 | ?>
36 | --CLEAN--
37 |
41 | --EXPECTF--
42 | *** Testing imap_fetchheader() : usage variations ***
43 | Create a temporary mailbox and add 3 msgs
44 | New mailbox created
45 |
46 | -- $message_num is 0 --
47 | imap_fetchheader(): Argument #2 ($message_num) must be greater than 0
48 |
49 | -- $message_num is 4 --
50 |
51 | Warning: imap_fetchheader(): Bad message number in %s on line %d
52 | bool(false)
53 |
54 | -- $message_num is 1 --
55 | string(%d) "From: foo@anywhere.com
56 | Subject: Test msg 1
57 | To: %s
58 | MIME-Version: 1.0
59 | Content-Type: MULTIPART/mixed; BOUNDARY="%s=:%d"
60 |
61 | "
62 |
--------------------------------------------------------------------------------
/tests/imap_fetchmime_errors.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_fetchmime() errors: ValueError and Warnings
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 | getMessage() . \PHP_EOL;
22 | }
23 | try {
24 | imap_fetchmime($imap_mail_box, 1, $section, -1);
25 | } catch (\ValueError $e) {
26 | echo $e->getMessage() . \PHP_EOL;
27 | }
28 |
29 | // Access not existing
30 | var_dump(imap_fetchmime($imap_mail_box, 255, $section));
31 | var_dump(imap_fetchmime($imap_mail_box, 255, $section, FT_UID));
32 |
33 | imap_close($imap_mail_box);
34 |
35 | ?>
36 | --CLEAN--
37 |
41 | --EXPECTF--
42 | Create a temporary mailbox and add 0 msgs
43 | New mailbox created
44 | imap_fetchmime(): Argument #2 ($message_num) must be greater than 0
45 | imap_fetchmime(): Argument #4 ($flags) must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL
46 |
47 | Warning: imap_fetchmime(): Bad message number in %s on line %d
48 | bool(false)
49 |
50 | Warning: imap_fetchmime(): UID does not exist in %s on line %d
51 | bool(false)
52 |
--------------------------------------------------------------------------------
/tests/imap_fetchmime_uid.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_fetchmime() passing a unique ID
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
22 | --CLEAN--
23 |
27 | --EXPECT--
28 | Create a temporary mailbox and add 10 msgs
29 | New mailbox created
30 | Delete 4 messages for Unique ID generation
31 | bool(true)
32 |
--------------------------------------------------------------------------------
/tests/imap_fetchstructure_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_fetchstructure() function : basic functionality
3 | --CREDITS--
4 | Olivier Doucet
5 | --EXTENSIONS--
6 | imap
7 | --SKIPIF--
8 |
11 | --FILE--
12 | getMessage() . \PHP_EOL;
21 | }
22 |
23 | $z = imap_fetchstructure($stream_id,1);
24 |
25 |
26 | $fields = array('type','encoding','ifsubtype','subtype',
27 | 'ifdescription','lines','bytes','parameters');
28 |
29 | foreach ($fields as $key) {
30 | var_dump(isset($z->$key));
31 | }
32 | var_dump($z->type);
33 | var_dump($z->encoding);
34 | var_dump($z->bytes);
35 | var_dump($z->lines);
36 | var_dump($z->ifparameters);
37 | var_dump(is_object($z->parameters[0]));
38 |
39 | imap_close($stream_id);
40 | ?>
41 | --CLEAN--
42 |
46 | --EXPECTF--
47 | Create a temporary mailbox and add 1 msgs
48 | New mailbox created
49 | imap_fetchstructure(): Argument #2 ($message_num) must be greater than 0
50 | bool(true)
51 | bool(true)
52 | bool(true)
53 | bool(true)
54 | bool(true)
55 | bool(true)
56 | bool(true)
57 | bool(true)
58 | int(%d)
59 | int(%d)
60 | int(%d)
61 | int(%d)
62 | int(1)
63 | bool(true)
64 |
--------------------------------------------------------------------------------
/tests/imap_fetchstructure_errors.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_fetchstructure() errors: ValueError and Warnings
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 | getMessage() . \PHP_EOL;
20 | }
21 | try {
22 | imap_fetchstructure($imap_mail_box, 1, -1);
23 | } catch (\ValueError $e) {
24 | echo $e->getMessage() . \PHP_EOL;
25 | }
26 |
27 | // Access not existing
28 | var_dump(imap_fetchstructure($imap_mail_box, 255));
29 | var_dump(imap_fetchstructure($imap_mail_box, 255, FT_UID));
30 |
31 | imap_close($imap_mail_box);
32 |
33 | ?>
34 | --CLEAN--
35 |
39 | --EXPECTF--
40 | Create a temporary mailbox and add 0 msgs
41 | New mailbox created
42 | imap_fetchstructure(): Argument #2 ($message_num) must be greater than 0
43 | imap_fetchstructure(): Argument #3 ($flags) must be FT_UID or 0
44 |
45 | Warning: imap_fetchstructure(): Bad message number in %s on line %d
46 | bool(false)
47 |
48 | Warning: imap_fetchstructure(): UID does not exist in %s on line %d
49 | bool(false)
50 |
--------------------------------------------------------------------------------
/tests/imap_fetchstructure_uid.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_fetchstructure() passing a unique ID
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
22 | --CLEAN--
23 |
27 | --EXPECT--
28 | Create a temporary mailbox and add 10 msgs
29 | New mailbox created
30 | Delete 4 messages for Unique ID generation
31 | bool(true)
32 |
--------------------------------------------------------------------------------
/tests/imap_final.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check that IMAP\Connection is declared final
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 |
10 | --EXPECTF--
11 | Fatal error: Class T cannot extend final class IMAP\Connection in %s on line %d
12 |
--------------------------------------------------------------------------------
/tests/imap_gc_error.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_gc() ValueError
3 | --CREDITS--
4 | Paul Sohier
5 | #phptestfest utrecht
6 | --EXTENSIONS--
7 | imap
8 | --SKIPIF--
9 |
12 | --FILE--
13 | getMessage() . \PHP_EOL;
22 | }
23 |
24 | ?>
25 | --CLEAN--
26 |
30 | --EXPECT--
31 | Create a temporary mailbox and add 1 msgs
32 | New mailbox created
33 | imap_gc(): Argument #2 ($flags) must be a bitmask of IMAP_GC_TEXTS, IMAP_GC_ELT, and IMAP_GC_ENV
34 |
--------------------------------------------------------------------------------
/tests/imap_getsubscribed_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_getsubscribed() function : basic functionality
3 | --CREDITS--
4 | Olivier Doucet
5 | --EXTENSIONS--
6 | imap
7 | --SKIPIF--
8 |
12 | --CONFLICTS--
13 | defaultmailbox
14 | --FILE--
15 |
38 | --CLEAN--
39 |
43 | --EXPECTF--
44 | bool(false)
45 | Checking OK
46 | bool(true)
47 | object(stdClass)#%d (%d) {
48 | [%sname"]=>
49 | string(%d) "{%s}%s"
50 | [%sattributes"]=>
51 | int(%d)
52 | [%sdelimiter"]=>
53 | string(%d) "%s"
54 | }
55 |
--------------------------------------------------------------------------------
/tests/imap_headerinfo_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_headerinfo() function : basic functionality
3 | --CREDITS--
4 | Olivier Doucet
5 | --EXTENSIONS--
6 | imap
7 | --SKIPIF--
8 |
11 | --FILE--
12 | $key));
29 | }
30 |
31 | echo "Check type\n";
32 | var_dump($z->toaddress);
33 | var_dump($z->fromaddress);
34 | var_dump($z->reply_toaddress);
35 | var_dump($z->senderaddress);
36 | var_dump($z->subject);
37 | var_dump($z->Subject);
38 |
39 | if ($z->Recent == 'R' || $z->Recent == 'N' || $z->Recent == ' ') {
40 | echo "Recent: OK";
41 | } else {
42 | echo "Recent: error: ".$z->Recent;
43 | }
44 | echo "\n";
45 |
46 | if ($z->Unseen == 'U' || $z->Unseen == ' ') {
47 | echo "Unseen: OK";
48 | } else {
49 | echo "Unseen: error: ".$z->Unseen;
50 | }
51 | echo "\n";
52 |
53 | if ($z->Flagged == 'F' || $z->Flagged == ' ') {
54 | echo "Flagged: OK";
55 | } else {
56 | echo "Flagged: error: ".$z->Flagged;
57 | }
58 | echo "\n";
59 |
60 | if ($z->Answered == 'A' || $z->Answered == ' ') {
61 | echo "Answered: OK";
62 | } else {
63 | echo "Answered: error";
64 | }
65 | echo "\n";
66 |
67 | if ($z->Deleted == 'D' || $z->Deleted == ' ') {
68 | echo "Deleted: OK";
69 | } else {
70 | echo "Deleted: error";
71 | }
72 | echo "\n";
73 |
74 | if ($z->Draft == 'X' || $z->Draft == ' ') {
75 | echo "Draft: OK";
76 | } else {
77 | echo "Draft: error";
78 | }
79 | echo "\n";
80 |
81 | var_dump($z->Msgno);
82 | var_dump($z->Size);
83 | var_dump($z->udate);
84 |
85 | imap_close($stream_id);
86 |
87 | ?>
88 | --CLEAN--
89 |
93 | --EXPECTF--
94 | Create a temporary mailbox and add 1 msgs
95 | New mailbox created
96 | Check general fields
97 | bool(true)
98 | bool(true)
99 | bool(true)
100 | bool(true)
101 | bool(true)
102 | bool(true)
103 | bool(true)
104 | bool(true)
105 | bool(true)
106 | bool(true)
107 | bool(true)
108 | bool(true)
109 | bool(true)
110 | bool(true)
111 | bool(true)
112 | bool(true)
113 | bool(true)
114 | bool(true)
115 | bool(true)
116 | bool(true)
117 | Check type
118 | string(%d) "%s"
119 | string(%d) "%s"
120 | string(%d) "%s"
121 | string(%d) "%s"
122 | string(%d) "%s"
123 | string(%d) "%s"
124 | Recent: OK
125 | Unseen: OK
126 | Flagged: OK
127 | Answered: OK
128 | Deleted: OK
129 | Draft: OK
130 | string(%d) "%s"
131 | string(%d) "%d"
132 | int(%d)
133 |
--------------------------------------------------------------------------------
/tests/imap_is_open.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Test imap_is_open()
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
27 | --CLEAN--
28 |
32 | --EXPECT--
33 | Create a temporary mailbox and add 0 msgs
34 | New mailbox created
35 | bool(true)
36 | bool(true)
37 | bool(false)
38 |
--------------------------------------------------------------------------------
/tests/imap_list_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_list() function : basic functionality
3 | --CREDITS--
4 | Olivier Doucet
5 | --EXTENSIONS--
6 | imap
7 | --SKIPIF--
8 |
11 | --FILE--
12 |
29 | --EXPECTF--
30 | bool(true)
31 | string(%s) "{%s}%s"
32 |
--------------------------------------------------------------------------------
/tests/imap_lsub_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_lsub() function : basic functionality
3 | --CREDITS--
4 | Olivier Doucet
5 | --EXTENSIONS--
6 | imap
7 | --SKIPIF--
8 |
12 | --CONFLICTS--
13 | defaultmailbox
14 | --FILE--
15 |
40 | --CLEAN--
41 |
45 | --EXPECTF--
46 | bool(false)
47 | Checking OK
48 | bool(true)
49 | string(%s) "{%s}%s"
50 |
--------------------------------------------------------------------------------
/tests/imap_mail_copy_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Test imap_mail_copy() function : basic functionality
3 | --CREDITS--
4 | Olivier Doucet
5 | --EXTENSIONS--
6 | imap
7 | --SKIPIF--
8 |
11 | --FILE--
12 | Nmsgs . "\n";
22 |
23 | var_dump(imap_mail_copy($imap_stream, '1', 'INBOX.' . IMAP_MAILBOX_PHPT_PREFIX . 'copybasic'));
24 |
25 | imap_close($imap_stream);
26 | ?>
27 | --CLEAN--
28 |
32 | --EXPECT--
33 | *** Testing imap_mail_copy() : basic functionality ***
34 | Create a new mailbox for test
35 | Create a temporary mailbox and add 1 msgs
36 | New mailbox created
37 | Msg Count in new mailbox: 1
38 | bool(true)
39 |
--------------------------------------------------------------------------------
/tests/imap_mail_move_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Test imap_mail_move() function : basic functionality
3 | --CREDITS--
4 | Olivier Doucet
5 | --EXTENSIONS--
6 | imap
7 | --SKIPIF--
8 |
11 | --FILE--
12 | Nmsgs . "\n";
22 |
23 | var_dump(imap_mail_move($imap_stream, '1', 'INBOX.' . IMAP_MAILBOX_PHPT_PREFIX . 'movebasic'));
24 |
25 | imap_close($imap_stream);
26 | ?>
27 | --CLEAN--
28 |
32 | --EXPECT--
33 | *** Testing imap_mail_move() : basic functionality ***
34 | Create a new mailbox for test
35 | Create a temporary mailbox and add 1 msgs
36 | New mailbox created
37 | Msg Count in new mailbox: 1
38 | bool(true)
39 |
--------------------------------------------------------------------------------
/tests/imap_mutf7_to_utf8.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_mutf7_to_utf8
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
13 | --FILE--
14 |
22 | --EXPECT--
23 | string(0) ""
24 | string(1) "1"
25 | string(5) "täst"
26 | Done
27 |
--------------------------------------------------------------------------------
/tests/imap_open_error.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_open() ValueErrors
3 | --CREDITS--
4 | Paul Sohier
5 | #phptestfest utrecht
6 | --EXTENSIONS--
7 | imap
8 | --SKIPIF--
9 |
13 | --FILE--
14 | getMessage() . \PHP_EOL;
23 | }
24 |
25 | try {
26 | imap_open('', '', '', 0, -1);
27 | } catch (\ValueError $e) {
28 | echo $e->getMessage() . \PHP_EOL;
29 | }
30 |
31 | ?>
32 | --EXPECTF--
33 | Checking with incorrect parameters
34 |
35 | Warning: imap_open(): Couldn't open stream in %s on line %d
36 | imap_open(): Argument #4 ($flags) must be a bitmask of the OP_* constants, and CL_EXPUNGE
37 | imap_open(): Argument #5 ($retries) must be greater than or equal to 0
38 |
39 | Notice: PHP Request Shutdown: Can't open mailbox : no such mailbox (errflg=2) in Unknown on line 0
40 |
--------------------------------------------------------------------------------
/tests/imap_open_with_cl_expunge.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Test imap_open() using the CL_EXPUNGE flag
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
33 | --CLEAN--
34 |
38 | --EXPECTF--
39 | Create a temporary mailbox and add 3 msgs
40 | New mailbox created
41 |
42 | -- Call to imap_close() --
43 | bool(true)
44 | There are now 0 msgs in mailbox '%sINBOX.phpttestimapopenwithclexpunge'
45 | bool(true)
46 |
--------------------------------------------------------------------------------
/tests/imap_renamemailbox_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_renamemailbox() function : basic functionality
3 | --CREDITS--
4 | Olivier Doucet
5 | --EXTENSIONS--
6 | imap
7 | --SKIPIF--
8 |
11 | --FILE--
12 |
31 | --CLEAN--
32 |
36 | --EXPECT--
37 | Create a temporary mailbox and add 1 msgs
38 | New mailbox created
39 | Checking OK
40 | bool(true)
41 |
--------------------------------------------------------------------------------
/tests/imap_reopen_with_cl_expunge.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Test imap_reopen() using the CL_EXPUNGE flag
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
37 | --CLEAN--
38 |
42 | --EXPECTF--
43 | Create a temporary mailbox and add 3 msgs
44 | New mailbox created
45 | bool(true)
46 |
47 | -- Call to imap_close() --
48 | bool(true)
49 | There are now 0 msgs in mailbox '%sINBOX.phpttestimapreopenwithclexpunge'
50 | bool(true)
51 |
--------------------------------------------------------------------------------
/tests/imap_rfc822_parse_headers_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_rfc822_parse_headers() function : basic functionality
3 | --CREDITS--
4 | Olivier Doucet
5 | --EXTENSIONS--
6 | imap
7 | --SKIPIF--
8 |
11 | --FILE--
12 | $key));
29 | }
30 |
31 | echo "Check type\n";
32 | var_dump($z->toaddress);
33 | var_dump($z->fromaddress);
34 | var_dump($z->reply_toaddress);
35 | var_dump($z->senderaddress);
36 | var_dump($z->subject);
37 | var_dump($z->Subject);
38 |
39 | if ($z->Recent == 'R' || $z->Recent == 'N' || $z->Recent == ' ') {
40 | echo "Recent: OK";
41 | } else {
42 | echo "Recent: error";
43 | }
44 | echo "\n";
45 |
46 | if ($z->Unseen == 'U' || $z->Unseen == ' ') {
47 | echo "Unseen: OK";
48 | } else {
49 | echo "Unseen: error";
50 | }
51 | echo "\n";
52 |
53 | if ($z->Flagged == 'F' || $z->Flagged == ' ') {
54 | echo "Flagged: OK";
55 | } else {
56 | echo "Flagged: error";
57 | }
58 | echo "\n";
59 |
60 | if ($z->Answered == 'A' || $z->Answered == ' ') {
61 | echo "Answered: OK";
62 | } else {
63 | echo "Answered: error";
64 | }
65 | echo "\n";
66 |
67 | if ($z->Deleted == 'D' || $z->Deleted == ' ') {
68 | echo "Deleted: OK";
69 | } else {
70 | echo "Deleted: error";
71 | }
72 | echo "\n";
73 |
74 | if ($z->Draft == 'X' || $z->Draft == ' ') {
75 | echo "Draft: OK";
76 | } else {
77 | echo "Draft: error";
78 | }
79 | echo "\n";
80 |
81 | var_dump($z->Msgno);
82 | var_dump($z->Size);
83 | var_dump($z->udate);
84 |
85 | imap_close($stream_id);
86 |
87 | ?>
88 | --CLEAN--
89 |
93 | --EXPECTF--
94 | Create a temporary mailbox and add 1 msgs
95 | New mailbox created
96 | Check general fields
97 | bool(true)
98 | bool(true)
99 | bool(true)
100 | bool(true)
101 | bool(true)
102 | bool(true)
103 | bool(true)
104 | bool(true)
105 | bool(true)
106 | bool(true)
107 | bool(true)
108 | bool(true)
109 | bool(true)
110 | Check type
111 | string(%d) "%s"
112 | string(%d) "%s"
113 | string(%d) "%s"
114 | string(%d) "%s"
115 | string(%d) "%s"
116 | string(%d) "%s"
117 | Recent: OK
118 | Unseen: OK
119 | Flagged: OK
120 | Answered: OK
121 | Deleted: OK
122 | Draft: OK
123 | string(%d) "%s"
124 | string(%d) "%d"
125 | int(%d)
126 |
--------------------------------------------------------------------------------
/tests/imap_rfc822_write_address_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_rfc822_write_address() : basic functionality
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 |
9 | --EXPECT--
10 | string(24) "My Name "
11 |
--------------------------------------------------------------------------------
/tests/imap_savebody_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_savebody() function : basic functionality
3 | --CREDITS--
4 | Olivier Doucet
5 | --EXTENSIONS--
6 | imap
7 | --SKIPIF--
8 |
11 | --FILE--
12 |
33 | --CLEAN--
34 |
39 | --EXPECTF--
40 | Create a temporary mailbox and add 1 msgs
41 | New mailbox created
42 | bool(true)
43 | Size: %d
44 | bool(true)
45 | Size: %d
46 |
--------------------------------------------------------------------------------
/tests/imap_savebody_errors.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_savebody() errors: ValueError and Warnings
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 | getMessage() . \PHP_EOL;
22 | }
23 | try {
24 | imap_savebody($imap_mail_box, '', 1, $section, -1);
25 | } catch (\ValueError $e) {
26 | echo $e->getMessage() . \PHP_EOL;
27 | }
28 |
29 | // Access not existing
30 | var_dump(imap_savebody($imap_mail_box, '', 255, $section));
31 | var_dump(imap_savebody($imap_mail_box, '', 255, $section, FT_UID));
32 |
33 | imap_close($imap_mail_box);
34 |
35 | ?>
36 | --CLEAN--
37 |
41 | --EXPECTF--
42 | Create a temporary mailbox and add 0 msgs
43 | New mailbox created
44 | imap_savebody(): Argument #3 ($message_num) must be greater than 0
45 | imap_savebody(): Argument #5 ($flags) must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL
46 |
47 | Warning: imap_savebody(): Bad message number in %s on line %d
48 | bool(false)
49 |
50 | Warning: imap_savebody(): UID does not exist in %s on line %d
51 | bool(false)
52 |
--------------------------------------------------------------------------------
/tests/imap_savebody_uid.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_savebody() passing a unique ID
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
32 | --CLEAN--
33 |
37 | --EXPECT--
38 | Create a temporary mailbox and add 10 msgs
39 | New mailbox created
40 | Delete 4 messages for Unique ID generation
41 | bool(true)
42 |
--------------------------------------------------------------------------------
/tests/imap_search_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_search() with unique ID (SE_UID) flag
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
21 | --CLEAN--
22 |
26 | --EXPECT--
27 | Create a temporary mailbox and add 10 msgs
28 | New mailbox created
29 | Delete 4 messages for Unique ID generation
30 | array(6) {
31 | [0]=>
32 | int(1)
33 | [1]=>
34 | int(2)
35 | [2]=>
36 | int(7)
37 | [3]=>
38 | int(8)
39 | [4]=>
40 | int(9)
41 | [5]=>
42 | int(10)
43 | }
44 |
--------------------------------------------------------------------------------
/tests/imap_setflag_full_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_setflag_full() basic test
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
37 | --CLEAN--
38 |
42 | --EXPECT--
43 | Create a temporary mailbox and add 10 msgs
44 | New mailbox created
45 | ALL: array(10) {
46 | [0]=>
47 | int(1)
48 | [1]=>
49 | int(2)
50 | [2]=>
51 | int(3)
52 | [3]=>
53 | int(4)
54 | [4]=>
55 | int(5)
56 | [5]=>
57 | int(6)
58 | [6]=>
59 | int(7)
60 | [7]=>
61 | int(8)
62 | [8]=>
63 | int(9)
64 | [9]=>
65 | int(10)
66 | }
67 | ANSWERED: array(1) {
68 | [0]=>
69 | int(1)
70 | }
71 | DELETED: array(2) {
72 | [0]=>
73 | int(2)
74 | [1]=>
75 | int(7)
76 | }
77 | FLAGGED: array(3) {
78 | [0]=>
79 | int(3)
80 | [1]=>
81 | int(4)
82 | [2]=>
83 | int(5)
84 | }
85 |
--------------------------------------------------------------------------------
/tests/imap_setflag_full_uid.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_setflag_full() passing a unique ID
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
47 | --CLEAN--
48 |
52 | --EXPECT--
53 | Create a temporary mailbox and add 10 msgs
54 | New mailbox created
55 | Delete 4 messages for Unique ID generation
56 | bool(true)
57 | ALL: array(6) {
58 | [0]=>
59 | int(1)
60 | [1]=>
61 | int(2)
62 | [2]=>
63 | int(3)
64 | [3]=>
65 | int(4)
66 | [4]=>
67 | int(5)
68 | [5]=>
69 | int(6)
70 | }
71 | ALL (with UID correspondance): array(6) {
72 | [0]=>
73 | int(1)
74 | [1]=>
75 | int(2)
76 | [2]=>
77 | int(7)
78 | [3]=>
79 | int(8)
80 | [4]=>
81 | int(9)
82 | [5]=>
83 | int(10)
84 | }
85 | ANSWERED: array(1) {
86 | [0]=>
87 | int(4)
88 | }
89 | DELETED: array(2) {
90 | [0]=>
91 | int(3)
92 | [1]=>
93 | int(6)
94 | }
95 | FLAGGED: array(3) {
96 | [0]=>
97 | int(3)
98 | [1]=>
99 | int(4)
100 | [2]=>
101 | int(5)
102 | }
103 | SEEN: array(3) {
104 | [0]=>
105 | int(3)
106 | [1]=>
107 | int(4)
108 | [2]=>
109 | int(5)
110 | }
111 |
--------------------------------------------------------------------------------
/tests/imap_sort_uid.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_sort() basics
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
22 | --CLEAN--
23 |
27 | --EXPECT--
28 | Create a temporary mailbox and add 10 msgs
29 | New mailbox created
30 | Delete 4 messages for Unique ID generation
31 | array(6) {
32 | [0]=>
33 | int(1)
34 | [1]=>
35 | int(6)
36 | [2]=>
37 | int(2)
38 | [3]=>
39 | int(3)
40 | [4]=>
41 | int(4)
42 | [5]=>
43 | int(5)
44 | }
45 | array(6) {
46 | [0]=>
47 | int(1)
48 | [1]=>
49 | int(10)
50 | [2]=>
51 | int(2)
52 | [3]=>
53 | int(7)
54 | [4]=>
55 | int(8)
56 | [5]=>
57 | int(9)
58 | }
59 |
--------------------------------------------------------------------------------
/tests/imap_timeout_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_timeout() function : basic functionality
3 | --CREDITS--
4 | Olivier Doucet
5 | --EXTENSIONS--
6 | imap
7 | --SKIPIF--
8 |
11 | --FILE--
12 |
37 | --EXPECTF--
38 | GET values:
39 | int(%d)
40 | int(%d)
41 | int(%d)
42 | int(%d)
43 | SET values:
44 | bool(true)
45 | bool(true)
46 | bool(true)
47 | CHECK values:
48 | int(10)
49 | int(10)
50 | int(10)
51 |
--------------------------------------------------------------------------------
/tests/imap_undelete_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_undelete() function : basic functionality
3 | --CREDITS--
4 | Olivier Doucet
5 | --EXTENSIONS--
6 | imap
7 | --SKIPIF--
8 |
11 | --FILE--
12 |
24 | --CLEAN--
25 |
29 | --EXPECT--
30 | Create a temporary mailbox and add 1 msgs
31 | New mailbox created
32 | bool(true)
33 |
--------------------------------------------------------------------------------
/tests/imap_undelete_uid.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_undelete() passing a unique ID
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
9 | --FILE--
10 |
25 | --CLEAN--
26 |
30 | --EXPECT--
31 | Create a temporary mailbox and add 10 msgs
32 | New mailbox created
33 | Delete 4 messages for Unique ID generation
34 | array(6) {
35 | [0]=>
36 | int(1)
37 | [1]=>
38 | int(2)
39 | [2]=>
40 | int(7)
41 | [3]=>
42 | int(8)
43 | [4]=>
44 | int(9)
45 | [5]=>
46 | int(10)
47 | }
48 |
--------------------------------------------------------------------------------
/tests/imap_utf8.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_utf8() tests
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 |
14 | --EXPECT--
15 | string(0) ""
16 | string(1) "1"
17 | string(4) "test"
18 | Done
19 |
--------------------------------------------------------------------------------
/tests/imap_utf8_to_mutf7_basic.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | imap_utf8_to_mutf7
3 | --EXTENSIONS--
4 | imap
5 | --SKIPIF--
6 |
13 | --FILE--
14 |
22 | --EXPECT--
23 | string(0) ""
24 | string(1) "1"
25 | string(8) "t&AOQ-st"
26 | Done
27 |
--------------------------------------------------------------------------------
/tests/nil_constant.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | NIL constant is deprecated
3 | --EXTENSIONS--
4 | imap
5 | --FILE--
6 |
9 | --EXPECTF--
10 | Deprecated: Constant NIL is deprecated in %s on line %d
11 | int(0)
12 |
--------------------------------------------------------------------------------
/tests/setup/clean.inc:
--------------------------------------------------------------------------------
1 | Nmsgs; $i++) {
11 | imap_delete($imap_stream, $i);
12 | }
13 |
14 |
15 | $mailboxes = imap_getmailboxes($imap_stream, IMAP_SERVER, '*');
16 |
17 | if (!is_array($mailbox_suffix)) {
18 | $mailbox_suffixes = [$mailbox_suffix];
19 | } else {
20 | $mailbox_suffixes = $mailbox_suffix;
21 | }
22 |
23 | foreach ($mailbox_suffixes as $mailbox_suffix) {
24 | foreach($mailboxes as $value) {
25 | // Only delete mailbox with our prefix (+ optional test suffix)
26 | if (preg_match('/\{.*?\}INBOX\.' . IMAP_MAILBOX_PHPT_PREFIX . $mailbox_suffix .'$/', $value->name, $match) == 1) {
27 | imap_deletemailbox($imap_stream, $value->name);
28 | }
29 | }
30 | }
31 |
32 | imap_close($imap_stream, CL_EXPUNGE);
33 |
--------------------------------------------------------------------------------
/tests/setup/dovecot.conf:
--------------------------------------------------------------------------------
1 | # 2.2.33.2 (d6601f4ec): /etc/dovecot/dovecot.conf
2 | # Pigeonhole version 0.4.21 (92477967)
3 | listen = *, ::
4 |
5 | # For SSL need to setup a certificate
6 | # See https://wiki.dovecot.org/SSL/DovecotConfiguration
7 | ssl = no
8 |
9 | # Disable plaintext to prevent a warning at each login
10 | disable_plaintext_auth = yes
11 |
12 | auth_mechanisms = cram-md5
13 | auth_username_format = %u
14 | auth_verbose = yes
15 | auth_debug = yes
16 | auth_failure_delay = 1secs
17 |
18 | # This need dovecot 2.3.12.
19 | # login_proxy_timeout = 500milliseconds
20 | # ^ This would allow to kill login processes early, but needs testing. So would use v instead
21 | # login_proxy_timeout = 5s
22 | # There is a 1 second delay between each reconnection attempt.
23 | # https://doc.dovecot.org/settings/core/#login-proxy-max-reconnects
24 | # This need dovecot 2.3.12.
25 | # login_proxy_max_reconnects = 3
26 |
27 | # Log config
28 | log_path = /var/log/dovecot.log
29 | # If not set, use the value from log_path
30 | info_log_path = /var/log/dovecot-info.log
31 | # If not set, use the value from info_log_path
32 | debug_log_path = /var/log/dovecot-debug.log
33 | ## Mailbox locations and namespaces
34 | mail_location = maildir:/var/vmail/dovecot/mail/%d/%n/Maildir
35 | passdb {
36 | args = scheme=cram-md5 /etc/dovecot/dovecotpass
37 | driver = passwd-file
38 | }
39 | protocols = imap
40 | service auth {
41 | user = root
42 | }
43 | userdb {
44 | args = /etc/dovecot/dovecotpass
45 | driver = passwd-file
46 | override_fields = home=/var/vmail/dovecot/mail/%d/%n
47 | }
48 |
--------------------------------------------------------------------------------
/tests/setup/dovecotpass:
--------------------------------------------------------------------------------
1 | webmaster@example.com:{CRAM-MD5}be5f3177e9c7c06403272f25d983ba630df4ef40476b353bb3087a8401713451:vmail:vmail
2 |
--------------------------------------------------------------------------------
/tests/setup/imap_include.inc:
--------------------------------------------------------------------------------
1 | $mf;
46 | if ($mf == 'udate') {
47 | if (($z >= $start_time) && ($z <= time())) {
48 | echo "$mf is OK\n";
49 | } else {
50 | echo "$mf is BAD ($z)\n";
51 | }
52 | } else {
53 | echo "$mf is $z\n";
54 | }
55 | }
56 | }
57 |
58 |
59 | /**
60 | * Create a test mailbox and populate with msgs
61 | *
62 | * @param string mailbox_suffix Suffix used to uniquely identify mailboxes
63 | * @param int message_count number of test msgs to be written to new mailbox
64 | * @param null $new_mailbox
65 | * @param bool $simpleMessages
66 | * @param int $flags OP_* (or CL_EXPUNGE) flags to pass to imap_open() sub-call
67 | * @return resource IMAP stream to new mailbox
68 | * @throws Exception
69 | */
70 | function setup_test_mailbox(
71 | string $mailbox_suffix,
72 | int $message_count,
73 | &$new_mailbox = null,
74 | bool $simpleMessages = true,
75 | int $flags = 0,
76 | ){
77 | // open a stream to default mailbox
78 | $imap_stream = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD, flags: $flags);
79 |
80 | if ($imap_stream === false) {
81 | throw new Exception("Cannot connect to IMAP server " . IMAP_SERVER . ": " . imap_last_error());
82 | }
83 |
84 | echo "Create a temporary mailbox and add " . $message_count . " msgs\n";
85 | $new_mailbox = create_mailbox($imap_stream, $mailbox_suffix, $message_count, $simpleMessages);
86 |
87 | echo "New mailbox created\n";
88 |
89 | // reopen stream to new mailbox
90 | if (imap_reopen($imap_stream, $new_mailbox) === false) {
91 | throw new Exception("Can't re-open '$new_mailbox' mailbox: " . imap_last_error());
92 | }
93 |
94 | return $imap_stream;
95 | }
96 |
97 | /**
98 | * Create mailbox and fill with generic emails
99 | *
100 | * @param resource $imap_stream
101 | * @param string $mailbox_suffix
102 | * @param int $message_count
103 | * @param bool $simpleMessages
104 | * @return string
105 | * @throws Exception
106 | */
107 | function create_mailbox($imap_stream, string $mailbox_suffix, int $message_count, bool $simpleMessages = true): string {
108 | $mailbox = IMAP_DEFAULT_MAILBOX . '.' . IMAP_MAILBOX_PHPT_PREFIX . $mailbox_suffix;
109 |
110 | $mailboxes = imap_getmailboxes($imap_stream, $mailbox, '*');
111 |
112 | // check mailbox does not already exist
113 | if ($mailboxes) {
114 | foreach($mailboxes as $value) {
115 | if ($value->name == $mailbox) {
116 | throw new Exception("Mailbox '$mailbox' already exists");
117 | }
118 | }
119 | }
120 |
121 | if (imap_createmailbox($imap_stream, $mailbox) === false) {
122 | throw new Exception("Can't create a temporary mailbox: " . imap_last_error());
123 | }
124 |
125 | // Add number of test msgs requested
126 | if ($message_count > 0) {
127 | populate_mailbox($imap_stream, $mailbox, $message_count, $simpleMessages);
128 | }
129 |
130 | return $mailbox;
131 | }
132 |
133 | function setup_test_mailbox_for_uid_tests(string $mailbox_suffix, &$msg_no = null, &$msg_uid = null)
134 | {
135 | $mail_box = setup_test_mailbox($mailbox_suffix, 10);
136 | echo "Delete 4 messages for Unique ID generation\n";
137 | // Delete messages to remove the numerical ordering
138 | imap_delete($mail_box, 3);
139 | imap_delete($mail_box, 4);
140 | imap_delete($mail_box, 5);
141 | imap_delete($mail_box, 6);
142 | imap_expunge($mail_box);
143 | $msg_no = 5;
144 | $msg_uid = 9;
145 |
146 | return $mail_box;
147 | }
148 |
149 | /**
150 | * Populate a mailbox with generic emails
151 | *
152 | * @param resource $imap_stream
153 | * @param string $mailbox
154 | * @param int $message_count
155 | * @param bool $simpleMessages
156 | */
157 | function populate_mailbox($imap_stream, string $mailbox, int $message_count, bool $simpleMessages = true): void {
158 | for ($i = 1; $i <= $message_count; $i++) {
159 | if ($simpleMessages) {
160 | $msg = "From: foo@anywhere.com\r\n"
161 | . "To: ". IMAP_USERS[0] . "@" . IMAP_MAIL_DOMAIN . "\r\n"
162 | . "Subject: test$i\r\n"
163 | . "\r\n"
164 | . "$i: this is a test message, please ignore\r\nnewline";
165 | } else {
166 | $envelope["from"]= "foo@anywhere.com";
167 | $envelope["to"] = IMAP_USERS[0] . "@" . IMAP_MAIL_DOMAIN;
168 | $envelope["subject"] = "Test msg $i";
169 |
170 | $part1["type"] = TYPEMULTIPART;
171 | $part1["subtype"] = "mixed";
172 |
173 | $part2["type"] = TYPETEXT;
174 | $part2["subtype"] = "plain";
175 | $part2["description"] = "imap_mail_compose() function";
176 | $part2["contents.data"] = "message 1:xxxxxxxxxxxxxxxxxxxxxxxxxx";
177 |
178 | $part3["type"] = TYPETEXT;
179 | $part3["subtype"] = "plain";
180 | $part3["description"] = "Example";
181 | $part3["contents.data"] = "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy";
182 |
183 | $part4["type"] = TYPETEXT;
184 | $part4["subtype"] = "plain";
185 | $part4["description"] = "Return Values";
186 | $part4["contents.data"] = "message 3:zzzzzzzzzzzzzzzzzzzzzzzzzz";
187 |
188 | $body[1] = $part1;
189 | $body[2] = $part2;
190 | $body[3] = $part3;
191 | $body[4] = $part4;
192 |
193 | $msg = imap_mail_compose($envelope, $body);
194 | }
195 |
196 | imap_append($imap_stream, $mailbox, $msg);
197 | }
198 | }
199 |
200 | /**
201 | * Get the mailbox name from a mailbox description, i.e strip off server details.
202 | *
203 | * @param string mailbox complete mailbox name
204 | * @return string mailbox name
205 | */
206 | function get_mailbox_name(string $mailboxName): string {
207 |
208 | if (preg_match('/\{.*?\}(.*)/', $mailboxName, $match) != 1) {
209 | throw new Exception("Unrecognized mailbox name '$mailboxName'");
210 | }
211 |
212 | return $match[1];
213 | }
214 |
--------------------------------------------------------------------------------
/tests/setup/setup.sh:
--------------------------------------------------------------------------------
1 | sudo service dovecot stop
2 | sudo groupadd -g 5000 vmail
3 | sudo useradd -m -d /var/vmail -s /bin/false -u 5000 -g vmail vmail
4 | sudo cp ext/imap/tests/setup/dovecot.conf /etc/dovecot/dovecot.conf
5 | sudo cp ext/imap/tests/setup/dovecotpass /etc/dovecot/dovecotpass
6 | sudo service dovecot start
7 |
--------------------------------------------------------------------------------
/tests/setup/skipif.inc:
--------------------------------------------------------------------------------
1 |