mirror of
https://github.com/itflow-org/itflow
synced 2026-06-26 11:40:40 +00:00
Replace webklex/php-imap with directorytree/imapengine in the ticket email parser. ImapEngine is pure PHP over sockets. Parser improvements: - Wrap per-message processing in try/catch so one malformed email can't abort the run; failures are flagged and logged with UID - Query unseen + unflagged so previously-failed (flagged) messages are no longer re-processed on every cron run - Skip vacation/auto-responder emails (RFC 3834) to prevent mail loops with the ticket auto-reply - Cap messages per run (50) and attachment size (15MB); inline images over 2MB are stored as attachments instead of base64-embedded in ticket details - Atomic lock file creation - preg_quote() the ticket prefix in subject matching - Dedupe CC watchers and exclude the sender - Map webklex 'tls' encryption setting to STARTTLS for compatibility NDR/DSN parsing now walks MIME parts via the underlying zbateson parser instead of relying on attachment extraction.
79 lines
1.7 KiB
PHP
79 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Egulias\EmailValidator;
|
|
|
|
use Egulias\EmailValidator\Result\Result;
|
|
use Egulias\EmailValidator\Result\ValidEmail;
|
|
use Egulias\EmailValidator\Result\InvalidEmail;
|
|
use Egulias\EmailValidator\Result\Reason\ExpectingATEXT;
|
|
|
|
abstract class Parser
|
|
{
|
|
/**
|
|
* @var Warning\Warning[]
|
|
*/
|
|
protected $warnings = [];
|
|
|
|
/**
|
|
* @var EmailLexer
|
|
*/
|
|
protected $lexer;
|
|
|
|
/**
|
|
* id-left "@" id-right
|
|
*/
|
|
abstract protected function parseRightFromAt(): Result;
|
|
abstract protected function parseLeftFromAt(): Result;
|
|
abstract protected function preLeftParsing(): Result;
|
|
|
|
|
|
public function __construct(EmailLexer $lexer)
|
|
{
|
|
$this->lexer = $lexer;
|
|
}
|
|
|
|
public function parse(string $str): Result
|
|
{
|
|
$this->lexer->setInput($str);
|
|
|
|
if ($this->lexer->hasInvalidTokens()) {
|
|
return new InvalidEmail(new ExpectingATEXT("Invalid tokens found"), $this->lexer->current->value);
|
|
}
|
|
|
|
$preParsingResult = $this->preLeftParsing();
|
|
if ($preParsingResult->isInvalid()) {
|
|
return $preParsingResult;
|
|
}
|
|
|
|
$localPartResult = $this->parseLeftFromAt();
|
|
|
|
if ($localPartResult->isInvalid()) {
|
|
return $localPartResult;
|
|
}
|
|
|
|
$domainPartResult = $this->parseRightFromAt();
|
|
|
|
if ($domainPartResult->isInvalid()) {
|
|
return $domainPartResult;
|
|
}
|
|
|
|
return new ValidEmail();
|
|
}
|
|
|
|
/**
|
|
* @return Warning\Warning[]
|
|
*/
|
|
public function getWarnings(): array
|
|
{
|
|
return $this->warnings;
|
|
}
|
|
|
|
protected function hasAtToken(): bool
|
|
{
|
|
$this->lexer->moveNext();
|
|
$this->lexer->moveNext();
|
|
|
|
return !$this->lexer->current->isA(EmailLexer::S_AT);
|
|
}
|
|
}
|