From 8681ae6c451d45cb670675d300c0c03af076f10d Mon Sep 17 00:00:00 2001 From: vicenteampliffy Date: Wed, 22 Jun 2022 19:12:59 +0200 Subject: [PATCH 1/4] Error parsing base64 attachment with a TAG within it --- src/Imap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Imap.php b/src/Imap.php index 2449bb2..531991a 100644 --- a/src/Imap.php +++ b/src/Imap.php @@ -1150,7 +1150,7 @@ private function getEmailResponse($command, $parameters = array(), $first = fals } //if there is a tag it means we are at the end - if (strpos($line, 'TAG'.$this->tag) !== false) { + if (strpos($line, 'TAG'.$this->tag) === 0) { //if email details are not empty and the last line is just a ) if (!empty($email) && strpos(trim($email[count($email) -1]), ')') === 0) { //take it out because that is not part of the details From 0057d3c3f48bc289468b1f6526d476e79f24a434 Mon Sep 17 00:00:00 2001 From: vicenteampliffy Date: Fri, 5 Aug 2022 09:36:58 +0200 Subject: [PATCH 2/4] Fix attachments specified through the content-disposition header --- src/Imap.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Imap.php b/src/Imap.php index 531991a..5e3da2a 100644 --- a/src/Imap.php +++ b/src/Imap.php @@ -1340,6 +1340,19 @@ private function getParts($content, array $parts = array()) if (isset($extra['name'])) { //add to parts $parts['attachment'][$extra['name']][$type] = $body; + } elseif (isset($head['content-disposition']) && strpos($head['content-disposition'],'attachment')===0) { + //add to parts + //split the content type + $filename=null; + if (is_string($head['content-disposition'])&&strpos($head['content-disposition'],'filename=')!==false) { + if(preg_match("/filename=([^;]*)/",$head['content-disposition'],$matches)) { + $filename=$matches[1]; + } + } + if($filename) + $parts['attachment'][$filename][$type] = $body; + else + $parts['attachment'][][$type] = $body; } else { //it's just a regular body //add to parts From e059d87bc6a7218888fb274e40d73e3ca8636c48 Mon Sep 17 00:00:00 2001 From: vicenteampliffy Date: Sun, 16 Jun 2024 11:11:21 +0200 Subject: [PATCH 3/4] Update Imap.php with xOauth2 Authentication --- src/Imap.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Imap.php b/src/Imap.php index 5e3da2a..98722a4 100644 --- a/src/Imap.php +++ b/src/Imap.php @@ -6,7 +6,6 @@ * Copyright and license information can be found at LICENSE.txt * distributed with this package. */ - namespace Eden\Mail; /** @@ -60,6 +59,11 @@ class Imap extends Base */ protected $password = null; + /** + * @var string|null $xoauth2token The mailbox token + */ + protected $xoauth2token = null; + /** * @var int $tag The tag number */ @@ -109,6 +113,7 @@ class Imap extends Base * @param int|null $port The IMAP port * @param bool $ssl Whether to use SSL * @param bool $tls Whether to use TLS + * @param *string|null $xoauth2token The oauth2token */ public function __construct( $host, @@ -116,7 +121,8 @@ public function __construct( $pass, $port = null, $ssl = false, - $tls = false + $tls = false, + $xoauth2token = null ) { Argument::i() ->test(1, 'string') @@ -124,7 +130,8 @@ public function __construct( ->test(3, 'string') ->test(4, 'int', 'null') ->test(5, 'bool') - ->test(6, 'bool'); + ->test(6, 'bool') + ->test(7, 'string', 'null'); if (is_null($port)) { $port = $ssl ? 993 : 143; @@ -136,6 +143,7 @@ public function __construct( $this->port = $port; $this->ssl = $ssl; $this->tls = $tls; + $this->xoauth2token = $xoauth2token; } /** @@ -202,7 +210,14 @@ public function connect($timeout = self::TIMEOUT, $test = false) } //login - $result = $this->call('LOGIN', $this->escape($this->username, $this->password)); + if ($this->xoauth2token) { + $access_token=$this->xoauth2token; + $auth = "user={$this->username}\1auth=Bearer {$access_token}\1\1"; + $auth = base64_encode($auth); + $result = $this->call('AUTHENTICATE XOAUTH2', $auth); + } else { + $result = $this->call('LOGIN', $this->escape($this->username, $this->password)); + } if (!is_array($result) || strpos(implode(' ', $result), 'OK') === false) { $this->disconnect(); From 4a2862696319aeb1aa2b37305dbae2a171a06b45 Mon Sep 17 00:00:00 2001 From: vicenteampliffy Date: Sun, 16 Jun 2024 11:30:21 +0200 Subject: [PATCH 4/4] Add xOauth2support in Index instantiating --- src/Index.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Index.php b/src/Index.php index b71f019..546a434 100644 --- a/src/Index.php +++ b/src/Index.php @@ -33,10 +33,11 @@ class Index extends Base * @param int|null $port The IMAP port * @param bool $ssl Whether to use SSL * @param bool $tls Whether to use TLS + * @param *string|null $xoauth2token The oauth2token * * @return Eden\Mail\Imap */ - public function imap($host, $user, $pass, $port = null, $ssl = false, $tls = false) + public function imap($host, $user, $pass, $port = null, $ssl = false, $tls = false, $xoauth2token = null) { Argument::i() ->test(1, 'string') @@ -44,9 +45,10 @@ public function imap($host, $user, $pass, $port = null, $ssl = false, $tls = fal ->test(3, 'string') ->test(4, 'int', 'null') ->test(5, 'bool') - ->test(6, 'bool'); + ->test(6, 'bool') + ->test(7, 'string', 'null'); - return Imap::i($host, $user, $pass, $port, $ssl, $tls); + return Imap::i($host, $user, $pass, $port, $ssl, $tls, $xoauth2token); } /**