From: Leandro Lucarella Date: Fri, 1 Apr 2005 05:25:23 +0000 (+0000) Subject: Bugfix. Se decodifican los headers MIME con caracteres no ASCII antes de validar... X-Git-Tag: svn_import~23 X-Git-Url: https://git.llucax.com/software/sercom-old.git/commitdiff_plain/28cf965313c3635a9b4914802262c888607c17e4?ds=sidebyside Bugfix. Se decodifican los headers MIME con caracteres no ASCII antes de validar el subject. --- diff --git a/src/sc_fetch b/src/sc_fetch index 7a1e407..82bf902 100755 --- a/src/sc_fetch +++ b/src/sc_fetch @@ -90,7 +90,7 @@ while (1) { $mbox_errcount = 0; logs('Conectado como '.@$mconf['user']." a $mailbox", DEBUG); if (imap_num_msg($mbox) and $hdr = imap_headerinfo($mbox, 1)) { - logs("Nuevo mail '{$hdr->subject}' de {$hdr->fromaddress}"); + logs(sprintf("Nuevo mail '%s' de %s", decode_header($hdr->subject), decode_header($hdr->subject))); @list($padron, $ej, $ent, $codigo) = validar_cabecera($hdr); if ($padron) { logs('Cabecera vĂ¡lida', DEBUG); @@ -176,7 +176,7 @@ Return-Path: {$mconf['admin']} X-Mailer: $NAME $VERSION X-Priority: 5 EOT; - mail($to, $subject, $body, $headers); + mail(decode_header($to), $subject, $body, $headers); return true; } @@ -185,7 +185,8 @@ EOT; */ function validar_cabecera($hdr) { // Subject: padron nro_ej nro_entrega clave_alumno - if (preg_match('/^\s*(\d{5})\s+([1-4])\.([12])\s+(.*)$/', $hdr->subject, $m)) { + $subject = decode_header($hdr->subject); + if (preg_match('/^\s*(\d{5})\s+([1-4])\.([12])\s+(.*)$/', $subject, $m)) { return array_slice($m, 1, 5); } return false; @@ -293,4 +294,13 @@ function fix_eol($str) { return str_replace("\r\n", "\n", $str); } +function decode_header($str) { + $elems = imap_mime_header_decode($str); + $result = ''; + foreach ($elems as $elem) { + $result .= $elem->text; + } + return $result; +} + ?> \ No newline at end of file