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

fix for multiple of the same headers and getter for rawFields #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions PlancakeEmailParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,35 @@ private function extractHeadersAndRawBody()
preg_match('/([^:]+): ?(.*)$/', $line, $matches);
$newHeader = strtolower($matches[1]);
$value = $matches[2];
$this->rawFields[$newHeader] = $value;
if (is_array($this->rawFields[$newHeader]))
$this->rawFields[$newHeader][] = $value;
else if (isset($this->rawFields[$newHeader]))
$this->rawFields[$newHeader] = array($this->rawFields[$newHeader], $value);
else
$this->rawFields[$newHeader] = $value;
$currentHeader = $newHeader;
}
else // more lines related to the current header
{
if ($currentHeader) { // to prevent notice from empty lines
$this->rawFields[$currentHeader] .= substr($line, 1);
if (is_array($this->rawFields[$currentHeader])) {
$this->rawFields[$currentHeader][count($this->rawFields[$currentHeader]) - 1] .= substr($line, 1);
} else {
$this->rawFields[$currentHeader] .= substr($line, 1);
}
}
}
$i++;
}
}

/**
* @return array the parsed headers as associative array
*/
public function getHeaders()
{
return $this->rawFields;
}

/**
*
Expand Down