fix(pago): diagnose and harden IMAP email validation

- PagoValidadorService: add detailed Log::info at every step (emails count,
  body preview, parser result, which filter fails) so failures are visible in laravel.log
- CorreoImapService::cleanBody: detect and decode base64-encoded BODY[1] before
  QP decoding — critical fix when Bancolombia sends HTML part as base64
- BancolombiaParser: make esBancolombia() broader (includes 'valor','$','abono' etc.),
  add extraerPrimero() helper, add multiple regex fallbacks for remitente/fecha/hora/valor
  to handle different Bancolombia email HTML formats beyond the SMS text pattern

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro
2026-07-18 17:01:34 +00:00
co-authored by Claude Sonnet 4.6
parent 1fd9a92afa
commit 595c75837f
3 changed files with 147 additions and 79 deletions
+12 -3
View File
@@ -304,9 +304,18 @@ class CorreoImapService
private function cleanBody(string $body): string
{
// ── 1. Decoded quoted-printable ──────────────────────────────────
// BODY.PEEK[1] retorna directamente el contenido de la parte (sin
// boundaries), pero puede estar codificado en quoted-printable.
// ── 0. Base64 — detectar antes que QP ────────────────────────────
// BODY[1] puede llegar codificado en base64 (Content-Transfer-Encoding: base64)
// si el servidor no decodifica automáticamente.
$noWs = preg_replace('/[\r\n\t ]/', '', $body);
if (strlen($noWs) > 60 && preg_match('/^[A-Za-z0-9+\/]+=*$/', $noWs)) {
$decoded = base64_decode($noWs, true);
if ($decoded !== false && preg_match('//u', $decoded)) {
$body = $decoded;
}
}
// ── 1. Quoted-printable ──────────────────────────────────────────
if (preg_match('/=[0-9A-F]{2}/i', $body) || preg_match('/=\r?\n/m', $body)) {
$body = quoted_printable_decode($body);
}