Skip to content
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
40 changes: 40 additions & 0 deletions PlancakeEmailParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class PlancakeEmailParser {
const PLAINTEXT = 1;
const HTML = 2;

const FROM = 0;
const FROMNAME = 1;
const FROMADDRESS = 2;

/**
*
* @var boolean
Expand Down Expand Up @@ -333,5 +337,41 @@ private function isLineStartingWithPrintableChar($line)
{
return preg_match('/^[A-Za-z]/', $line);
}

/**
*
* @return string
* @throws Exception if a to header is not found or if there is no sender
*/
public function getFrom($returnIndex=self::FROM)
{
if ( (!isset($this->rawFields['from'])) || (!count($this->rawFields['from'])))
{
throw new Exception("Couldn't find the sender of the email");
}
if (!preg_match('/\"([^\"]+)\" <([^>]+)>/', $this->rawFields['from'], $matches)) {
(preg_match('/([^<]+) <([^>]+)>/', $this->rawFields['from'], $matches));
}
}

/**
*
* @return string
* @throws Exception if a to header is not found or if there is no sender
*/
public function getFromName()
{
return $this->getFrom(self::FROMNAME);
}

/**
*
* @return string
* @throws Exception if a to header is not found or if there is no sender
*/
public function getFromAddress()
{
return $this->getFrom(self::FROMADDRESS);
}
}
?>