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

[BUG] Issue with certain date format #310

Closed
yellow1912 opened this issue May 7, 2019 · 2 comments
Closed

[BUG] Issue with certain date format #310

yellow1912 opened this issue May 7, 2019 · 2 comments
Labels
needs investigation This will be tested / debugged or checked out.

Comments

@yellow1912
Copy link

yellow1912 commented May 7, 2019

Environment (please complete the following information):

  • PHP IMAP version: Latest
  • PHP Version: [e.g. 7.2]
  • Type of execution: [php-fpm]

Describe the bug
The line 945 in Mailbox.php reads like this:

$dateRegex = '/\\s*\\(.*?\\)/';
                        $dateFormatted = \DateTime::createFromFormat(\DateTime::RFC2822, preg_replace($dateRegex, '', $dateHeader));
                        return $dateFormatted->format('Y-m-d H:i:s');

If the date does not meet the expected format, the $dateFormatted is a boolean variable so we need to ensure either throw an exception or just take current datetime as alternative?

To Reproduce

Use this date string for example: 7 Nov 2018 23:44:15 -0500

@yellow1912 yellow1912 added the needs investigation This will be tested / debugged or checked out. label May 7, 2019
@Sebbo94BY
Copy link
Collaborator

Sebbo94BY commented May 7, 2019

You're right. This is causing the following error:

Error: Call to a member function format() on boolean

I would rather just take the current datetime as throwing an exception would always end in the result, that you can not parse these emails.

// Edit: Or we'll leave the date unformatted.

I'll commit this change this evening.

Sebbo94BY pushed a commit that referenced this issue May 7, 2019
Sebbo94BY added a commit that referenced this issue May 7, 2019
- Updated formatting of class DataPartInfo to make it more human-readable
- Issue #310: Fixed issue with unparseable datetimes and updated/added PHPUnit tests
@Sebbo94BY
Copy link
Collaborator

This issue has been fixed. See references above.

  • If the given $dateHeader is empty, it will throw an InvalidParameterException
  • If the provided $dateHeader can not be formatted, it will return the current datetime (as before)
  • If the provided $dateHeader could be formatted, it will return this formatted / normalized datetime

The latest release 3.0.12 includes this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs investigation This will be tested / debugged or checked out.
Projects
None yet
Development

No branches or pull requests

2 participants