-
Notifications
You must be signed in to change notification settings - Fork 4
/
qresync_test.php
77 lines (63 loc) · 2.05 KB
/
qresync_test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* qresync_test.php
*
* In order to test this extension 2 connections to the IMAP server are
* required. The first builds some cache data about a mailbox, the second
* changes the mailbox state, then the original connection detects and
* adjusts the cache to that state change.
*/
/* check for username and password */
if ( isset( $argv[2] ) ) {
$username = $argv[1];
$password = $argv[2];
}
else {
die( "\nyou need to pass your IMAP login and password to this script:\n\nphp ./qresync_test.php jason 123456\n\n" );
}
/* show all notices */
error_reporting ( E_ALL | E_STRICT );
/* set a default timezone */
date_default_timezone_set( 'UTC' );
/* include IMAP library */
require( 'hm-imap.php' );
/* start up primary connection */
$imap = new Hm_IMAP();
/* start up secondary connection */
$imap2 = new Hm_IMAP();
/* connect to gmail's IMAP server in read only mode */
if ( $imap->connect( [
'username' => $username,
'password' => $password,
'server' => '127.0.0.1',
'use_cache' => true ] ) ) {
/* select the INBOX and fetch some headers */
$folder_detail = $imap->select_mailbox( 'INBOX' );
$imap->message_action('UNFLAG', array( 18 ) );
$imap->get_message_list( array( 18 ) );
/* connect as a second client and change a flag */
$imap2->connect( [
'username' => $username,
'password' => $password,
'server' => '127.0.0.1',
'use_cache' => true
] );
$imap2->select_mailbox( 'INBOX' );
$imap2->message_action('FLAG', array( 18 ) );
$imap2->disconnect();
/* poll should trigger a QRESYNC untagged response */
$imap->poll();
/* collect response */
$result = $imap->show_debug( false, true );
/* search for cache update success message */
if ( !strstr( $result, 'Cache bust avoided' ) ) {
die( "QRESYNC test FAILED\n" );
}
else {
printf("QRESYNC test PASSED\n");
}
/* show debug statements and IMAP commands */
$imap->show_debug();
$imap2->show_debug();
}
?>