Demrit

Miguel Vazquez Gocobachi



Mail body decoded

Una manera funcional de obtener el body de un mensaje de correo que quizá quiera ser analizado para otras tareas es la siguiente manera. Cabe aclarar que es una solución que generé por necesidad, claro esta, puede ser mejorado inclusive con mucho menos código... aunque, por el momento es útil para adaptarlo a nuestras aplicaciones.
use strict;
use Mail::Message;
use HTML::Entities;
my $rfc2822 = "";
{local $/; $rfc2822 = <STDIN>;}
sub getBody
{
    my $data = shift;
    my $ret  = '';
    my $type = 'plain';
    my $obj  = Mail::Message->read($data->{mail});
    my $body = $obj->body;
    if ($body->isMultipart) {
        $type = 'html';
        my @matches = $body->decoded->string =~ m/charset=\"PERL\"\n{2}(.*?)--(?:[0-9a-zA-Z]+)/gsc;
        $ret  = encode_entities($matches[1]);
        $ret =~ s/^\s//;
        $ret =~ s/\s$//;
        $ret =~ s/^\n//;
        $ret =~ s/\n$//;
        $ret =~ s/\n\s*\n/<wbr \/>/g;
        $ret =~ s/\n/ /g;
        $ret =~ s/<wbr \/>/\n/g;
    } else {
        $ret = encode_entities($body->decoded->string);
    }
    $ret =~ s/& lt;/</g;
    $ret =~ s/& gt;/>/g;
    $ret =~ s/& quot;/"/g;
    $ret =~ s/& amp;quot;/& quot;/g;
    $ret =~ s/& amp;nbsp;/& nbsp;/g;
    my $result = {body => $ret, type => $type};
    return $result;
}

print getBody({mail => $rfc2822});
 
Simple y funcional, si tienes una idea mejor por favor compartela face-smile.png
Happy hacking!

#1 Re:Mail body decoded

david, <> / Septiembre 28, 8:09am  
avatar

great info,its function can using to wordpress
http://www.id3.info
http://www.arfree.com

[ Responder (0) ]

Dejar un comentario

Escribe el código Captcha que estás viendo

Fuentes XML de comentario: RSS | Atom

Calendario del Blog

Marzo 2010
Dom Lun Mar Mie Jue Vie Sab
28 1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31 1 2 3
rss
atom