Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OAuth support #443

Open
sombatos opened this issue Dec 25, 2019 · 30 comments
Open

Add OAuth support #443

sombatos opened this issue Dec 25, 2019 · 30 comments

Comments

@sombatos
Copy link

Starting February 15, 2021, G Suite accounts will only allow access to apps using OAuth
google/gmail-oauth2-tools#18

@Slamdunk
Copy link
Collaborator

Ouch :\

@LinusBrockmeyer
Copy link

Hi I am are using your library to get emails from gmail. I want to switch to googles new oauth system quite soon. Is there any progress on this issue for ddeboer/imap?

@Slamdunk
Copy link
Collaborator

No one is working on it, as far as I know

@croensch
Copy link

I believe ddboer/imap can do nothing unless something is done to the PHP extension: https://wiki.php.net/todo/ext/imap
TL;DR ddeboer/imap only gives the basic auth to the extension and the extension gives it to an old C library not written by the PHP community

@Slamdunk
Copy link
Collaborator

This gives me hope: https://wiki.php.net/todo/ext/imap/xoauth2

@freescout-helpdesk
Copy link

There are also some workarounds for G Suite: https://medium.com/@freescout/oauth-2-0-g-suite-microsoft-365-and-php-7da16ca74314

@Slamdunk
Copy link
Collaborator

Huh, nice, I've always used App password indeed.

I consider this topic closed.

@francescobianco
Copy link

francescobianco commented May 24, 2022

Hi! @Slamdunk @freescout-helpdesk @croensch @LinusBrockmeyer @sombatos

The strategy to overcome the problem is replacing all the imap_* functions with the equivalent imap2_*

  • imap_open(...) become imap2_open(...)
  • imap_getmailboxes(...) become imap2_getmailboxes(...)

etc...

The idea behind the imap2 library is to replace the core php imap extension with a new one written in PHP.
Why? The problem is related to the UW-IMAP https://github.com/uw-imap/imap it seem outdate from 2019. There are many security concerns about it

I'm waiting from your feedback! I hope that imap2 is a good replacement for imap

@Slamdunk
Copy link
Collaborator

Hi @francescobianco, I guess you are referring to your library https://github.com/javanile/php-imap2

I have to say App passwords are now well spread and supported, so I'm not intended to change this library auth methods.

@francescobianco
Copy link

Hi @Orgoth , please, get you a chance to PHP-IMAP2 (https://github.com/javanile/php-imap2)
This is a FULL implementation of standard PHP IMAP functions like (imap_open, imap_getmailboxes, imap_*, etc...)

This was full tested, every input to imap2_* functions get back the same output of imap_* equivalent

The IMAP2 works well with OAUTH

This libray can be installed with composer

composer require javanile/php-imap2

This libray introduce a easy way to replace the old PHP-IMAP with new one:

JUST replace all imap_(...) functions with imap2_(...)

NO OTHER AMENDS are required.

Please give me the opportunity to make my sacrifices useful to the community.

cc @sombatos @freescout-helpdesk @croensch @ddeboer

@francescobianco
Copy link

Thanks! @Orgoth ! I'm not scared by hard work, my mission is to work full time on it, to build a professional replacement for standard IMAP. I'm looking for people who believe in this project to have the peace of mind to invest all my time on it.

I will do an update of the compatibility table later this month of course both imap_open and many others will be 100% by that date.

@RickKock
Copy link

RickKock commented Oct 6, 2022

Hi @Orgoth,

Does this competeer work for you? After I'm trying this I get a lot of errors inside isAttachment function, event when I fix this other errors fetching the body occurs.

@dicode-nl
Copy link

javanile/php-imap2#12 I've fixed most of the issues in BodyStructure.php, perhaps that will help you as well.

@dicode-nl
Copy link

@Orgoth I've tested this version on over 2000 e-mails and compared the output to the original imap_fetchstructure function to make sure these matched exactly, I think I got most of them covered, not sure about charsets though.

@dicode-nl
Copy link

@Orgoth probably caused by yet another flashy structured e-mail indeed, causing it to break much earlier in parsing and landing here with wrong item data. If you need help just let me know. Fyi what I did to compare the outputs was running both imap2_fetchstructure and imap_fetchstructure and json_encoding the results and compare them :-) quick and dirty.

@dicode-nl
Copy link

@Orgoth To me it seems something before we get into getEncoding is broken, a list of attachments should never arrive at that function. Although your fix hides the issue I think we should determine the real issue. If you could send me a json encoded version of the structure I'll have a look into it. You can do this easily by enabling line 33 (and 34) in BodyStructure

@dicode-nl
Copy link

@Orgoth could you also supply the json encode of the original imap_fetchstructure of the message?

@dicode-nl
Copy link

@Orgoth I've fixed the array version, only there is some discrepancy in the output/source for the text/html part

          ["lines"]=>int(167)
          ["bytes"]=>int(5493)

vs

                    "lines": 194,
                    "bytes": 5852,

but these two values match your input, so that's strange. The root cause however is fixed.

@dicode-nl
Copy link

@Orgoth I will update my patch shortly. For the "*" e-mail, is it possible to get the raw IMAP response from the FETCH command? Perhaps by using telnet to speak IMAP yourself to the server or by adding a print/echo in Roundcube/ImapClient.php around line 2472 with the $line data?

@dicode-nl
Copy link

javanile/php-imap2@2874eb9 is the new commit for the array issue, this was caused by how a related part was parsed.

@dicode-nl
Copy link

Fixed in javanile/php-imap2@f119d25

No need to compensate, I need this php-imap2 library working properly too :-)

@dicode-nl
Copy link

Fixed in javanile/php-imap2@2fe8fad

However the output still differs in line/bytes on the RFC822 part but possible thats caused by the different imap servers used.

@dicode-nl
Copy link

@Orgoth sorry had a few days off :-) You fixed the last issue afaik? So all works now? Then I'll all your 2 updates in my pull request.

@dicode-nl
Copy link

@Orgoth I've taken a new approach which simplifies everything. I've updated the PR javanile/php-imap2#12 for those interested

@maxwellc-dal
Copy link

maxwellc-dal commented Mar 16, 2023

Original Comment:

I am not sure what the best venue for asking this would be, and I am sorry if this is something I should already know (I am a bit of a PHP tourist rather than a proper developer), but... I was thrilled to find the javanile/php-imap2 project when I had to convert one of our projects to use OAuth2 instead of password for O365 access, but now I am trying to figure the best way to actually do this.

This thread suggests that that testing has been done for using PHP Imap Library (this project) using javanile/php-imap2 instead of php-core imap. I was wondering how to do this - is there a block of php_function_rename calls, a way of unloading the core imap library so php-imap2 can use its bootstrap.php to define things like imap_open to point to an imap2_open call, or is there a version of ddeboer/imap that has all the imap_XXXX calls substituted for imap2_XXXX calls?

In case anyone else is having the same question, I will leave this here, but the answer is "just do not install the php-imap official module." ie yum/apt remove php-imap if you installed via package, and such.

@fresent
Copy link

fresent commented Jan 22, 2024

I am aware that, general conscious on this is to not integrate oAuth in this library.

However, with two major Email Providers out of 3 phasing out IMAP completely, it's a good opportunity to revisit it.

Google is phasing out IMAP : https://workspaceupdates.googleblog.com/2023/09/winding-down-google-sync-and-less-secure-apps-support.html

Unfortunately, the reliability of the library https://github.com/javanile/php-imap2 is a major concern, as it breaks at multiple levels, even critical PRs on it are not integrated. Not to mention, the roundcube library it uses under the hood, has it's own issues with getting stuck and time-outs.

@apparatchiki
Copy link

I came to this issue looking for a solution to connect via OAuth using my existing ddeboer/imap code / integration and I'm now leaving certain that IMAP in general is in its way out of commercial email services as it's now deemed unsafe / obsolete.

@Orgoth
Copy link

Orgoth commented Oct 22, 2024

Imap will not be discontinued, only the login procedure via username and password.
The type of login or authentication, so to speak.

As far as I know "I can be wrong", there is currently no developer who maintains the imap extension within PHP and integrates new functions such as oAuth.

https://wiki.php.net/todo/ext/imap/xoauth2
https://bugs.php.net/bug.php?id=64039

Edit:
I have created a fallback mode, If the user still uses a provider which is not MS or Google, the native functions are used.
To reduce possible problems of the php-imap2 lib.

@apparatchiki
Copy link

@Orgoth at least regarding MS or Google, it seems IMAP as a protocol is being removed from user's settings, regardless of auth method, maybe I didn't got that right? I understand IMAP itself lives on elsewhere.

@Orgoth
Copy link

Orgoth commented Oct 22, 2024

https://support.google.com/mail/answer/78892
For Google, imap is still present, only the authentication has changed to oAuth.

https://support.microsoft.com/de-de/office/pop-imap-und-smtp-einstellungen-f%C3%BCr-outlook-com-d088b986-291d-42b8-9564-9c414e2aa040
Same for Microsoft.

It is possible, you have misunderstood something, but I can also be wrong.

At the moment, my partners did not report problems regarding fetching emails from their office365/exchange-servers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests