3
3
$ server = '{127.0.0.1/norsh} ' ;
4
4
$ default_mailbox = $ server . "INBOX " ;
5
5
$ domain = "something.com " ;
6
- $ admin_user = "webmaster " ; // a user with admin access
6
+ $ admin_user = "webmaster " ; // a user with admin access
7
7
$ username = "$ admin_user@ $ domain " ;
8
8
$ password = 'p4ssw0rd ' ;
9
9
$ users = array ("webmaster " , "info " , "admin " , "foo " ); // tests require 4 valid userids
@@ -56,39 +56,39 @@ function displayOverviewFields($resp, $fields=null) {
56
56
57
57
58
58
/**
59
- * Create a test mailbox and populate with msgs
59
+ * Create a test mailbox and populate with msgs
60
60
*
61
61
* @param string mailbox_suffix Suffix used to uniquely identify mailboxes
62
- * @param int message_count number of test msgs to be written to new mailbox
63
- *
62
+ * @param int message_count number of test msgs to be written to new mailbox
63
+ *
64
64
* @return IMAP stream to new mailbox on success; FALSE on failure
65
65
*/
66
66
function setup_test_mailbox ($ mailbox_suffix , $ message_count , &$ new_mailbox = null , $ msg_type = "simple " ){
67
67
global $ server , $ default_mailbox , $ username , $ password ;
68
-
68
+
69
69
// open a stream to default mailbox
70
70
$ imap_stream = imap_open ($ default_mailbox , $ username , $ password );
71
71
72
72
if ($ imap_stream === false ) {
73
73
echo "Cannot connect to IMAP server $ server: " . imap_last_error () . "\n" ;
74
74
return false ;
75
- }
76
-
75
+ }
76
+
77
77
echo "Create a temporary mailbox and add " . $ message_count . " msgs \n" ;
78
78
$ new_mailbox = create_mailbox ($ imap_stream , $ mailbox_suffix , $ message_count , $ msg_type );
79
79
if ($ new_mailbox === false ) {
80
80
echo "Cant create a temporary mailbox: " . imap_last_error (). "\n" ;
81
81
return false ;
82
82
}
83
-
83
+
84
84
echo ".. mailbox ' $ new_mailbox' created \n" ;
85
-
85
+
86
86
// reopen stream to new mailbox
87
87
if (imap_reopen ($ imap_stream , $ new_mailbox ) === false ) {
88
88
echo "cant re-open ' $ new_mailbox' mailbox: " . imap_last_error () . "\n" ;
89
89
return false ;
90
90
}
91
-
91
+
92
92
return $ imap_stream ;
93
93
}
94
94
@@ -101,27 +101,27 @@ function setup_test_mailbox($mailbox_suffix, $message_count, &$new_mailbox = nul
101
101
function create_mailbox ($ imap_stream , $ mailbox_suffix , $ message_count , $ msg_type = "simple " ){
102
102
global $ default_mailbox , $ mailbox_prefix ;
103
103
$ mailbox = $ default_mailbox . ". " . $ mailbox_prefix . $ mailbox_suffix ;
104
-
104
+
105
105
$ mailboxes = imap_getmailboxes ($ imap_stream , $ mailbox , '* ' );
106
-
106
+
107
107
// check mailbox does not already exist
108
108
if ($ mailboxes ) {
109
109
foreach ($ mailboxes as $ value ) {
110
110
if ($ value ->name == $ mailbox ) {
111
111
exit ("TEST FAILED : Mailbox ' $ mailbox' already exists \n" );
112
112
}
113
113
}
114
- }
114
+ }
115
115
116
116
if (imap_createmailbox ($ imap_stream , $ mailbox ) === false ) {
117
117
return false ;
118
118
}
119
-
119
+
120
120
// Add number of test msgs requested
121
121
if ($ message_count > 0 ) {
122
122
populate_mailbox ($ imap_stream , $ mailbox , $ message_count , $ msg_type );
123
- }
124
-
123
+ }
124
+
125
125
return $ mailbox ;
126
126
}
127
127
@@ -146,42 +146,42 @@ function populate_mailbox($imap_stream, $mailbox, $message_count, $msg_type = "s
146
146
$ envelope[
"from " ]=
"[email protected] " ;
147
147
$ envelope ["to " ] = "$ users [0 ]@ $ domain " ;
148
148
$ envelope ["subject " ] = "Test msg $ i " ;
149
-
149
+
150
150
$ part1 ["type " ] = TYPEMULTIPART ;
151
151
$ part1 ["subtype " ] = "mixed " ;
152
-
152
+
153
153
$ part2 ["type " ] = TYPETEXT ;
154
154
$ part2 ["subtype " ] = "plain " ;
155
155
$ part2 ["description " ] = "imap_mail_compose() function " ;
156
156
$ part2 ["contents.data " ] = "message 1:xxxxxxxxxxxxxxxxxxxxxxxxxx " ;
157
-
157
+
158
158
$ part3 ["type " ] = TYPETEXT ;
159
159
$ part3 ["subtype " ] = "plain " ;
160
160
$ part3 ["description " ] = "Example " ;
161
161
$ part3 ["contents.data " ] = "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy " ;
162
-
162
+
163
163
$ part4 ["type " ] = TYPETEXT ;
164
164
$ part4 ["subtype " ] = "plain " ;
165
165
$ part4 ["description " ] = "Return Values " ;
166
166
$ part4 ["contents.data " ] = "message 3:zzzzzzzzzzzzzzzzzzzzzzzzzz " ;
167
-
167
+
168
168
$ body [1 ] = $ part1 ;
169
169
$ body [2 ] = $ part2 ;
170
170
$ body [3 ] = $ part3 ;
171
171
$ body [4 ] = $ part4 ;
172
-
172
+
173
173
$ msg = imap_mail_compose ($ envelope , $ body );
174
174
}
175
-
175
+
176
176
imap_append ($ imap_stream , $ mailbox , $ msg );
177
177
}
178
178
}
179
179
180
180
/**
181
- * Get the mailbox name from a mailbox decription, i.e strip off server details.
181
+ * Get the mailbox name from a mailbox decription, i.e strip off server details.
182
182
*
183
- * @param string mailbox complete mailbox name
184
- * @return mailbox name
183
+ * @param string mailbox complete mailbox name
184
+ * @return mailbox name
185
185
*/
186
186
function get_mailbox_name ($ mailbox ){
187
187
0 commit comments