# TMail question / ?error?

**URL:** <https://www.ruby-forum.com/t/tmail-question-error/62112>\
**Category:** Ruby\
**Created:** [May 31, 2006, 5:34pm UTC](https://www.ruby-forum.com/t/tmail-question-error/62112 "2006-05-31T17:34:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ror-user](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/22d042/32.png) [@ror-user](https://www.ruby-forum.com/u/ror-user)\
**Post date:** [May 31, 2006, 5:34pm UTC](https://www.ruby-forum.com/t/tmail-question-error/62112/1 "2006-05-31T17:34:27Z")

</div>

Hi I am trying to write a Ruby program to test our antispam filter. So  
the first  
part of my strategy is to take a bunch of spam and a bunch of notspam  
messages  
which I’ve sorted into two mozilla-thunderbird mbox files and pump them  
into the  
spamfilter.

However, I may be getting stuck with Ruby syntax. The following code  
works properly:

require ‘tmail’  
@loader = TMail::UNIXMbox.new(‘spamfile’)  
@loader.each\_port do |port|  
mail=TMail::Mail.new(port)  
do something with the mail  
end

However the following fails:

ro@atlas:/tmp$ irb  
irb(main):001:0\> require ‘tmail’  
=\> true  
irb(main):002:0\> @loader = TMail::UNIXMbox.new(‘spamfile’)  
=\> #\<TMail::UNIXMbox:0xb7aceb40 @readonly=false, @filename=“spamfile”,  
@finalizer=#Proc:0xb7adf9f4@/usr/local/stow/ruby-1.8.4/lib/ruby/site\_ruby/1.8/tmail/mailbox.rb:150,  
@closed=false, @real=#\<TMail::MhMailbox  
/tmp/ruby\_tmail\_8378\_0.860064296748723\>\>  
irb(main):003:0\> port = @loader.new\_port  
=\> #\<TMail::MhPort /tmp/ruby\_tmail\_8378\_0.860064296748723/1\>  
irb(main):004:0\> mail = TMail::Mail.new(port)  
Errno::ENOENT: No such file or directory -  
/tmp/ruby\_tmail\_8378\_0.860064296748723/1  
from  
/usr/local/stow/ruby-1.8.4/lib/ruby/site\_ruby/1.8/tmail/port.rb:62:in  
`initialize' from /usr/local/stow/ruby-1.8.4/lib/ruby/site_ruby/1.8/tmail/port.rb:62:in`ropen’  
from  
/usr/local/stow/ruby-1.8.4/lib/ruby/site\_ruby/1.8/tmail/mail.rb:42:in  
`initialize’  
from (irb):4

I noticed that when the @loader.each\_port do loop starts it creates a  
directory full of files  
in /tmp, and each appears to be a file containing a single message from  
my mbox file,  
but @loader.new\_port does not do this. Is new\_port not working  
properly? (I’m looking  
at mailbox.rb, but I’m not sure that I understand what’s going on)

The reason I want to do things this way is because I want to create  
wrapper classes  
SpamSource and NotSpamSource so I can send a controlled percentage of  
spam to our gateway.  
I’d like to be able to do:

a=rand(100)  
if (a\<spamPercentage)  
message = mySpamSource.getMessage  
else  
message = myNotSpamSource.getMessage  
end  
dosomething with message

Am I doing something wrong?

Rohit

---

<div class="post-metadata">

**Author:** ![ror-user](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/22d042/32.png) [@ror-user](https://www.ruby-forum.com/u/ror-user)\
**Post date:** [May 31, 2006, 5:59pm UTC](https://www.ruby-forum.com/t/tmail-question-error/62112/2 "2006-05-31T17:59:01Z")

</div>

> > > > > “R” == Rohit M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

R\> but @loader.new\_port does not do this. Is new\_port not working  
R\> properly? (I’m looking

Well #new\_port returns a new TMail::Port, which must be used with  
#wopen  
or #aopen to create a new message, no ?

Guy Decoux

---

<div class="post-metadata">

**Author:** ![ror-user](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/22d042/32.png) [@ror-user](https://www.ruby-forum.com/u/ror-user)\
**Post date:** [May 31, 2006, 6:34pm UTC](https://www.ruby-forum.com/t/tmail-question-error/62112/3 "2006-05-31T18:34:44Z")

</div>

Ahh, “new\_port” does not do what I imagined it did.  
I am really looking for a “next\_port” method. Perhaps the easiest  
thing to do would be to use “each\_port” to extract the MBox file into  
a separate file and then work with the files.

Thanks!

Rohit
