# Procmail to ruby

**URL:** <https://www.ruby-forum.com/t/procmail-to-ruby/119261>\
**Category:** Ruby\
**Created:** [November 5, 2007, 3:12pm UTC](https://www.ruby-forum.com/t/procmail-to-ruby/119261 "2007-11-05T15:12:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mislav\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/fbc32d/32.png) [@Mislav\_K](https://www.ruby-forum.com/u/Mislav_K)\
**Post date:** [November 5, 2007, 3:12pm UTC](https://www.ruby-forum.com/t/procmail-to-ruby/119261/1 "2007-11-05T15:12:33Z")

</div>

Hello,

I want to write a Procmail recipe that pipes a message to a  
Ruby script as ARGV argument.  
I wrote this recipe but it doesn’t work.

:0

- ^TO\_\*  
| ruby main.rb

How can I pass a message as argument to the script?

---

<div class="post-metadata">

**Author:** ![Mislav\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/fbc32d/32.png) [@Mislav\_K](https://www.ruby-forum.com/u/Mislav_K)\
**Post date:** [November 5, 2007, 3:24pm UTC](https://www.ruby-forum.com/t/procmail-to-ruby/119261/2 "2007-11-05T15:24:20Z")

</div>

> I wrote this recipe but it doesn’t work.
> 
> :0
> 
> - ^TO\_\*  
> | ruby main.rb
> 
> How can I pass a message as argument to the script?

## You don’t pass the message as an argument, you pass it on standard input

the pipe in the procmail recipe acts much like shell piping.

There are several ways to get standard input in Ruby, here’s one using  
the  
‘magic’ variable ARGF:

$ cat test.text  
this is just a test line  
$ cat test.rb  
ARGF.each\_line do |line|  
puts line  
end  
$ cat test.text | ruby test.rb  
this is just a test line  
$

HTH,

Felix

---

<div class="post-metadata">

**Author:** ![Mislav\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/fbc32d/32.png) [@Mislav\_K](https://www.ruby-forum.com/u/Mislav_K)\
**Post date:** [November 5, 2007, 6:25pm UTC](https://www.ruby-forum.com/t/procmail-to-ruby/119261/3 "2007-11-05T18:25:07Z")

</div>

On Mon, 5 Nov 2007 15:05:36 +0100  
Mislav K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> How can I pass a message as argument to the script?  
> e.g.

:0 fw

- ^X-MS-Has-Attach: yes  
| ${HOME}/bin/fixup\_b0rken\_tnef.rb

---

<div class="post-metadata">

**Author:** ![Mislav\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/fbc32d/32.png) [@Mislav\_K](https://www.ruby-forum.com/u/Mislav_K)\
**Post date:** [November 6, 2007, 6:13pm UTC](https://www.ruby-forum.com/t/procmail-to-ruby/119261/4 "2007-11-06T18:13:59Z")

</div>

On Mon, 05 Nov 2007 14:50:30 -0800  
barjunk [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > :0
> 
> The above implies a properly formated bang line, correct?

As quoted yes, but the following works as well, assuming ruby in on  
the PATH known to procmail.

:0 fw

- ^X-MS-Has-Attach: yes  
| ruby ${HOME}/bin/fixup\_b0rken\_tnef.rb

-jh

---

<div class="post-metadata">

**Author:** ![Mislav\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/fbc32d/32.png) [@Mislav\_K](https://www.ruby-forum.com/u/Mislav_K)\
**Post date:** [November 5, 2007, 11:55pm UTC](https://www.ruby-forum.com/t/procmail-to-ruby/119261/5 "2007-11-05T23:55:59Z")

</div>

On Nov 5, 8:01 am, Jonathan H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > - ^TO\_\*  
> > | ruby main.rb
> 
> > How can I pass a message as argument to the script?
> 
> e.g.
> 
> :0 fw
> 
> - ^X-MS-Has-Attach: yes  
> | ${HOME}/bin/fixup\_b0rken\_tnef.rb

The above implies a properly formated bang line, correct?

Mike B.
