From 46a46482ba10ff1471c8db6955f2364ed4cd28a8 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Fri, 14 Mar 2025 16:57:16 +0000 Subject: [PATCH] Fixed #97: Zoho IMAP Authentication Fails --- ChangeLog | 7 +++++++ src/transports/imap/imap_transport.php | 25 +++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index f6ca2e0..f413a5e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +1.10.1 - [RELEASEDATE] +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +- Fixed #97: Zoho IMAP authentication fails, as there is an extra line in the + response, just like GMail does. + + 1.10.0 - Wednesday 12 March 2025 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/transports/imap/imap_transport.php b/src/transports/imap/imap_transport.php index f4722a6..260d114 100644 --- a/src/transports/imap/imap_transport.php +++ b/src/transports/imap/imap_transport.php @@ -244,6 +244,13 @@ class ezcMailImapTransport */ const SERVER_GIMAP = 'Gimap'; + /** + * The string returned by Zoho IMAP servers at connection time. + * + * @access private + */ + const SERVER_ZOHO = 'Zoho Mail'; + /** * Authenticate with 'AUTH LOGIN'. */ @@ -332,7 +339,8 @@ class ezcMailImapTransport * Holds the string which identifies the IMAP server type. * * Used for fixing problems with Google IMAP (see issue #14360). Possible - * values are {@link self::SERVER_GIMAP} or null for all other servers. + * values are {@link self::SERVER_GIMAP}, {@link self::SERVER_ZOHO}, or + * null for all other servers. * * @todo Add identification strings for each existing IMAP server? * @@ -407,10 +415,16 @@ public function __construct( $server, $port = null, $options = array() ) { throw new ezcMailTransportException( "The connection to the IMAP server is ok, but a negative response from server was received. Try again later." ); } + if ( strpos( $response, self::SERVER_GIMAP ) !== false ) { $this->serverType = self::SERVER_GIMAP; // otherwise it is null } + if ( strpos( $response, self::SERVER_ZOHO ) !== false ) + { + $this->serverType = self::SERVER_ZOHO; // otherwise it is null + } + $this->state = self::STATE_NOT_AUTHENTICATED; } @@ -585,9 +599,12 @@ public function authenticate( $user, $password, $method = ezcMailImapTransport:: } $response = trim( $this->connection->getLine() ); - // hack for gmail, to fix issue #15837: imap.google.com (google gmail) changed IMAP response - if ( $this->serverType === self::SERVER_GIMAP && strpos( $response, "* CAPABILITY" ) === 0 ) - { + // Hacks for Zoho Mail, and Gmail, to fix issue #15837: imap.google.com (google gmail) changed IMAP response + if ( + ( $this->serverType === self::SERVER_GIMAP || $this->serverType === self::SERVER_ZOHO ) + && + strpos( $response, "* CAPABILITY" ) === 0 + ) { $response = trim( $this->connection->getLine() ); } if ( strpos( $response, '* OK' ) !== false )