| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of the PHP IMAP2 package. |
| 5 |
* |
| 6 |
* (c) Francesco Bianco <[email protected]> |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace AcyMailing\Libraries\Imap2; |
| 13 |
|
| 14 |
class Errors |
| 15 |
{ |
| 16 |
protected static $alerts = []; |
| 17 |
|
| 18 |
protected static $errors = []; |
| 19 |
|
| 20 |
protected static $lastError; |
| 21 |
|
| 22 |
public static function appendAlert($alert) |
| 23 |
{ |
| 24 |
self::$alerts[] = $alert; |
| 25 |
} |
| 26 |
|
| 27 |
public static function appendError($error) |
| 28 |
{ |
| 29 |
self::$lastError = $error; |
| 30 |
|
| 31 |
self::$errors[] = $error; |
| 32 |
} |
| 33 |
|
| 34 |
public static function alerts() |
| 35 |
{ |
| 36 |
if (empty(self::$alerts)) { |
| 37 |
return false; |
| 38 |
} |
| 39 |
|
| 40 |
$return = self::$alerts; |
| 41 |
|
| 42 |
self::$alerts = []; |
| 43 |
|
| 44 |
return $return; |
| 45 |
} |
| 46 |
|
| 47 |
public static function errors() |
| 48 |
{ |
| 49 |
if (empty(self::$errors)) { |
| 50 |
return false; |
| 51 |
} |
| 52 |
|
| 53 |
$return = self::$errors; |
| 54 |
|
| 55 |
self::$errors = []; |
| 56 |
|
| 57 |
return $return; |
| 58 |
} |
| 59 |
|
| 60 |
public static function lastError() |
| 61 |
{ |
| 62 |
if (empty(self::$lastError)) { |
| 63 |
return false; |
| 64 |
} |
| 65 |
|
| 66 |
return self::$lastError; |
| 67 |
} |
| 68 |
|
| 69 |
public static function raiseWarning($warning, $backtrace, $depth) |
| 70 |
{ |
| 71 |
$message = $warning.' in '.$backtrace[$depth]['file'].' on line '.$backtrace[$depth]['line']; |
| 72 |
|
| 73 |
trigger_error($message, E_USER_WARNING); |
| 74 |
} |
| 75 |
|
| 76 |
public static function invalidImapConnection($backtrace, $depth, $return) |
| 77 |
{ |
| 78 |
$warning = 'Invalid IMAP connection parameter for '.$backtrace[$depth]['function'].'() ' |
| 79 |
.'at '.$backtrace[$depth]['file'].' on line '.$backtrace[$depth]['line'].'. Source code'; |
| 80 |
|
| 81 |
trigger_error($warning, E_USER_WARNING); |
| 82 |
|
| 83 |
return $return; |
| 84 |
} |
| 85 |
|
| 86 |
public static function couldNotOpenStream($mailbox, $backtrace, $depth) |
| 87 |
{ |
| 88 |
if (isset($backtrace[$depth + 1]['function']) && $backtrace[$depth + 1]['function'] == 'imap_open') { |
| 89 |
$depth++; |
| 90 |
} |
| 91 |
|
| 92 |
return $backtrace[$depth]['function'].'(): Couldn\'t open stream '.$mailbox |
| 93 |
.' in '.$backtrace[$depth]['file'].' on line '.$backtrace[$depth]['line'].'. Source code'; |
| 94 |
} |
| 95 |
|
| 96 |
public static function badMessageNumber($backtrace, $depth) |
| 97 |
{ |
| 98 |
if (Functions::isBackportCall($backtrace, $depth)) { |
| 99 |
$depth++; |
| 100 |
} |
| 101 |
|
| 102 |
return $backtrace[$depth]['function'].'(): Bad message number in ' |
| 103 |
.$backtrace[$depth]['file'].' on line '.$backtrace[$depth]['line'].'. Source code'; |
| 104 |
} |
| 105 |
|
| 106 |
public static function appendErrorCanNotOpen($mailbox, $error) |
| 107 |
{ |
| 108 |
if ($mailbox[0] == '{') { |
| 109 |
$error = preg_replace("/^AUTHENTICATE [A-Z]+\d*:\s/i", '', $error); |
| 110 |
//$error = preg_replace("/^([A-Z]+\d+ )(OK|NO|BAD|BYE|PREAUTH)?\s/i", '', $error); |
| 111 |
$error = 'Can not authenticate to IMAP server: '.$error; |
| 112 |
} else { |
| 113 |
$error = "Can't open mailbox {$mailbox}: no such mailbox"; |
| 114 |
} |
| 115 |
|
| 116 |
self::appendError($error); |
| 117 |
} |
| 118 |
} |
| 119 |
|