Philipp Hasenfratz: MIME::Entity

Beitrag lesen

Halihallo Forumer, nochmals

meld mich mal mit einer ganz "dummen" Frage:

und steht noch immer im Raum, aber TIMTOWTDI ;)

Nach ca. 15 Minuten Fehlersuchen und Testen ist mir die Lust vergangen und hab ein eigenes Modul gebastelt:

package myMIME;

use strict;
use base qw(MIME::Entity);

sub new {
   my ($class, @params) = @_;

my $self;
   if (ref($params[0]) eq 'ARRAY') {
      $self = $class->build( @params );
   } else {
      $self = $class->SUPER::new( @params );
   }
   bless ($self, $class);

return $self;
}

sub build {
   my ($class, @params) = @_;
   if (ref($params[0]) eq 'ARRAY') {
      my @lines = @{$params[0]};
      my (@head, @body);
      my ($inHead) = 1;
      foreach (@lines) {
         if ($inHead == 1) {
            push @head, $_;
         } else {
            push @body, $_;
         }
         if (($_ eq '') or ($_ =~ /\015|\012|\015\012/)) { $inHead = 0; }
      }

my $head = new MIME::Head( [@head] );

my $head_ref = $head->header_hashref;
      my %head = %{$head_ref};
      my %props = (%head, Data=>[@body]);

my $entity = MIME::Entity->build( %props );
      return $entity;
   } else {
      return $class->SUPER::build( @_ );
   }
}

1;

dazu:

use strict;
use Data::Dumper;
use myMIME;

my @lines = ('Content-Type: text/html',
  'From: cto@entryon.ch',
  'To: cto@entryon.ch',
  '',
  'hello world :-)');

my $mail = myMIME->new( [@lines] );

print $mail->as_string;

1:0 für mich ;-)

Viele Grüsse

Philipp