Forum: Ruby TMail question / ?error?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bb118b6226ebc13ac995cb349c43d6c6?d=identicon&s=25 Rohit Mehta (Guest)
on 2006-05-31 17:34
(Received via mailing list)
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
956f185be9eac1760a2a54e287c4c844?d=identicon&s=25 ts (Guest)
on 2006-05-31 17:59
(Received via mailing list)
>>>>> "R" == Rohit Mehta <ro@paper-mill.com> 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
Bb118b6226ebc13ac995cb349c43d6c6?d=identicon&s=25 Rohit Mehta (Guest)
on 2006-05-31 18:34
(Received via mailing list)
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
This topic is locked and can not be replied to.