-
Notifications
You must be signed in to change notification settings - Fork 458
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
office365 setServerEncoding US_ASCII mb_list_encodings #306
Comments
Thanks for the feedback and possible solution. I'll look into those Exchange / Office 365 specific issues the rest of this week. @blu-towers: Is there a way to get a test mail inbox for debugging and testing this with a Microsoft mail server? As far as I could see, the Exchange / Mail feature is only included in the company / business paid plans. If not, I need to push the changes into develop and someone else (eg. you) needs to test it. |
i dont have a test mail server but i can check any updates on my server, thanks for the response on this. |
I think you can also get away with setting the encoding to null, https://github.com/freescout-helpdesk/freescout/issues/176 |
Thanks, I'll check this. I just found, that this may can solve the issue as well: $mailbox->setConnectionArgs(0, 0, array('DISABLE_AUTHENTICATOR' => 'GSSAPI'));
// OR
// $mailbox->setConnectionArgs(0, 0, array('DISABLE_AUTHENTICATOR' => 'PLAIN')); |
@blu-towers I could create an account at https://outlook.live.com/owa/ for free. This account allows IMAP with these settings:
So the host connection string for Using my test script, I'm able to connect and fetch $ php outlook.php
Trying to connect to '{outlook.office365.com:993/imap/ssl}'...
Found 2 email(s)...
+------ P A R S I N G ------+
From: Outlook-Team <no-reply@microsoft.com>
Subject: Welcome to your new Outlook.com account
+------ P A R S I N G ------+
From: Sebastian Krätzig <sebastian.kraetzig@example.com>
Subject: PHP-IMAP Test on outlook.office365.com But as soon as I try to fetch for example $ php outlook.php
Trying to connect to '{outlook.office365.com:993/imap/ssl}INBOX'...
PHP Fatal error: Uncaught PhpImap\Exception: IMAP method imap_search() failed with error: [BADCHARSET (US-ASCII)] The specified charset is not supported. in /home/sebastian/imap-test/vendor/php-imap/php-imap/src/PhpImap/Mailbox.php:941
Stack trace:
#0 /home/sebastian/imap-test/vendor/php-imap/php-imap/src/PhpImap/Mailbox.php(302): PhpImap\Mailbox->imap('search', Array)
#1 /home/sebastian/imap-test/outlook.php(24): PhpImap\Mailbox->searchMailbox('UNSEEN SINCE 01...')
#2 {main}
thrown in /home/sebastian/imap-test/vendor/php-imap/php-imap/src/PhpImap/Mailbox.php on line 941 This is the reported issue, so I'm able to debug and test it. I'll update you as soon as I could solve the issue. References:
|
Yes i can confim i am using searchMailbox() with a SINCE query with the same fatal error |
Yeah, I'm currently testing, how we can support UTF-8 characters, because when you simply set no encoding at all, you won't find strings (emails) with non-ascii characters. For example, the search will work with So, this is a bit tricky and I couldn't find a solution yet, but I'm sure, that I'll find one. :) |
Setting the charset / server encoding to I would like to solve both of these issues, so you can use all criterias and search for non-ASCII characters. I've tried to convert the search string into any other charset then I've asked a question at stack overflow, where I've explained everything more detailed. Seems like as the Exchange servers have only implemented the RFC 3501 (US-ASCII must be supported) and will not support a charset based search. However, I've already committed and pushed some changes into
By default the charset used by imap_search is set to NULL, but the source code also mentions, that it will be // serverEncoding is set to 'UTF-8'
// php-imap v3.0.10 and older
$mailsIds = $mailbox->searchMailbox('UNSEEN'); // will fail with Microsoft Exchange servers
// php-imap v3.0.x and newer (not released yet)
$mailsIds = $mailbox->searchMailbox('UNSEEN', true); // will work with Microsoft Exchange servers So the only missing change is the fix for being able to search for non-ASCII characters as well. Let's test, if we can build a function / some logic to do the search by our own instead by the IMAP server. |
Hi, I don't know if it will help, but I've done some testing in an office365 account: Subject: "Hi Käfer" Testing with: Testing with: Results: It seems, that if I replace, the ä letter with the same letter without the diaeresis (a), and instead of using the SUBJECT parameter I use the TEXT parameter, the server returns a correct result. So, why don't we try to "translate" the non-ascii characters with the same letter but without the umlaut mark (For example: ä to a) and using a "TEXT" search instead of "Subject" ? One again, forgive my English, is not my primary language. |
Thanks for testing! There are unfortunately a few issues with this solution:
You usually want to use those other search criterias to speed up the search. :) I believe, we really need to fetch all headers, decode them and then return matching mails. |
- Updated README - Move phpunit to require-dev - Add note about installing dev dependencies in README - Replaced spaces with tabs - Added PHPUnit tests for MIME decoding - Updated formatting of PHPUnit function testParsedDateTimeWithEmptyHeaderDate() - Issue #209: Function to parse datetime correctly RFC2822 - Issue #280: Added 'Sender' to headers and added additional if-conditions - Issue #115: getMail() method returns an object even for nonexistent mail ID - Issue #273: Added connection check to example - Issue #227: Added Failed-Recipients to IncomingMailHeader - Issue #140, #246: Improved exception handling and added PHPUnit test - Issue #140: Added PHPUnit test for testing ConnectionException - Issue #140: Improved exception / error handling and improved / added PHPUnit tests - Issue #154: Added ability to change the imap_search option from SE_UID to SE_FREE and added PHPUnit tests - Issue #306: Added support for US-ASCII and added ability to disable serverEncoding for searchMailbox() - Imported missing namespaces to avoid 'unknown class' error messages - Issue #86: Simplified and improved one replace regex for attachment file names - Issue #247: Improved grabbing of fromName, fromHost, senderName and senderHost - Issue #39, #71, #229: Fixed body content gets incorrectly processed as attachments - Issue #122, #150, #167: Added ability to skip processing of attachments to increase performance, when attachments are not required - PR #284: Added missing PHPUnit tests - Issue #122, #150, #167: Lazy load message text and attachments data
Closing this issue since it is now possible to set and use the server encoding (charset) The other issue regarding the failing IMAP search is handled in the issue #250. Please note, that this is an issue of Microsoft Exchange servers, not this library. So we are trying to build a workaround to be able to do the searches even although the mail server doesn't support it. |
I recently updated to the latest version and office365 is not working corrrectly.
It seems that the US-ASCII needed for office365 is not in the list of mb_list_encodings(), PHP 7.2.16 and mbstrings, iconv installed.
On line 76 in Mailbox.php i put a bit of a hack in to fix the issue for me:
if(in_array($serverEncoding, mb_list_encodings()) || $serverEncoding = 'US-ASCII') {
It now seems to be working again with no issues but would like to take that hack out any ideas?
The text was updated successfully, but these errors were encountered: