|
dolibarr 25.0.0-alpha
|
Class EmailCleaner. More...

Public Member Functions | |
| __construct ($db) | |
| Constructor. | |
| processEmailCollectorMessage ($parameters, &$object) | |
| Process one EmailCollector message through the isolated EmailCleaner workflow. | |
| runEmailCleaner ($subject, $from, $rawBody) | |
| Run AI cleaner with conservative fallback. | |
Static Public Member Functions | |
| static | isRuntimeAvailable () |
| Check if the runtime dependencies for EmailCleaner are available. | |
| static | isEmailCollectorHookAction ($action) |
| Check if the EmailCollector hook action targets EmailCleaner. | |
| static | parseActionParamConfig ($raw) |
| Parse action parameter configuration (JSON). | |
| static | buildNoiseSummaryFromSegments ($segments) |
| Build minimal excluded-noise summary from segments. | |
| static | buildComplianceMetadata ($engine, $fallbackUsed, $confidence) |
| Build compliance metadata for transparency and supervision. | |
| static | collectAttachmentRows ($attachments, $savedAttachments, $savedDir='') |
| Extract attachment rows with stable metadata. | |
| static | detectPdfDocTypeFromAttachmentName ($filename) |
| Detect a generic document-like type from attachment metadata. | |
| static | normalizeText ($text) |
| Normalize text to UTF-8 LF-only. | |
| static | extractMessageIdFromHeader ($header) |
| Extract Message-ID from raw RFC822 header. | |
| static | extractHeaderFieldValue ($header, $fieldName) |
| Extract unfolded RFC822 header value. | |
| static | extractHeaderMessageIds ($raw) |
| Parse message-id list from References-like header. | |
| static | normalizeMessageId ($messageId) |
| Normalize one RFC message identifier for comparisons. | |
| static | normalizeMessageIdList ($messageIds) |
| Normalize and de-duplicate RFC message identifiers without changing order. | |
| static | buildThreadKey ($messageId, $inReplyTo, $references) |
| Build a stable technical thread key from RFC lineage. | |
| static | buildMessageScopesBasic ($body, $subject='', $from='', $date='', $messageId='', $inReplyTo='', $references=array()) |
| Build deterministic current/quoted scopes and a technical timeline. | |
| static | extractQuotedMessageBlocksBasic ($body, $maxBlocks=16) |
| Extract quoted message blocks with neutral RFC metadata. | |
| static | extractReplyOnlyTextBasic ($body) |
| Extract reply-only part with a conservative separator strategy. | |
| static | extractQuotedThreadSnippetBasic ($body, $maxLen=1200) |
| Build compact quoted context snippet for auditing/context transfer. | |
Private Member Functions | |
| findActionCommIdByMessageId ($entity, $msgid) | |
| Find the agenda event created for the collected email. | |
| insertAiRequestLogRow ($entity, $actioncommId, $collectorId, $msgid, $rawBody, $cleanedText, $segments, $confidence, $engine, $model, $promptCode, $promptVersion, $contextProfileCode, $contextProfileVersion, $emailContext, $emailUnderstanding, $handoffPayload, $payload) | |
| Insert cleaner output in the shared AI request log. | |
| isAiRequestLogTableAvailable () | |
| Check if the shared AI request log table is available. | |
Static Private Member Functions | |
| static | buildFallbackEmailUnderstanding ($cleanBody) |
| Build a minimal understanding payload when AI structured preprocessing is unavailable. | |
| static | sanitizeEmailUnderstanding ($raw, $fallbackCleanBody='') |
| Sanitize structured understanding returned by AI. | |
| static | sanitizeStringList ($items, $maxItems, $maxLen) |
| Sanitize a list of short strings. | |
| static | extractLeadingQuotedHeaderBasic ($raw) |
| Parse neutral metadata from the leading header of a quoted block. | |
| static | fallbackCleanBody ($rawBody) |
| Conservative fallback cleaner. | |
| static | decodeJsonFromAiString ($raw) |
| Decode JSON from AI output that may contain wrappers. | |
Class EmailCleaner.
Definition at line 21 of file emailcleaner.class.php.
| EmailCleaner::__construct | ( | $db | ) |
Constructor.
Definition at line 35 of file emailcleaner.class.php.
|
static |
Build compliance metadata for transparency and supervision.
| string | $engine | Cleaner engine |
| bool | $fallbackUsed | 1 if fallback mode was used |
| float | $confidence | Cleaner confidence |
Definition at line 494 of file emailcleaner.class.php.
References getDolGlobalInt(), and getDolGlobalString().
Referenced by processEmailCollectorMessage().
|
staticprivate |
Build a minimal understanding payload when AI structured preprocessing is unavailable.
| string | $cleanBody | Cleaned body |
Definition at line 756 of file emailcleaner.class.php.
References dol_strlen(), dol_substr(), and normalizeText().
Referenced by processEmailCollectorMessage(), and sanitizeEmailUnderstanding().
|
static |
Build deterministic current/quoted scopes and a technical timeline.
| string | $body | Raw email body |
| string | $subject | Current subject |
| string | $from | Current sender |
| string | $date | Current Date header |
| string | $messageId | Current message identifier |
| string | $inReplyTo | Direct parent identifier |
| array<int,string> | $references Reference lineage |
Definition at line 1052 of file emailcleaner.class.php.
References dol_strlen(), dol_substr(), extractQuotedMessageBlocksBasic(), extractQuotedThreadSnippetBasic(), extractReplyOnlyTextBasic(), normalizeMessageId(), and normalizeText().
Referenced by processEmailCollectorMessage().
|
static |
Build minimal excluded-noise summary from segments.
| array<int,mixed> | $segments Segments returned by the cleaner |
Definition at line 467 of file emailcleaner.class.php.
References dol_strlen(), dol_strtolower(), and dol_substr().
Referenced by processEmailCollectorMessage().
|
static |
Build a stable technical thread key from RFC lineage.
The oldest References entry is preferred because replies that are not consecutive still share it. This is only correlation metadata and never a business interpretation.
| string | $messageId | Current message identifier |
| string | $inReplyTo | Direct parent identifier |
| array<int,string> | $references Reference lineage |
Definition at line 1032 of file emailcleaner.class.php.
References normalizeMessageId(), and normalizeMessageIdList().
Referenced by processEmailCollectorMessage().
|
static |
Extract attachment rows with stable metadata.
| array<int,mixed> | $attachments EmailCollector attachments | |
| array<int,mixed> | $savedAttachments Saved attachment metadata | |
| string | $savedDir | Directory where attachments were saved |
Definition at line 520 of file emailcleaner.class.php.
References dol_strtolower().
Referenced by processEmailCollectorMessage().
|
staticprivate |
Decode JSON from AI output that may contain wrappers.
| string | $raw | Raw AI output |
Definition at line 1350 of file emailcleaner.class.php.
References dol_substr().
Referenced by runEmailCleaner().
|
static |
Detect a generic document-like type from attachment metadata.
| string | $filename | Attachment filename |
Definition at line 598 of file emailcleaner.class.php.
References dol_strtolower().
|
static |
Extract unfolded RFC822 header value.
| string | $header | Raw RFC822 header |
| string | $fieldName | Header field name |
Definition at line 922 of file emailcleaner.class.php.
References dol_strlen(), and dol_substr().
Referenced by processEmailCollectorMessage().
|
static |
Parse message-id list from References-like header.
| string | $raw | Raw References header |
Definition at line 958 of file emailcleaner.class.php.
Referenced by processEmailCollectorMessage().
|
staticprivate |
Parse neutral metadata from the leading header of a quoted block.
| string | $raw | Quoted block |
| array<int,string> | $names Accepted header names |
Definition at line 1179 of file emailcleaner.class.php.
References normalizeMessageId().
Referenced by extractQuotedMessageBlocksBasic().
|
static |
Extract Message-ID from raw RFC822 header.
| string | $header | Raw RFC822 header |
Definition at line 902 of file emailcleaner.class.php.
Referenced by processEmailCollectorMessage().
|
static |
Extract quoted message blocks with neutral RFC metadata.
| string | $body | Raw email body |
| int | $maxBlocks | Maximum blocks |
| array<int,array<string,mixed>> | $blocks Parsed quoted blocks | |
| array<int,string> | $current Current block lines | |
| bool | $collecting | Whether a quoted block has started |
Definition at line 1110 of file emailcleaner.class.php.
References dol_strlen(), dol_substr(), extractLeadingQuotedHeaderBasic(), and normalizeText().
Referenced by buildMessageScopesBasic().
|
static |
Build compact quoted context snippet for auditing/context transfer.
| string | $body | Raw email body |
| int | $maxLen | Maximum snippet length |
Definition at line 1272 of file emailcleaner.class.php.
References dol_strlen(), dol_substr(), and normalizeText().
Referenced by buildMessageScopesBasic().
|
static |
Extract reply-only part with a conservative separator strategy.
| string | $body | Raw email body |
Definition at line 1226 of file emailcleaner.class.php.
References dol_strlen(), dol_substr(), and normalizeText().
Referenced by buildMessageScopesBasic().
|
staticprivate |
Conservative fallback cleaner.
| string | $rawBody | Raw email body |
Definition at line 1310 of file emailcleaner.class.php.
References dol_string_nospecial(), dol_strlen(), dol_strtolower(), dol_substr(), and normalizeText().
Referenced by runEmailCleaner().
|
private |
Find the agenda event created for the collected email.
| int | $entity | Entity id |
| string | $msgid | Message id |
Definition at line 309 of file emailcleaner.class.php.
Referenced by processEmailCollectorMessage().
|
private |
Insert cleaner output in the shared AI request log.
| int | $entity | Entity id |
| int | $actioncommId | Agenda event id |
| int | $collectorId | Collector id |
| string | $msgid | Message id |
| string | $rawBody | Raw message body |
| string | $cleanedText | Cleaned message body |
| array<int,array<string,mixed>> | $segments Cleaner segments | |
| float | $confidence | Cleaner confidence |
| string | $engine | Cleaner engine |
| string | null | $model | AI model identifier |
| string | $promptCode | Prompt code |
| string | $promptVersion | Prompt version |
| string | $contextProfileCode | Context profile code |
| string | $contextProfileVersion | Context profile version |
| array<string,mixed> | $emailContext Extracted email context | |
| array<string,mixed> | $emailUnderstanding Structured email understanding | |
| array<string,mixed> | $handoffPayload Handoff payload | |
| array<string,mixed> | $payload Full cleaner payload |
Definition at line 352 of file emailcleaner.class.php.
References $context, ai_log_request(), getDolGlobalInt(), getDolGlobalString(), and isAiRequestLogTableAvailable().
Referenced by processEmailCollectorMessage().
|
private |
Check if the shared AI request log table is available.
Definition at line 437 of file emailcleaner.class.php.
Referenced by insertAiRequestLogRow().
|
static |
Check if the EmailCollector hook action targets EmailCleaner.
| string | $action | Hook action |
Definition at line 58 of file emailcleaner.class.php.
References dol_strtolower().
Referenced by ActionsAi\doCollectImapOneCollector().
|
static |
Check if the runtime dependencies for EmailCleaner are available.
Definition at line 45 of file emailcleaner.class.php.
References isModEnabled().
Referenced by ActionsAi\addMoreActionsEmailCollector(), and ActionsAi\doCollectImapOneCollector().
|
static |
Normalize one RFC message identifier for comparisons.
| string | $messageId | Message identifier |
Definition at line 993 of file emailcleaner.class.php.
References dol_strtolower().
Referenced by buildMessageScopesBasic(), buildThreadKey(), extractLeadingQuotedHeaderBasic(), normalizeMessageIdList(), and processEmailCollectorMessage().
|
static |
Normalize and de-duplicate RFC message identifiers without changing order.
| array<int,string> | $messageIds Message identifiers |
Definition at line 1006 of file emailcleaner.class.php.
References normalizeMessageId().
Referenced by buildThreadKey(), and processEmailCollectorMessage().
|
static |
Normalize text to UTF-8 LF-only.
| string | $text | Text to normalize |
Definition at line 888 of file emailcleaner.class.php.
Referenced by buildFallbackEmailUnderstanding(), buildMessageScopesBasic(), extractQuotedMessageBlocksBasic(), extractQuotedThreadSnippetBasic(), extractReplyOnlyTextBasic(), fallbackCleanBody(), processEmailCollectorMessage(), and runEmailCleaner().
|
static |
Parse action parameter configuration (JSON).
| string | $raw | Raw action parameter |
Definition at line 451 of file emailcleaner.class.php.
Referenced by processEmailCollectorMessage().
| EmailCleaner::processEmailCollectorMessage | ( | $parameters, | |
| & | $object ) |
Process one EmailCollector message through the isolated EmailCleaner workflow.
| array<string,mixed> | $parameters Hook parameters | |
| CommonObject | $object | EmailCollector object |
Definition at line 72 of file emailcleaner.class.php.
References $conf, $object, buildComplianceMetadata(), buildFallbackEmailUnderstanding(), buildMessageScopesBasic(), buildNoiseSummaryFromSegments(), buildThreadKey(), collectAttachmentRows(), dol_mkdir(), dol_now(), dol_print_date(), dol_sanitizeFileName(), dol_strlen(), dol_substr(), dol_syslog(), extractHeaderFieldValue(), extractHeaderMessageIds(), extractMessageIdFromHeader(), findActionCommIdByMessageId(), getDolGlobalInt(), getDolGlobalString(), insertAiRequestLogRow(), normalizeMessageId(), normalizeMessageIdList(), normalizeText(), parseActionParamConfig(), and runEmailCleaner().
| EmailCleaner::runEmailCleaner | ( | $subject, | |
| $from, | |||
| $rawBody ) |
Run AI cleaner with conservative fallback.
| string | $subject | Email subject |
| string | $from | Sender address |
| string | $rawBody | Raw email body |
Definition at line 612 of file emailcleaner.class.php.
References decodeJsonFromAiString(), dol_strlen(), dol_substr(), fallbackCleanBody(), getDolGlobalInt(), getDolGlobalString(), normalizeText(), and sanitizeEmailUnderstanding().
Referenced by processEmailCollectorMessage().
|
staticprivate |
Sanitize structured understanding returned by AI.
| mixed | $raw | Raw AI understanding payload |
| string | $fallbackCleanBody | Cleaned body used as fallback |
Definition at line 805 of file emailcleaner.class.php.
References buildFallbackEmailUnderstanding(), and sanitizeStringList().
Referenced by runEmailCleaner().
|
staticprivate |
Sanitize a list of short strings.
| mixed | $items | Raw list |
| int | $maxItems | Maximum number of items |
| int | $maxLen | Maximum item length |
Definition at line 854 of file emailcleaner.class.php.
References dol_strlen(), dol_strtolower(), and dol_substr().
Referenced by sanitizeEmailUnderstanding().