> I am currently considering using TMail to process inbound emails. > However I''m missing two features:good to hear!> One is to retrieve the envelope sender which is often prepended to > the email using a From header without a colon. RubyMail supports this > with the mbox_from.I saw your RubyForge bug on this, and I think I fixed it in the latest trunk. From the documentation in the trunk for this, you can now do this: ================Returns a HeaderField object matching the header you specify in the "name" param. Requires an initialized TMail::Port to be passed in. The method searches the header of the Port you pass into it to find a match on the header line you pass. Once a match is found, it will unwrap the matching line as needed to return an initialized HeaderField object. If you want to get the Envelope sender of the email object, pass in "EnvelopeSender", if you want the From address of the email itself, pass in ''From''. This is because a mailbox doesn''t have the : after the From that designates the beginning of the envelope sender (which can be different to the from address of the emial) Other fields can be passed as normal, "Reply-To", "Received" etc. Note: Change of behaviour in 1.2.1 => returns nil if it does not find the specified header field, otherwise returns an instantiated object of the correct header class For example: port = TMail::FilePort.new("/test/fixtures/raw_email_simple") h = TMail::HeaderField.new_from_port(port, "From") h.addrs.to_s #=> "Mikel Lindsaar <mikel at nowhere.com>" h = TMail::HeaderField.new_from_port(port, "EvelopeSender") h.addrs.to_s #=> "mike at anotherplace.com.au" h = TMail::HeaderField.new_from_port(port, "SomeWeirdHeaderField") h #=> nil ================ Does that do what you were after?> The other is to retrieve the IP address of the sender from the > Received: header. When I have for example: > Received: from mail.example.com (mail.example.com [1.2.3.4]) > by ... > for ... > then neither TMail::ReceivedHeader#from nor > TMail::ReceivedHeader#body returns the part between brackets. > Is it thinkable that these features will be supported in the future?Yeah! That''s a good idea, we could have TMail::ReceivedHeader#source_address or something.... hmm... Sure, come on board and help out. You could grab the source and help whack it in, I don''t think that one would be too hard actually.> Maybe anyone knows a workaround to get the raw body of a header field?In the mean time, you could
Oopss.. sent without completing the thought... You can get to the raw body like this: irb(main):055:0> m[''received''] => [#<TMail::ReceivedHeader "from xxx.xxxx.xxx by xxx.xxxx.xxx with ESMTP id C1B953B4CB6 for <xxxxx at Exxx.xxxx.xxx>; Tue, 10 May 2005 15:27:05 -0500\n">, #<TMail::ReceivedHeader "from SMS-GTYxxx.xxxx.xxx by xxx.xxxx.xxx with ESMTP id ca for <xxxxx at Exxx.xxxx.xxx>; Tue, 10 May 2005 15:27:04 -0500\n">, #<TMail::ReceivedHeader "from xxx.xxxx.xxx by SMS-GTYxxx.xxxx.xxx with ESMTP id j4AKR3r23323 for <xxxxx at Exxx.xxxx.xxx>; Tue, 10 May 2005 15:27:03 -0500\n">] irb(main):056:0> m[''received''].length => 3 irb(main):057:0> m[''received''][0].to_s => "from xxx.xxxx.xxx by xxx.xxxx.xxx with ESMTP id C1B953B4CB6 for <xxxxx at Exxx.xxxx.xxx>; Wed, 11 May 2005 06:27:05 +1000" Hope that helps Mikel
The suggested workaround, using mail[''received''][0].to_s to get the complete header line doesn''t work. The to_s recreates the header line from it''s components. However the parser discards the part between brackets so it is also not returned by to_s. If the need arises I will think about a solution. However, the Racc based parser doesn''t look like it''s easy to understand. One general remark. I think TMail is an important component used by many others, so I don''t think anyone should "hack" or "whack" something in. Maybe that was just a matter of speaking, but when "not shining, badly commented, written shortly after starting to learn Ruby, and kinda Perlish" code will be added, I would rather have a well-written TMail without message threading. Cheers, Maarten O. On 17-jan-2008, at 6:35, Mikel Lindsaar wrote:> >> The other is to retrieve the IP address of the sender from the >> Received: header. When I have for example: >> Received: from mail.example.com (mail.example.com [1.2.3.4]) >> by ... >> for ... >> then neither TMail::ReceivedHeader#from nor >> TMail::ReceivedHeader#body returns the part between brackets. >> Is it thinkable that these features will be supported in the future? > > Yeah! That''s a good idea, we could have > TMail::ReceivedHeader#source_address or something.... hmm... > > Sure, come on board and help out. You could grab the source and help > whack it in, I don''t think that one would be too hard actually. > >> Maybe anyone knows a workaround to get the raw body of a header >> field? > > In the mean time, you couldOn 17-jan-2008, at 6:41, Mikel Lindsaar wrote:> Oopss.. sent without completing the thought... > > You can get to the raw body like this: > > irb(main):055:0> m[''received''] > => [#<TMail::ReceivedHeader "from xxx.xxxx.xxx by xxx.xxxx.xxx with > ESMTP id C1B953B4CB6 for <xxxxx at Exxx.xxxx.xxx>; Tue, 10 May 2005 > 15:27:05 -0500\n">, #<TMail::ReceivedHeader "from SMS-GTYxxx.xxxx.xxx > by xxx.xxxx.xxx with ESMTP id ca for <xxxxx at Exxx.xxxx.xxx>; Tue, 10 > May 2005 15:27:04 -0500\n">, #<TMail::ReceivedHeader "from > xxx.xxxx.xxx by SMS-GTYxxx.xxxx.xxx with ESMTP id j4AKR3r23323 for > <xxxxx at Exxx.xxxx.xxx>; Tue, 10 May 2005 15:27:03 -0500\n">] > > irb(main):056:0> m[''received''].length > => 3 > > irb(main):057:0> m[''received''][0].to_s > => "from xxx.xxxx.xxx by xxx.xxxx.xxx with ESMTP id C1B953B4CB6 for > <xxxxx at Exxx.xxxx.xxx>; Wed, 11 May 2005 06:27:05 +1000" > > > Hope that helps > > > Mikel > _______________________________________________ > Tmail-talk mailing list > Tmail-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/tmail-talk >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/tmail-talk/attachments/20080117/b15450cb/attachment.html
On 17-jan-2008, at 9:53, Mikel Lindsaar wrote:> In any case, my actions speak louder than perhaps my poor choice of > words, since I have taken over the library (in November) every release > has gotten more and more of the existing tests passing, when I took > over the library, there were about 30 tests failing, there are now > zero failing, plus about 200 more tests, plus compatibility with Ruby > 1.9Thanks for you reply. You cleared up my concerns. I''m impressed by, and grateful for your work in TMail. I was just afraid that others might have a "license to hack" into TMail, which is appearantly not the case. Maarten O. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/tmail-talk/attachments/20080117/c0f74fd9/attachment-0001.html
Hi Mikel, I studied the TMail parser for extending the ReceivedHeader with trace information. The current Yacc rules do not support the "extended-domain" syntax which may include a "tcp-info" block after the from-domain and by-domain. See also RFC 2821 section 4.4. The Racc parser is a bit too complex for me to fully understand yet so I don''t feel comfortable to make changes the parser. However I noticed that ReceivedHeader#comments does return the "tcp-info" block since it is enclosed in brackets. This provides me with an acceptable workaround. As soon as I have learned more about the parser I might give it another try. Cheers, Maarten O. On 17-jan-2008, at 13:58, Mikel Lindsaar wrote:> On Jan 17, 2008 11:53 PM, Maarten Oelering > <maarten at solovirtuoso.com> wrote: >> I checked out the code and was able to run the tests. So I should be >> set for now. >> svn checkout http://tmail.rubyforge.org/svn/trunk >> cd trunk >> rake test >> 204 tests, 4014 assertions, 0 failures, 0 errors > > Great! > >> I have ruby 1.8.5 on my local (OS-X) system. Let me know if Tmail >> development requires me to upgrade. > > Not at all. The stable datum is the tests - in fact, it shows that we > are good with 1.8.5 as well :) If they pass we are cool. When you > make a patch, I will test it against ruby 1.8.6 and 1.9 and help patch > anything. > > Regards > > Mikel
On Jan 24, 2008 1:43 AM, Maarten Oelering <maarten at solovirtuoso.com> wrote:> This provides me with an acceptable workaround. As soon as I have > learned more about the parser I might give it another try.Sounds good! Thanks for your work. Would you be willing to make a documentation patch in the appropriate spot on how to get this header information with an example of your work around? That way we won''t have to answer this question again. Regards Mikel