mirror of
https://github.com/itflow-org/itflow
synced 2026-06-13 13:21:05 +00:00
Rewrite email parser using ImapEngine, harden processing loop
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.
This commit is contained in:
105
plugins/vendor/directorytree/imapengine/src/Connection/ImapCommand.php
vendored
Normal file
105
plugins/vendor/directorytree/imapengine/src/Connection/ImapCommand.php
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace DirectoryTree\ImapEngine\Connection;
|
||||
|
||||
use Stringable;
|
||||
|
||||
class ImapCommand implements Stringable
|
||||
{
|
||||
/**
|
||||
* The compiled command lines.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected ?array $compiled = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
protected string $tag,
|
||||
protected string $command,
|
||||
protected array $tokens = [],
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get the IMAP tag.
|
||||
*/
|
||||
public function tag(): string
|
||||
{
|
||||
return $this->tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the IMAP command.
|
||||
*/
|
||||
public function command(): string
|
||||
{
|
||||
return $this->command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the IMAP tokens.
|
||||
*/
|
||||
public function tokens(): array
|
||||
{
|
||||
return $this->tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the command into lines for transmission.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function compile(): array
|
||||
{
|
||||
if (is_array($this->compiled)) {
|
||||
return $this->compiled;
|
||||
}
|
||||
|
||||
$lines = [];
|
||||
|
||||
$line = trim("{$this->tag} {$this->command}");
|
||||
|
||||
foreach ($this->tokens as $token) {
|
||||
if (is_array($token)) {
|
||||
// For tokens provided as arrays, the first element is a placeholder
|
||||
// (for example, "{20}") that signals a literal value will follow.
|
||||
// The second element holds the actual literal content.
|
||||
[$placeholder, $literal] = $token;
|
||||
|
||||
$lines[] = "{$line} {$placeholder}";
|
||||
|
||||
$line = $literal;
|
||||
} else {
|
||||
$line .= " {$token}";
|
||||
}
|
||||
}
|
||||
|
||||
$lines[] = $line;
|
||||
|
||||
return $this->compiled = $lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a redacted version of the command for safe exposure.
|
||||
*/
|
||||
public function redacted(): ImapCommand
|
||||
{
|
||||
return new static($this->tag, $this->command, array_map(
|
||||
function (mixed $token) {
|
||||
return is_array($token)
|
||||
? array_map(fn () => '[redacted]', $token)
|
||||
: '[redacted]';
|
||||
}, $this->tokens)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the command as a string.
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
return implode("\r\n", $this->compile());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user