TMail question / ?error?


#1

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:inropen’
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


#2

“R” == Rohit M. 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


#3

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