Thread Email::Stuffer Excel-Attachments teilweise defekt (6 answers)
Opened by Stefan_S at 2014-04-15 18:05

GwenDragon
 2014-04-15 20:31
#174797 #174797
User since
2005-01-17
14759 Artikel
Admin1
[Homepage]
user image
Der Bösewicht sitzt bei CPAN:Email::Stuffer in CPAN:IO::All von CPAN:Email::MIME.

Das Testcase zeigts.
Code (perl): (dl )
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use IO::All;
use Email::MIME;

my @parts = (
      Email::MIME->create(
          attributes => {
              filename     => "test.xlsx",
              content_type => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
              encoding     => "Base64",
              name         => "test.xlsx",
          },
          body => io( "test.xlsx" )->binmode()->all,
      ),
          Email::MIME->create(
          attributes => {
                        # 
              filename     => "test1.ods",
              content_type => "application/vnd.oasis.opendocument.spreadsheet",
              encoding     => "Base64",
              name         => "test1.ods",
          },
          body => io( "test1.ods" )->binmode()->all,
      ),
          # gerates DEFECT attachment
          Email::MIME->create(
          attributes => {
                        # 
              filename     => "DEF-test1.ods",
              content_type => "application/vnd.oasis.opendocument.spreadsheet",
              encoding     => "Base64",
              name         => "DEF-test1.ods",
          },
          body => io( "test1.ods" )->all,
      ),
      Email::MIME->create(
          attributes => {
              content_type => "text/plain",
              disposition  => "attachment",
                          encoding     => "quoted-printable",
              charset      => "US-ASCII",
          },
          body_str => "Hello there!",
      ),
  );
  
my $email = Email::MIME->create(
      header_str => [ From => 'casey@geeknest.com' ],
      parts      => [ @parts ],
  );

  # standard modifications
  $email->header_str_set( To            => 'test@local'       );

open (my $mh, '>', 'test.eml');
binmode $mh;
print $mh $email->as_string;
close $mh;
 


Beachte bitte Zeile 12, 22 und 33.
Testcase erzeugt bei binmode richtige Attachments.

Ob das ein Bug ist weiß ich nicht.

Das Problem sind folgende Codes, die keinen binmode nutzen/erkennen:
https://metacpan.org/source/RJBS/Email-Stuffer-0.0...
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
sub _slurp {
        my $file = shift;
        local $/ = undef;
        local *SLURP;
        open( SLURP, "<$file" ) or return undef;
        my $source = <SLURP>;
        close( SLURP ) or return undef;
        \$source;
}


https://metacpan.org/source/RJBS/Email-Stuffer-0.0...
Code (perl): (dl )
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
sub attach_file {
        my $self = shift;
  my $body_arg = shift;
        my $name = undef;
        my $body = undef;
 
        # Support IO::All::File arguments
        if ( Params::Util::_INSTANCE($body_arg, 'IO::All::File') ) {
                $name = $body_arg->name;
                $body = $body_arg->all;
 
        # Support file names
        } elsif ( defined $body_arg and -f $body_arg ) {
                $name = $body_arg;
                $body = _slurp( $body_arg ) or return undef;
 
        # That's it
        } else {
                return undef;
        }
 
        # Clean the file name
        $name = File::Basename::basename($name) or return undef;
 
        # Now attach as normal
        $self->attach( $body, name => $name, filename => $name, @_ );
}

Anhänge
application/zip
testattach.zip

Last edited: 2014-04-15 20:44:55 +0200 (CEST)

View full thread Email::Stuffer Excel-Attachments teilweise defekt