From f4dd5e6e0fc7a22f5daeb7f851a8b5f8560d52a5 Mon Sep 17 00:00:00 2001 From: Tonko Mulder Date: Mon, 27 Mar 2017 11:23:40 +0200 Subject: [PATCH 01/14] added reference to forked Eden/Core related to issue #30 --- composer.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ed63ece..48dccc5 100644 --- a/composer.json +++ b/composer.json @@ -11,9 +11,15 @@ "email": "cblanquera@openovate.com" } ], + "repositories": [ + { + "type": "git", + "url": "https://github.com/beeproger/core" + } + ], "require": { "php": ">=5.4.1", - "eden/core": "4.*", + "eden/core": "4.0.3.1", "eden/string": "4.*", "eden/array": "4.*", "eden/path": "4.*", From 955045391a2e8710dc8be7fa8b352295560979f3 Mon Sep 17 00:00:00 2001 From: Tonko Mulder Date: Tue, 18 Apr 2017 17:38:34 +0200 Subject: [PATCH 02/14] added checks for non existing items Signed-off-by: Tonko Mulder --- src/Imap.php | 81 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 25 deletions(-) diff --git a/src/Imap.php b/src/Imap.php index b652865..235e2d1 100644 --- a/src/Imap.php +++ b/src/Imap.php @@ -29,72 +29,72 @@ class Imap extends Base * @const string NO_SUBJECT Default subject */ const NO_SUBJECT = '(no subject)'; - + /** * @var string $host The IMAP Host */ protected $host = null; - + /** * @var string|null $port The IMAP port */ protected $port = null; - + /** * @var bool $ssl Whether to use SSL */ protected $ssl = false; - + /** * @var bool $tls Whether to use TLS */ protected $tls = false; - + /** * @var string|null $username The mailbox user name */ protected $username = null; - + /** * @var string|null $password The mailbox password */ protected $password = null; - + /** * @var int $tag The tag number */ protected $tag = 0; - + /** * @var int $total The total main in mailbox */ protected $total = 0; - + /** * @var int $next for pagination */ protected $next = 0; - + /** * @var string|null $buffer Mail body */ protected $buffer = null; - + /** * @var [RESOURCE] $socket The socket connection */ protected $socket = null; - + /** * @var string|null $mailbox The mailbox name */ protected $mailbox = null; - + /** * @var array $mailboxes The list of mailboxes */ protected $mailboxes = array(); - + /** * @var bool $debugging If true outputs the logs */ @@ -462,7 +462,7 @@ public function remove($uid) return $this; } - + /** * Remove an email from a mailbox * @@ -470,9 +470,8 @@ public function remove($uid) */ public function expunge() { - $this->call('expunge'); - + return $this; } @@ -890,7 +889,12 @@ private function getEmailFormat($email, $uniqueId = null, array $flags = array() } } - $sender['email'] = $headers1->from[0]->mailbox . '@' . $headers1->from[0]->host; + if (isset($headers1->from[0]) && is_object($headers1->from[0])) { + $sender['email'] = $headers1->from[0]->mailbox . '@' . $headers1->from[0]->host; + } + else { + $sender['email'] = 'unknown@localhost.localdomain'; + } //set the to if (isset($headers1->to)) { @@ -1059,6 +1063,15 @@ private function getEmailResponse($command, $parameters = array(), $first = fals //if the line starts with a fetch //it means it's the end of getting an email if (strpos($line, 'FETCH') !== false && strpos($line, 'TAG'.$this->tag) === false) { + /** + * simple regex to match the FETCH line + * used to skip over a $line that hasn't got to do with the FETCH or TAG line + */ + preg_match('/^\* [0-9]+/', $line, $arr); + // no match, there isn't sufficient information to parse the email. Skipping. + // potential exception: undefined $flags + if (empty($arr)) continue; + //if there is email data if (!empty($email)) { //create the email format and add it to emails @@ -1359,7 +1372,12 @@ function imap_rfc822_parse_headers($header) $headers->to = $headers->cc = $headers->bcc = array(); preg_match('#Message\-(ID|id|Id)\:([^\n]*)#', $header, $ID); - $headers->ID = trim($ID[2]); + if (isset($ID[2])){ + $headers->ID = trim($ID[2]); + } + else { + $headers->ID = 'Message-ID: '; + } unset($ID); preg_match('#\nTo\:([^\n]*)#', $header, $to); @@ -1372,7 +1390,12 @@ function imap_rfc822_parse_headers($header) $headers->from = array(new \stdClass()); preg_match('#\nFrom\:([^\n]*)#', $header, $from); - $headers->from[0] = imap_rfc822_parse_headers_decode(trim($from[1])); + if (isset($from[1])) { + $headers->from[0] = imap_rfc822_parse_headers_decode(trim($from[1])); + } + else { + $headers->from[0] = 'unknown@localhost.localdomain'; + } preg_match('#\nCc\:([^\n]*)#', $header, $cc); if (isset($cc[1])) { @@ -1391,15 +1414,23 @@ function imap_rfc822_parse_headers($header) } preg_match('#\nSubject\:([^\n]*)#', $header, $subject); - $headers->subject = trim($subject[1]); - unset($subject); + if (isset($subject[1])) { + $headers->subject = trim($subject[1]); + unset($subject); + } preg_match('#\nDate\:([^\n]*)#', $header, $date); - $date = substr(trim($date[0]), 6); + if (isset($date[0])) { + $date = substr(trim($date[0]), 6); - $date = preg_replace('/\(.*\)/', '', $date); - $headers->date = trim($date); + $date = preg_replace('/\(.*\)/', '', $date); + + $headers->date = trim($date); + } + else { + $headers->date = date('d-m-Y H:i:s'); + } unset($date); foreach ($ccs as $k => $cc) { From cbd8f4789cdc3f0405534e7aa48c0b8aa92c3f24 Mon Sep 17 00:00:00 2001 From: Tonko Mulder Date: Wed, 10 May 2017 14:52:03 +0200 Subject: [PATCH 03/14] added empty array variable this should prevent exceptions that the variable 'flags' couldn't be found Signed-off-by: Tonko Mulder --- src/Imap.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Imap.php b/src/Imap.php index 235e2d1..96e2b51 100644 --- a/src/Imap.php +++ b/src/Imap.php @@ -1063,6 +1063,7 @@ private function getEmailResponse($command, $parameters = array(), $first = fals //if the line starts with a fetch //it means it's the end of getting an email if (strpos($line, 'FETCH') !== false && strpos($line, 'TAG'.$this->tag) === false) { + $flags = []; /** * simple regex to match the FETCH line * used to skip over a $line that hasn't got to do with the FETCH or TAG line From 26780b2e63b2bc4b47056c26d86887ddcbe92a06 Mon Sep 17 00:00:00 2001 From: Tonko Mulder Date: Tue, 23 May 2017 16:58:00 +0200 Subject: [PATCH 04/14] added default value for when setting an inbox some inboxes don't have five items which are expected. if that is the case add a default empty one Signed-off-by: Tonko Mulder --- src/Imap.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Imap.php b/src/Imap.php index 96e2b51..75c9cf2 100644 --- a/src/Imap.php +++ b/src/Imap.php @@ -672,6 +672,10 @@ public function setActiveMailbox($mailbox) if (strpos($line, 'EXISTS') !== false) { list($star, $this->total, $type) = explode(' ', $line, 3); } else if (strpos($line, 'UIDNEXT') !== false) { + $explode = explode(' ', $line, 5); + // the list function expects 5 items + if (count($explode) < 5) array_push($explode, "The next unique identifier value"); + list($star, $ok, $next, $this->next, $type) = explode(' ', $line, 5); $this->next = substr($this->next, 0, -1); } From 8eaf646e41cb1b1011291657432a7a72d4c9882f Mon Sep 17 00:00:00 2001 From: Tonko Mulder Date: Wed, 24 May 2017 11:13:56 +0200 Subject: [PATCH 05/14] and now actually setting the default value Signed-off-by: Tonko Mulder --- src/Imap.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Imap.php b/src/Imap.php index 75c9cf2..cdab183 100644 --- a/src/Imap.php +++ b/src/Imap.php @@ -674,9 +674,14 @@ public function setActiveMailbox($mailbox) } else if (strpos($line, 'UIDNEXT') !== false) { $explode = explode(' ', $line, 5); // the list function expects 5 items - if (count($explode) < 5) array_push($explode, "The next unique identifier value"); - - list($star, $ok, $next, $this->next, $type) = explode(' ', $line, 5); + if (count($explode) < 5) { + array_push($explode, "The next unique identifier value"); + list($star, $ok, $next, $this->next, $type) = $explode; + } + else { + list($star, $ok, $next, $this->next, $type) = explode(' ', $line, + 5); + } $this->next = substr($this->next, 0, -1); } From fdb10ae80ad861531e6baa42860eca481e92a594 Mon Sep 17 00:00:00 2001 From: Tonko Mulder Date: Fri, 26 May 2017 15:53:01 +0200 Subject: [PATCH 06/14] preventing 'undefined index 1' error message --- src/Imap.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Imap.php b/src/Imap.php index cdab183..8c900b1 100644 --- a/src/Imap.php +++ b/src/Imap.php @@ -748,7 +748,11 @@ protected function receive($sentTag) $start = time(); while (time() < ($start + self::TIMEOUT)) { - list($receivedTag, $line) = explode(' ', $this->getLine(), 2); + $explode = explode(' ', $this->getLine(), 2); + if (count($explode) < 2) { + array_push($explode, "OK []\r\n"); + } + list($receivedTag, $line) = $explode; $this->buffer[] = trim($receivedTag . ' ' . $line); if ($receivedTag == 'TAG'.$sentTag) { return $this->buffer; From 9ae6f0d04d88e886eae71b13027eabe29f4c0d05 Mon Sep 17 00:00:00 2001 From: Leonardo Weslei Diniz Date: Tue, 15 Aug 2017 00:23:49 -0300 Subject: [PATCH 07/14] FIX mailbox names fetch --- src/Imap.php | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) diff --git a/src/Imap.php b/src/Imap.php index b652865..8a74925 100644 --- a/src/Imap.php +++ b/src/Imap.php @@ -371,7 +371,18 @@ public function getMailboxes() continue; } - $mailboxes[] = $line[count($line)-2]; + $mailbox = trim($line[count($line) - 2]); + + if ($mailbox == "/" || $mailbox == "") { + $mailbox = $line[count($line) - 1]; + } + + //Fix mailbox name encoded with utf7 + $mailbox = ImapUtf7::decode(trim($mailbox)); + //Decoding utf8 string result + $mailbox = utf8_decode($mailbox); + + $mailboxes[] = $mailbox; } return $mailboxes; @@ -1417,3 +1428,86 @@ function imap_rfc822_parse_headers($header) return $headers; } } + +/** http://php.net/manual/pt_BR/function.imap-utf7-decode.php#116677 */ +class ImapUtf7 { + static $imap_base64 = + 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,'; + static private function encode_b64imap($s) { + $a=0; $al=0; $res=''; $n=strlen($s); + for($i=0;$i<$n;$i++) { + $a=($a<<8)|ord($s[$i]); $al+=8; + for(;$al>=6;$al-=6) $res.=self::$imap_base64[($a>>($al-6))&0x3F]; + } + if ($al>0) { $res.=self::$imap_base64[($a<<(6-$al))&0x3F]; } + return $res; + } + static private function encode_utf8_char($w) { + if ($w&0x80000000) return ''; + if ($w&0xFC000000) $n=5; else + if ($w&0xFFE00000) $n=4; else + if ($w&0xFFFF0000) $n=3; else + if ($w&0xFFFFF800) $n=2; else + if ($w&0xFFFFFF80) $n=1; else return chr($w); + $res=chr(( (255<<(7-$n)) | ($w>>($n*6)) )&255); + while(--$n>=0) $res.=chr((($w>>($n*6))&0x3F)|0x80); + return $res; + } + static private function decode_b64imap($s) { + $a=0; $al=0; $res=''; $n=strlen($s); + for($i=0;$i<$n;$i++) { + $k=strpos(self::$imap_base64,$s[$i]); if ($k===FALSE) continue; + $a=($a<<6)|$k; $al+=6; + if ($al>=8) { $res.=chr(($a>>($al-8))&255);$al-=8; } + } + $r2=''; $n=strlen($res); + for($i=0;$i<$n;$i++) { + $c=ord($res[$i]); $i++; + if ($i<$n) $c=($c<<8) | ord($res[$i]); + $r2.=self::encode_utf8_char($c); + } + return $r2; + } + static function encode($s) { + $n=strlen($s);$err=0;$buf='';$res=''; + for($i=0;$i<$n;) { + $x=ord($s[$i++]); + if (($x&0x80)==0x00) { $r=$x;$w=0; } + else if (($x&0xE0)==0xC0) { $w=1; $r=$x &0x1F; } + else if (($x&0xF0)==0xE0) { $w=2; $r=$x &0x0F; } + else if (($x&0xF8)==0xF0) { $w=3; $r=$x &0x07; } + else if (($x&0xFC)==0xF8) { $w=4; $r=$x &0x03; } + else if (($x&0xFE)==0xFC) { $w=5; $r=$x &0x01; } + else if (($x&0xC0)==0x80) { $w=0; $r=-1; $err++; } + else { $w=0;$r=-2;$err++; } + for($k=0;$k<$w && $i<$n; $k++) { + $x=ord($s[$i++]); if ($x&0xE0!=0x80) { $err++; } + $r=($r<<6)|($x&0x3F); + } + if ($r<0x20 || $r>0x7E ) { + $buf.=chr(($r>>8)&0xFF); $buf.=chr($r&0xFF); + } else { + if (strlen($buf)) { + $res.='&'.self::encode_b64imap($buf).'-'; + $buf=''; + } + if ($r==0x26) { $res.='&-'; } else $res.=chr($r); + } + } + if (strlen($buf)) $res.='&'.self::encode_b64imap($buf).'-'; + return $res; + } + static function decode($s) { + $res=''; $n=strlen($s); $h=0; + while($h<$n) { + $t=strpos($s,'&',$h); if ($t===false) $t=$n; + $res.=substr($s,$h,$t-$h); $h=$t+1; if ($h>=$n) break; + $t=strpos($s,'-',$h); if ($t===false) $t=$n; + $k=$t-$h; + if ($k==0) $res.='&'; + else $res.=self::decode_b64imap(substr($s,$h,$k)); + $h=$t+1; + } + return $res; + } +} \ No newline at end of file From a98fc774d3d5e40aafda57392c5f14dfbbc32cae Mon Sep 17 00:00:00 2001 From: Leonardo Weslei Diniz Date: Tue, 15 Aug 2017 00:33:54 -0300 Subject: [PATCH 08/14] FIX mailbox names fetched --- src/Imap.php | 241 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 182 insertions(+), 59 deletions(-) diff --git a/src/Imap.php b/src/Imap.php index 8a74925..dd0613a 100644 --- a/src/Imap.php +++ b/src/Imap.php @@ -1430,84 +1430,207 @@ function imap_rfc822_parse_headers($header) } /** http://php.net/manual/pt_BR/function.imap-utf7-decode.php#116677 */ -class ImapUtf7 { +class ImapUtf7 +{ static $imap_base64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,'; - static private function encode_b64imap($s) { - $a=0; $al=0; $res=''; $n=strlen($s); - for($i=0;$i<$n;$i++) { - $a=($a<<8)|ord($s[$i]); $al+=8; - for(;$al>=6;$al-=6) $res.=self::$imap_base64[($a>>($al-6))&0x3F]; + + static private function encodeB64Imap($s) + { + $a = 0; + $al = 0; + $res = ''; + $n = strlen($s); + + for ($i = 0; $i < $n; $i++) { + $a = ($a << 8) | ord($s[$i]); + $al += 8; + + for (; $al >= 6; $al -= 6) { + $res .= self::$imap_base64[($a >> ($al - 6)) & 0x3F]; + } + } + + if ($al > 0) { + $res .= self::$imap_base64[($a << (6 - $al)) & 0x3F]; } - if ($al>0) { $res.=self::$imap_base64[($a<<(6-$al))&0x3F]; } + return $res; } - static private function encode_utf8_char($w) { - if ($w&0x80000000) return ''; - if ($w&0xFC000000) $n=5; else - if ($w&0xFFE00000) $n=4; else - if ($w&0xFFFF0000) $n=3; else - if ($w&0xFFFFF800) $n=2; else - if ($w&0xFFFFFF80) $n=1; else return chr($w); - $res=chr(( (255<<(7-$n)) | ($w>>($n*6)) )&255); - while(--$n>=0) $res.=chr((($w>>($n*6))&0x3F)|0x80); + + static private function encode_utf8_char($w) + { + if ($w & 0x80000000) { + return ''; + } + + if ($w & 0xFC000000) { + $n = 5; + } elseif ($w & 0xFFE00000) { + $n = 4; + } elseif ($w & 0xFFFF0000) { + $n = 3; + } elseif ($w & 0xFFFFF800) { + $n = 2; + } elseif ($w & 0xFFFFFF80) { + $n = 1; + } else { + return chr($w); + } + + $res = chr(((255 << (7 - $n)) | ($w >> ($n * 6))) & 255); + + while (--$n >= 0) { + $res .= chr((($w >> ($n * 6)) & 0x3F) | 0x80); + } + return $res; } - static private function decode_b64imap($s) { - $a=0; $al=0; $res=''; $n=strlen($s); - for($i=0;$i<$n;$i++) { - $k=strpos(self::$imap_base64,$s[$i]); if ($k===FALSE) continue; - $a=($a<<6)|$k; $al+=6; - if ($al>=8) { $res.=chr(($a>>($al-8))&255);$al-=8; } - } - $r2=''; $n=strlen($res); - for($i=0;$i<$n;$i++) { - $c=ord($res[$i]); $i++; - if ($i<$n) $c=($c<<8) | ord($res[$i]); - $r2.=self::encode_utf8_char($c); + + static private function decodeB64Imap($s) + { + $a = 0; + $al = 0; + $res = ''; + $n = strlen($s); + + for ($i = 0; $i < $n; $i++) { + $k = strpos(self::$imap_base64, $s[$i]); + if ($k === false) { + continue; + } + $a = ($a << 6) | $k; + $al += 6; + + if ($al >= 8) { + $res .= chr(($a >> ($al - 8)) & 255); + $al -= 8; + } } + + $r2 = ''; + $n = strlen($res); + + for ($i = 0; $i < $n; $i++) { + $c = ord($res[$i]); + $i++; + + if ($i < $n) { + $c = ($c << 8) | ord($res[$i]); + } + + $r2 .= self::encode_utf8_char($c); + } + return $r2; } - static function encode($s) { - $n=strlen($s);$err=0;$buf='';$res=''; - for($i=0;$i<$n;) { - $x=ord($s[$i++]); - if (($x&0x80)==0x00) { $r=$x;$w=0; } - else if (($x&0xE0)==0xC0) { $w=1; $r=$x &0x1F; } - else if (($x&0xF0)==0xE0) { $w=2; $r=$x &0x0F; } - else if (($x&0xF8)==0xF0) { $w=3; $r=$x &0x07; } - else if (($x&0xFC)==0xF8) { $w=4; $r=$x &0x03; } - else if (($x&0xFE)==0xFC) { $w=5; $r=$x &0x01; } - else if (($x&0xC0)==0x80) { $w=0; $r=-1; $err++; } - else { $w=0;$r=-2;$err++; } - for($k=0;$k<$w && $i<$n; $k++) { - $x=ord($s[$i++]); if ($x&0xE0!=0x80) { $err++; } - $r=($r<<6)|($x&0x3F); + + static function encode($s) + { + $n = strlen($s); + $err = 0; + $buf = ''; + $res = ''; + + for ($i = 0; $i < $n;) { + $x = ord($s[$i++]); + + if (($x & 0x80) == 0x00) { + $r = $x; + $w = 0; + } elseif (($x & 0xE0) == 0xC0) { + $w = 1; + $r = $x & 0x1F; + } elseif (($x & 0xF0) == 0xE0) { + $w = 2; + $r = $x & 0x0F; + } elseif (($x & 0xF8) == 0xF0) { + $w = 3; + $r = $x & 0x07; + } elseif (($x & 0xFC) == 0xF8) { + $w = 4; + $r = $x & 0x03; + } elseif (($x & 0xFE) == 0xFC) { + $w = 5; + $r = $x & 0x01; + } elseif (($x & 0xC0) == 0x80) { + $w = 0; + $r = -1; + $err++; + } else { + $w = 0; + $r = -2; + $err++; + } + + for ($k = 0; $k < $w && $i < $n; $k++) { + $x = ord($s[$i++]); + if ($x & 0xE0 != 0x80) { + $err++; + } + $r = ($r << 6) | ($x & 0x3F); } - if ($r<0x20 || $r>0x7E ) { - $buf.=chr(($r>>8)&0xFF); $buf.=chr($r&0xFF); + + if ($r < 0x20 || $r > 0x7E) { + $buf .= chr(($r >> 8) & 0xFF); + $buf .= chr($r & 0xFF); } else { if (strlen($buf)) { - $res.='&'.self::encode_b64imap($buf).'-'; - $buf=''; + $res .= '&' . self::encodeB64Imap($buf) . '-'; + $buf = ''; + } + if ($r == 0x26) { + $res .= '&-'; + } else { + $res .= chr($r); } - if ($r==0x26) { $res.='&-'; } else $res.=chr($r); } } - if (strlen($buf)) $res.='&'.self::encode_b64imap($buf).'-'; + + if (strlen($buf)) { + $res .= '&' . self::encodeB64Imap($buf) . '-'; + } + return $res; } - static function decode($s) { - $res=''; $n=strlen($s); $h=0; - while($h<$n) { - $t=strpos($s,'&',$h); if ($t===false) $t=$n; - $res.=substr($s,$h,$t-$h); $h=$t+1; if ($h>=$n) break; - $t=strpos($s,'-',$h); if ($t===false) $t=$n; - $k=$t-$h; - if ($k==0) $res.='&'; - else $res.=self::decode_b64imap(substr($s,$h,$k)); - $h=$t+1; + + static function decode($s) + { + $res = ''; + $n = strlen($s); + $h = 0; + + while ($h < $n) { + $t = strpos($s, '&', $h); + + if ($t === false) { + $t = $n; + } + + $res .= substr($s, $h, $t - $h); + $h = $t + 1; + + if ($h >= $n) { + break; + } + + $t = strpos($s, '-', $h); + + if ($t === false) { + $t = $n; + } + + $k = $t - $h; + + if ($k == 0) { + $res .= '&'; + } else { + $res .= self::decodeB64Imap(substr($s, $h, $k)); + } + + $h = $t + 1; } + return $res; } } \ No newline at end of file From 055631b5b7b5671151cc49e4d60a78ed373c21f2 Mon Sep 17 00:00:00 2001 From: Leonardo Weslei Diniz Date: Tue, 15 Aug 2017 00:36:36 -0300 Subject: [PATCH 09/14] FIX mailbox names fetched --- src/Imap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Imap.php b/src/Imap.php index dd0613a..b57bb07 100644 --- a/src/Imap.php +++ b/src/Imap.php @@ -1432,7 +1432,7 @@ function imap_rfc822_parse_headers($header) /** http://php.net/manual/pt_BR/function.imap-utf7-decode.php#116677 */ class ImapUtf7 { - static $imap_base64 = + private static $imap_base64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,'; static private function encodeB64Imap($s) From a7a83cdb2143f4f5c5a8e77d44a946670d9cd008 Mon Sep 17 00:00:00 2001 From: Leonardo Weslei Diniz Date: Tue, 15 Aug 2017 00:36:53 -0300 Subject: [PATCH 10/14] FIX mailbox names fetched --- src/Imap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Imap.php b/src/Imap.php index b57bb07..50d1fca 100644 --- a/src/Imap.php +++ b/src/Imap.php @@ -1633,4 +1633,4 @@ static function decode($s) return $res; } -} \ No newline at end of file +} From 08e749754489d678fb8031cba68c932b4e74e5d6 Mon Sep 17 00:00:00 2001 From: Leonardo Weslei Diniz Date: Tue, 15 Aug 2017 00:39:28 -0300 Subject: [PATCH 11/14] FIX mailbox names fetched --- src/Imap.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Imap.php b/src/Imap.php index 50d1fca..336abae 100644 --- a/src/Imap.php +++ b/src/Imap.php @@ -1435,7 +1435,7 @@ class ImapUtf7 private static $imap_base64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,'; - static private function encodeB64Imap($s) + private static function encodeB64Imap($s) { $a = 0; $al = 0; @@ -1458,7 +1458,7 @@ static private function encodeB64Imap($s) return $res; } - static private function encode_utf8_char($w) + private static function encode_utf8_char($w) { if ($w & 0x80000000) { return ''; @@ -1487,7 +1487,7 @@ static private function encode_utf8_char($w) return $res; } - static private function decodeB64Imap($s) + private static function decodeB64Imap($s) { $a = 0; $al = 0; @@ -1525,7 +1525,7 @@ static private function decodeB64Imap($s) return $r2; } - static function encode($s) + public static function encode($s) { $n = strlen($s); $err = 0; @@ -1594,7 +1594,7 @@ static function encode($s) return $res; } - static function decode($s) + public static function decode($s) { $res = ''; $n = strlen($s); From b9568de362f96353b6a27adb67fa4291fd53c2b9 Mon Sep 17 00:00:00 2001 From: Leonardo Weslei Diniz Date: Tue, 15 Aug 2017 00:43:30 -0300 Subject: [PATCH 12/14] FIX mailbox names fetched --- src/Imap.php | 206 ---------------------------------------------- src/ImapUtf7.php | 209 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 209 insertions(+), 206 deletions(-) create mode 100644 src/ImapUtf7.php diff --git a/src/Imap.php b/src/Imap.php index 336abae..1451be9 100644 --- a/src/Imap.php +++ b/src/Imap.php @@ -1428,209 +1428,3 @@ function imap_rfc822_parse_headers($header) return $headers; } } - -/** http://php.net/manual/pt_BR/function.imap-utf7-decode.php#116677 */ -class ImapUtf7 -{ - private static $imap_base64 = - 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,'; - - private static function encodeB64Imap($s) - { - $a = 0; - $al = 0; - $res = ''; - $n = strlen($s); - - for ($i = 0; $i < $n; $i++) { - $a = ($a << 8) | ord($s[$i]); - $al += 8; - - for (; $al >= 6; $al -= 6) { - $res .= self::$imap_base64[($a >> ($al - 6)) & 0x3F]; - } - } - - if ($al > 0) { - $res .= self::$imap_base64[($a << (6 - $al)) & 0x3F]; - } - - return $res; - } - - private static function encode_utf8_char($w) - { - if ($w & 0x80000000) { - return ''; - } - - if ($w & 0xFC000000) { - $n = 5; - } elseif ($w & 0xFFE00000) { - $n = 4; - } elseif ($w & 0xFFFF0000) { - $n = 3; - } elseif ($w & 0xFFFFF800) { - $n = 2; - } elseif ($w & 0xFFFFFF80) { - $n = 1; - } else { - return chr($w); - } - - $res = chr(((255 << (7 - $n)) | ($w >> ($n * 6))) & 255); - - while (--$n >= 0) { - $res .= chr((($w >> ($n * 6)) & 0x3F) | 0x80); - } - - return $res; - } - - private static function decodeB64Imap($s) - { - $a = 0; - $al = 0; - $res = ''; - $n = strlen($s); - - for ($i = 0; $i < $n; $i++) { - $k = strpos(self::$imap_base64, $s[$i]); - if ($k === false) { - continue; - } - $a = ($a << 6) | $k; - $al += 6; - - if ($al >= 8) { - $res .= chr(($a >> ($al - 8)) & 255); - $al -= 8; - } - } - - $r2 = ''; - $n = strlen($res); - - for ($i = 0; $i < $n; $i++) { - $c = ord($res[$i]); - $i++; - - if ($i < $n) { - $c = ($c << 8) | ord($res[$i]); - } - - $r2 .= self::encode_utf8_char($c); - } - - return $r2; - } - - public static function encode($s) - { - $n = strlen($s); - $err = 0; - $buf = ''; - $res = ''; - - for ($i = 0; $i < $n;) { - $x = ord($s[$i++]); - - if (($x & 0x80) == 0x00) { - $r = $x; - $w = 0; - } elseif (($x & 0xE0) == 0xC0) { - $w = 1; - $r = $x & 0x1F; - } elseif (($x & 0xF0) == 0xE0) { - $w = 2; - $r = $x & 0x0F; - } elseif (($x & 0xF8) == 0xF0) { - $w = 3; - $r = $x & 0x07; - } elseif (($x & 0xFC) == 0xF8) { - $w = 4; - $r = $x & 0x03; - } elseif (($x & 0xFE) == 0xFC) { - $w = 5; - $r = $x & 0x01; - } elseif (($x & 0xC0) == 0x80) { - $w = 0; - $r = -1; - $err++; - } else { - $w = 0; - $r = -2; - $err++; - } - - for ($k = 0; $k < $w && $i < $n; $k++) { - $x = ord($s[$i++]); - if ($x & 0xE0 != 0x80) { - $err++; - } - $r = ($r << 6) | ($x & 0x3F); - } - - if ($r < 0x20 || $r > 0x7E) { - $buf .= chr(($r >> 8) & 0xFF); - $buf .= chr($r & 0xFF); - } else { - if (strlen($buf)) { - $res .= '&' . self::encodeB64Imap($buf) . '-'; - $buf = ''; - } - if ($r == 0x26) { - $res .= '&-'; - } else { - $res .= chr($r); - } - } - } - - if (strlen($buf)) { - $res .= '&' . self::encodeB64Imap($buf) . '-'; - } - - return $res; - } - - public static function decode($s) - { - $res = ''; - $n = strlen($s); - $h = 0; - - while ($h < $n) { - $t = strpos($s, '&', $h); - - if ($t === false) { - $t = $n; - } - - $res .= substr($s, $h, $t - $h); - $h = $t + 1; - - if ($h >= $n) { - break; - } - - $t = strpos($s, '-', $h); - - if ($t === false) { - $t = $n; - } - - $k = $t - $h; - - if ($k == 0) { - $res .= '&'; - } else { - $res .= self::decodeB64Imap(substr($s, $h, $k)); - } - - $h = $t + 1; - } - - return $res; - } -} diff --git a/src/ImapUtf7.php b/src/ImapUtf7.php new file mode 100644 index 0000000..002530c --- /dev/null +++ b/src/ImapUtf7.php @@ -0,0 +1,209 @@ += 6; $al -= 6) { + $res .= self::$imap_base64[($a >> ($al - 6)) & 0x3F]; + } + } + + if ($al > 0) { + $res .= self::$imap_base64[($a << (6 - $al)) & 0x3F]; + } + + return $res; + } + + private static function encodeUtf8Char($w) + { + if ($w & 0x80000000) { + return ''; + } + + if ($w & 0xFC000000) { + $n = 5; + } elseif ($w & 0xFFE00000) { + $n = 4; + } elseif ($w & 0xFFFF0000) { + $n = 3; + } elseif ($w & 0xFFFFF800) { + $n = 2; + } elseif ($w & 0xFFFFFF80) { + $n = 1; + } else { + return chr($w); + } + + $res = chr(((255 << (7 - $n)) | ($w >> ($n * 6))) & 255); + + while (--$n >= 0) { + $res .= chr((($w >> ($n * 6)) & 0x3F) | 0x80); + } + + return $res; + } + + private static function decodeB64Imap($s) + { + $a = 0; + $al = 0; + $res = ''; + $n = strlen($s); + + for ($i = 0; $i < $n; $i++) { + $k = strpos(self::$imap_base64, $s[$i]); + if ($k === false) { + continue; + } + $a = ($a << 6) | $k; + $al += 6; + + if ($al >= 8) { + $res .= chr(($a >> ($al - 8)) & 255); + $al -= 8; + } + } + + $r2 = ''; + $n = strlen($res); + + for ($i = 0; $i < $n; $i++) { + $c = ord($res[$i]); + $i++; + + if ($i < $n) { + $c = ($c << 8) | ord($res[$i]); + } + + $r2 .= self::encodeUtf8Char($c); + } + + return $r2; + } + + public static function encode($s) + { + $n = strlen($s); + $err = 0; + $buf = ''; + $res = ''; + + for ($i = 0; $i < $n;) { + $x = ord($s[$i++]); + + if (($x & 0x80) == 0x00) { + $r = $x; + $w = 0; + } elseif (($x & 0xE0) == 0xC0) { + $w = 1; + $r = $x & 0x1F; + } elseif (($x & 0xF0) == 0xE0) { + $w = 2; + $r = $x & 0x0F; + } elseif (($x & 0xF8) == 0xF0) { + $w = 3; + $r = $x & 0x07; + } elseif (($x & 0xFC) == 0xF8) { + $w = 4; + $r = $x & 0x03; + } elseif (($x & 0xFE) == 0xFC) { + $w = 5; + $r = $x & 0x01; + } elseif (($x & 0xC0) == 0x80) { + $w = 0; + $r = -1; + $err++; + } else { + $w = 0; + $r = -2; + $err++; + } + + for ($k = 0; $k < $w && $i < $n; $k++) { + $x = ord($s[$i++]); + if ($x & 0xE0 != 0x80) { + $err++; + } + $r = ($r << 6) | ($x & 0x3F); + } + + if ($r < 0x20 || $r > 0x7E) { + $buf .= chr(($r >> 8) & 0xFF); + $buf .= chr($r & 0xFF); + } else { + if (strlen($buf)) { + $res .= '&' . self::encodeB64Imap($buf) . '-'; + $buf = ''; + } + if ($r == 0x26) { + $res .= '&-'; + } else { + $res .= chr($r); + } + } + } + + if (strlen($buf)) { + $res .= '&' . self::encodeB64Imap($buf) . '-'; + } + + return $res; + } + + public static function decode($s) + { + $res = ''; + $n = strlen($s); + $h = 0; + + while ($h < $n) { + $t = strpos($s, '&', $h); + + if ($t === false) { + $t = $n; + } + + $res .= substr($s, $h, $t - $h); + $h = $t + 1; + + if ($h >= $n) { + break; + } + + $t = strpos($s, '-', $h); + + if ($t === false) { + $t = $n; + } + + $k = $t - $h; + + if ($k == 0) { + $res .= '&'; + } else { + $res .= self::decodeB64Imap(substr($s, $h, $k)); + } + + $h = $t + 1; + } + + return $res; + } +} From 1ada7bf6c849a39ce73ea29115d5e02498454761 Mon Sep 17 00:00:00 2001 From: Leonardo Weslei Diniz Date: Wed, 16 Aug 2017 20:05:27 -0300 Subject: [PATCH 13/14] master: Changing the repository while pulling the request is not accepted --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ed63ece..22892d7 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "eden/mail", + "name": "leonardoweslei/eden-mail", "type": "library", "description": "Eden POP3, IMAP and SMTP component", "keywords": ["eden", "library"], From b807c8996ca346c77ecc5a117f40bd57f8775069 Mon Sep 17 00:00:00 2001 From: Leonardo Weslei Diniz Date: Thu, 28 Sep 2017 19:27:08 -0300 Subject: [PATCH 14/14] tests --- composer.json | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 48dccc5..22892d7 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "eden/mail", + "name": "leonardoweslei/eden-mail", "type": "library", "description": "Eden POP3, IMAP and SMTP component", "keywords": ["eden", "library"], @@ -11,15 +11,9 @@ "email": "cblanquera@openovate.com" } ], - "repositories": [ - { - "type": "git", - "url": "https://github.com/beeproger/core" - } - ], "require": { "php": ">=5.4.1", - "eden/core": "4.0.3.1", + "eden/core": "4.*", "eden/string": "4.*", "eden/array": "4.*", "eden/path": "4.*",