Skip to content

Multipart-Message Boundaries are empty #27

Closed
@DasTobbel

Description

@DasTobbel

Describe the bug
Got an Email, where a parsed header contains a malformed header, so that somehow the getBoundary() method is called twice and returns the correct boundary in the first run, but a empty one in the second
src/Structure.php:99:

    public function getBoundary(){
        $tmp = $this->header->find("/boundary\=\"(.*)\"/");
        \Log::debug(print_r(["getBoundary" => $tmp], true));
        return tmp;
    }
[...]
    public function find_parts(){
        if($this->type === IMAP::MESSAGE_TYPE_MULTIPART) {
            if (($boundary = $this->getBoundary()) === null)  {
                throw new MessageContentFetchingException("no content found", 0);
            }
          
            $boundaries = [
                $boundary
            ];
            \Log::debug(print_r(["boundaries" => $boundaries], true));
            if (preg_match("/boundary\=\"(.*)\"/", $this->raw, $match) == 1) {
                if(is_array($match[1])){
                    foreach($match[1] as $matched){
                        $boundaries[] = $matched;
                    }
                }else{
                    if(!empty($match[1])) {
                        $boundaries[] = $match[1];
                    }
                }
            }
            \Log::debug(print_r(["boundaries #2" => $boundaries], true));
            $raw_parts = explode( $boundaries[0], str_replace($boundaries, $boundaries[0], $this->raw) );
            $parts = [];
[...]
Log:
[2020-10-13 13:51:30] production.DEBUG: Array( [getBoundary()] => _009_VI1PR05MB57270B55FFCF7840254D7E6F95040VI1PR05MB5727eurp_ )
[2020-10-13 13:51:30] production.DEBUG: Array( [boundaries] => Array( [0] => _009_VI1PR05MB57270B55FFCF7840254D7E6F95040VI1PR05MB5727eurp_ ))
[2020-10-13 13:51:30] production.DEBUG: Array( [boundaries #2] => Array ([0] => _009_VI1PR05MB57270B55FFCF7840254D7E6F95040VI1PR05MB5727eurp_ , [1] => _000_VI1PR05MB57270B55FFCF7840254D7E6F95040VI1PR05MB5727eurp_ ))
[2020-10-13 13:51:30] production.DEBUG: Array( [getBoundary()] => null ) 
[2020-10-13 13:51:30] production.DEBUG: Array( [boundaries] => Array([0] => null ))
[2020-10-13 13:51:30] production.DEBUG: Array( [boundaries #2] => Array([0] => null ))

To Reproduce
Steps to reproduce the behavior:
Create an email where a the Header have a definition like this

Content-Language: de-DE

Content-Type: multipart/related;

	boundary="_009_VI1PR05MB57270B55FFCF7840254D7E6F95040VI1PR05MB5727eurp_";

	type="multipart/alternative"

MIME-Version: 1.0

Try to recive the said mail
Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop / Server (please complete the following information):

  • OS: ubuntu 20
  • PHP: 7.4
  • Version 2.1.11

Additional context
Another smaller Issue was that some boundary params were set without any qoute (") markers, could be fixed with an alternation on the regex = boundary\=\"?(.*)\"?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions