$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);
X-Mailer: $NAME $VERSION
X-Priority: 5
EOT;
- mail($to, $subject, $body, $headers);
+ mail(decode_header($to), $subject, $body, $headers);
return true;
}
*/
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;
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