Mail gem working for "gz" attachments but not "zip" ones

People,

This script gives correctly gives me an attachment count of 1 on email #1 which has a "gz" attachment:

#!/usr/bin/ruby

require 'mail'
require 'pry'

binding.pry

mail = Mail.read( ARGF.filename )

if mail.attachments.count == 0
   puts "No attachment found"
   exit
end

but exits with a count of 0 for a similar mail with a "zip" attachment - bits of each mail's header below:

Working #1:

  <b668af$db2a64f=17ef983e54ff3bce@firstwave.com.au>
X-FW-MsgID: <09/13/20-00:06:20-701161698@ibesp5.cl.csx2.local>

--===============6015493280949977166==
Content-Type: multipart/alternative; boundary="===============4977881524327184193=="
MIME-Version: 1.0

--===============4977881524327184193==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64

RmluZCBhdHRhY2hlZCB0aGUgRE1BUkMgQWdncmVnYXRlIFJlcG9ydC4=

--===============4977881524327184193==--
--===============6015493280949977166==
Content-Type: application/gzip
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
  filename="firstwave.com.au!xxxxxx!1599832803!1599919203.xml.gz"

H4sICNzVXF8C/2ZpcnN0d2F2ZS5jb20uYXUhcHJpY29tLmNvbS5hdSExNTk5ODMyODAzITE1OTk5
.

Failing #2:

11440614040166430979
Content-Type: application/zip;
  name="google.com!pricom.com.au!1599782400!1599868799.zip"
Content-Disposition: attachment;
  filename="google.com!xxxxx!1599782400!1599868799.zip"
Content-Transfer-Encoding: base64

UEsDBAoAAAAIAK1KLFGNyG0w0QIAAG8VAAAyAAAAZ29vZ2xlLmNvbSFwcmljb20uY29tLmF1ITE1
.

Am I missing something?

Thanks,

Phil.

···

Subject: Report Domain: xxxxx Submitter: firstwave.com.au Report-ID:
Subject: Report Domain: xxxxxx Submitter: google.com Report-ID:
--
Philip Rhoades

PO Box 896
Cowra NSW 2794
Australia
E-mail: phil@pricom.com.au

The second message isn't multipart (i.e. it doesn't have a 'body' that the
attachment is attached to). Are you sure it's a zip-gzip issue and not
multipart/alternative ?

Matthew Kerwin

···

On Sun., 13 Sep. 2020, 02:24 Philip Rhoades, <phil@pricom.com.au> wrote:

People,

This script gives correctly gives me an attachment count of 1 on email
#1 which has a "gz" attachment:

#!/usr/bin/ruby

require 'mail'
require 'pry'

binding.pry

mail = Mail.read( ARGF.filename )

if mail.attachments.count == 0
   puts "No attachment found"
   exit
end

but exits with a count of 0 for a similar mail with a "zip" attachment -
bits of each mail's header below:

Working #1:

Subject: Report Domain: xxxxx Submitter: firstwave.com.au Report-ID:
  <b668af$db2a64f=17ef983e54ff3bce@firstwave.com.au>
X-FW-MsgID: <09/13/20-00:06:20-701161698@ibesp5.cl.csx2.local>

--===============6015493280949977166==
Content-Type: multipart/alternative;
boundary="===============4977881524327184193=="
MIME-Version: 1.0

--===============4977881524327184193==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64

RmluZCBhdHRhY2hlZCB0aGUgRE1BUkMgQWdncmVnYXRlIFJlcG9ydC4=

--===============4977881524327184193==--
--===============6015493280949977166==
Content-Type: application/gzip
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
  filename="firstwave.com.au!xxxxxx!1599832803!1599919203.xml.gz"

H4sICNzVXF8C/2ZpcnN0d2F2ZS5jb20uYXUhcHJpY29tLmNvbS5hdSExNTk5ODMyODAzITE1OTk5
.
.

Failing #2:

Subject: Report Domain: xxxxxx Submitter: google.com Report-ID:
11440614040166430979
Content-Type: application/zip;
        name="google.com!pricom.com.au!1599782400!1599868799.zip"
Content-Disposition: attachment;
        filename="google.com!xxxxx!1599782400!1599868799.zip"
Content-Transfer-Encoding: base64

UEsDBAoAAAAIAK1KLFGNyG0w0QIAAG8VAAAyAAAAZ29vZ2xlLmNvbSFwcmljb20uY29tLmF1ITE1
.
.

Am I missing something?

Thanks,

Phil.
--
Philip Rhoades

PO Box 896
Cowra NSW 2794
Australia
E-mail: phil@pricom.com.au

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Matthew,

The second message isn't multipart (i.e. it doesn't have a 'body' that
the attachment is attached to).

Hmm . . when I view the mails from RoundCubeMail they both show attachments:

   firstwave.com.au!xxxxx...832803!1599919203.xml.gz(~571 B)

   google.com!xxxxxx!1599523200!1599609599.zip(~708 B)

Are you sure it's a zip-gzip issue and
not multipart/alternative ?

All the messages from:

   noreply-dmarc-support@google.com

have something like:

   filename="google.com [2]!xxxxx!1599782400!1599868799.zip"

in them and from RCM I can decompress the attachment and view the xml file . . but the ruby script does not work on them . .

Thanks,

Phil.

···

On 2020-09-13 08:08, Matthew Kerwin wrote:

Matthew Kerwin

On Sun., 13 Sep. 2020, 02:24 Philip Rhoades, <phil@pricom.com.au> > wrote:

People,

This script gives correctly gives me an attachment count of 1 on
email
#1 which has a "gz" attachment:

#!/usr/bin/ruby

require 'mail'
require 'pry'

binding.pry

mail = Mail.read( ARGF.filename )

if mail.attachments.count == 0
puts "No attachment found"
exit
end

but exits with a count of 0 for a similar mail with a "zip"
attachment -
bits of each mail's header below:

Working #1:

Subject: Report Domain: xxxxx Submitter: firstwave.com.au [1]
Report-ID:
<b668af$db2a64f=17ef983e54ff3bce@firstwave.com.au>
X-FW-MsgID: <09/13/20-00:06:20-701161698@ibesp5.cl.csx2.local>

--===============6015493280949977166==
Content-Type: multipart/alternative;
boundary="===============4977881524327184193=="
MIME-Version: 1.0

--===============4977881524327184193==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64

RmluZCBhdHRhY2hlZCB0aGUgRE1BUkMgQWdncmVnYXRlIFJlcG9ydC4=

--===============4977881524327184193==--
--===============6015493280949977166==
Content-Type: application/gzip
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="firstwave.com.au
[1]!xxxxxx!1599832803!1599919203.xml.gz"

H4sICNzVXF8C/2ZpcnN0d2F2ZS5jb20uYXUhcHJpY29tLmNvbS5hdSExNTk5ODMyODAzITE1OTk5

.

Failing #2:

Subject: Report Domain: xxxxxx Submitter: google.com [2] Report-ID:
11440614040166430979
Content-Type: application/zip;
name="google.com [2]!pricom.com.au
[3]!1599782400!1599868799.zip"
Content-Disposition: attachment;
filename="google.com [2]!xxxxx!1599782400!1599868799.zip"
Content-Transfer-Encoding: base64

UEsDBAoAAAAIAK1KLFGNyG0w0QIAAG8VAAAyAAAAZ29vZ2xlLmNvbSFwcmljb20uY29tLmF1ITE1

.

Am I missing something?

Thanks,

Phil.
--
Philip Rhoades

PO Box 896
Cowra NSW 2794
Australia
E-mail: phil@pricom.com.au

Unsubscribe:
<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Links:
------
[1] http://firstwave.com.au
[2] http://google.com
[3] http://pricom.com.au

--
Philip Rhoades

PO Box 896
Cowra NSW 2794
Australia
E-mail: phil@pricom.com.au