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

UnexpectedEncodingException: Cannot decode "5" #278

Closed
wujku opened this issue Jan 15, 2018 · 4 comments
Closed

UnexpectedEncodingException: Cannot decode "5" #278

wujku opened this issue Jan 15, 2018 · 4 comments
Labels

Comments

@wujku
Copy link
Contributor

wujku commented Jan 15, 2018

From: Testowy Wujka <testowywujka@gmail.com>
Content-Type: multipart/mixed;
    boundary="Apple-Mail=_BC51FF68-314D-4AC3-BAF7-0432A230E7F6"
Mime-Version: 1.0 (Mac OS X Mail 11.2 \(3445.5.20\))
Subject: Inline Attachment
Message-Id: <40712F7B-4A03-4800-AD6E-97BBF53DAA39@gmail.com>
Date: Mon, 15 Jan 2018 08:58:30 +0100
To: Sample <sample@example.com>


--Apple-Mail=_BC51FF68-314D-4AC3-BAF7-0432A230E7F6
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
    charset=us-ascii

Lorem ipsum


--Apple-Mail=_BC51FF68-314D-4AC3-BAF7-0432A230E7F6
Content-Disposition: attachment;
    filename=attachment.txt
Content-Type: text/plain;
    x-unix-mode=0644;
    name="attachment.txt"
Content-Transfer-Encoding: 7bit

Hello!

--Apple-Mail=_BC51FF68-314D-4AC3-BAF7-0432A230E7F6--
@Slamdunk
Copy link
Collaborator

I cannot reproduce the Exception: may you create a PR with a failing test please?

@wujku
Copy link
Contributor Author

wujku commented Jan 15, 2018

I tried reproduce the Exception with phpunit and above mail.
\imap_fetchstructure (Message:60) returns something different for imap server which contains problematic mail.

phpunit:

class stdClass#43 (11) {
  public $type =>
  int(1)
  public $encoding =>
  int(0)
  public $ifsubtype =>
  int(1)
  public $subtype =>
  string(5) "MIXED"
  public $ifdescription =>
  int(0)
  public $ifid =>
  int(0)
  public $ifdisposition =>
  int(0)
  public $ifdparameters =>
  int(0)
  public $ifparameters =>
  int(1)
  public $parameters =>
  array(1) {
    [0] =>
    class stdClass#44 (2) {
      public $attribute =>
      string(8) "BOUNDARY"
      public $value =>
      string(48) "Apple-Mail=_BC51FF68-314D-4AC3-BAF7-0432A230E7F6"
    }
  }
  public $parts =>
  array(2) {
    [0] =>
    class stdClass#45 (12) {
      public $type =>
      int(0)
      public $encoding =>
      int(0)
      public $ifsubtype =>
      int(1)
      public $subtype =>
      string(5) "PLAIN"
      public $ifdescription =>
      int(0)
      public $ifid =>
      int(0)
      public $lines =>
      int(2)
      public $bytes =>
      int(15)
      public $ifdisposition =>
      int(0)
      public $ifdparameters =>
      int(0)
      public $ifparameters =>
      int(1)
      public $parameters =>
      array(1) {
        ...
      }
    }
    [1] =>
    class stdClass#47 (14) {
      public $type =>
      int(0)
      public $encoding =>
      int(0)
      public $ifsubtype =>
      int(1)
      public $subtype =>
      string(5) "PLAIN"
      public $ifdescription =>
      int(0)
      public $ifid =>
      int(0)
      public $lines =>
      int(1)
      public $bytes =>
      int(8)
      public $ifdisposition =>
      int(1)
      public $disposition =>
      string(10) "ATTACHMENT"
      public $ifdparameters =>
      int(1)
      public $dparameters =>
      array(1) {
        ...
      }
      public $ifparameters =>
      int(1)
      public $parameters =>
      array(2) {
        ...
      }
    }
  }
}

direct connection to problematic imap account:

class stdClass#646 (11) {
  public $type =>
  int(1)
  public $encoding =>
  int(0)
  public $ifsubtype =>
  int(1)
  public $subtype =>
  string(5) "MIXED"
  public $ifdescription =>
  int(0)
  public $ifid =>
  int(0)
  public $ifdisposition =>
  int(0)
  public $ifdparameters =>
  int(0)
  public $ifparameters =>
  int(0)
  public $parameters =>
  class stdClass#647 (0) {
  }
  public $parts =>
  array(3) {
    [0] =>
    class stdClass#648 (11) {
      public $type =>
      int(0)
      public $encoding =>
      int(0)
      public $ifsubtype =>
      int(1)
      public $subtype =>
      string(5) "PLAIN"
      public $ifdescription =>
      int(0)
      public $ifid =>
      int(0)
      public $bytes =>
      int(15)
      public $ifdisposition =>
      int(0)
      public $ifdparameters =>
      int(0)
      public $ifparameters =>
      int(1)
      public $parameters =>
      array(1) {
        ...
      }
    }
    [1] =>
    class stdClass#650 (11) {
      public $type =>
      int(0)
      public $encoding =>
      int(0)
      public $ifsubtype =>
      int(1)
      public $subtype =>
      string(5) "PLAIN"
      public $ifdescription =>
      int(0)
      public $ifid =>
      int(0)
      public $bytes =>
      int(8)
      public $ifdisposition =>
      int(0)
      public $ifdparameters =>
      int(0)
      public $ifparameters =>
      int(1)
      public $parameters =>
      array(2) {
        ...
      }
    }
    [2] =>
    class stdClass#653 (10) {
      public $type =>
      int(9)
      public $encoding =>
      int(5)
      public $ifsubtype =>
      int(1)
      public $subtype =>
      string(7) "UNKNOWN"
      public $ifdescription =>
      int(0)
      public $ifid =>
      int(0)
      public $ifdisposition =>
      int(0)
      public $ifdparameters =>
      int(0)
      public $ifparameters =>
      int(0)
      public $parameters =>
      class stdClass#654 (0) {
        ...
      }
    }
  }
}

@Slamdunk
Copy link
Collaborator

Slamdunk commented Jan 15, 2018

Ok, I get the issue. By itself, is not resolvable: without the encoding we can't provide the AbstractPart::getDecodedContent() functionality, and I prefer to prohibit it to avoid malfunctions.

But of course we can handle all this in a much more graceful way: I'll move the Exception to the getDecodedContent method, so you can fetch and use the message and also manually skip the part that can't be decoded if you don't want to decode them.

PR soon

@Slamdunk
Copy link
Collaborator

Released in 1.2.0

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