| 1 |
<?php |
| 2 |
|
| 3 |
abstract class pMailServer { |
| 4 |
|
| 5 |
abstract function deleteMessages($uids); |
| 6 |
|
| 7 |
abstract function countMessages(); |
| 8 |
|
| 9 |
abstract function close(); |
| 10 |
|
| 11 |
abstract function fetchMessageSource($uid); |
| 12 |
|
| 13 |
abstract function listMessages($limit = NULL, $page = NULL); |
| 14 |
|
| 15 |
protected function cleanDate($date) { |
| 16 |
$date = preg_replace('#\([^)]+\)#', ' ', trim($date)); |
| 17 |
$date = preg_replace('#\s+#', ' ', $date); |
| 18 |
$date = preg_replace('#(\d+)-([a-z]+)-(\d{4})#i', '\1 \2 \3', $date); |
| 19 |
$date = preg_replace('#^[a-z]+\s*,\s*#i', '', trim($date)); |
| 20 |
return trim($date); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Joins parsed emails into a comma-delimited string |
| 25 |
* |
| 26 |
* @param array $emails An array of emails split into personal, mailbox and host parts |
| 27 |
* @return string An comma-delimited list of emails |
| 28 |
*/ |
| 29 |
protected function joinEmails($emails) { |
| 30 |
$output = ''; |
| 31 |
foreach ($emails as $email) { |
| 32 |
if ($output) { |
| 33 |
$output .= ', '; |
| 34 |
} |
| 35 |
|
| 36 |
if (!isset($email[0])) { |
| 37 |
$email[0] = !empty($email['personal']) ? $email['personal'] : ''; |
| 38 |
$email[2] = $email['mailbox']; |
| 39 |
$email[3] = !empty($email['host']) ? $email['host'] : ''; |
| 40 |
} |
| 41 |
|
| 42 |
$address = $email[2]; |
| 43 |
if (!empty($email[3])) { |
| 44 |
$address .= '@' . $email[3]; |
| 45 |
} |
| 46 |
$output .= fEmail::combineNameEmail($email[0], $address); |
| 47 |
} |
| 48 |
return $output; |
| 49 |
} |
| 50 |
|
| 51 |
protected function decodeHeader($text) { |
| 52 |
$parts = preg_split('#(=\?[^\?]+\?[QB]\?[^\?]+\?=)#i', $text, -1, PREG_SPLIT_DELIM_CAPTURE); |
| 53 |
|
| 54 |
$part_with_encoding = array(); |
| 55 |
$output = ''; |
| 56 |
foreach ($parts as $part) { |
| 57 |
if ($part === '') { |
| 58 |
continue; |
| 59 |
} |
| 60 |
|
| 61 |
if (preg_match_all('#=\?([^\?]+)\?([QB])\?([^\?]+)\?=#i', $part, $matches, PREG_SET_ORDER)) { |
| 62 |
foreach ($matches as $match) { |
| 63 |
if (strtoupper($match[2]) == 'Q') { |
| 64 |
$part_string = rawurldecode(strtr( |
| 65 |
$match[3], array( |
| 66 |
'=' => '%', |
| 67 |
'_' => ' ' |
| 68 |
) |
| 69 |
)); |
| 70 |
} else { |
| 71 |
$part_string = base64_decode($match[3]); |
| 72 |
} |
| 73 |
$lower_encoding = strtolower($match[1]); |
| 74 |
$last_key = count($part_with_encoding) - 1; |
| 75 |
if (isset($part_with_encoding[$last_key]) && $part_with_encoding[$last_key]['encoding'] == $lower_encoding) { |
| 76 |
$part_with_encoding[$last_key]['string'] .= $part_string; |
| 77 |
} else { |
| 78 |
$part_with_encoding[] = array('encoding' => $lower_encoding, 'string' => $part_string); |
| 79 |
} |
| 80 |
} |
| 81 |
} else { |
| 82 |
$last_key = count($part_with_encoding) - 1; |
| 83 |
if (isset($part_with_encoding[$last_key]) && $part_with_encoding[$last_key]['encoding'] == 'iso-8859-1') { |
| 84 |
$part_with_encoding[$last_key]['string'] .= $part; |
| 85 |
} else { |
| 86 |
$part_with_encoding[] = array('encoding' => 'iso-8859-1', 'string' => $part); |
| 87 |
} |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
foreach ($part_with_encoding as $part) { |
| 92 |
$output .= $this->iconv($part['encoding'], 'UTF-8', $part['string']); |
| 93 |
} |
| 94 |
|
| 95 |
return $output; |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* This works around a bug in MAMP 1.9.4+ and PHP 5.3 where iconv() |
| 100 |
* does not seem to properly assign the return value to a variable, but |
| 101 |
* does work when returning the value. |
| 102 |
* |
| 103 |
* @param string $in_charset The incoming character encoding |
| 104 |
* @param string $out_charset The outgoing character encoding |
| 105 |
* @param string $string The string to convert |
| 106 |
* @return string The converted string |
| 107 |
*/ |
| 108 |
protected function iconv($in_charset, $out_charset, $string) { |
| 109 |
return iconv($in_charset, "$out_charset//IGNORE", $string); |
| 110 |
} |
| 111 |
|
| 112 |
} |
| 113 |
|