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

Buggy imap_search/encoding on Microsoft Exchange/Office365 #128

Closed
dico opened this issue Feb 19, 2016 · 13 comments
Closed

Buggy imap_search/encoding on Microsoft Exchange/Office365 #128

dico opened this issue Feb 19, 2016 · 13 comments
Labels
need help Your support is required to solve this issue.

Comments

@dico
Copy link

dico commented Feb 19, 2016

Hi

I have found some kind of issue. Tested on Office365 and local Microsoft Exchange server.

If serverEncoding is sent as an empty string when creating the object, the imap_search would fail and return empty array. The string would look like this: imap_search(Resource id #72, FROM "mail@address.com", SE_UID, ); - with a comma and no encoding at the end.

In some weird way, the imap_search criteria "ALL" seems to work in this case, but no other criteria-parameters.

Also if I don't send any encoding parameter at all, UTF-8 would be set as default. I don't know why or what kind of encoding is used by Microsoft - but UTF-8 has the same problem, criteria "ALL" work, but no other criterias.

If I just remove ", $this->serverEncoding" on line 174, all imap_search criterias works.

Suggested solution: Don't set any server encoding as default and/or check if server-encoding parameter is empty.

@dico dico changed the title imap_search filters is buggy when server encoding is blank Buggy imap_search/encoding on Microsoft Exchange/Office365 Feb 19, 2016
@stevebauman
Copy link

I have the same issue, do you know what type of encoding to use with Exchange and Office 365?

@DonCallisto
Copy link

Same issue here. @barbushin is this onto a todo list, do you recognize the issue, do you need help? Please let us know :)

@barbushin barbushin added need help Your support is required to solve this issue. and removed need help Your support is required to solve this issue. labels May 23, 2016
@barbushin
Copy link
Owner

Sorry guys, I'm just too busy in last few months. It will be great if somebody can find solution and send me Pull request. Cheers!

@DonCallisto
Copy link

DonCallisto commented May 23, 2016

If someone is interested in this kind of situation - I will tackle it, if I ever find time, later - I've tried to understood what's goes on here as PHP itself returns a false either for "bad request" than for "no results" (a very poor choice in my humble opinion).

BTW I've played around with python and what I got is

>>> import imaplib;
>>> M = imaplib.IMAP4_SSL('outlook.office365.com', 993)
>>> M.login('my@mail.com, 'myPassword')
('OK', ['LOGIN completed.'])
>>> M.select('INBOX')
('OK', ['18'])
>>> M.search('UTF-8', '(SINCE "23-May-2016" BEFORE "24-May-2016")')
('NO', ['[BADCHARSET (US-ASCII)] The specified charset is not supported.'])
>>> M.search(None, '(SINCE "23-May-2016" BEFORE "24-May-2016")')
('OK', ['17 18'])

@a7lan
Copy link

a7lan commented Dec 1, 2016

Any news? I have same problem too

@DonCallisto
Copy link

@a7lan Unfortunately, no.

@littleylv
Copy link

@barbushin You can take a look at here. Maybe we can do what they said: "When searching fall back to US-ASCII if BADCHARSET is received."

@mrefaie
Copy link

mrefaie commented Feb 6, 2017

@littleylv You are right the US-ASCII encoding is the solutions for that. Every one who faces this problem can try to initialize the mailbox with US-ASCII encoding.
$mailbox = new PhpImap\Mailbox('{imap.gmail.com:993/imap/ssl}INBOX', 'some@gmail.com', '*********', __DIR__, 'US-ASCII');

@mrefaie
Copy link

mrefaie commented Feb 6, 2017

With that solution a search in the mailbox like that $mailbox->searchMailbox(('UNFLAGGED FROM "Sender Name <sender@gmail.com>"')); will not work. You have to use only the username $mailbox->searchMailbox(('UNFLAGGED FROM "Sender Name"'));

@commanddotcom
Copy link
Contributor

commanddotcom commented Jan 11, 2018

US-ASCII leads to the issue with gmail accounts:
Error:

Mime string encoding conversion failed

@yusufalakavuk
Copy link

I had the same issue while converting iso-8859-1 to UTF-8 and added following lines
if(!$convertedString ) {
$convertedString = @utf8_encode($string);
}
just before
if(!$convertedString) {
throw new Exception('Mime string encoding conversion failed');
}

and it works fine for me now.

@NormanEdance
Copy link

NormanEdance commented Apr 4, 2018

See fixes: Problem with serverEncoding #101 🔗

@Sebbo94BY
Copy link
Collaborator

This is an issue on Exchange servers and not related to this library. However, we're still checking, if we can implement a workaround to get it somehow working. See #306.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need help Your support is required to solve this issue.
Projects
None yet
Development

No branches or pull requests