Current File : /home/mmdealscpanel/yummmdeals.com/alt-php84-pecl-imap_1.0.3-1.el8.zip
PK#�ZX��:��tests/imap_close_basic.phptnu�[���--TEST--
Test imap_close() function : basic functionality
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
echo "*** Testing imap_close() : basic functionality ***\n";

// include file for required variables in imap_open()
require_once(__DIR__.'/setup/imap_include.inc');

// Initialize required variables
$stream_id = setup_test_mailbox('imapclosebasic', 3, $mailbox); // set up temp mailbox with 3 messages
$options = CL_EXPUNGE;

// mark messages in inbox for deletion
for ($i = 1; $i < 4; $i++) {
    imap_delete($stream_id, $i);
}

// Calling imap_close() with all possible arguments
echo "\n-- Call to imap_close() with all possible arguments --\n";
var_dump( imap_close($stream_id, $options) );

// check that CL_EXPUNGE worked
$stream_id = imap_open($mailbox, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD);
echo "There are now " . imap_num_msg($stream_id) . " msgs in mailbox '$mailbox'\n";

// Calling imap_close() with mandatory arguments
echo "\n-- Call to imap_close() with mandatory arguments --\n";
var_dump( imap_close($stream_id) );
?>
--CLEAN--
<?php
$mailbox_suffix = 'imapclosebasic';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECTF--
*** Testing imap_close() : basic functionality ***
Create a temporary mailbox and add 3 msgs
New mailbox created

-- Call to imap_close() with all possible arguments --
bool(true)
There are now 0 msgs in mailbox '%sINBOX.phpttestimapclosebasic'

-- Call to imap_close() with mandatory arguments --
bool(true)
PK#�Z/��a[[tests/gh9309.phptnu�[���--TEST--
Bug GH-9309 (Segfault when connection is used after imap_close())
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
require_once(__DIR__.'/setup/imap_include.inc');
$stream_id = setup_test_mailbox('gh9309', 0, $mailbox);
imap_close($stream_id);
try {
    imap_headers($stream_id);
} catch (ValueError $ex) {
    echo $ex->getMessage(), PHP_EOL;
}
?>
--CLEAN--
<?php
$mailbox_suffix = 'gh9309';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECT--
Create a temporary mailbox and add 0 msgs
New mailbox created
IMAP\Connection is already closed
PK#�Z%�ˬ�tests/imap_savebody_uid.phptnu�[���--TEST--
imap_savebody() passing a unique ID
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');

$imap_mail_box = setup_test_mailbox_for_uid_tests("imapsavebodyuid", $msg_no, $uid);

$section = '';

$stream_uid = fopen('php://memory', 'w+');
imap_savebody($imap_mail_box, $stream_uid, $uid, $section, FT_UID);

$stream_msg_no = fopen('php://memory', 'w+');
imap_savebody($imap_mail_box, $stream_msg_no, $msg_no, $section);

// Compare what was written.
rewind($stream_uid);
rewind($stream_msg_no);
var_dump(stream_get_contents($stream_uid) === stream_get_contents($stream_msg_no));

imap_close($imap_mail_box);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapsavebodyuid';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECT--
Create a temporary mailbox and add 10 msgs
New mailbox created
Delete 4 messages for Unique ID generation
bool(true)
PK#�ZV�W��)tests/imap_fetch_overview_variation5.phptnu�[���--TEST--
Test imap_fetch_overview() function : usage variations - $msg_no argument
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
/*
 * Pass different sequences/msg numbers as $msg_no argument to test behaviour
 * of imap_fetch_overview()
 */

echo "*** Testing imap_fetch_overview() : usage variations ***\n";
require_once __DIR__.'/setup/imap_include.inc';

$stream_id = setup_test_mailbox('imapfetchoverviewvar5', 3, $mailbox, false); // set up temp mailbox with 3 msgs

$sequences = [
    0,
    4, // out of range
    '4', // out of range
    '2',
    '1,3',
    '1, 2',
    '1:3', // pass uid without setting FT_UID option
];

foreach ($sequences as $msg_no) {
    echo "\n-- \$msg_no is $msg_no --\n";
    $overview = imap_fetch_overview($stream_id, $msg_no);
    if (!$overview) {
        echo imap_last_error() . "\n";
    } else {
        foreach($overview as $ov) {
            echo "\n";
            displayOverviewFields($ov);
        }
    }
}

// clear error stack
imap_errors();
?>
--CLEAN--
<?php
$mailbox_suffix = 'imapfetchoverviewvar5';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECTF--
*** Testing imap_fetch_overview() : usage variations ***
Create a temporary mailbox and add 3 msgs
New mailbox created

-- $msg_no is 0 --
Sequence out of range

-- $msg_no is 4 --
Sequence out of range

-- $msg_no is 4 --
Sequence out of range

-- $msg_no is 2 --

size is %d
uid is %d
msgno is 2
recent is %d
flagged is 0
answered is 0
deleted is 0
seen is 0
draft is 0
udate is OK

-- $msg_no is 1,3 --

size is %d
uid is %d
msgno is 1
recent is %d
flagged is 0
answered is 0
deleted is 0
seen is 0
draft is 0
udate is OK

size is %d
uid is %d
msgno is 3
recent is %d
flagged is 0
answered is 0
deleted is 0
seen is 0
draft is 0
udate is OK

-- $msg_no is 1, 2 --
Syntax error in sequence

-- $msg_no is 1:3 --

size is %d
uid is %d
msgno is 1
recent is %d
flagged is 0
answered is 0
deleted is 0
seen is 0
draft is 0
udate is OK

size is %d
uid is %d
msgno is 2
recent is %d
flagged is 0
answered is 0
deleted is 0
seen is 0
draft is 0
udate is OK

size is %d
uid is %d
msgno is 3
recent is %d
flagged is 0
answered is 0
deleted is 0
seen is 0
draft is 0
udate is OK
PK$�Z�:�Ċ�tests/bug75774.phptnu�[���--TEST--
Bug #75774 imap_append HeapCorruction
--EXTENSIONS--
imap
--FILE--
<?php

$fn = __DIR__ . DIRECTORY_SEPARATOR . "foo75774";
$var1 = fopen($fn, "w");

try {
    imap_append($var1, "", "", "", "");
} catch (\TypeError $e) {
    echo $e->getMessage() . "\n";
}

fclose($var1);
unlink($fn);

?>
--EXPECT--
imap_append(): Argument #1 ($imap) must be of type IMAP\Connection, resource given
PK$�ZKP7rrtests/imap_body_errors.phptnu�[���--TEST--
imap_body() errors: ValueError and Warnings
--CREDITS--
Paul Sohier
#phptestfest utrecht
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');

$imap_mail_box = setup_test_mailbox("imapbodyerror", 0);

try {
    imap_body($imap_mail_box, -1);
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}
try {
    imap_body($imap_mail_box, 1, -1);
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}

// Access not existing
var_dump(imap_body($imap_mail_box, 255));
var_dump(imap_body($imap_mail_box, 255, FT_UID));

imap_close($imap_mail_box);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapbodyerror';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECTF--
Create a temporary mailbox and add 0 msgs
New mailbox created
imap_body(): Argument #2 ($message_num) must be greater than 0
imap_body(): Argument #3 ($flags) must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL

Warning: imap_body(): Bad message number in %s on line %d
bool(false)

Warning: imap_body(): UID does not exist in %s on line %d
bool(false)
PK$�Z~�:}kktests/imap_body_uid.phptnu�[���--TEST--
imap_body() passing a unique ID
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');

$imap_mail_box = setup_test_mailbox_for_uid_tests("imapbodyuid", $msg_no, $uid);

var_dump(imap_body($imap_mail_box, $uid, FT_UID) === imap_body($imap_mail_box, $msg_no));

imap_close($imap_mail_box);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapbodyuid';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECT--
Create a temporary mailbox and add 10 msgs
New mailbox created
Delete 4 messages for Unique ID generation
bool(true)
PK$�Z��4%%"tests/imap_clearflag_full_uid.phptnu�[���--TEST--
imap_clearflag_full() passing a unique ID
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');

$imap_mail_box = setup_test_mailbox_for_uid_tests("imapclearflagfulluid");

/* This works on the assumption that UID message 3 to 6 inclusive are deleted. */

imap_setflag_full($imap_mail_box, '2,8,9', '\Answered', ST_UID);
imap_setflag_full($imap_mail_box, '7,10', '\Deleted', ST_UID);
imap_setflag_full($imap_mail_box, '7:9', '\Flagged', ST_UID);

// Testing individual entry
imap_clearflag_full($imap_mail_box, '10', '\Deleted', ST_UID);
// Testing multiple entries entry
imap_clearflag_full($imap_mail_box, '2,9', '\Answered', ST_UID);
// Testing entry range
imap_clearflag_full($imap_mail_box, '7:8', '\Flagged', ST_UID);


echo 'ALL: ';
var_dump(imap_search($imap_mail_box, 'ALL'));
echo 'ALL (with UID correspondance): ';
var_dump(imap_search($imap_mail_box, 'ALL', SE_UID));
echo 'ANSWERED: ';
var_dump(imap_search($imap_mail_box, 'ANSWERED'));
echo 'DELETED: ';
var_dump(imap_search($imap_mail_box, 'DELETED'));
echo 'FLAGGED: ';
var_dump(imap_search($imap_mail_box, 'FLAGGED'));

imap_close($imap_mail_box);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapclearflagfulluid';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECT--
Create a temporary mailbox and add 10 msgs
New mailbox created
Delete 4 messages for Unique ID generation
ALL: array(6) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  int(4)
  [4]=>
  int(5)
  [5]=>
  int(6)
}
ALL (with UID correspondance): array(6) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(7)
  [3]=>
  int(8)
  [4]=>
  int(9)
  [5]=>
  int(10)
}
ANSWERED: array(1) {
  [0]=>
  int(4)
}
DELETED: array(1) {
  [0]=>
  int(3)
}
FLAGGED: array(1) {
  [0]=>
  int(5)
}
PK$�Z�]�Itests/bug80215.phptnu�[���--TEST--
Bug #80215 (imap_mail_compose() may modify by-val parameters)
--EXTENSIONS--
imap
--FILE--
<?php
$envelope = [
    "from" => 1,
    "to" => 2,
    "custom_headers" => [3],
];
$body = [[
    "contents.data" => 4,
    "type.parameters" => ['foo' => 5],
    "disposition" => ['bar' => 6],
], [
    "contents.data" => 7,
    "type.parameters" => ['foo' => 8],
    "disposition" => ['bar' => 9],
]];
imap_mail_compose($envelope, $body);
var_dump($envelope, $body);
?>
--EXPECT--
array(3) {
  ["from"]=>
  int(1)
  ["to"]=>
  int(2)
  ["custom_headers"]=>
  array(1) {
    [0]=>
    int(3)
  }
}
array(2) {
  [0]=>
  array(3) {
    ["contents.data"]=>
    int(4)
    ["type.parameters"]=>
    array(1) {
      ["foo"]=>
      int(5)
    }
    ["disposition"]=>
    array(1) {
      ["bar"]=>
      int(6)
    }
  }
  [1]=>
  array(3) {
    ["contents.data"]=>
    int(7)
    ["type.parameters"]=>
    array(1) {
      ["foo"]=>
      int(8)
    }
    ["disposition"]=>
    array(1) {
      ["bar"]=>
      int(9)
    }
  }
}
PK$�Z6;0���tests/imap_final.phptnu�[���--TEST--
Check that IMAP\Connection is declared final
--EXTENSIONS--
imap
--FILE--
<?php

class T extends IMAP\Connection {}
?>
--EXPECTF--
Fatal error: Class T cannot extend final class IMAP\Connection in %s on line %d
PK$�Z"��g
g
)tests/imap_fetch_overview_variation6.phptnu�[���--TEST--
Test imap_fetch_overview() function : usage variations - multipart message
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
/*
 * Pass a multipart message to imap_fetch_overview() to test the contents of returned array
 */

echo "*** Testing imap_fetch_overview() : usage variations ***\n";

require_once __DIR__.'/setup/imap_include.inc';

$stream_id = setup_test_mailbox('imapfetchoverviewvar6', 0, $mailbox); // setup temp mailbox
create_multipart_message($stream_id, $mailbox);

// refresh msg numbers
imap_check($stream_id);
$msg_no = 1;

$a = imap_fetch_overview($stream_id, $msg_no);
echo "\n--> Object #1\n";
displayOverviewFields($a[0]);




/**
 * Create a multipart message with subparts
 *
 * @param resource $imap_stream
 * @param string $mailbox
 */
function create_multipart_message($imap_stream, $mailbox) {
    global $users, $domain;
    $envelope["from"]= "foo@anywhere.com";
    $envelope["to"]  = IMAP_USERS[0] . '@' . IMAP_MAIL_DOMAIN;
    $envelope["subject"] = "Test msg 1";

    $part1["type"] = TYPEMULTIPART;
    $part1["subtype"] = "mixed";

    $part2["type"] = TYPETEXT;
    $part2["subtype"] = "plain";
    $part2["description"] = "imap_mail_compose() function";
    $part2["contents.data"] = "message 1:xxxxxxxxxxxxxxxxxxxxxxxxxx";

    $part3["type"] = TYPETEXT;
    $part3["subtype"] = "plain";
    $part3["description"] = "Example";
    $part3["contents.data"] = "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy";

    $file_handle = fopen(__FILE__, 'r+');
    $file_size = 1;

    $part4["type"] = TYPEAPPLICATION;
    $part4["encoding"] = ENCBASE64;
    $part4["subtype"] = "octet-stream";
    $part4["description"] = 'Test';
    $part4['disposition.type'] = 'attachment';
    $part4['disposition'] = array ('filename' => 'Test');
    $part4['type.parameters'] = array('name' => 'Test');
    $part4["contents.data"] = base64_encode(fread($file_handle, 1));

    $body[1] = $part1;
    $body[2] = $part2;
    $body[3] = $part3;
    $body[4] = $part4;

    $msg = imap_mail_compose($envelope, $body);

    if (imap_append($imap_stream, $mailbox, $msg) === false) {
        echo imap_last_error() . "\n";
        echo "TEST FAILED : could not append new message to mailbox '$mailbox'\n";
        exit;
    }
}

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapfetchoverviewvar6';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECTF--
*** Testing imap_fetch_overview() : usage variations ***
Create a temporary mailbox and add 0 msgs
New mailbox created

--> Object #1
size is %d
uid is %d
msgno is 1
recent is %d
flagged is 0
answered is 0
deleted is 0
seen is 0
draft is 0
udate is OK
PK$�Z����tests/bug63126.phptnu�[���--TEST--
imap_open() DISABLE_AUTHENTICATOR ignores array param
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__. '/setup/imap_include.inc');

$in = @imap_open(IMAP_SERVER_DEBUG, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD, OP_HALFOPEN, 1);
if (!$in) {
    die("skip could not connect to mailbox " . IMAP_SERVER_DEBUG);
}
$kerberos = false;
if (is_array($errors = imap_errors())) {
    foreach ($errors as $err) {
        if (strstr($err, 'GSSAPI') || strstr($err, 'Kerberos')) {
            $kerberos = true;
        }
    }
}
if (!$kerberos) {
    die("skip need a GSSAPI/Kerberos aware server");
}
?>
--CONFLICTS--
defaultmailbox
--FILE--
<?php
// TODO Test Kerberos on CI
$tests = array(
    'Array'  => array('DISABLE_AUTHENTICATOR' => array('GSSAPI','NTLM')),
    'String' => array('DISABLE_AUTHENTICATOR' => 'GSSAPI'),
);
require_once(__DIR__. '/setup/imap_include.inc');
foreach ($tests as $name => $testparams) {
    echo "Test for $name\n";
    $in = imap_open(IMAP_SERVER_DEBUG, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD, OP_HALFOPEN, 1, $testparams);
    if ($in) {
        if (is_array($errors = imap_errors())) {
            foreach ($errors as $err) {
                if (strstr($err, 'GSSAPI') || strstr($err, 'Kerberos')) {
                    echo "$err\n";
                }
            }
        }
    } else {
        echo "Can't connect\n";
    }
}
echo "Done\n";
?>
--EXPECT--
Test for Array
Test for String
Done
PK$�Z��p�hhtests/imap_binary_basic.phptnu�[���--TEST--
Test imap_binary() function : basic functionality
--EXTENSIONS--
imap
--FILE--
<?php
echo "*** Testing imap_binary() : basic functionality ***\n";

echo "Encode as short string\n";
$str = 'This is an example string to be base 64 encoded';
$base64 = imap_binary($str);
var_dump(bin2hex($base64));

echo "Encode a string which results in more than 60 charters of output\n";
$str = 'This is a long string with results in more than 60 characters of output';
$base64 = imap_binary($str);
var_dump(bin2hex($base64));

echo "Encode a string with special characters\n";
$str = '_+-={][];;@~#?/>.<,';
$base64 = imap_binary($str);
var_dump(bin2hex($base64));

echo "Encode some hexadecimal data\n";
$hex = 'x00\x01\x02\x03\x04\x05\x06\xFA\xFB\xFC\xFD\xFE\xFF';
$base64 = imap_binary($hex);
var_dump(bin2hex($base64));

?>
--EXPECT--
*** Testing imap_binary() : basic functionality ***
Encode as short string
string(136) "5647687063794270637942686269426c654746746347786c49484e30636d6c755a794230627942695a53426959584e6c49445930494756755932396b0d0a5a57513d0d0a"
Encode a string which results in more than 60 charters of output
string(200) "56476870637942706379426849477876626d6367633352796157356e4948647064476767636d567a64577830637942706269427462334a6c4948526f0d0a595734674e6a416759326868636d466a64475679637942765a694276645852776458513d0d0a"
Encode a string with special characters
string(60) "5879737450587464573130374f30422b497a3876506934384c413d3d0d0a"
Encode some hexadecimal data
string(144) "65444177584867774d5678344d444a636544417a584867774e4678344d445663654441325848684751567834526b4a6365455a4458486847524678340d0a526b566365455a470d0a"
PK$�Z�_]��tests/imap_fetchbody_uid.phptnu�[���--TEST--
imap_fetchbody() passing a unique ID
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');

$imap_mail_box = setup_test_mailbox_for_uid_tests("imapfetchbodyuid", $msg_no, $uid);

$section = '2';
var_dump(imap_fetchbody($imap_mail_box, $uid, $section, FT_UID) === imap_fetchbody($imap_mail_box, $msg_no, $section));

imap_close($imap_mail_box);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapfetchbodyuid';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECT--
Create a temporary mailbox and add 10 msgs
New mailbox created
Delete 4 messages for Unique ID generation
bool(true)
PK$�Z�0~ك� tests/imap_setflag_full_uid.phptnu�[���--TEST--
imap_setflag_full() passing a unique ID
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');

$imap_mail_box = setup_test_mailbox_for_uid_tests("imapsetflagfulluid");

/* This works on the assumption that UID message 3 to 6 inclusive are deleted. */

// Testing individual entry
imap_setflag_full($imap_mail_box, '8', '\Answered', ST_UID);

// Testing multiple entries entry
imap_setflag_full($imap_mail_box, '7,10', '\Deleted', ST_UID);

// Testing entry range
imap_setflag_full($imap_mail_box, '7:9', '\Flagged', ST_UID);

// Testing entry range invalid
var_dump(imap_setflag_full($imap_mail_box, '4:9', '\Seen', ST_UID));


echo 'ALL: ';
var_dump(imap_search($imap_mail_box, 'ALL'));
echo 'ALL (with UID correspondance): ';
var_dump(imap_search($imap_mail_box, 'ALL', SE_UID));
echo 'ANSWERED: ';
var_dump(imap_search($imap_mail_box, 'ANSWERED'));
echo 'DELETED: ';
var_dump(imap_search($imap_mail_box, 'DELETED'));
echo 'FLAGGED: ';
var_dump(imap_search($imap_mail_box, 'FLAGGED'));
echo 'SEEN: ';
var_dump(imap_search($imap_mail_box, 'SEEN'));

imap_close($imap_mail_box);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapsetflagfulluid';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECT--
Create a temporary mailbox and add 10 msgs
New mailbox created
Delete 4 messages for Unique ID generation
bool(true)
ALL: array(6) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  int(4)
  [4]=>
  int(5)
  [5]=>
  int(6)
}
ALL (with UID correspondance): array(6) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(7)
  [3]=>
  int(8)
  [4]=>
  int(9)
  [5]=>
  int(10)
}
ANSWERED: array(1) {
  [0]=>
  int(4)
}
DELETED: array(2) {
  [0]=>
  int(3)
  [1]=>
  int(6)
}
FLAGGED: array(3) {
  [0]=>
  int(3)
  [1]=>
  int(4)
  [2]=>
  int(5)
}
SEEN: array(3) {
  [0]=>
  int(3)
  [1]=>
  int(4)
  [2]=>
  int(5)
}
PK$�Z�E  tests/bug80226.phptnu�[���--TEST--
Bug #80226 (imap_sort() leaks sortpgm memory)
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
require_once(__DIR__.'/setup/imap_include.inc');

echo "Create a new mailbox for test\n";

$stream = setup_test_mailbox("bug80226", 0);
var_dump(imap_sort($stream, SORTFROM, 0));
?>
--CLEAN--
<?php
$mailbox_suffix = 'bug80226';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECT--
Create a new mailbox for test
Create a temporary mailbox and add 0 msgs
New mailbox created
array(0) {
}
PK$�Z��#tests/imap_renamemailbox_basic.phptnu�[���--TEST--
imap_renamemailbox() function : basic functionality
--CREDITS--
Olivier Doucet
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');

$stream_id = setup_test_mailbox('imaprenamemailbox1', 1);

$mailboxBaseName = IMAP_DEFAULT_MAILBOX . '.' . IMAP_MAILBOX_PHPT_PREFIX;

//commented because of bug #49901
//$ancError = error_reporting(0);
//$z = imap_renamemailbox($stream_id, $newbox.'not2', $newbox.'2');
//var_dump($z);
//error_reporting($ancError);
echo "Checking OK\n";

var_dump(imap_renamemailbox($stream_id, $mailboxBaseName . 'imaprenamemailbox1', $mailboxBaseName . 'imaprenamemailbox2'));

imap_close($stream_id);
?>
--CLEAN--
<?php
$mailbox_suffix = ['imaprenamemailbox1', 'imaprenamemailbox2'];
require_once('setup/clean.inc');
?>
--EXPECT--
Create a temporary mailbox and add 1 msgs
New mailbox created
Checking OK
bool(true)
PK$�Z�1��=="tests/imap_setflag_full_basic.phptnu�[���--TEST--
imap_setflag_full() basic test
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');

$imap_mail_box = setup_test_mailbox("imapsetflagfullbasic", 10);

// Testing individual entry
imap_setflag_full($imap_mail_box, '1', '\Answered');

// Testing multiple entries entry
imap_setflag_full($imap_mail_box, '2,7', '\Deleted');

// Testing entry range
imap_setflag_full($imap_mail_box, '3:5', '\Flagged');

echo 'ALL: ';
var_dump(imap_search($imap_mail_box, 'ALL'));
echo 'ANSWERED: ';
var_dump(imap_search($imap_mail_box, 'ANSWERED'));
echo 'DELETED: ';
var_dump(imap_search($imap_mail_box, 'DELETED'));
echo 'FLAGGED: ';
var_dump(imap_search($imap_mail_box, 'FLAGGED'));

imap_close($imap_mail_box);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapsetflagfullbasic';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECT--
Create a temporary mailbox and add 10 msgs
New mailbox created
ALL: array(10) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  int(4)
  [4]=>
  int(5)
  [5]=>
  int(6)
  [6]=>
  int(7)
  [7]=>
  int(8)
  [8]=>
  int(9)
  [9]=>
  int(10)
}
ANSWERED: array(1) {
  [0]=>
  int(1)
}
DELETED: array(2) {
  [0]=>
  int(2)
  [1]=>
  int(7)
}
FLAGGED: array(3) {
  [0]=>
  int(3)
  [1]=>
  int(4)
  [2]=>
  int(5)
}
PK$�ZX�/�**tests/imap_lsub_basic.phptnu�[���--TEST--
imap_lsub() function : basic functionality
--CREDITS--
Olivier Doucet
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
if (getenv("SKIP_ASAN")) die("xleak leak sanitizer crashes");
?>
--CONFLICTS--
defaultmailbox
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');
$stream_id = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD) or
    die("Cannot connect to mailbox " .IMAP_DEFAULT_MAILBOX. ": " . imap_last_error());

var_dump(imap_lsub($stream_id, IMAP_DEFAULT_MAILBOX, 'ezDvfXvbvcxSerz'));


echo "Checking OK\n";

$newbox = IMAP_DEFAULT_MAILBOX . "." . IMAP_MAILBOX_PHPT_PREFIX;

imap_createmailbox($stream_id, $newbox);
imap_subscribe($stream_id, $newbox);

$z = imap_lsub($stream_id, IMAP_DEFAULT_MAILBOX, '*');

var_dump(is_array($z));

// e.g. "{127.0.0.1:143/norsh}INBOX.phpttest"
var_dump($z[0]);

imap_close($stream_id);
?>
--CLEAN--
<?php
$mailbox_suffix = '';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECTF--
bool(false)
Checking OK
bool(true)
string(%s) "{%s}%s"
PK$�Z"@�MMtests/bug77020.phptnu�[���--TEST--
Bug #77020 (null pointer dereference in imap_mail)
--EXTENSIONS--
imap
--INI--
sendmail_path="echo >/dev/null"
--FILE--
<?php
// For Windows, set it to a string of length HOST_NAME_LEN (256) so the mail is not actually sent
ini_set("SMTP", str_repeat("A", 256));

@imap_mail('1', 1, NULL);
echo 'done'
?>
--EXPECTF--
%Adone
PK$�Z����tests/imap_timeout_basic.phptnu�[���--TEST--
imap_timeout() function : basic functionality
--CREDITS--
Olivier Doucet
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

echo "GET values:\n";
var_dump(imap_timeout(IMAP_OPENTIMEOUT));
var_dump(imap_timeout(IMAP_READTIMEOUT));
var_dump(imap_timeout(IMAP_WRITETIMEOUT));
var_dump(imap_timeout(IMAP_CLOSETIMEOUT));

echo "SET values:\n";
var_dump(imap_timeout(IMAP_OPENTIMEOUT, 10));
var_dump(imap_timeout(IMAP_READTIMEOUT, 10));
var_dump(imap_timeout(IMAP_WRITETIMEOUT, 10));

//IMAP_CLOSETIMEOUT not implemented
//var_dump(imap_timeout(IMAP_CLOSETIMEOUT, 10));

echo "CHECK values:\n";
var_dump(imap_timeout(IMAP_OPENTIMEOUT));
var_dump(imap_timeout(IMAP_READTIMEOUT));
var_dump(imap_timeout(IMAP_WRITETIMEOUT));

//IMAP_CLOSETIMEOUT not implemented
//var_dump(imap_timeout(IMAP_CLOSETIMEOUT));

?>
--EXPECTF--
GET values:
int(%d)
int(%d)
int(%d)
int(%d)
SET values:
bool(true)
bool(true)
bool(true)
CHECK values:
int(10)
int(10)
int(10)
PK$�ZK����tests/imap_utf8.phptnu�[���--TEST--
imap_utf8() tests
--EXTENSIONS--
imap
--FILE--
<?php

var_dump(imap_utf8(""));
var_dump(imap_utf8(1));
var_dump(imap_utf8("test"));

echo "Done\n";
?>
--EXPECT--
string(0) ""
string(1) "1"
string(4) "test"
Done
PK$�Z��3�TTtests/imap_savebody_basic.phptnu�[���--TEST--
imap_savebody() function : basic functionality
--CREDITS--
Olivier Doucet
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');
$stream_id = setup_test_mailbox('imapsavebodybasic', 1);

$file = __DIR__.'/tmpsavebody.txt';

//with URL
$z = imap_savebody($stream_id, $file, 1);
var_dump($z);
echo "Size: ".filesize($file)."\n";

//With FOPEN
$fp = fopen($file, 'w');
$z = imap_savebody($stream_id, $fp, 1);
fclose($fp);
var_dump($z);
echo "Size: ".filesize($file)."\n";

imap_close($stream_id);
?>
--CLEAN--
<?php
@unlink(__DIR__.'/tmpsavebody.txt');
$mailbox_suffix = 'imapsavebodybasic';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECTF--
Create a temporary mailbox and add 1 msgs
New mailbox created
bool(true)
Size: %d
bool(true)
Size: %d
PK%�Z���stests/imap_8bit_basic.phptnu�[���--TEST--
Test imap_8bit() function : basic functionality
--EXTENSIONS--
imap
--FILE--
<?php
echo "*** Testing imap_8bit() : basic functionality ***\n";

var_dump(imap_8bit("String with CRLF at end \r\n"));
//NB this appears to be a bug in cclient; a space at end of string should be encoded as =20
var_dump(imap_8bit("String with space at end "));
var_dump(imap_8bit("String with tabs \t\t in middle"));
var_dump(imap_8bit("String with tab at end \t"));
var_dump(imap_8bit("\x00\x01\x02\x03\x04\xfe\xff\x0a\x0d"));

?>
--EXPECT--
*** Testing imap_8bit() : basic functionality ***
string(28) "String with CRLF at end=20
"
string(25) "String with space at end "
string(33) "String with tabs =09=09 in middle"
string(26) "String with tab at end =09"
string(27) "=00=01=02=03=04=FE=FF=0A=0D"
PK%�Z3}�\��tests/bug46918.phptnu�[���--TEST--
Bug #46918 (imap_rfc822_parse_adrlist host part not filled in correctly)
--EXTENSIONS--
imap
--FILE--
<?php

$adds = 'ian eiloart <iane@example.ac.uk>,
      shuf6@example.ac.uk,
      blobby,
      "ian,eiloart"<ian@example.ac.uk>,
      <@example.com:foo@example.ac.uk>,
      foo@#,
      ian@-example.com,
      ian@one@two';
$add_arr = imap_rfc822_parse_adrlist($adds, 'example.com');
var_export($add_arr);

?>
--EXPECT--
array (
  0 => 
  (object) array(
     'mailbox' => 'iane',
     'host' => 'example.ac.uk',
     'personal' => 'ian eiloart',
  ),
  1 => 
  (object) array(
     'mailbox' => 'shuf6',
     'host' => 'example.ac.uk',
  ),
  2 => 
  (object) array(
     'mailbox' => 'blobby',
     'host' => 'example.com',
  ),
  3 => 
  (object) array(
     'mailbox' => 'ian',
     'host' => 'example.ac.uk',
     'personal' => 'ian,eiloart',
  ),
  4 => 
  (object) array(
     'mailbox' => 'foo',
     'host' => 'example.ac.uk',
     'adl' => '@example.com',
  ),
  5 => 
  (object) array(
     'mailbox' => 'foo',
     'host' => '#',
  ),
  6 => 
  (object) array(
     'mailbox' => 'ian',
     'host' => '-example.com',
  ),
  7 => 
  (object) array(
     'mailbox' => 'ian',
     'host' => 'one',
  ),
  8 => 
  (object) array(
     'mailbox' => 'UNEXPECTED_DATA_AFTER_ADDRESS',
     'host' => '.SYNTAX-ERROR.',
  ),
)
Notice: PHP Request Shutdown: Unexpected characters at end of address: @two (errflg=3) in Unknown on line 0
PK%�Z'��tests/imap_body_basic.phptnu�[���--TEST--
Test imap_body() function : basic functionality
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
echo "*** Testing imap_body() : basic functionality ***\n";

require_once(__DIR__.'/setup/imap_include.inc');

echo "Create a new mailbox for test\n";
$imap_stream = setup_test_mailbox("imapbodybasic", 1);

$check = imap_check($imap_stream);
echo "Msg Count in new mailbox: ". $check->Nmsgs . "\n";

// show body for msg 1
var_dump(imap_body($imap_stream, 1));

//Access via FT_UID
var_dump(imap_body($imap_stream, 1, FT_UID));

imap_close($imap_stream);
?>
--CLEAN--
<?php
$mailbox_suffix = 'imapbodybasic';
require_once __DIR__.'/setup/clean.inc';
?>
--EXPECTF--
*** Testing imap_body() : basic functionality ***
Create a new mailbox for test
Create a temporary mailbox and add 1 msgs
New mailbox created
Msg Count in new mailbox: 1
string(%d) "1: this is a test message, please ignore
newline%r\R?%r"
string(%d) "1: this is a test message, please ignore
newline%r\R?%r"
PK%�Z=tests/imap_mail_copy_basic.phptnu�[���--TEST--
Test imap_mail_copy() function : basic functionality
--CREDITS--
Olivier Doucet
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
echo "*** Testing imap_mail_copy() : basic functionality ***\n";

require_once(__DIR__.'/setup/imap_include.inc');

echo "Create a new mailbox for test\n";
$imap_stream = setup_test_mailbox('copybasic', 1);

$check = imap_check($imap_stream);
echo "Msg Count in new mailbox: ". $check->Nmsgs . "\n";

var_dump(imap_mail_copy($imap_stream, '1', 'INBOX.' . IMAP_MAILBOX_PHPT_PREFIX  . 'copybasic'));

imap_close($imap_stream);
?>
--CLEAN--
<?php
$mailbox_suffix = 'copybasic';
require_once('setup/clean.inc');
?>
--EXPECT--
*** Testing imap_mail_copy() : basic functionality ***
Create a new mailbox for test
Create a temporary mailbox and add 1 msgs
New mailbox created
Msg Count in new mailbox: 1
bool(true)
PK%�Z����tests/bug35669.phptnu�[���--TEST--
Bug #35669 (imap_mail_compose() crashes with multipart-multiboundary-email)
--EXTENSIONS--
imap
--FILE--
<?php
$envelope["from"] = 'Santa <somewhere@northpole.gov>';
$envelope["to"]  = 'The bad smurf <bad@smurf.com>';
$envelope['date'] = 'Wed, 04 Jan 2006 19:24:43 -0500';

$multipart["type"] = TYPEMULTIPART;
$multipart["subtype"] = "MIXED";
$body[] = $multipart; //add multipart stuff

$textpart["type"] = TYPEMULTIPART;
$textpart["subtype"] = "ALTERNATIVE";
$body[] = $textpart; //add body part

$plain["type"] = TYPETEXT;
$plain["subtype"] = "PLAIN";
$plain["charset"] = "iso-8859-1";
$plain["encoding"] = ENCQUOTEDPRINTABLE;
$plain["description"] = "Plaintype part of message";
$plain['disposition'] = "inline";
$plain["contents.data"] = 'See mom, it will crash';

$body[] = $plain; //next add plain text part

$html["type"] = TYPETEXT;
$html["subtype"] = "HTML";
$html["charset"] = "iso-8859-1";
$html["encoding"] = ENCQUOTEDPRINTABLE;
$html["description"] = "HTML part of message";
$html['disposition'] = "inline";
$html["contents.data"] = 'See mom, it will <b>crash</b>';

$body[] = $html;

echo imap_mail_compose($envelope, $body);
?>
--EXPECTF--
Date: Wed, 04 Jan 2006 19:24:43 -0500
From: Santa <somewhere@northpole.gov>
To: The bad smurf <bad@smurf.com>
MIME-Version: 1.0
Content-Type: MULTIPART/MIXED; BOUNDARY="%s"

--%s
Content-Type: TEXT/ALTERNATIVE; CHARSET=US-ASCII


--%s
Content-Type: TEXT/PLAIN; CHARSET=iso-8859-1
Content-Transfer-Encoding: QUOTED-PRINTABLE
Content-Description: Plaintype part of message

See mom, it will crash
--%s
Content-Type: TEXT/HTML; CHARSET=iso-8859-1
Content-Transfer-Encoding: QUOTED-PRINTABLE
Content-Description: HTML part of message

See mom, it will <b>crash</b>
--%s--
PK%�Z���9��tests/README.mdnu�[���# The imap extension tests

Many of the tests in this directory require a mail server to be running, if
there is no mail server the test will skip and warn, see skipif.inc for details.

To make the tests run parameters in the `skipif.inc` and `imap_include.inc`
files will need to be changed to match the local mailserver configuration.

The tests have been checked using dovecot (on Linux 32 and 64 bit systems) and
hMailServer on Windows. The tests are intended to be mailserver agnostic.

## Set-up tests on Ubuntu (checked on Ubuntu 18.04 (Bionic))
The necessary packages can be installed using the following command;
`apt-get install libc-client-dev libkrb5-dev dovecot-core dovecot-pop3d dovecot-imapd sendmail`

The build of PHP will need to be compiled with the following flags:
```
--with-imap --with-kerberos --with-imap-ssl
```

Then run the set-up script `ext/imap/tests/setup/setup.sh` which will add the `vmail`
group and user which is used by Dovecot for the mailbox. It will also copy the
`ext/imap/tests/setup/dovecot.conf` and `ext/imap/tests/setup/dovecotpass` to the correct
location for Dovecot and restarts it for the new configuration to be enabled.
PK%�Zպ�U==tests/imap_undelete_basic.phptnu�[���--TEST--
imap_undelete() function : basic functionality
--CREDITS--
Olivier Doucet
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');
$stream_id = setup_test_mailbox('imapundeletebasic', 1);

imap_delete($stream_id, 1);

var_dump(imap_undelete($stream_id, 1));

imap_close($stream_id);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapundeletebasic';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECT--
Create a temporary mailbox and add 1 msgs
New mailbox created
bool(true)
PK%�Zz�\|��tests/nil_constant.phptnu�[���--TEST--
NIL constant is deprecated
--EXTENSIONS--
imap
--FILE--
<?php
var_dump(NIL);
?>
--EXPECTF--
Deprecated: Constant NIL is deprecated in %s on line %d
int(0)
PK%�ZDvCH��&tests/imap_fetchheader_variation5.phptnu�[���--TEST--
Test imap_fetchheader() function : usage variations - $message_num argument
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
/*
 * Pass different integers and strings as $message_num argument
 * to test behaviour of imap_fetchheader()
 */

echo "*** Testing imap_fetchheader() : usage variations ***\n";

require_once(__DIR__.'/setup/imap_include.inc');

$stream_id = setup_test_mailbox('imapfetchheadervar5', 3, $mailbox, false); // set up temp mailbox with 3 msgs

$sequences = [0, /* out of range */ 4, 1];

foreach($sequences as $message_num) {
    echo "\n-- \$message_num is $message_num --\n";
    try {
        var_dump(imap_fetchheader($stream_id, $message_num));
    } catch (\ValueError $e) {
        echo $e->getMessage() . \PHP_EOL;
    }
}

// clear error stack
imap_errors();
?>
--CLEAN--
<?php
$mailbox_suffix = 'imapfetchheadervar5';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECTF--
*** Testing imap_fetchheader() : usage variations ***
Create a temporary mailbox and add 3 msgs
New mailbox created

-- $message_num is 0 --
imap_fetchheader(): Argument #2 ($message_num) must be greater than 0

-- $message_num is 4 --

Warning: imap_fetchheader(): Bad message number in %s on line %d
bool(false)

-- $message_num is 1 --
string(%d) "From: foo@anywhere.com
Subject: Test msg 1
To: %s
MIME-Version: 1.0
Content-Type: MULTIPART/mixed; BOUNDARY="%s=:%d"

"
PK%�Z@�n55 tests/imap_bodystruct_basic.phptnu�[���--TEST--
Test imap_bodystruct() function : basic functionality
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
echo "*** Testing string imap_bodystruct : basic functionality ***\n";
require_once(__DIR__.'/setup/imap_include.inc');

echo "Create a new mailbox for test and add a multipart msgs\n";
$imap_stream = setup_test_mailbox("imapbodystructbasic", 1, $mailbox, "multipart");

echo "\nGet and validate structure of body part 1\n";

$m = imap_bodystruct($imap_stream, 1, "1");

$mandatoryFields = [
    'ifsubtype',
    'ifdescription',
    'ifid',
    'ifdisposition',
    'ifdparameters',
    'ifparameters',
];

function isValid($param) {
    return ($param == 0) || ($param == 1);
}

foreach($mandatoryFields as $mf) {
    if (isValid($m->$mf)) {
        echo "$mf is 0 or 1\n";
    } else {
        echo "$mf FAIL\n";
    }
}

if(is_array($m->parameters)) {
    echo "parameters is an array\n";
}

echo "\nTry to get part 4!\n";
var_dump(imap_bodystruct($imap_stream, 1, "4"));

imap_close($imap_stream);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapbodystructbasic';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECT--
*** Testing string imap_bodystruct : basic functionality ***
Create a new mailbox for test and add a multipart msgs
Create a temporary mailbox and add 1 msgs
New mailbox created

Get and validate structure of body part 1
ifsubtype is 0 or 1
ifdescription is 0 or 1
ifid is 0 or 1
ifdisposition is 0 or 1
ifdparameters is 0 or 1
ifparameters is 0 or 1
parameters is an array

Try to get part 4!
bool(false)
PK%�Z1��^��%tests/imap_fetchstructure_errors.phptnu�[���--TEST--
imap_fetchstructure() errors: ValueError and Warnings
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');

$imap_mail_box = setup_test_mailbox("imapfetchstructureerrors", 0);

try {
    imap_fetchstructure($imap_mail_box, -1);
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}
try {
    imap_fetchstructure($imap_mail_box, 1, -1);
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}

// Access not existing
var_dump(imap_fetchstructure($imap_mail_box, 255));
var_dump(imap_fetchstructure($imap_mail_box, 255, FT_UID));

imap_close($imap_mail_box);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapfetchstructureerrors';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECTF--
Create a temporary mailbox and add 0 msgs
New mailbox created
imap_fetchstructure(): Argument #2 ($message_num) must be greater than 0
imap_fetchstructure(): Argument #3 ($flags) must be FT_UID or 0

Warning: imap_fetchstructure(): Bad message number in %s on line %d
bool(false)

Warning: imap_fetchstructure(): UID does not exist in %s on line %d
bool(false)
PK%�Z���p��tests/imap_mail_move_basic.phptnu�[���--TEST--
Test imap_mail_move() function : basic functionality
--CREDITS--
Olivier Doucet
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
echo "*** Testing imap_mail_move() : basic functionality ***\n";

require_once(__DIR__.'/setup/imap_include.inc');

echo "Create a new mailbox for test\n";
$imap_stream = setup_test_mailbox("movebasic", 1);

$check = imap_check($imap_stream);
echo "Msg Count in new mailbox: ". $check->Nmsgs . "\n";

var_dump(imap_mail_move($imap_stream, '1', 'INBOX.' . IMAP_MAILBOX_PHPT_PREFIX . 'movebasic'));

imap_close($imap_stream);
?>
--CLEAN--
<?php
$mailbox_suffix = 'movebasic';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECT--
*** Testing imap_mail_move() : basic functionality ***
Create a new mailbox for test
Create a temporary mailbox and add 1 msgs
New mailbox created
Msg Count in new mailbox: 1
bool(true)
PK%�Z�7�D��tests/imap_savebody_errors.phptnu�[���--TEST--
imap_savebody() errors: ValueError and Warnings
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');

$imap_mail_box = setup_test_mailbox("imapsavebodyerrors", 0);

$section = '';

try {
    imap_savebody($imap_mail_box, '', -1, $section);
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}
try {
    imap_savebody($imap_mail_box, '', 1, $section, -1);
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}

// Access not existing
var_dump(imap_savebody($imap_mail_box, '', 255, $section));
var_dump(imap_savebody($imap_mail_box, '', 255, $section, FT_UID));

imap_close($imap_mail_box);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapsavebodyerrors';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECTF--
Create a temporary mailbox and add 0 msgs
New mailbox created
imap_savebody(): Argument #3 ($message_num) must be greater than 0
imap_savebody(): Argument #5 ($flags) must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL

Warning: imap_savebody(): Bad message number in %s on line %d
bool(false)

Warning: imap_savebody(): UID does not exist in %s on line %d
bool(false)
PK%�Z���+	+	$tests/imap_clearflag_full_basic.phptnu�[���--TEST--
Test imap_clearflag_full() function : basic functionality
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
echo "*** Testing imap_clearflag_full() : basic functionality ***\n";

require_once(__DIR__.'/setup/imap_include.inc');

echo "Create a new mailbox for test\n";
$imap_stream = setup_test_mailbox("imapclearflagfullbasic", 10);

$check = imap_check($imap_stream);
echo "Initial msg count in new_mailbox : ". $check->Nmsgs . "\n";

echo "Set some flags\n";
var_dump(imap_setflag_full($imap_stream, "1,3", "\\Seen \\Answered"));
var_dump(imap_setflag_full($imap_stream, "2,4", "\\Answered"));
var_dump(imap_setflag_full($imap_stream, "5,7", "\\Flagged \\Deleted"));
var_dump(imap_setflag_full($imap_stream, "6,8", "\\Deleted"));
var_dump(imap_setflag_full($imap_stream, "9,10", "\\Draft \\Flagged"));

var_dump(imap_search($imap_stream, "SEEN"));
var_dump(imap_search($imap_stream, "ANSWERED"));
var_dump(imap_search($imap_stream, "FLAGGED"));
var_dump(imap_search($imap_stream, "DELETED"));

var_dump(imap_clearflag_full($imap_stream, "1,4", "\\Answered"));
var_dump(imap_clearflag_full($imap_stream, "5,6,7,8", "\\Deleted"));
var_dump(imap_clearflag_full($imap_stream, "9", "\\Flagged"));

var_dump(imap_search($imap_stream, "SEEN"));
var_dump(imap_search($imap_stream, "ANSWERED"));
var_dump(imap_search($imap_stream, "FLAGGED"));
var_dump(imap_search($imap_stream, "DELETED"));

imap_close($imap_stream);
?>
--CLEAN--
<?php
$mailbox_suffix = 'imapclearflagfullbasic';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECT--
*** Testing imap_clearflag_full() : basic functionality ***
Create a new mailbox for test
Create a temporary mailbox and add 10 msgs
New mailbox created
Initial msg count in new_mailbox : 10
Set some flags
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
array(2) {
  [0]=>
  int(1)
  [1]=>
  int(3)
}
array(4) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  int(4)
}
array(4) {
  [0]=>
  int(5)
  [1]=>
  int(7)
  [2]=>
  int(9)
  [3]=>
  int(10)
}
array(4) {
  [0]=>
  int(5)
  [1]=>
  int(6)
  [2]=>
  int(7)
  [3]=>
  int(8)
}
bool(true)
bool(true)
bool(true)
array(2) {
  [0]=>
  int(1)
  [1]=>
  int(3)
}
array(2) {
  [0]=>
  int(2)
  [1]=>
  int(3)
}
array(3) {
  [0]=>
  int(5)
  [1]=>
  int(7)
  [2]=>
  int(10)
}
bool(false)
PK%�Z���ZGGtests/imap_sort_uid.phptnu�[���--TEST--
imap_sort() basics
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');

$imap_mail_box = setup_test_mailbox_for_uid_tests("imapsortbasic");

var_dump(imap_sort($imap_mail_box, SORTSUBJECT, 0));
var_dump(imap_sort($imap_mail_box, SORTSUBJECT, 0, SE_UID));

imap_close($imap_mail_box);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapsortbasic';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECT--
Create a temporary mailbox and add 10 msgs
New mailbox created
Delete 4 messages for Unique ID generation
array(6) {
  [0]=>
  int(1)
  [1]=>
  int(6)
  [2]=>
  int(2)
  [3]=>
  int(3)
  [4]=>
  int(4)
  [5]=>
  int(5)
}
array(6) {
  [0]=>
  int(1)
  [1]=>
  int(10)
  [2]=>
  int(2)
  [3]=>
  int(7)
  [4]=>
  int(8)
  [5]=>
  int(9)
}
PK%�Z`�*�&&tests/imap_base64_basic.phptnu�[���--TEST--
Test imap_base64() function : basic functionality
--EXTENSIONS--
imap
--FILE--
<?php
echo "*** Testing imap_base64() : basic functionality ***\n";

$str = 'This is an example string to be base 64 encoded';
$base64 = base64_encode($str);
if (imap_base64($base64) == $str) {
    echo "TEST PASSED\n";
} else {
    echo "TEST FAILED";
}

$str = '!£$%^&*()_+-={][];;@~#?/>.<,';
$base64 = base64_encode($str);
if (imap_base64($base64) == $str) {
    echo "TEST PASSED\n";
} else {
    echo "TEST FAILED";
}

$hex = 'x00\x01\x02\x03\x04\x05\x06\xFA\xFB\xFC\xFD\xFE\xFF';
$base64 = base64_encode($hex);
if (imap_base64($base64) == $hex) {
    echo "TEST PASSED\n";
} else {
    echo "TEST FAILED";
}

?>
--EXPECT--
*** Testing imap_base64() : basic functionality ***
TEST PASSED
TEST PASSED
TEST PASSED
PK%�Z�;d��"tests/imap_fetchstructure_uid.phptnu�[���--TEST--
imap_fetchstructure() passing a unique ID
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');

$imap_mail_box = setup_test_mailbox_for_uid_tests("imapfetchstructureuid", $msg_no, $uid);

// Usage of == because comparing objects
var_dump(imap_fetchstructure($imap_mail_box, $uid, FT_UID) == imap_fetchstructure($imap_mail_box, $msg_no));

imap_close($imap_mail_box);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapfetchstructureuid';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECT--
Create a temporary mailbox and add 10 msgs
New mailbox created
Delete 4 messages for Unique ID generation
bool(true)
PK%�Z�^���tests/imap_fetchmime_uid.phptnu�[���--TEST--
imap_fetchmime() passing a unique ID
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');

$imap_mail_box = setup_test_mailbox_for_uid_tests("imapfetchmimeuid", $msg_no, $uid);

$section = '2';
var_dump(imap_fetchbody($imap_mail_box, $uid, $section, FT_UID) === imap_fetchbody($imap_mail_box, $msg_no, $section));

imap_close($imap_mail_box);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapfetchmimeuid';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECT--
Create a temporary mailbox and add 10 msgs
New mailbox created
Delete 4 messages for Unique ID generation
bool(true)
PK%�Z���й�tests/imap_delete_uid.phptnu�[���--TEST--
imap_delete() passing a unique ID
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');

$imap_mail_box = setup_test_mailbox_for_uid_tests("imapdeleteuid", $msg_no, $uid);

imap_delete($imap_mail_box, $uid, FT_UID);
var_dump(imap_search($imap_mail_box, 'DELETED', SE_UID));
imap_expunge($imap_mail_box);

echo 'After expunging: ';
var_dump(imap_search($imap_mail_box, 'DELETED', SE_UID));

var_dump(imap_search($imap_mail_box, 'ALL', SE_UID));

imap_close($imap_mail_box);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapdeleteuid';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECT--
Create a temporary mailbox and add 10 msgs
New mailbox created
Delete 4 messages for Unique ID generation
array(1) {
  [0]=>
  int(9)
}
After expunging: bool(false)
array(5) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(7)
  [3]=>
  int(8)
  [4]=>
  int(10)
}
PK%�ZC���%	%	 tests/imap_headerinfo_basic.phptnu�[���--TEST--
imap_headerinfo() function : basic functionality
--CREDITS--
Olivier Doucet
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');
$stream_id = setup_test_mailbox('imapheaderinfobasic', 1);

$z = imap_headerinfo($stream_id, 1);

$fields = array ('toaddress','to','fromaddress','from',
'reply_toaddress','reply_to',
    'senderaddress', 'sender',
'subject','Subject',
    'Recent','Unseen','Flagged','Answered','Deleted','Draft',
    'Msgno','MailDate','Size','udate');

echo "Check general fields\n";
foreach ($fields as $key) {
    var_dump(isset($z->$key));
}

echo "Check type\n";
var_dump($z->toaddress);
var_dump($z->fromaddress);
var_dump($z->reply_toaddress);
var_dump($z->senderaddress);
var_dump($z->subject);
var_dump($z->Subject);

if ($z->Recent == 'R' || $z->Recent == 'N' || $z->Recent == ' ') {
    echo "Recent: OK";
} else {
    echo "Recent: error: ".$z->Recent;
}
echo "\n";

if ($z->Unseen == 'U' || $z->Unseen == ' ') {
    echo "Unseen: OK";
} else {
    echo "Unseen: error: ".$z->Unseen;
}
echo "\n";

if ($z->Flagged == 'F' || $z->Flagged == ' ') {
    echo "Flagged: OK";
} else {
    echo "Flagged: error: ".$z->Flagged;
}
echo "\n";

if ($z->Answered == 'A' || $z->Answered == ' ') {
    echo "Answered: OK";
} else {
    echo "Answered: error";
}
echo "\n";

if ($z->Deleted == 'D' || $z->Deleted == ' ') {
    echo "Deleted: OK";
} else {
    echo "Deleted: error";
}
echo "\n";

if ($z->Draft == 'X' || $z->Draft == ' ') {
    echo "Draft: OK";
} else {
    echo "Draft: error";
}
echo "\n";

var_dump($z->Msgno);
var_dump($z->Size);
var_dump($z->udate);

imap_close($stream_id);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapheaderinfobasic';
require_once('setup/clean.inc');
?>
--EXPECTF--
Create a temporary mailbox and add 1 msgs
New mailbox created
Check general fields
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
Check type
string(%d) "%s"
string(%d) "%s"
string(%d) "%s"
string(%d) "%s"
string(%d) "%s"
string(%d) "%s"
Recent: OK
Unseen: OK
Flagged: OK
Answered: OK
Deleted: OK
Draft: OK
string(%d) "%s"
string(%d) "%d"
int(%d)
PK%�Z�3���tests/imap_list_basic.phptnu�[���--TEST--
imap_list() function : basic functionality
--CREDITS--
Olivier Doucet
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');
$stream_id = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD) or
    die("Cannot connect to mailbox " .IMAP_DEFAULT_MAILBOX.": " . imap_last_error());

imap_list($stream_id, IMAP_DEFAULT_MAILBOX,'ezerz');


$z = imap_list($stream_id, IMAP_DEFAULT_MAILBOX,'*');
var_dump(is_array($z));

// e.g. "{127.0.0.1:143/norsh}INBOX"
var_dump($z[0]);

imap_close($stream_id);
?>
--EXPECTF--
bool(true)
string(%s) "{%s}%s"
PK%�Z��h�tests/imap_open_error.phptnu�[���--TEST--
imap_open() ValueErrors
--CREDITS--
Paul Sohier
#phptestfest utrecht
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
if (getenv("SKIP_ASAN")) die("xleak leak sanitizer crashes");
?>
--FILE--
<?php

echo "Checking with incorrect parameters\n" ;
imap_open('', '', '');

try {
    imap_open('', '', '', -1);
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}

try {
    imap_open('', '', '', 0, -1);
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}

?>
--EXPECTF--
Checking with incorrect parameters

Warning: imap_open(): Couldn't open stream  in %s on line %d
imap_open(): Argument #4 ($flags) must be a bitmask of the OP_* constants, and CL_EXPUNGE
imap_open(): Argument #5 ($retries) must be greater than or equal to 0

Notice: PHP Request Shutdown: Can't open mailbox : no such mailbox (errflg=2) in Unknown on line 0
PK%�Z6G6L�� tests/imap_fetchbody_errors.phptnu�[���--TEST--
imap_fetchbody() errors: ValueError and Warnings
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');

$imap_mail_box = setup_test_mailbox("imapfetchbodyerrors", 0);

$section = '';

try {
    imap_fetchbody($imap_mail_box, -1, $section);
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}
try {
    imap_fetchbody($imap_mail_box, 1, $section, -1);
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}

// Access not existing
var_dump(imap_fetchbody($imap_mail_box, 255, $section));
var_dump(imap_fetchbody($imap_mail_box, 255, $section, FT_UID));

imap_close($imap_mail_box);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapfetchbodyerrors';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECTF--
Create a temporary mailbox and add 0 msgs
New mailbox created
imap_fetchbody(): Argument #2 ($message_num) must be greater than 0
imap_fetchbody(): Argument #4 ($flags) must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL

Warning: imap_fetchbody(): Bad message number in %s on line %d
bool(false)

Warning: imap_fetchbody(): UID does not exist in %s on line %d
bool(false)
PK&�Z�jv��tests/imap_fetchheader_uid.phptnu�[���--TEST--
imap_fetchheader() passing a unique ID
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');

$imap_mail_box = setup_test_mailbox_for_uid_tests("imapfetchheaderuid", $msg_no, $uid);

var_dump(imap_fetchheader($imap_mail_box, $uid, FT_UID) === imap_fetchheader($imap_mail_box, $msg_no));

imap_close($imap_mail_box);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapfetchheaderuid';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECT--
Create a temporary mailbox and add 10 msgs
New mailbox created
Delete 4 messages for Unique ID generation
bool(true)
PK&�Z@֊/tests/bug80438.phptnu�[���--TEST--
Bug #80438: imap_msgno() incorrectly warns and return false on valid UIDs in PHP 8.0.0
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once __DIR__.'/setup/imap_include.inc';

// create a new mailbox and add 10 new messages to it
$mail_box = setup_test_mailbox_for_uid_tests('bug80438');

$message_number_array = imap_search($mail_box, 'ALL', SE_UID);

var_dump($message_number_array);

foreach ($message_number_array as $message_unique_id)
{
    echo 'Unique ID: ';
    var_dump($message_unique_id);
    echo 'Ordered message number: ';
    var_dump(imap_msgno($mail_box, $message_unique_id));
}

imap_close($mail_box);

?>
--CLEAN--
<?php
$mailbox_suffix = 'bug80438';
require_once __DIR__.'/setup/clean.inc';
?>
--EXPECT--
Create a temporary mailbox and add 10 msgs
New mailbox created
Delete 4 messages for Unique ID generation
array(6) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(7)
  [3]=>
  int(8)
  [4]=>
  int(9)
  [5]=>
  int(10)
}
Unique ID: int(1)
Ordered message number: int(1)
Unique ID: int(2)
Ordered message number: int(2)
Unique ID: int(7)
Ordered message number: int(3)
Unique ID: int(8)
Ordered message number: int(4)
Unique ID: int(9)
Ordered message number: int(5)
Unique ID: int(10)
Ordered message number: int(6)
PK&�Z��Jz]]tests/bug80242.phptnu�[���--TEST--
Bug #80242 (imap_mail_compose() segfaults for multipart with rfc822)
--EXTENSIONS--
imap
--FILE--
<?php
$bodies = [[
    'type' => TYPEMULTIPART,
], [
    'type' => TYPETEXT,
    'contents.data' => 'some text',
], [
    'type' => TYPEMESSAGE,
    'subtype' => 'RFC822',
]];
imap_mail_compose([], $bodies);
echo "done\n";
?>
--EXPECT--
done
PK&�Z�ʞtests/bug80800.phptnu�[���--TEST--
Bug #80800: imap_open() fails when the flags parameter includes CL_EXPUNGE
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once __DIR__.'/setup/imap_include.inc';

$mail_box = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD, flags: CL_EXPUNGE);
var_dump(imap_reopen($mail_box, IMAP_DEFAULT_MAILBOX, flags: CL_EXPUNGE));
imap_close($mail_box);

echo 'Connected without any issues', "\n";

?>
--EXPECT--
bool(true)
Connected without any issues
PK&�Z,�е77tests/bug40854.phptnu�[���--TEST--
Bug #40854 (imap_mail_compose() creates an invalid terminator for multipart e-mails)
--EXTENSIONS--
imap
--FILE--
<?php
$envelope["from"]= "joe@example.com";
$envelope["to"]  = "foo@example.com";
$envelope["cc"]  = "bar@example.com";

$part1["type"] = TYPEMULTIPART;
$part1["subtype"] = "mixed";

$part2["type"] = TYPEAPPLICATION;
$part2["encoding"] = ENCBINARY;
$part2["subtype"] = "octet-stream";
$part2["description"] = 'a.txt';
$part2["contents.data"] = '';

$part3["type"] = TYPETEXT;
$part3["subtype"] = "plain";
$part3["description"] = "description3";
$part3["contents.data"] = "contents.data3\n\n\n\t";

$body[1] = $part1;
$body[2] = $part2;
$body[3] = $part3;

echo imap_mail_compose($envelope, $body);
?>
--EXPECTF--
From: joe@example.com
To: foo@example.com
cc: bar@example.com
MIME-Version: 1.0
Content-Type: MULTIPART/mixed; BOUNDARY="%s"

--%s
Content-Type: APPLICATION/octet-stream
Content-Transfer-Encoding: BASE64
Content-Description: a.txt



--%s
Content-Type: TEXT/plain; CHARSET=US-ASCII
Content-Description: description3

contents.data3


	
--%s--
PK&�Z��`77tests/bug31142_1.phptnu�[���--TEST--
Bug #31142 test #1 (imap_mail_compose() generates incorrect output)
--EXTENSIONS--
imap
--FILE--
<?php

$envelope["from"]= "joe@example.com";
$envelope["to"]  = "foo@example.com";
$envelope["cc"]  = "bar@example.com";

$part1["type"] = TYPEMULTIPART;
$part1["subtype"] = "mixed";

$part2["type"] = TYPEAPPLICATION;
$part2["encoding"] = ENCBINARY;
$part2["subtype"] = "octet-stream";
$part2["description"] = "some file";
$part2["contents.data"] = "ABC";

$part3["type"] = TYPETEXT;
$part3["subtype"] = "plain";
$part3["description"] = "description3";
$part3["contents.data"] = "contents.data3\n\n\n\t";

$body[1] = $part1;
$body[2] = $part2;
$body[3] = $part3;

echo imap_mail_compose($envelope, $body);

?>
--EXPECTF--
From: joe@example.com
To: foo@example.com
cc: bar@example.com
MIME-Version: 1.0
Content-Type: MULTIPART/mixed; BOUNDARY="%s"

--%s
Content-Type: APPLICATION/octet-stream
Content-Transfer-Encoding: BASE64
Content-Description: some file

QUJD

--%s
Content-Type: TEXT/plain; CHARSET=US-ASCII
Content-Description: description3

contents.data3


	
--%s--
PK&�ZES%%&tests/imap_reopen_with_cl_expunge.phptnu�[���--TEST--
Test imap_reopen() using the CL_EXPUNGE flag
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

// include file for required variables in imap_open()
require_once(__DIR__.'/setup/imap_include.inc');

$mailbox_suffix = 'imapreopenwithclexpunge';

// set up temp mailbox with 3 messages
$stream_id = setup_test_mailbox($mailbox_suffix , 3, $mailbox);

var_dump(imap_reopen($stream_id, IMAP_DEFAULT_MAILBOX . '.' . IMAP_MAILBOX_PHPT_PREFIX . $mailbox_suffix, flags: CL_EXPUNGE));

// mark messages in inbox for deletion
for ($i = 1; $i < 4; $i++) {
    imap_delete($stream_id, $i);
}

echo "\n-- Call to imap_close() --\n";
var_dump( imap_close($stream_id) );

// check that CL_EXPUNGE in previous imap_reopen() call worked
$stream_id = imap_open($mailbox, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD);
echo "There are now " . imap_num_msg($stream_id) . " msgs in mailbox '$mailbox'\n";

// Close connection
var_dump( imap_close($stream_id) );
?>
--CLEAN--
<?php
$mailbox_suffix = 'imapreopenwithclexpunge';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECTF--
Create a temporary mailbox and add 3 msgs
New mailbox created
bool(true)

-- Call to imap_close() --
bool(true)
There are now 0 msgs in mailbox '%sINBOX.phpttestimapreopenwithclexpunge'
bool(true)
PK&�Z+�jKtests/bug77153.phptnu�[���--TEST--
Bug #77153 (imap_open allows to run arbitrary shell commands via mailbox parameter)
--EXTENSIONS--
imap
--CONFLICTS--
defaultmailbox
--FILE--
<?php
$payload = "echo 'BUG'> " . __DIR__ . '/__bug';
$payloadb64 = base64_encode($payload);
$server = "x -oProxyCommand=echo\t$payloadb64|base64\t-d|sh}";
@imap_open('{'.$server.':143/imap}INBOX', '', '');
// clean
imap_errors();
var_dump(file_exists(__DIR__ . '/__bug'));
?>
--EXPECT--
bool(false)
--CLEAN--
<?php
if(file_exists(__DIR__ . '/__bug')) unlink(__DIR__ . '/__bug');
?>
PK&�ZH�,���#tests/imap_createmailbox_basic.phptnu�[���--TEST--
Test imap_createmailbox() function : basic functionality
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once __DIR__.'/setup/skipif.inc';
?>
--FILE--
<?php
echo "*** Testing imap_createmailbox() : basic functionality ***\n";

require_once __DIR__.'/setup/imap_include.inc';

$imap_stream = setup_test_mailbox("imapcreatemailboxbasic", 0);

$newname = "phpnewbox";

echo "Newname will be '$newname'\n";

$newbox = imap_utf7_encode(IMAP_SERVER.$newname);
if (imap_createmailbox($imap_stream, $newbox)) {

    echo "Add a couple of msgs to '$newname' mailbox\n";
    populate_mailbox($imap_stream, $newbox, 2);

    $status = imap_status($imap_stream, $newbox, SA_ALL);
    if ($status) {
        echo "Your new mailbox '$newname' has the following status:\n";
        echo "Messages:    " . $status->messages    . "\n";
        echo "Recent:      " . $status->recent      . "\n";
        echo "Unseen:      " . $status->unseen      . "\n";
        echo "UIDnext:     " . $status->uidnext     . "\n";
        echo "UIDvalidity: " . $status->uidvalidity . "\n";

    } else {
        echo "imap_status on new mailbox failed: " . imap_last_error() . "\n";
    }

    if (imap_deletemailbox($imap_stream, $newbox)) {
        echo "Mailbox '$newname' removed to restore initial state\n";
    } else {
        echo "imap_deletemailbox on new mailbox failed: " . implode("\n", imap_errors()) . "\n";
    }

} else {
    echo "could not create new mailbox: " . implode("\n", imap_errors()) . "\n";
}

imap_close($imap_stream);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapcreatemailboxbasic';
require_once __DIR__ . '/setup/clean.inc';
?>
--EXPECTF--
*** Testing imap_createmailbox() : basic functionality ***
Create a temporary mailbox and add 0 msgs
New mailbox created
Newname will be 'phpnewbox'
Add a couple of msgs to 'phpnewbox' mailbox
Your new mailbox 'phpnewbox' has the following status:
Messages:    2
Recent:      2
Unseen:      2
UIDnext:     %d
UIDvalidity: %d
Mailbox 'phpnewbox' removed to restore initial state
PK&�Zx���ZZtests/bug64076.phptnu�[���--TEST--
Bug #64076 (imap_sort() does not return FALSE on failure)
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once __DIR__ . '/setup/skipif.inc';
?>
--FILE--
<?php
require_once __DIR__ . '/setup/imap_include.inc';
$stream = setup_test_mailbox('bug64076', 2);
imap_errors(); // clear error stack
var_dump(imap_sort($stream, SORTFROM, 0, 0, 'UNSUPPORTED SEARCH CRITERIUM'));
var_dump(imap_errors() !== false);
?>
--CLEAN--
<?php
$mailbox_suffix = 'bug64076';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECT--
Create a temporary mailbox and add 2 msgs
New mailbox created
bool(false)
bool(true)
PK&�ZM�k���*tests/imap_rfc822_write_address_basic.phptnu�[���--TEST--
imap_rfc822_write_address() : basic functionality
--EXTENSIONS--
imap
--FILE--
<?php
var_dump(imap_rfc822_write_address('me', 'example.com', 'My Name'));
?>
--EXPECT--
string(24) "My Name <me@example.com>"
PK&�Z�-]OOtests/bug31142_2.phptnu�[���--TEST--
Bug #31142 test #2 (imap_mail_compose() generates incorrect output)
--EXTENSIONS--
imap
--FILE--
<?php
$envelope["from"]= 'host@domain.com';
$envelope["return_path"]= 'host@domain.com';

$part1["type"]=TYPETEXT;
$part1["subtype"]="plain";
$part1["encoding"]=ENCQUOTEDPRINTABLE ;
$part1["charset"]='iso-8859-2';
$part1["contents.data"]=imap_8bit('asn řkl');

$body = array($part1);

echo imap_mail_compose($envelope, $body);
?>
--EXPECT--
From: host@domain.com
MIME-Version: 1.0
Content-Type: TEXT/plain; CHARSET=iso-8859-2
Content-Transfer-Encoding: QUOTED-PRINTABLE

asn =C5=99kl
PK&�Z��~~$tests/imap_open_with_cl_expunge.phptnu�[���--TEST--
Test imap_open() using the CL_EXPUNGE flag
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

// include file for required variables in imap_open()
require_once(__DIR__.'/setup/imap_include.inc');

// set up temp mailbox with 3 messages
$stream_id = setup_test_mailbox('imapopenwithclexpunge', 3, $mailbox, flags: CL_EXPUNGE);

// mark messages in inbox for deletion
for ($i = 1; $i < 4; $i++) {
    imap_delete($stream_id, $i);
}

echo "\n-- Call to imap_close() --\n";
var_dump( imap_close($stream_id) );

// check that CL_EXPUNGE in previous imap_open() call worked
$stream_id = imap_open($mailbox, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD);
echo "There are now " . imap_num_msg($stream_id) . " msgs in mailbox '$mailbox'\n";

// Close connection
var_dump( imap_close($stream_id) );
?>
--CLEAN--
<?php
$mailbox_suffix = 'imapopenwithclexpunge';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECTF--
Create a temporary mailbox and add 3 msgs
New mailbox created

-- Call to imap_close() --
bool(true)
There are now 0 msgs in mailbox '%sINBOX.phpttestimapopenwithclexpunge'
bool(true)
PK&�ZPsCttests/imap_mutf7_to_utf8.phptnu�[���--TEST--
imap_mutf7_to_utf8
--EXTENSIONS--
imap
--SKIPIF--
<?php
// The underlying imap_mutf7_to_utf8 function can be missing; there's a
// ./configure check for it that disables the corresponding PHP function.
if (!function_exists('imap_mutf7_to_utf8')) {
    die("skip no imap_mutf7_to_utf8 function");
}
?>
--FILE--
<?php

var_dump(imap_mutf7_to_utf8(""));
var_dump(imap_mutf7_to_utf8(1));
var_dump(imap_mutf7_to_utf8("t&AOQ-st"));

echo "Done\n";
?>
--EXPECT--
string(0) ""
string(1) "1"
string(5) "täst"
Done
PK&�Z���L�� tests/imap_fetchmime_errors.phptnu�[���--TEST--
imap_fetchmime() errors: ValueError and Warnings
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');

$imap_mail_box = setup_test_mailbox("imapfetchmimeerrors", 0);

$section = '';

try {
    imap_fetchmime($imap_mail_box, -1, $section);
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}
try {
    imap_fetchmime($imap_mail_box, 1, $section, -1);
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}

// Access not existing
var_dump(imap_fetchmime($imap_mail_box, 255, $section));
var_dump(imap_fetchmime($imap_mail_box, 255, $section, FT_UID));

imap_close($imap_mail_box);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapfetchmimeerrors';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECTF--
Create a temporary mailbox and add 0 msgs
New mailbox created
imap_fetchmime(): Argument #2 ($message_num) must be greater than 0
imap_fetchmime(): Argument #4 ($flags) must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL

Warning: imap_fetchmime(): Bad message number in %s on line %d
bool(false)

Warning: imap_fetchmime(): UID does not exist in %s on line %d
bool(false)
PK&�Z_��#tests/imap_utf8_to_mutf7_basic.phptnu�[���--TEST--
imap_utf8_to_mutf7
--EXTENSIONS--
imap
--SKIPIF--
<?php
// The underlying imap_utf8_to_mutf7 function can be missing; there's a
// ./configure check for it that disables the corresponding PHP function.
if (!function_exists('imap_utf8_to_mutf7')) {
    die("skip no imap_utf8_to_mutf7 function");
}
?>
--FILE--
<?php

var_dump(imap_utf8_to_mutf7(""));
var_dump(imap_utf8_to_mutf7(1));
var_dump(imap_utf8_to_mutf7("täst"));

echo "Done\n";
?>
--EXPECT--
string(0) ""
string(1) "1"
string(8) "t&AOQ-st"
Done
PK&�Z`CF|pptests/bug80710_1.phptnu�[���--TEST--
Bug #80710 (imap_mail_compose() header injection) - MIME Splitting Attack
--EXTENSIONS--
imap
--FILE--
<?php
$envelope["from"]= "joe@example.com\n From : X-INJECTED";
$envelope["to"]  = "foo@example.com\nFrom: X-INJECTED";
$envelope["cc"]  = "bar@example.com\nFrom: X-INJECTED";
$envelope["subject"]  = "bar@example.com\n\n From : X-INJECTED";
$envelope["x-remail"]  = "bar@example.com\nFrom: X-INJECTED";
$envelope["something"]  = "bar@example.com\nFrom: X-INJECTED";

$part1["type"] = TYPEMULTIPART;
$part1["subtype"] = "mixed";

$part2["type"] = TYPEAPPLICATION;
$part2["encoding"] = ENCBINARY;
$part2["subtype"] = "octet-stream\nContent-Type: X-INJECTED";
$part2["description"] = "some file\nContent-Type: X-INJECTED";
$part2["contents.data"] = "ABC\nContent-Type: X-INJECTED";

$part3["type"] = TYPETEXT;
$part3["subtype"] = "plain";
$part3["description"] = "description3";
$part3["contents.data"] = "contents.data3\n\n\n\t";

$body[1] = $part1;
$body[2] = $part2;
$body[3] = $part3;

echo imap_mail_compose($envelope, $body);
?>
--EXPECTF--
Warning: imap_mail_compose(): header injection attempt in from in %s on line %d
PK&�Z��)1�	�	 tests/imap_close_variation4.phptnu�[���--TEST--
Test imap_close() function : usage variations - different ints as $flags arg
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
/*
 * Pass different integers as $flags arg to imap_close() to test which are
 * recognised as CL_EXPUNGE option
 */

echo "*** Testing imap_close() : usage variations ***\n";

require_once(__DIR__.'/setup/imap_include.inc');

$inputs = array (0, 3.2768e4, -32768, PHP_INT_MAX, -PHP_INT_MAX);

$stream_id = setup_test_mailbox('imapclosevar4', 3, $mailbox); // set up temp mailbox with 3 messages

// loop through each element of $inputs to check the behavior of imap_close()
$iterator = 1;
foreach($inputs as $input) {

    // mark added messages for deletion
    for ($i = 1; $i < 4; $i++) {
        imap_delete($stream_id, $i);
    }
    echo "\n-- Iteration $iterator --\n";
    try {
        var_dump( $check = imap_close($stream_id, $input) );
    } catch (\ValueError $e) {
        echo $e->getMessage() . \PHP_EOL;
        $check = false;
    }

    // check that imap_close was successful, if not call imap_close and explicitly set CL_EXPUNGE
    if(false === $check) {
        imap_close($stream_id, CL_EXPUNGE);
    } else {
        // if imap_close was successful test whether CL_EXPUNGE was set by doing a message count
        $imap_stream = imap_open($mailbox, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD);
        $num_msg = imap_num_msg($imap_stream);
        if ($num_msg != 0) {
            echo "CL_EXPUNGE was not set, $num_msg msgs in mailbox\n";
        } else {
            echo "CL_EXPUNGE was set\n";
        }
        // call imap_close with CL_EXPUNGE explicitly set in case mailbox not empty
        imap_close($imap_stream, CL_EXPUNGE);
    }
    $iterator++;

    // get $stream_id for next iteration
    $stream_id = imap_open($mailbox, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD);
    populate_mailbox($stream_id, $mailbox, 3);

};
?>
--CLEAN--
<?php
$mailbox_suffix = 'imapclosevar4';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECT--
*** Testing imap_close() : usage variations ***
Create a temporary mailbox and add 3 msgs
New mailbox created

-- Iteration 1 --
bool(true)
CL_EXPUNGE was not set, 3 msgs in mailbox

-- Iteration 2 --
bool(true)
CL_EXPUNGE was set

-- Iteration 3 --
imap_close(): Argument #2 ($flags) must be CL_EXPUNGE or 0

-- Iteration 4 --
imap_close(): Argument #2 ($flags) must be CL_EXPUNGE or 0

-- Iteration 5 --
imap_close(): Argument #2 ($flags) must be CL_EXPUNGE or 0
PK&�Z"o'���tests/imap_fetchbody_basic.phptnu�[���--TEST--
Test imap_fetchbody() function : basic functionality
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
/*           [, int $options])
 * Description: Get a specific body section
 * Source code: ext/imap/php_imap.c
 */

echo "*** Testing imap_fetchbody() : basic functionality ***\n";
require_once(__DIR__.'/setup/imap_include.inc');

// Initialise all required variables

// set up mailbox with one message
$stream_id = setup_test_mailbox('imapfetchbodybasic', 1, $mailbox, false);

$msg_no = 1;
$section = '2';
$options = array ('FT_UID' => FT_UID, 'FT_PEEK' => FT_PEEK, 'FT_INTERNAL' => FT_INTERNAL);

// Calling imap_fetchbody() with all possible arguments
echo "\n-- All possible arguments --\n";
foreach ($options as $key => $option) {
    echo "-- Option is $key --\n";
    switch ($key) {

        case 'FT_UID';
        $msg_uid = imap_uid($stream_id, $msg_no);
        var_dump( imap_fetchbody($stream_id, $msg_uid, $section, $option) );
        break;

        case 'FT_PEEK';
        var_dump( imap_fetchbody($stream_id, $msg_no, $section, $option) );
        $overview = imap_fetch_overview($stream_id, 1);
        echo "Seen Flag: ";
        var_dump( $overview[0]->seen );
        break;

        case 'FT_INTERNAL';
        var_dump( imap_fetchbody($stream_id, $msg_no, $section, $option) );
        break;

    }
}

// Calling imap_fetchbody() with mandatory arguments
echo "\n-- Mandatory arguments --\n";
var_dump( imap_fetchbody($stream_id, $msg_no, $section) );
$overview = imap_fetch_overview($stream_id, 1);
echo "Seen Flag: ";
var_dump( $overview[0]->seen );
?>
--CLEAN--
<?php
$mailbox_suffix = 'imapfetchbodybasic';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECTF--
*** Testing imap_fetchbody() : basic functionality ***
Create a temporary mailbox and add 1 msgs
New mailbox created

-- All possible arguments --
-- Option is FT_UID --
string(36) "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy"
-- Option is FT_PEEK --
string(36) "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy"
Seen Flag: int(%d)
-- Option is FT_INTERNAL --
string(36) "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy"

-- Mandatory arguments --
string(36) "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy"
Seen Flag: int(%d)
PK&�Z4�``tests/bug45705_2.phptnu�[���--TEST--
Bug #45705 test #2 (imap rfc822_parse_adrlist() modifies passed address parameter)
--EXTENSIONS--
imap
--FILE--
<?php

$envelope = array('return_path' => 'John Doe <john@example.com>',
                  'from'        => 'John Doe <john@example.com>',
                  'reply_to'    => 'John Doe <john@example.com>',
                  'to'          => 'John Doe <john@example.com>',
                  'cc'          => 'John Doe <john@example.com>',
                  'bcc'         => 'John Doe <john@example.com>',
);

var_dump($envelope);
imap_mail_compose($envelope, [1 => ['cc' => 'Steve Doe <steve@example.com>',]]);
var_dump($envelope);

?>
--EXPECT--
array(6) {
  ["return_path"]=>
  string(27) "John Doe <john@example.com>"
  ["from"]=>
  string(27) "John Doe <john@example.com>"
  ["reply_to"]=>
  string(27) "John Doe <john@example.com>"
  ["to"]=>
  string(27) "John Doe <john@example.com>"
  ["cc"]=>
  string(27) "John Doe <john@example.com>"
  ["bcc"]=>
  string(27) "John Doe <john@example.com>"
}
array(6) {
  ["return_path"]=>
  string(27) "John Doe <john@example.com>"
  ["from"]=>
  string(27) "John Doe <john@example.com>"
  ["reply_to"]=>
  string(27) "John Doe <john@example.com>"
  ["to"]=>
  string(27) "John Doe <john@example.com>"
  ["cc"]=>
  string(27) "John Doe <john@example.com>"
  ["bcc"]=>
  string(27) "John Doe <john@example.com>"
}
PK'�Z?���tests/imap_search_basic.phptnu�[���--TEST--
imap_search() with unique ID (SE_UID) flag
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');

$imap_mail_box = setup_test_mailbox_for_uid_tests("imapsearchuid");

var_dump(imap_search($imap_mail_box, 'ALL', SE_UID));

imap_close($imap_mail_box);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapsearchuid';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECT--
Create a temporary mailbox and add 10 msgs
New mailbox created
Delete 4 messages for Unique ID generation
array(6) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(7)
  [3]=>
  int(8)
  [4]=>
  int(9)
  [5]=>
  int(10)
}
PK'�Z�|��tests/bug32589.phptnu�[���--TEST--
Bug #32589 (crash inside imap_mail_compose() function)
--EXTENSIONS--
imap
--FILE--
<?php
$m_envelope["To"] = "mail@example.com";
$m_part1["type"] = TYPEMULTIPART;
$m_part1["subtype"] = "mixed";
$m_part2["type"] = TYPETEXT;
$m_part2["subtype"] = "plain";
$m_part2["description"] = "text_message";

$m_part2["charset"] = "ISO-8859-2";

$m_part2["contents.data"] = "hello";
$m_body[1] = $m_part1;
$m_body[2] = $m_part2;
echo imap_mail_compose($m_envelope, $m_body);
?>
--EXPECTF--
MIME-Version: 1.0
Content-Type: MULTIPART/mixed; BOUNDARY="%s"

%s
Content-Type: TEXT/plain; CHARSET=ISO-8859-2
Content-Description: text_message

hello
%s
PK'�Z'.b&&tests/imap_constructor.phptnu�[���--TEST--
Attempt to instantiate an IMAP\Connection directly
--EXTENSIONS--
imap
--FILE--
<?php

try {
    new IMAP\Connection();
} catch (Error $ex) {
    echo "Exception: ", $ex->getMessage(), "\n";
}
?>
--EXPECT--
Exception: Cannot directly construct IMAP\Connection, use imap_open() instead
PK'�Zż=��*tests/imap_rfc822_parse_headers_basic.phptnu�[���--TEST--
imap_rfc822_parse_headers() function : basic functionality
--CREDITS--
Olivier Doucet
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');
$stream_id = setup_test_mailbox('imaprfc822parseheadersbasic', 1);

$z = imap_headerinfo($stream_id, 1);

$fields = array ('toaddress','to','fromaddress','from',
'reply_toaddress','reply_to',
    'senderaddress', 'sender',
'subject','Subject',
    'MailDate','Size','udate');


echo "Check general fields\n";
foreach ($fields as $key) {
    var_dump(isset($z->$key));
}

echo "Check type\n";
var_dump($z->toaddress);
var_dump($z->fromaddress);
var_dump($z->reply_toaddress);
var_dump($z->senderaddress);
var_dump($z->subject);
var_dump($z->Subject);

if ($z->Recent == 'R' || $z->Recent == 'N' || $z->Recent == ' ') {
    echo "Recent: OK";
} else {
    echo "Recent: error";
}
echo "\n";

if ($z->Unseen == 'U' || $z->Unseen == ' ') {
    echo "Unseen: OK";
} else {
    echo "Unseen: error";
}
echo "\n";

if ($z->Flagged == 'F' || $z->Flagged == ' ') {
    echo "Flagged: OK";
} else {
    echo "Flagged: error";
}
echo "\n";

if ($z->Answered == 'A' || $z->Answered == ' ') {
    echo "Answered: OK";
} else {
    echo "Answered: error";
}
echo "\n";

if ($z->Deleted == 'D' || $z->Deleted == ' ') {
    echo "Deleted: OK";
} else {
    echo "Deleted: error";
}
echo "\n";

if ($z->Draft == 'X' || $z->Draft == ' ') {
    echo "Draft: OK";
} else {
    echo "Draft: error";
}
echo "\n";

var_dump($z->Msgno);
var_dump($z->Size);
var_dump($z->udate);

imap_close($stream_id);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imaprfc822parseheadersbasic';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECTF--
Create a temporary mailbox and add 1 msgs
New mailbox created
Check general fields
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
Check type
string(%d) "%s"
string(%d) "%s"
string(%d) "%s"
string(%d) "%s"
string(%d) "%s"
string(%d) "%s"
Recent: OK
Unseen: OK
Flagged: OK
Answered: OK
Deleted: OK
Draft: OK
string(%d) "%s"
string(%d) "%d"
int(%d)
PK'�ZSs����#tests/imap_getsubscribed_basic.phptnu�[���--TEST--
imap_getsubscribed() function : basic functionality
--CREDITS--
Olivier Doucet
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
if (getenv("SKIP_ASAN")) die("xleak asan chokes on this: 'LeakSanitizer does not work under ptrace (strace, gdb, etc)'");
?>
--CONFLICTS--
defaultmailbox
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');
$stream_id = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD) or
    die("Cannot connect to mailbox ". IMAP_DEFAULT_MAILBOX. ": " . imap_last_error());

var_dump(imap_getsubscribed($stream_id, IMAP_DEFAULT_MAILBOX, 'ezDvfXvbvcxSerz'));


echo "Checking OK\n";

$newbox = IMAP_DEFAULT_MAILBOX . "." . IMAP_MAILBOX_PHPT_PREFIX;

imap_createmailbox($stream_id, $newbox);
imap_subscribe($stream_id, $newbox);

$z = imap_getsubscribed($stream_id, IMAP_DEFAULT_MAILBOX, '*');

var_dump(is_array($z));
var_dump($z[0]);

imap_close($stream_id);
?>
--CLEAN--
<?php
$mailbox_suffix = '';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECTF--
bool(false)
Checking OK
bool(true)
object(stdClass)#%d (%d) {
  [%sname"]=>
  string(%d) "{%s}%s"
  [%sattributes"]=>
  int(%d)
  [%sdelimiter"]=>
  string(%d) "%s"
}
PK'�Zka����tests/imap_gc_error.phptnu�[���--TEST--
imap_gc() ValueError
--CREDITS--
Paul Sohier
#phptestfest utrecht
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');
$stream_id = setup_test_mailbox('imapgcerror', 1);

try {
    imap_gc($stream_id, -1);
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapgcerror';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECT--
Create a temporary mailbox and add 1 msgs
New mailbox created
imap_gc(): Argument #2 ($flags) must be a bitmask of IMAP_GC_TEXTS, IMAP_GC_ELT, and IMAP_GC_ENV
PK'�Z��)��tests/bug80213.phptnu�[���--TEST--
Bug #80213 (imap_mail_compose() segfaults on certain $bodies)
--EXTENSIONS--
imap
--FILE--
<?php
$envelope = [];
$body = [[
    'type.parameters' => ['param'],
    'disposition' => ['disp'],
], [
    'type.parameters' => ['param'],
    'disposition' => ['disp'],
]];
var_dump(imap_mail_compose($envelope, $body));
echo "done\n";
?>
--EXPECT--
string(67) "MIME-Version: 1.0
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII


"
done
PK'�Z���33tests/imap_undelete_uid.phptnu�[���--TEST--
imap_undelete() passing a unique ID
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');

$imap_mail_box = setup_test_mailbox_for_uid_tests("imapundeleteuid", $msg_no, $uid);

imap_delete($imap_mail_box, $uid, FT_UID);
imap_undelete($imap_mail_box, $uid, FT_UID);
imap_expunge($imap_mail_box);

var_dump(imap_search($imap_mail_box, 'ALL', SE_UID));

imap_close($imap_mail_box);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapundeleteuid';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECT--
Create a temporary mailbox and add 10 msgs
New mailbox created
Delete 4 messages for Unique ID generation
array(6) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(7)
  [3]=>
  int(8)
  [4]=>
  int(9)
  [5]=>
  int(10)
}
PK'�Z�L���$tests/imap_fetchstructure_basic.phptnu�[���--TEST--
imap_fetchstructure() function : basic functionality
--CREDITS--
Olivier Doucet
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');
$stream_id = setup_test_mailbox('imapfetchstructurebasic', 1);

try {
    imap_fetchstructure($stream_id,0);
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}

$z = imap_fetchstructure($stream_id,1);


$fields = array('type','encoding','ifsubtype','subtype',
'ifdescription','lines','bytes','parameters');

foreach ($fields as $key) {
    var_dump(isset($z->$key));
}
var_dump($z->type);
var_dump($z->encoding);
var_dump($z->bytes);
var_dump($z->lines);
var_dump($z->ifparameters);
var_dump(is_object($z->parameters[0]));

imap_close($stream_id);
?>
--CLEAN--
<?php
$mailbox_suffix = 'imapfetchstructurebasic';
require_once('setup/clean.inc');
?>
--EXPECTF--
Create a temporary mailbox and add 1 msgs
New mailbox created
imap_fetchstructure(): Argument #2 ($message_num) must be greater than 0
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
int(%d)
int(%d)
int(%d)
int(%d)
int(1)
bool(true)
PK'�Z��I��"tests/imap_fetchheader_errors.phptnu�[���--TEST--
imap_fetchheader() errors: ValueError and Warnings
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');

$imap_mail_box = setup_test_mailbox("imapfetchheadererrors", 0);

try {
    imap_fetchheader($imap_mail_box, -1);
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}
try {
    imap_fetchheader($imap_mail_box, 1, -1);
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}

// Access not existing
var_dump(imap_fetchheader($imap_mail_box, 255));
var_dump(imap_fetchheader($imap_mail_box, 255, FT_UID));

imap_close($imap_mail_box);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapfetchheadererrors';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECTF--
Create a temporary mailbox and add 0 msgs
New mailbox created
imap_fetchheader(): Argument #2 ($message_num) must be greater than 0
imap_fetchheader(): Argument #3 ($flags) must be a bitmask of FT_UID, FT_PREFETCHTEXT, and FT_INTERNAL

Warning: imap_fetchheader(): Bad message number in %s on line %d
bool(false)

Warning: imap_fetchheader(): UID does not exist in %s on line %d
bool(false)
PK'�Z�L�H��tests/imap_is_open.phptnu�[���--TEST--
Test imap_is_open()
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

// include file for required variables in imap_open()
require_once(__DIR__.'/setup/imap_include.inc');

$mailbox_suffix = 'imapisopen';

// set up temp mailbox with 0 messages
$stream_id = setup_test_mailbox($mailbox_suffix, 0, $mailbox);

var_dump(imap_is_open($stream_id));

// Close connection
var_dump(imap_close($stream_id));
var_dump(imap_is_open($stream_id));

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapisopen';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECT--
Create a temporary mailbox and add 0 msgs
New mailbox created
bool(true)
bool(true)
bool(false)
PK'�Zj�Ɩ\\tests/bug45705_1.phptnu�[���--TEST--
Bug #45705 test #1 (imap rfc822_parse_adrlist() modifies passed address parameter)
--EXTENSIONS--
imap
--FILE--
<?php

$address = 'John Doe <john@example.com>';
var_dump($address);
imap_rfc822_parse_adrlist($address, '');
var_dump($address);

?>
--EXPECT--
string(27) "John Doe <john@example.com>"
string(27) "John Doe <john@example.com>"
PK'�Z1�2nn!tests/imap_fetchheader_basic.phptnu�[���--TEST--
Test imap_fetchheader() function : basic function
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
echo "*** Testing imap_fetchheader() : basic functionality ***\n";
require_once(__DIR__.'/setup/imap_include.inc');

// Initialise all required variables
$stream_id = setup_test_mailbox('imapfetchheaderbasic', 1, $mailbox, false); // setup temp mailbox with 1 msg
$msg_no = 1;
$options = array('FT_UID' => FT_UID, 'FT_INTERNAL' => FT_INTERNAL,
                 'FT_PREFETCHTEXT' => FT_PREFETCHTEXT);

// Calling imap_fetchheader() with all possible arguments
echo "\n-- All possible arguments --\n";
foreach ($options as $key => $option) {
    echo "-- Option is $key --\n";
    if ($key == 'FT_UID') {
        $msg_uid = imap_uid($stream_id, $msg_no);
        var_dump(imap_fetchheader($stream_id, $msg_uid, $option));
    } else {
        var_dump(imap_fetchheader($stream_id, $msg_no, $option));
    }
}

// Calling imap_fetchheader() with mandatory arguments
echo "\n-- Mandatory arguments --\n";
var_dump( imap_fetchheader($stream_id, $msg_no) );
?>
--CLEAN--
<?php
$mailbox_suffix = 'imapfetchheaderbasic';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECTF--
*** Testing imap_fetchheader() : basic functionality ***
Create a temporary mailbox and add 1 msgs
New mailbox created

-- All possible arguments --
-- Option is FT_UID --
string(%d) "From: foo@anywhere.com
Subject: Test msg 1
To: %s
MIME-Version: 1.0
Content-Type: %s; %s

"
-- Option is FT_INTERNAL --
string(%d) "From: foo@anywhere.com
Subject: Test msg 1
To: %s
MIME-Version: 1.0
Content-Type: %s; %s

"
-- Option is FT_PREFETCHTEXT --
string(%d) "From: foo@anywhere.com
Subject: Test msg 1
To: %s
MIME-Version: 1.0
Content-Type: %s; %s

"

-- Mandatory arguments --
string(%d) "From: foo@anywhere.com
Subject: Test msg 1
To: %s
MIME-Version: 1.0
Content-Type: %s; %s

"
PK'�Z������tests/bug80223.phptnu�[���--TEST--
Bug #80223 (imap_mail_compose() leaks envelope on malformed bodies)
--EXTENSIONS--
imap
--FILE--
<?php
try {
    imap_mail_compose([], []);
} catch (\ValueError $e) {
    echo $e->getMessage(), \PHP_EOL;
}
try {
    imap_mail_compose([], [1]);
} catch (\TypeError $e) {
    echo $e->getMessage(), \PHP_EOL;
}
try {
    imap_mail_compose([], [[]]);
} catch (\ValueError $e) {
    echo $e->getMessage(), \PHP_EOL;
}
?>
--EXPECT--
imap_mail_compose(): Argument #2 ($bodies) cannot be empty
imap_mail_compose(): Argument #2 ($bodies) individual body must be of type array, int given
imap_mail_compose(): Argument #2 ($bodies) individual body cannot be empty
PK'�Z�y�i��tests/bug80216.phptnu�[���--TEST--
Bug #80216 (imap_mail_compose() does not validate types/encodings)
--EXTENSIONS--
imap
--FILE--
<?php
imap_mail_compose([], [['type' => TYPEMULTIPART], []]);
imap_mail_compose([], [['type' => 12]]);
imap_mail_compose([], [['type' => TYPEMULTIPART], ['type' => 12]]);
imap_mail_compose([], [['encoding' => 8]]);
imap_mail_compose([], [['type' => TYPEMULTIPART], ['encoding' => 8]]);
echo "done\n";
?>
--EXPECT--
done
PK'�Z.O��tests/bug44098.phptnu�[���--TEST--
Bug #44098 (imap_utf8() returns only capital letters)
--EXTENSIONS--
imap
--FILE--
<?php
$exp = 'Luzon®14 dot CoM';
$res = imap_utf8('=?iso-8859-1?b?THV6b26uMTQ=?= dot CoM');
var_dump($res);

?>
--EXPECT--
string(17) "Luzon®14 dot CoM"
PK'�ZV_P�^^tests/bug53377.phptnu�[���--TEST--
Bug #53377 (imap_mime_header_decode() doesn't ignore \t during long MIME header unfolding)
--EXTENSIONS--
imap
--FILE--
<?php
$s = "=?UTF-8?Q?=E2=82=AC?=";
$header = "$s\n $s\n\t$s";

var_dump(imap_mime_header_decode($header));
?>
--EXPECT--
array(3) {
  [0]=>
  object(stdClass)#1 (2) {
    ["charset"]=>
    string(5) "UTF-8"
    ["text"]=>
    string(3) "€"
  }
  [1]=>
  object(stdClass)#2 (2) {
    ["charset"]=>
    string(5) "UTF-8"
    ["text"]=>
    string(3) "€"
  }
  [2]=>
  object(stdClass)#3 (2) {
    ["charset"]=>
    string(5) "UTF-8"
    ["text"]=>
    string(3) "€"
  }
}
PK'�Z(,�PPtests/imap_append_basic.phptnu�[���--TEST--
Test imap_append() function : basic functionality
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__. '/setup/skipif.inc');
?>
--FILE--
<?php
echo "*** Testing imap_append() : basic functionality ***\n";

require_once(__DIR__. '/setup/imap_include.inc');

echo "Create a new mailbox for test\n";
$imap_stream = setup_test_mailbox("imapappendbaisc", 0);

$mb_details = imap_mailboxmsginfo($imap_stream);
echo "Add a couple of msgs to the new mailbox\n";
var_dump(imap_append($imap_stream, $mb_details->Mailbox
                   , "From: webmaster@example.com\r\n"
                   . "To: info@example.com\r\n"
                   . "Subject: Test message\r\n"
                   . "\r\n"
                   . "this is a test message, please ignore\r\n"
                   ));

var_dump(imap_append($imap_stream, $mb_details->Mailbox
                   , "From: webmaster@example.com\r\n"
                   . "To: info@example.com\r\n"
                   . "Subject: Another test\r\n"
                   . "\r\n"
                   . "this is another test message, please ignore it too!!\r\n"
                   ));

$check = imap_check($imap_stream);
echo "Msg Count after append : ". $check->Nmsgs . "\n";

echo "List the msg headers\n";
var_dump(imap_headers($imap_stream));

imap_close($imap_stream);
?>
--CLEAN--
<?php
$mailbox_suffix = 'imapappendbaisc';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECTF--
*** Testing imap_append() : basic functionality ***
Create a new mailbox for test
Create a temporary mailbox and add 0 msgs
New mailbox created
Add a couple of msgs to the new mailbox
bool(true)
bool(true)
Msg Count after append : 2
List the msg headers
array(2) {
  [0]=>
  string(%d) "%w%s       1)%s webmaster@example.co Test message (%d chars)"
  [1]=>
  string(%d) "%w%s       2)%s webmaster@example.co Another test (%d chars)"
}
PK'�ZB�chh$tests/imap_fetchbody_variation6.phptnu�[���--TEST--
Test imap_fetchbody() function : usage variations - $message_num arg
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
/*
 * Pass different integers, strings, msg sequences and msg UIDs as $message_num argument
 * to test behaviour of imap_fetchbody()
 */

echo "*** Testing imap_fetchbody() : usage variations ***\n";

require_once(__DIR__.'/setup/imap_include.inc');

//Initialise required variables
$stream_id = setup_test_mailbox('imapfetchbodyvar6', 3); // set up temp mailbox with  simple msgs
$section = 1;

$sequences = [0, /* out of range */ 4, 1];

foreach($sequences as $message_num) {
    echo "\n-- \$message_num is $message_num --\n";
    try {
        var_dump(imap_fetchbody($stream_id, $message_num, $section));
    } catch (\ValueError $e) {
        echo $e->getMessage() . \PHP_EOL;
    }
}
?>
--CLEAN--
<?php
$mailbox_suffix = 'imapfetchbodyvar6';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECTF--
*** Testing imap_fetchbody() : usage variations ***
Create a temporary mailbox and add 3 msgs
New mailbox created

-- $message_num is 0 --
imap_fetchbody(): Argument #2 ($message_num) must be greater than 0

-- $message_num is 4 --

Warning: imap_fetchbody(): Bad message number in %s on line %d
bool(false)

-- $message_num is 1 --
string(%d) "1: this is a test message, please ignore
newline%r\R?%r"
PK'�Z72��tests/bug80220.phptnu�[���--TEST--
Bug #80220 (imap_mail_compose() may leak memory) - message/rfc822 regression
--EXTENSIONS--
imap
--FILE--
<?php
$bodies = [[
    'type' => TYPEMESSAGE,
    'subtype' => 'RFC822',
], [
    'contents.data' => 'asd',
]];
var_dump(imap_mail_compose([], $bodies));

$bodies = [[
    'type' => TYPEMESSAGE,
], [
    'contents.data' => 'asd',
]];
var_dump(imap_mail_compose([], $bodies));
?>
--EXPECT--
string(53) "MIME-Version: 1.0
Content-Type: MESSAGE/RFC822


"
string(53) "MIME-Version: 1.0
Content-Type: MESSAGE/RFC822


"
PK'�Z�BJ��tests/setup/clean.incnu�[���<?php
require_once 'imap_include.inc';

if (!isset($mailbox_suffix)) { throw new Exception("No suffix provided"); }

$imap_stream = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD);

// delete all msgs in default mailbox, i.e INBOX
$check = imap_check($imap_stream);
for ($i = 1; $i <= $check->Nmsgs; $i++) {
    imap_delete($imap_stream, $i);
}


$mailboxes = imap_getmailboxes($imap_stream, IMAP_SERVER, '*');

if (!is_array($mailbox_suffix)) {
    $mailbox_suffixes = [$mailbox_suffix];
} else {
    $mailbox_suffixes = $mailbox_suffix;
}

foreach ($mailbox_suffixes as $mailbox_suffix) {
    foreach($mailboxes as $value) {
        // Only delete mailbox with our prefix (+ optional test suffix)
        if (preg_match('/\{.*?\}INBOX\.' . IMAP_MAILBOX_PHPT_PREFIX . $mailbox_suffix .'$/', $value->name, $match) == 1) {
            imap_deletemailbox($imap_stream, $value->name);
        }
    }
}

imap_close($imap_stream, CL_EXPUNGE);
PK(�Z$��Klltests/setup/skipif.incnu�[���<?php
include __DIR__ . '/imap_include.inc';

$options = OP_HALFOPEN; // this should be enough to verify server present
$retries = 0; // don't retry connect on failure

$mbox = @imap_open(IMAP_SERVER, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD, $options, $retries);
if (!$mbox) {
    die("skip could not connect to mailbox " . IMAP_SERVER);
}
imap_close($mbox);
PK(�Z��,_VVtests/setup/dovecot.confnu�[���# 2.2.33.2 (d6601f4ec): /etc/dovecot/dovecot.conf
# Pigeonhole version 0.4.21 (92477967)
listen = *, ::

# For SSL need to setup a certificate
# See https://wiki.dovecot.org/SSL/DovecotConfiguration
ssl = no

# Disable plaintext to prevent a warning at each login
disable_plaintext_auth = yes

auth_mechanisms = cram-md5
auth_username_format = %u
auth_verbose = yes
auth_debug = yes
auth_failure_delay = 1secs

# This need dovecot 2.3.12.
# login_proxy_timeout = 500milliseconds
# ^ This would allow to kill login processes early, but needs testing. So would use v instead
# login_proxy_timeout = 5s
# There is a 1 second delay between each reconnection attempt.
# https://doc.dovecot.org/settings/core/#login-proxy-max-reconnects
# This need dovecot 2.3.12.
# login_proxy_max_reconnects = 3

# Log config
log_path = /var/log/dovecot.log
# If not set, use the value from log_path
info_log_path = /var/log/dovecot-info.log
# If not set, use the value from info_log_path
debug_log_path = /var/log/dovecot-debug.log
## Mailbox locations and namespaces
mail_location = maildir:/var/vmail/dovecot/mail/%d/%n/Maildir
passdb {
  args = scheme=cram-md5 /etc/dovecot/dovecotpass
  driver = passwd-file
}
protocols = imap
service auth {
  user = root
}
userdb {
  args = /etc/dovecot/dovecotpass
  driver = passwd-file
  override_fields = home=/var/vmail/dovecot/mail/%d/%n
}
PK(�ZF�s���tests/setup/imap_include.incnu�[���<?php
/** If required change these values to make the test runs */
const IMAP_SERVER_NO_DEBUG = '{127.0.0.1:143/norsh}';
const IMAP_SERVER_DEBUG = '{127.0.0.1:143/debug/norsh}';
const IMAP_SERVER = IMAP_SERVER_DEBUG;
const IMAP_DEFAULT_MAILBOX = IMAP_SERVER . 'INBOX';
const IMAP_MAIL_DOMAIN = 'example.com';
const IMAP_ADMIN_USER = 'webmaster'; // a user with admin access
const IMAP_MAILBOX_USERNAME = IMAP_ADMIN_USER . '@' . IMAP_MAIL_DOMAIN;
const IMAP_MAILBOX_PASSWORD = 'p4ssw0rd';
const IMAP_MAILBOX_PHPT_PREFIX = 'phpttest';
/** Tests require 4 valid userids */
const IMAP_USERS = ["webmaster", "info", "admin", "foo"];

/** list of fields to expect */
const MANDATORY_OVERVIEW_FIELDS = [
    'size',
    'uid',
    'msgno',
    'recent',
    'flagged',
    'answered',
    'deleted',
    'seen',
    'draft',
    'udate',
];

// record test start time (used by displayOverviewFields())
$start_time = time();

/**
 * Display all fields in an element from an imap_fetch_overview() response
 *
 * Special handling for 'udate', which will vary run-to-run; assumes an IMAP
 * server with its clock synced to the current system, which is consistent with
 * setup instructions in ext/imap/tests/README.md
 *
 * @param $resp
 * @param string[] $fields
 */
function displayOverviewFields($resp, array $fields = MANDATORY_OVERVIEW_FIELDS) {
    global $start_time;
    foreach ($fields as $mf) {
        $z = $resp->$mf;
        if ($mf == 'udate') {
            if (($z >= $start_time) && ($z <= time())) {
                echo "$mf is OK\n";
            } else {
                echo "$mf is BAD ($z)\n";
            }
        } else {
            echo "$mf is $z\n";
        }
    }
}


/**
 * Create a test mailbox and populate with msgs
 *
 * @param string mailbox_suffix Suffix used to uniquely identify mailboxes
 * @param int message_count number of test msgs to be written to new mailbox
 * @param null $new_mailbox
 * @param bool $simpleMessages
 * @param int $flags OP_* (or CL_EXPUNGE) flags to pass to imap_open() sub-call
 * @return resource IMAP stream to new mailbox
 * @throws Exception
 */
function setup_test_mailbox(
    string $mailbox_suffix,
    int $message_count,
    &$new_mailbox = null,
    bool $simpleMessages = true,
    int $flags = 0,
){
    // open a stream to default mailbox
    $imap_stream = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD, flags: $flags);

    if ($imap_stream === false) {
        throw new Exception("Cannot connect to IMAP server " . IMAP_SERVER . ": " . imap_last_error());
    }

    echo "Create a temporary mailbox and add " . $message_count .  " msgs\n";
    $new_mailbox = create_mailbox($imap_stream, $mailbox_suffix, $message_count, $simpleMessages);

    echo "New mailbox created\n";

    // reopen stream to new mailbox
    if (imap_reopen($imap_stream, $new_mailbox) === false) {
        throw new Exception("Can't re-open '$new_mailbox' mailbox: " . imap_last_error());
    }

    return $imap_stream;
}

/**
 * Create mailbox and fill with generic emails
 *
 * @param resource $imap_stream
 * @param string $mailbox_suffix
 * @param int $message_count
 * @param bool $simpleMessages
 * @return string
 * @throws Exception
 */
function create_mailbox($imap_stream, string $mailbox_suffix, int $message_count, bool $simpleMessages = true): string {
    $mailbox = IMAP_DEFAULT_MAILBOX . '.' . IMAP_MAILBOX_PHPT_PREFIX . $mailbox_suffix;

    $mailboxes = imap_getmailboxes($imap_stream, $mailbox, '*');

    // check mailbox does not already exist
    if ($mailboxes) {
        foreach($mailboxes as $value) {
            if ($value->name == $mailbox) {
                throw new Exception("Mailbox '$mailbox' already exists");
            }
        }
    }

    if (imap_createmailbox($imap_stream, $mailbox) === false) {
        throw new Exception("Can't create a temporary mailbox: " . imap_last_error());
    }

    // Add number of test msgs requested
    if ($message_count > 0) {
        populate_mailbox($imap_stream, $mailbox, $message_count, $simpleMessages);
    }

    return $mailbox;
}

function setup_test_mailbox_for_uid_tests(string $mailbox_suffix, &$msg_no = null, &$msg_uid = null)
{
    $mail_box = setup_test_mailbox($mailbox_suffix, 10);
    echo "Delete 4 messages for Unique ID generation\n";
    // Delete messages to remove the numerical ordering
    imap_delete($mail_box, 3);
    imap_delete($mail_box, 4);
    imap_delete($mail_box, 5);
    imap_delete($mail_box, 6);
    imap_expunge($mail_box);
    $msg_no = 5;
    $msg_uid = 9;

    return $mail_box;
}

/**
 * Populate a mailbox with generic emails
 *
 * @param resource $imap_stream
 * @param string $mailbox
 * @param int $message_count
 * @param bool $simpleMessages
 */
function populate_mailbox($imap_stream, string $mailbox, int $message_count, bool $simpleMessages = true): void {
    for ($i = 1; $i <= $message_count; $i++) {
        if ($simpleMessages) {
            $msg =  "From: foo@anywhere.com\r\n"
                . "To: ". IMAP_USERS[0] . "@" . IMAP_MAIL_DOMAIN . "\r\n"
                . "Subject: test$i\r\n"
                . "\r\n"
                . "$i: this is a test message, please ignore\r\nnewline";
        } else {
            $envelope["from"]= "foo@anywhere.com";
            $envelope["to"]  = IMAP_USERS[0] . "@" . IMAP_MAIL_DOMAIN;
            $envelope["subject"] = "Test msg $i";

            $part1["type"] = TYPEMULTIPART;
            $part1["subtype"] = "mixed";

            $part2["type"] = TYPETEXT;
            $part2["subtype"] = "plain";
            $part2["description"] = "imap_mail_compose() function";
            $part2["contents.data"] = "message 1:xxxxxxxxxxxxxxxxxxxxxxxxxx";

            $part3["type"] = TYPETEXT;
            $part3["subtype"] = "plain";
            $part3["description"] = "Example";
            $part3["contents.data"] = "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy";

            $part4["type"] = TYPETEXT;
            $part4["subtype"] = "plain";
            $part4["description"] = "Return Values";
            $part4["contents.data"] = "message 3:zzzzzzzzzzzzzzzzzzzzzzzzzz";

            $body[1] = $part1;
            $body[2] = $part2;
            $body[3] = $part3;
            $body[4] = $part4;

            $msg = imap_mail_compose($envelope, $body);
        }

        imap_append($imap_stream, $mailbox, $msg);
    }
}

/**
 * Get the mailbox name from a mailbox description, i.e strip off server details.
 *
 * @param string mailbox complete mailbox name
 * @return string mailbox name
 */
function get_mailbox_name(string $mailboxName): string {

    if (preg_match('/\{.*?\}(.*)/', $mailboxName, $match) != 1) {
        throw new Exception("Unrecognized mailbox name '$mailboxName'");
    }

    return $match[1];
}
PK(�ZAUmmtests/setup/dovecotpassnu�[���webmaster@example.com:{CRAM-MD5}be5f3177e9c7c06403272f25d983ba630df4ef40476b353bb3087a8401713451:vmail:vmail
PK(�Z#[�Ftests/setup/setup.shnu�[���sudo service dovecot stop
sudo groupadd -g 5000 vmail
sudo useradd -m -d /var/vmail -s /bin/false -u 5000 -g vmail vmail
sudo cp ext/imap/tests/setup/dovecot.conf /etc/dovecot/dovecot.conf
sudo cp ext/imap/tests/setup/dovecotpass /etc/dovecot/dovecotpass
sudo service dovecot start
PK(�Z�o�ۘ�tests/bug80710_2.phptnu�[���--TEST--
Bug #80710 (imap_mail_compose() header injection) - Remail
--EXTENSIONS--
imap
--FILE--
<?php
$envelope["from"]= "joe@example.com\n From : X-INJECTED";
$envelope["to"]  = "foo@example.com\nFrom: X-INJECTED";
$envelope["cc"]  = "bar@example.com\nFrom: X-INJECTED";
$envelope["subject"]  = "bar@example.com\n\n From : X-INJECTED";
$envelope["remail"]  = "X-INJECTED-REMAIL: X-INJECTED\nFrom: X-INJECTED-REMAIL-FROM"; //<--- Injected as first hdr
$envelope["something"]  = "bar@example.com\nFrom: X-INJECTED";

$part1["type"] = TYPEMULTIPART;
$part1["subtype"] = "mixed";

$part2["type"] = TYPEAPPLICATION;
$part2["encoding"] = ENCBINARY;
$part2["subtype"] = "octet-stream\nContent-Type: X-INJECTED";
$part2["description"] = "some file\nContent-Type: X-INJECTED";
$part2["contents.data"] = "ABC\nContent-Type: X-INJECTED";

$part3["type"] = TYPETEXT;
$part3["subtype"] = "plain";
$part3["description"] = "description3";
$part3["contents.data"] = "contents.data3\n\n\n\t";

$body[1] = $part1;
$body[2] = $part2;
$body[3] = $part3;

echo imap_mail_compose($envelope, $body);
?>
--EXPECTF--
Warning: imap_mail_compose(): header injection attempt in remail in %s on line %d
PK(�ZU��l��"tests/imap_fetch_overview_uid.phptnu�[���--TEST--
imap_fetch_overview() passing a unique ID
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

require_once(__DIR__.'/setup/imap_include.inc');

$imap_mail_box = setup_test_mailbox_for_uid_tests("imapfetchoverviewuid", $msg_no, $uid);

// Usage of == because comparing objects
var_dump(imap_fetch_overview($imap_mail_box, $uid, FT_UID) == imap_fetch_overview($imap_mail_box, $msg_no));

imap_close($imap_mail_box);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapfetchoverviewuid';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECT--
Create a temporary mailbox and add 10 msgs
New mailbox created
Delete 4 messages for Unique ID generation
bool(true)
PK(�Z�+6M��$tests/imap_fetch_overview_basic.phptnu�[���--TEST--
Test imap_fetch_overview() function : basic functionality
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
echo "*** Testing imap_fetch_overview() : basic functionality ***\n";

require_once __DIR__.'/setup/imap_include.inc';

// create a new mailbox and add two new messages to it
$stream_id = setup_test_mailbox('imapfetchoverviewbasic', 2, $mailbox, false);

// get UID for new message
$msg_no = imap_uid($stream_id, 1);
$options = FT_UID;

// Calling imap_fetch_overview() with all possible arguments
echo "\n-- All possible arguments --\n";
$a =  imap_fetch_overview($stream_id, "$msg_no", $options) ;
echo "\n--> Object #1\n";
displayOverviewFields($a[0]);

// Calling imap_fetch_overview() with mandatory arguments
echo "\n-- Mandatory arguments --\n";
$a = imap_fetch_overview($stream_id, '1:2') ;

//first object in array
echo "\n--> Object #1\n";
displayOverviewFields($a[0]);

//Second object in array
echo "\n--> Object #2\n";
displayOverviewFields($a[1]);

imap_close($stream_id);

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapfetchoverviewbasic';
require_once __DIR__.'/setup/clean.inc';
?>
--EXPECTF--
*** Testing imap_fetch_overview() : basic functionality ***
Create a temporary mailbox and add 2 msgs
New mailbox created

-- All possible arguments --

--> Object #1
size is %d
uid is %d
msgno is 1
recent is %d
flagged is 0
answered is 0
deleted is 0
seen is 0
draft is 0
udate is OK

-- Mandatory arguments --

--> Object #1
size is %d
uid is %d
msgno is 1
recent is %d
flagged is 0
answered is 0
deleted is 0
seen is 0
draft is 0
udate is OK

--> Object #2
size is %d
uid is %d
msgno is 2
recent is %d
flagged is 0
answered is 0
deleted is 0
seen is 0
draft is 0
udate is OK
PK(�ZP�;;tests/imap_errors_basic.phptnu�[���--TEST--
Test imap_errors() function : anonymous user not supported
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once __DIR__.'/setup/skipif.inc';
?>
--FILE--
<?php
echo "*** Testing imap_errors() : anonymous user not supported ***\n";
require_once __DIR__.'/setup/imap_include.inc';

$mbox = @imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD, OP_ANONYMOUS);

echo "List any errors\n";
var_dump(imap_errors());

?>
--EXPECTF--
*** Testing imap_errors() : anonymous user not supported ***
List any errors
array(1) {
  [0]=>
  string(%d) "%s"
}
PK#�ZX��:��tests/imap_close_basic.phptnu�[���PK#�Z/��a[[:tests/gh9309.phptnu�[���PK#�Z%�ˬ��tests/imap_savebody_uid.phptnu�[���PK#�ZV�W��)�tests/imap_fetch_overview_variation5.phptnu�[���PK$�Z�:�Ċ��tests/bug75774.phptnu�[���PK$�ZKP7rr�tests/imap_body_errors.phptnu�[���PK$�Z~�:}kkmtests/imap_body_uid.phptnu�[���PK$�Z��4%%" tests/imap_clearflag_full_uid.phptnu�[���PK$�Z�]�I�&tests/bug80215.phptnu�[���PK$�Z6;0����*tests/imap_final.phptnu�[���PK$�Z"��g
g
)�+tests/imap_fetch_overview_variation6.phptnu�[���PK$�Z�����6tests/bug63126.phptnu�[���PK$�Z��p�hh�<tests/imap_binary_basic.phptnu�[���PK$�Z�_]��^Ctests/imap_fetchbody_uid.phptnu�[���PK$�Z�0~ك� SFtests/imap_setflag_full_uid.phptnu�[���PK$�Z�E  &Ntests/bug80226.phptnu�[���PK$�Z�Ь�#�Ptests/imap_renamemailbox_basic.phptnu�[���PK$�Z�1��=="�Ttests/imap_setflag_full_basic.phptnu�[���PK$�ZX�/�**Ztests/imap_lsub_basic.phptnu�[���PK$�Z"@�MM�^tests/bug77020.phptnu�[���PK$�Z����`tests/imap_timeout_basic.phptnu�[���PK$�ZK����Ndtests/imap_utf8.phptnu�[���PK$�Z��3�TTnetests/imap_savebody_basic.phptnu�[���PK%�Z���sitests/imap_8bit_basic.phptnu�[���PK%�Z3}�\��nltests/bug46918.phptnu�[���PK%�Z'��]rtests/imap_body_basic.phptnu�[���PK%�Z=�vtests/imap_mail_copy_basic.phptnu�[���PK%�Z����yztests/bug35669.phptnu�[���PK%�Z���9����tests/README.mdnu�[���PK%�Zպ�U==U�tests/imap_undelete_basic.phptnu�[���PK%�Zz�\|���tests/nil_constant.phptnu�[���PK%�ZDvCH��&ˉtests/imap_fetchheader_variation5.phptnu�[���PK%�Z@�n55 ��tests/imap_bodystruct_basic.phptnu�[���PK%�Z1��^��%C�tests/imap_fetchstructure_errors.phptnu�[���PK%�Z���p��+�tests/imap_mail_move_basic.phptnu�[���PK%�Z�7�D���tests/imap_savebody_errors.phptnu�[���PK%�Z���+	+	$�tests/imap_clearflag_full_basic.phptnu�[���PK%�Z���ZGG��tests/imap_sort_uid.phptnu�[���PK%�Z`�*�&&�tests/imap_base64_basic.phptnu�[���PK%�Z�;d��"��tests/imap_fetchstructure_uid.phptnu�[���PK%�Z�^�����tests/imap_fetchmime_uid.phptnu�[���PK%�Z���й���tests/imap_delete_uid.phptnu�[���PK%�ZC���%	%	 ��tests/imap_headerinfo_basic.phptnu�[���PK%�Z�3����tests/imap_list_basic.phptnu�[���PK%�Z��h���tests/imap_open_error.phptnu�[���PK%�Z6G6L�� ��tests/imap_fetchbody_errors.phptnu�[���PK&�Z�jv����tests/imap_fetchheader_uid.phptnu�[���PK&�Z@֊/��tests/bug80438.phptnu�[���PK&�Z��Jz]]�tests/bug80242.phptnu�[���PK&�Z�ʞ��tests/bug80800.phptnu�[���PK&�Z,�е77�tests/bug40854.phptnu�[���PK&�Z��`77z�tests/bug31142_1.phptnu�[���PK&�ZES%%&��tests/imap_reopen_with_cl_expunge.phptnu�[���PK&�Z+�jKq�tests/bug77153.phptnu�[���PK&�ZH�,���#��tests/imap_createmailbox_basic.phptnu�[���PK&�Zx���ZZ�tests/bug64076.phptnu�[���PK&�ZM�k���*��tests/imap_rfc822_write_address_basic.phptnu�[���PK&�Z�-]OO�tests/bug31142_2.phptnu�[���PK&�Z��~~$g�tests/imap_open_with_cl_expunge.phptnu�[���PK&�ZPsCt9tests/imap_mutf7_to_utf8.phptnu�[���PK&�Z���L�� �tests/imap_fetchmime_errors.phptnu�[���PK&�Z_��#�tests/imap_utf8_to_mutf7_basic.phptnu�[���PK&�Z`CF|pp�
tests/bug80710_1.phptnu�[���PK&�Z��)1�	�	 �tests/imap_close_variation4.phptnu�[���PK&�Z"o'����tests/imap_fetchbody_basic.phptnu�[���PK&�Z4�``�%tests/bug45705_2.phptnu�[���PK'�Z?���~+tests/imap_search_basic.phptnu�[���PK'�Z�|��z.tests/bug32589.phptnu�[���PK'�Z'.b&&A1tests/imap_constructor.phptnu�[���PK'�Zż=��*�2tests/imap_rfc822_parse_headers_basic.phptnu�[���PK'�ZSs����#�;tests/imap_getsubscribed_basic.phptnu�[���PK'�Zka�����@tests/imap_gc_error.phptnu�[���PK'�Z��)���Ctests/bug80213.phptnu�[���PK'�Z���33uEtests/imap_undelete_uid.phptnu�[���PK'�Z�L���$�Htests/imap_fetchstructure_basic.phptnu�[���PK'�Z��I��"�Mtests/imap_fetchheader_errors.phptnu�[���PK'�Z�L�H���Rtests/imap_is_open.phptnu�[���PK'�Zj�Ɩ\\�Utests/bug45705_1.phptnu�[���PK'�Z1�2nn!{Wtests/imap_fetchheader_basic.phptnu�[���PK'�Z������:_tests/bug80223.phptnu�[���PK'�Z�y�i��btests/bug80216.phptnu�[���PK'�Z.O��dtests/bug44098.phptnu�[���PK'�ZV_P�^^:etests/bug53377.phptnu�[���PK'�Z(,�PP�gtests/imap_append_basic.phptnu�[���PK'�ZB�chh$wotests/imap_fetchbody_variation6.phptnu�[���PK'�Z72��3utests/bug80220.phptnu�[���PK'�Z�BJ���wtests/setup/clean.incnu�[���PK(�Z$��Kll�{tests/setup/skipif.incnu�[���PK(�Z��,_VVI}tests/setup/dovecot.confnu�[���PK(�ZF�s����tests/setup/imap_include.incnu�[���PK(�ZAUmm��tests/setup/dovecotpassnu�[���PK(�Z#[�Fh�tests/setup/setup.shnu�[���PK(�Z�o�ۘ�Ɵtests/bug80710_2.phptnu�[���PK(�ZU��l��"��tests/imap_fetch_overview_uid.phptnu�[���PK(�Z�+6M��$��tests/imap_fetch_overview_basic.phptnu�[���PK(�ZP�;;�tests/imap_errors_basic.phptnu�[���PK``!"i�