diff --git a/classes/emailcatcher.class.php b/classes/emailcatcher.class.php index 54ca9a78b39ffdd67353939e86599dc253ba94c6..a41745940f039bbc701a059e2e14c85c63bcca8d 100644 --- a/classes/emailcatcher.class.php +++ b/classes/emailcatcher.class.php @@ -12,22 +12,36 @@ * * ---------------------------------------------------------------------- * 2024-10-08 v0.1 initial version + * 2024-10-16 v0.2 detect parse error when reading email data * ======================================================================= */ class emailcatcher { + /** + * Filename for email data + * @var string + */ protected string $sMailData='emaildata.txt'; + /** + * Id of selected email + * @var string + */ protected string $sId=''; + + /** + * Email data of the selected email + * @var array + */ protected array $aSelectedEmail=[]; + // ------------------------------------------------------------------ public function __construct() { $this->sMailData=dirname(__DIR__) . '/data/' . $this->sMailData; - // $this->_readEmails(); } // ------------------------------------------------------------------ @@ -37,6 +51,7 @@ class emailcatcher /** * Fetch email of a single email from stdin and store it. * It returns the return value of file_put_contents(). + * used in php-sendmail.php * * @return bool|int */ @@ -70,6 +85,11 @@ class emailcatcher // ------------------------------------------------------------------ + /** + * Read all stored emails and return them as an array + * @param string $sEmail2Show optional: id of email to show + * @return array + */ protected function _readEmails(string $sEmail2Show=''): array { if(!file_exists($this->sMailData)){ @@ -77,7 +97,14 @@ class emailcatcher } foreach(file($this->sMailData) as $line) { + if (empty(trim($line))) { + continue; + } $aLinedata=json_decode($line, true); + if(!is_array($aLinedata)){ + // echo "ERROR: unable to parse line as single json object: <code>$line</code>"; + continue; + } [$sHead, $sBody] = explode("\r\n\r\n", $aLinedata['mail']); $sHead="\n$sHead";