#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    6
    Rep Power
    0

    Plperl, Email::Mime and gethostbyname()


    Within PostgreSQL I want to transform the body of (sometimes misformatted) MIME documents into utf-8. For plain documents this works well using MIME::Email and Encode::decode().

    For MIME containers however I fail (using Perl5):

    Code:
    my $mime = Email::MIME->new($text);
    if ($mime->header('content-type') =~ /^multipart/i) {
        $mime->walk_parts(sub {
            my ($part) = @_;                    
            # FIXME yet to be done
        });
    }
    else {
        $encoding = $mime->{ct}{attributes}{charset};
        $body = Encode::decode($encoding, $mime->body, Encode::FB_DEFAULT);
    }
    This does not work in postgreSQL because plperl does not permit all statements to be executed:

    Code:
    2012-08-08 13:23:29 CEST ERROR:  'gethostbyname' trapped by operation mask at /usr/lib/perl/5.10/Sys/Hostname.pm line 42.
    But the thing is: the gethostbyname() function seems to be executed for generating a message id. And as I do not want to send a message, I do not need any id either. All I want to do is to read the individual MIME parts...

    Is there any chance to stop or circumvent this? Is there any other way to parse MIME containers without too much pain? (Actually I like Email::MIME quite will, with the notable exception of this error). Please aks if I forgot to include some relevant information.
  2. #2
  3. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,254
    Rep Power
    1810
    It's been a long time since I did anything with plperl, but I think the answer is that you have to use the untrusted version: plperlu

    http://www.postgresql.org/docs/8.4/i...l-trusted.html
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    6
    Rep Power
    0
    Originally Posted by keath
    It's been a long time since I did anything with plperl, but I think the answer is that you have to use the untrusted version: plperlu
    That is one possible answer, yes, but it needs root access or the admin completely trusting the owner of the script. For the sake of staying portable I really would like to avoid this like hell (and as I don't do anything critical, I still hope this is possible).

IMN logo majestic logo threadwatch logo seochat tools logo