I am trying to test a script that generates email using uses Rails
ActionMailer 2.3.2. I have installed the TMail 1.2.3.1 gem.
The way that this works is this. In the script I dump the contents
of ActionMailer::Base.deliveries into a disk file:
ActionMailer::Base.deliveries.each do |msg|
fo = File.open(''deliver.txt'',''a'')
fo.write(msg)
fo.write("\n")
fo.close
end
To the best of my ability to determine, this creates a valid mbox
format file. I might be wrong but according to what I have read,
the mbox format simply requires a blank line after each message. A
message is deemed to begin with the ''From: '' header.
The contents of this disk file appear correct given the foregoing
expectation:
$ cat deliver.txt
From: Forex at harte-lyne.ca
Reply-To: support at harte-lyne.ca
To: forex.test at harte-lyne.ca
Subject: [ForEx] 2009-05-04 - Foreign Exchange Rates Notice
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary=mimepart_49ff56b0689be_25e01588753607c83ab
--mimepart_49ff56b0689be_25e01588753607c83ab
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: inline
...
--mimepart_49ff56b0689be_25e01588753607c83ab--
--- end of file here - not part of actual file
I gather from the documentation that I should be able to read this
message back into a TMail::Mail object doing this:
>> mbox = TMail::UNIXMbox.new(''deliver.txt'', nil, true)
=> #<TMail::UNIXMbox:0x2abdae52cb00
@finalizer=#<Proc:0x00002abdabad57f8@/usr/lib64/ruby/gems/1.8/gems/tmail-1.2.3.1/lib/tmail/mailbox.rb:249>,
@readonly=true, @real=#<TMail::MhMailbox
/tmp/ruby_tmail_9702_0.657023759401038>, @closed=false,
@filename="deliver.txt">>> mbox.each do |port|
?> mail = TMAIL::Mail.new(port)>> puts mail.subject
>> y mail.methods.sort
>> end
=> Mon May 04 17:11:07 -0400 2009
What I get is a time object and I see no mail message.
If I try this instead, taken from the example given in the
documentation:
>> mailbox = TMail::UNIXMbox.new(''deliver.txt'', nil,
true)
=> #<TMail::UNIXMbox:0x2abdae4d6b10
@finalizer=#<Proc:0x00002abdabad57f8@/usr/lib64/ruby/gems/1.8/gems/tmail-1.2.3.1/lib/tmail/mailbox.rb:249>,
@readonly=true, @real=#<TMail::MhMailbox
/tmp/ruby_tmail_9702_0.0737049330962023>, @closed=false,
@filename="deliver.txt">>> @emails = []
=> []>> @emails = mailbox.each_port { |m| @emails << TMail::Mail.new(m)
}
=> Mon May 04 17:36:07 -0400 2009>> @emails.class
=> Time
Another time object is returned. What is going on here. What am I
doing wrong?
--
*** E-Mail is NOT a SECURE channel ***
James B. Byrne mailto:ByrneJB at Harte-Lyne.ca
Harte & Lyne Limited http://www.harte-lyne.ca
9 Brockley Drive vox: +1 905 561 1241
Hamilton, Ontario fax: +1 905 561 0757
Canada L8E 3C3