ARGF almost doing what I want with MAIL

People,

I have this script (tmail.rb):

#!/usr/bin/ruby

require 'mail.rb'

mail = Mail.read( ARGF.filename )
p mail.attachments[0].filename

I have a text file that is an email with base64 encoded attachment and if I do this:

   tmail.rb email.txt

- the script runs correctly with no errors but if I do this:

   cat email.txt | temail.rb

I get:

/usr/share/gems/gems/mail-2.6.3/lib/mail/mail.rb:176:in `initialize': No such file or directory @ rb_sysopen - - (Errno::ENOENT)
  from /usr/share/gems/gems/mail-2.6.3/lib/mail/mail.rb:176:in `open'
  from /usr/share/gems/gems/mail-2.6.3/lib/mail/mail.rb:176:in `read'
  from ./t010_1.rb:5:in `<main>'

ie "-" is not recognised as a legitimate file name - is there a way of (simply) doing what I want with pipes ie STDIN?

Thanks,

Phil.

···

--
Philip Rhoades

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

Hello, Phil!

···

On Fri, Feb 5, 2016 at 3:11 PM, Philip Rhoades <phil@pricom.com.au> wrote:

mail = Mail.read( ARGF.filename )

I think you should change this line to:

mail = Mail.read( ARGF.read )

--
Sincerely yours,

Aurel Branzeanu,

mailto: branzeanu.aurel@gmail.com
Skype: tvorogov
GSM Orange: +373 6 940-7700
GSM Moldcell: +373 7 940-7700

Sg like
if ARGV== then ARGF=STDIN
You have to test if that works,
please let me know!
Berg

···

Am 05.02.2016 14:41 schrieb "Aurel Branzeanu" <branzeanu.aurel@gmail.com>:

Hello, Phil!

On Fri, Feb 5, 2016 at 3:11 PM, Philip Rhoades <phil@pricom.com.au> wrote:

mail = Mail.read( ARGF.filename )

I think you should change this line to:

mail = Mail.read( ARGF.read )

--
Sincerely yours,

Aurel Branzeanu,

mailto: branzeanu.aurel@gmail.com
Skype: tvorogov
GSM Orange: +373 6 940-7700
GSM Moldcell: +373 7 940-7700

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

Sg like
if ARGV== then ARGF=STDIN
You have to test if that works,
please let me know!
Berg

Hello, Phil!

···

Am 05.02.2016 14:41 schrieb "Aurel Branzeanu" <branzeanu.aurel@gmail.com>:

On Fri, Feb 5, 2016 at 3:11 PM, Philip Rhoades <phil@pricom.com.au> wrote:

mail = Mail.read( ARGF.filename )

I think you should change this line to:

mail = Mail.read( ARGF.read )

--
Sincerely yours,

Aurel Branzeanu,

mailto: branzeanu.aurel@gmail.com
Skype: tvorogov
GSM Orange: +373 6 940-7700
GSM Moldcell: +373 7 940-7700