GithubHelp home page GithubHelp logo

Exception Parse Data about laravel-imap HOT 19 CLOSED

webklex avatar webklex commented on August 15, 2024
Exception Parse Data

from laravel-imap.

Comments (19)

Webklex avatar Webklex commented on August 15, 2024 1

Hi @GuiAndra ,
thanks for the report. I think I would rather like to validate the given datestring and perhaps "fix it" if it seems to be broken. This way anyone can be sure to always have a valid Carbon object.

Please give me a few days or perhaps the upcomming weekend to come up with a fix :)

Best regards

from laravel-imap.

archond avatar archond commented on August 15, 2024 1

@Webklex
Fri, 1 Feb 2019 01:30:04 +0600 (+06)
string №346
Fix my exception
case preg_match('/([A-Z]{2,3},\s+[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:
work it

from laravel-imap.

rxmgrudy avatar rxmgrudy commented on August 15, 2024 1

For anyone that comes across this in the future, you can switch over to php-imap with very minor changes to your code and you can pass in a fallback_date to deal with errors related to parsing time strings.

https://github.com/Webklex/php-imap/blob/master/src/Header.php#L736

$clientManager = new ClientManager(['options' => ['fallback_date' => Carbon::now()]]);

from laravel-imap.

GuiAndra avatar GuiAndra commented on August 15, 2024

Sure @Webklex, i'm waiting for the fix.

thanks :)

from laravel-imap.

Webklex avatar Webklex commented on August 15, 2024

Hi @GuiAndra,
please update to v 1.0.3.9 :)

from laravel-imap.

GuiAndra avatar GuiAndra commented on August 15, 2024

Thaanks @Webklex :)

from laravel-imap.

RpCoding avatar RpCoding commented on August 15, 2024

04 Jan 2018 10:12:47 UT is a timestamp I have in one of the emails I'm trying to read. This caused a crash because of Carbon::parse.

Edit: My dirty fix was to replace

try{
    $this->date = Carbon::parse($date);
}catch(\Exception $e){
    switch(true){
        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}\ \([A-Z]{2,3}\+[0-9]{1,2}\:[0-9]{1,2})\)+$/i', $date):
            $array = explode('(', $date);
            $array = array_reverse($array);
            $date = trim(array_pop($array));
            break;
    }
    $this->date = Carbon::parse($date);
}

with

try{
    $this->date = Carbon::parse($date);
}catch(\Exception $e){
    switch(true){
        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}\ \([A-Z]{2,3}\+[0-9]{1,2}\:[0-9]{1,2})\)+$/i', $date):
            $array = explode('(', $date);
            $array = array_reverse($array);
            $date = trim(array_pop($array));
            break;
     }

    if(strpos($date, "UT") !== FALSE && strpos($date, "UTC") === FALSE){
        $date = str_replace("UT", "UTC", $date);
    }

    $this->date = Carbon::parse($date);
}

in https://github.com/Webklex/laravel-imap/blob/master/src/IMAP/Message.php but as I said, quick and dirty.

from laravel-imap.

Webklex avatar Webklex commented on August 15, 2024

@RpCoding thanks for your report :) I just released a new version containing the new validation rule.

Ref.: v. 1.0.5.5

from laravel-imap.

Davronjuraev avatar Davronjuraev commented on August 15, 2024

Hello, please help me, How can i reply to message from laravel application

from laravel-imap.

brandxtc avatar brandxtc commented on August 15, 2024

Got a new invalid timestamp. :)
Failed to parse time string (22 Jun 18 03:56:36 PM
-05:00 (GMT -05:00)) at position 35 (-): Double timezone specification

from laravel-imap.

tortato avatar tortato commented on August 15, 2024

I got a new error into datetime:
"DateTime::__construct(): Failed to parse time string (Thu, 8 Nov 2018 08:54:58 -0200 (-02)) at position 31 ((): Unexpected character" -- double espaces into Thu, and 8

Sugestion

switch (true) {
  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:
  $date = str_replace('  ', ' ', $date);
  $array = explode('(', $date);
  $array = array_reverse($array);
  $date = trim(array_pop($array));
  break;
  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:
  
  $date .= 'C';
  break;
}

from laravel-imap.

Webklex avatar Webklex commented on August 15, 2024

@tortato wow you've found a new way to write a date^^ Thanks for the report and a solution. This will be part of the next release :)

Best regards

from laravel-imap.

AronWebSolutionPVTLTD avatar AronWebSolutionPVTLTD commented on August 15, 2024

@Webklex
I got a new error
DateTime::__construct(): Failed to parse time string (Sat, 31 Aug 2013 20:08:23 +0580) at position 30 (0): Unexpected character

image

from laravel-imap.

anibalealvarezs avatar anibalealvarezs commented on August 15, 2024

'DateTime::__construct(): Failed to parse time string (Mon, 4 Feb 2019 04:03:49 -0300 (-03)) at position 32 ((): Unexpected character

Note: there are 2 spaces between "Mon," and "4"

from laravel-imap.

Webklex avatar Webklex commented on August 15, 2024

Hi @tortato @VijayTahkur @archond @anibalealvarezs ,
please update to v. 1.3.0 :)

from laravel-imap.

dmitryplus avatar dmitryplus commented on August 15, 2024

Hi @Webklex
I caught an exception 'Invalid message date' for the date
Sun, 6 Apr 2008 21:24:33 UT

v 1.4.1

from laravel-imap.

Eldar89 avatar Eldar89 commented on August 15, 2024

@Webklex
I got a new error
Warning: DateTime::modify(): Failed to parse time string (Wed, 11 Sep 2019 15:23:06 +0600 (+06)) at position 32 ((): Unexpected character

v.1.4.2

from laravel-imap.

bsralph avatar bsralph commented on August 15, 2024

@Webklex
I got the following error, could you assist?

DateTime::__construct(): Failed to parse time string (14 Sep 2019 00:10:08 UT +0200) at position 21 (U): The timezone could not be found in the database

from laravel-imap.

danielkleach avatar danielkleach commented on August 15, 2024

@Webklex

Getting the following error:
Failed to parse time string (Tue, 08 Nov 2022 18:47:20 +0000 14:03:33 +0000) at position 32 (1): Double time specification

We are on version 1.6.2. Is this particular date error handled in later versions?

from laravel-imap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.