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

Getting "imap_fetchheader(): Bad message number" when working on Office365 servers #243

Closed
todorowww opened this issue Sep 2, 2019 · 1 comment
Labels

Comments

@todorowww
Copy link
Contributor

I am adding this just for the future reference, so that folks that run into this problem like I did, know what to do, without losing a few hours of their life :)

After working properly for months, our script stopped fetching emails. The error we started getting was the above one, "imap_fetchheader(): Bad message number". After spending a few hours looking back and forth through the code, and laravel-imap library, I finally tried one stupid thing, and it worked. I hope it works for you too.

The exception was happening in the Query class.. This is the code in question, that was presenting with this issue:

$client = new Client($config);
$client->connect();
$folder = $client->getFolder('INBOX');
$messages = $folder->query(null)
    ->since($since->format("d-M-Y"))
    ->setFetchBody(false)->setFetchAttachment(false)->get();

Adding imap.option "message_key", and setting it to "number", resolved the issue.

// Appending this key to our configuration
$config['message_key'] = "number"; // Office365 servers require this, because, well, Microsoft.
$client = new Client($config);
$client->connect();
$folder = $client->getFolder('INBOX');
$messages = $folder->query(null)
    ->since($since->format("d-M-Y"))
    ->setFetchBody(false)->setFetchAttachment(false)->get();

Et voilà, works like a charm, emails started being processed again.

I tested this with the latest laravel-imap version, 1.4.2, running on:
Linux, Server - PHP 7.1.3
Virual Box, Linux - PHP 7.2.19

@Webklex
Copy link
Owner

Webklex commented Sep 2, 2019

Hi @todorowww ,
thanks for your post! You could also set the message_key inside the config file :) Depending on the given "server features" you can choose between id, number and list.

Message key identifier option:
You can choose between 'id', 'number' or 'list'
'id' - Use the MessageID as array key (default, might cause hickups with yahoo mail)
'number' - Use the message number as array key (isn't always unique and can cause some interesting behavior)
'list' - Use the message list number as array key (incrementing integer (does not always start at 0 or 1)

Update: I've added a link to this issue inside the readme.md

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

No branches or pull requests

2 participants