-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathErrors.php
118 lines (89 loc) · 2.99 KB
/
Errors.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/*
* This file is part of the PHP IMAP2 package.
*
* (c) Francesco Bianco <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Javanile\Imap2;
class Errors
{
protected static $alerts = [];
protected static $errors = [];
protected static $lastError;
public static function appendAlert($alert)
{
self::$alerts[] = $alert;
}
public static function appendError($error)
{
self::$lastError = $error;
self::$errors[] = $error;
}
public static function alerts()
{
if (empty(self::$alerts)) {
return false;
}
$return = self::$alerts;
self::$alerts = [];
return $return;
}
public static function errors()
{
if (empty(self::$errors)) {
return false;
}
$return = self::$errors;
self::$errors = [];
return $return;
}
public static function lastError()
{
if (empty(self::$lastError)) {
return false;
}
return self::$lastError;
}
public static function raiseWarning($warning, $backtrace, $depth)
{
$message = $warning . ' in '.$backtrace[$depth]['file']. ' on line '.$backtrace[$depth]['line'];
trigger_error($message, E_USER_WARNING);
}
public static function invalidImapConnection($backtrace, $depth, $return)
{
$warning = 'Invalid IMAP connection parameter for '.$backtrace[$depth]['function'].'() '
. 'at '.$backtrace[$depth]['file']. ' on line '.$backtrace[$depth]['line'].'. Source code';
trigger_error($warning, E_USER_WARNING);
return $return;
}
public static function couldNotOpenStream($mailbox, $backtrace, $depth)
{
if (isset($backtrace[$depth + 1]['function']) && $backtrace[$depth + 1]['function'] == 'imap_open') {
$depth++;
}
return $backtrace[$depth]['function'].'(): Couldn\'t open stream '.$mailbox
. ' in '.$backtrace[$depth]['file']. ' on line '.$backtrace[$depth]['line'].'. Source code';
}
public static function badMessageNumber($backtrace, $depth)
{
if (Functions::isBackportCall($backtrace, $depth)) {
$depth++;
}
return $backtrace[$depth]['function'].'(): Bad message number in '
. $backtrace[$depth]['file']. ' on line '.$backtrace[$depth]['line'].'. Source code';
}
public static function appendErrorCanNotOpen($mailbox, $error)
{
if ($mailbox[0] == '{') {
$error = preg_replace("/^AUTHENTICATE [A-Z]+\d*:\s/i", '', $error);
//$error = preg_replace("/^([A-Z]+\d+ )(OK|NO|BAD|BYE|PREAUTH)?\s/i", '', $error);
$error = 'Can not authenticate to IMAP server: '.$error;
} else {
$error = "Can't open mailbox {$mailbox}: no such mailbox";
}
self::appendError($error);
}
}