javanile / php-imap2

PHP IMAP with OAUTH2
https://php-imap2.javanile.org/
GNU General Public License v3.0
48 stars 28 forks source link

shared mailboxes in combination with OAUTH2 #31

Open IZSkiSurfer opened 1 year ago

IZSkiSurfer commented 1 year ago

To support the so called shared mailboxes with OAUTH2 I would suggest following changes:

  1. Within the Connection class add a new protected property $sharedUser.
  2. Within the Connection classes openMailbox method add the following snippet: $this->sharedUser = array_reduce($mailboxParts['path'], function($carry, $item) { return preg_match('/^user=(.+)$/', $item, $matches) ? $matches[1] : $carry; }, false);
  3. Within the Connection classes connect method change the 2nd argument of the connect call to: ($this->flags & OP_XOAUTH2) && !empty($this->sharedUser) ? $this->sharedUser : $this->user Maybe the ($this->flags & OP_XOAUTH2) part in step 3 might be omitted - haven't tried php-imap2 with normal IMAP login in combination with shared mailboxes - in which case I would use PHP's integrated imap_ functions anyway :p