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

How to solve Invalid Message Date #198

Closed
dannylifino opened this issue Feb 16, 2022 · 4 comments
Closed

How to solve Invalid Message Date #198

dannylifino opened this issue Feb 16, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@dannylifino
Copy link

dannylifino commented Feb 16, 2022

Our company is currently automatically fetching our inbox messages using:
$inboxMessages = $this->inboxFolder->messages()->all()->get();

Occassionaly, we get a bad message in there with an invalid message date, which throws an error and terminates the whole script. If this happens, we manually clear out our inbox that consists of like 500+ messages a day. This is a real struggle, because if we get this error, we have to spend a lot of time searching and fixing it.

Error:
GetMessagesFailedException Invalid message date. ID: Date:Di., 15 Feb. 2022 06:52:44 +0100 (MEZ)/Di., 15 Feb. 2022 06:52:44 +0100 (MEZ)

Is there some sort of way that we can skip these messages from fetching or like delete them, without editing your whole package @Webklex ?

@Webklex Webklex added the enhancement New feature or request label Feb 16, 2022
@dannylifino
Copy link
Author

dannylifino commented Feb 17, 2022

@Webklex do you know of an easy fix for this, that i can implement at this particular moment?

@Webklex
Copy link
Owner

Webklex commented Aug 19, 2022

Hi @dannylifino ,
many thanks for your report. Is this Di., 15 Feb. 2022 06:52:44 +0100 (MEZ)/Di., 15 Feb. 2022 06:52:44 +0100 (MEZ) the actual date string or a combined string from two different messages?

This is our current collection:

php-imap/src/Header.php

Lines 708 to 744 in 0897d64

$date = $header->date;
if (preg_match('/\+0580/', $date)) {
$date = str_replace('+0580', '+0530', $date);
}
$date = trim(rtrim($date));
try {
$parsed_date = Carbon::parse($date);
} catch (\Exception $e) {
switch (true) {
case preg_match('/([0-9]{1,2}\ [A-Z]{2,3}\ [0-9]{4}\ [0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}\ UT)+$/i', $date) > 0:
case preg_match('/([A-Z]{2,3}\,\ [0-9]{1,2}\ [A-Z]{2,3}\ [0-9]{4}\ [0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}\ UT)+$/i', $date) > 0:
$date .= 'C';
break;
case preg_match('/([A-Z]{2,3}\,\ [0-9]{1,2}\ [A-Z]{2,3}\ [0-9]{4}\ [0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}\ \+[0-9]{2,4}\ \(\+[0-9]{1,2}\))+$/i', $date) > 0:
case preg_match('/([A-Z]{2,3}[\,|\ \,]\ [0-9]{1,2}\ [A-Z]{2,3}\ [0-9]{4}\ [0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}.*)+$/i', $date) > 0:
case preg_match('/([A-Z]{2,3}\,\ [0-9]{1,2}\ [A-Z]{2,3}\ [0-9]{4}\ [0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}\ [\-|\+][0-9]{4}\ \(.*)\)+$/i', $date) > 0:
case preg_match('/([A-Z]{2,3}\, \ [0-9]{1,2}\ [A-Z]{2,3}\ [0-9]{4}\ [0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}\ [\-|\+][0-9]{4}\ \(.*)\)+$/i', $date) > 0:
case preg_match('/([0-9]{1,2}\ [A-Z]{2,3}\ [0-9]{2,4}\ [0-9]{2}\:[0-9]{2}\:[0-9]{2}\ [A-Z]{2}\ \-[0-9]{2}\:[0-9]{2}\ \([A-Z]{2,3}\ \-[0-9]{2}:[0-9]{2}\))+$/i', $date) > 0:
$array = explode('(', $date);
$array = array_reverse($array);
$date = trim(array_pop($array));
break;
}
try {
$parsed_date = Carbon::parse($date);
} catch (\Exception $_e) {
if (!isset($this->config["fallback_date"])) {
throw new InvalidMessageDateException("Invalid message date. ID:" . $this->get("message_id") . " Date:" . $header->date . "/" . $date, 1100, $e);
} else {
$parsed_date = Carbon::parse($this->config["fallback_date"]);
}
}
}
$this->set("date", $parsed_date);

Please feel free to add an additional rule.

You can also disable this behavior by providing a fallback date fallback_date within your config:

// 'fallback_date' => "01.01.1970 00:00:00",

Best regards & happy coding,

@sergiy-petrov
Copy link

sergiy-petrov commented Dec 7, 2022

Same here, I got the similar exception quite often

'Invalid message date. ID*** Date:fr., 25 nov. 2022 06:27:14 +0100/fr., 25 nov. 2022 06:27:14 +0100'

@jazz-max
Copy link

I have same problem on 5.5.0 version :(
This is error message:
Invalid message date. ID:[email protected] Date:Tue, 22 Feb 2024 19:23:29 +0000k5b3sk0m/Tue, 22 Feb 2024 19:23:29 +0000k5b3sk0m

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

No branches or pull requests

4 participants