From my.lists at mac.com Wed Jan 7 12:58:42 2009 From: my.lists at mac.com (Morten) Date: Wed, 07 Jan 2009 18:58:42 +0100 Subject: [Tmail-talk] Obtaining raw header text for "illegal" headers Message-ID: Hi, I got an email with this From: header: >> mail['From'] => #\r\n"> >> mail.from => nil Now, I would like to read the "xxyy at xxyy.zz\r\n" value, but how do I do this? >> mail['From'].body => "" Is it not possible to access the raw header data if the header is illegal? >> mail['From'].illegal? => true Thanks, Morten From ba at sanitarium.se Thu Jan 8 02:29:40 2009 From: ba at sanitarium.se (=?ISO-8859-1?Q?Bj=F6rn_Andersson?=) Date: Thu, 8 Jan 2009 08:29:40 +0100 Subject: [Tmail-talk] writing out or extracting attachments? In-Reply-To: <3F8EDE64-1F55-48D3-AEF2-67E2C382F743@three60.com> References: <3F8EDE64-1F55-48D3-AEF2-67E2C382F743@three60.com> Message-ID: Hi! To write out an attachment you need to fetch the body of the attachment and write it to a file. I've written a script using TMail to extract mime attachments and uuencoded attachments that you could look at to get an idea. :) http://cell.sanitarium.se/~ba/tmp/strip-email-attachment.rb.txt /Bj?rn On Tue, Dec 30, 2008 at 4:59 PM, Sam Luther wrote: > Hello, > @email = TMail::Mail.load('/Users/sam/Desktop/test.eml') > @email.attachments.each do |f| > # how do i write out the attachment or move it? I tried this, > # FileUtils.mv f, "/Users/sam/Desktop/processed/#{f.original_filename}" > end > > thanks in advance for any help. > _______________________________________________ > Tmail-talk mailing list > Tmail-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/tmail-talk > -- "Beauty is more important in computing than anywhere else in technology because software is so complicated. Beauty is the ultimate defense against complexity." -- David Gelernter, Machine Beauty: Elegance and the Heart of Technology From matt.simpson3 at gmail.com Thu Jan 8 09:17:22 2009 From: matt.simpson3 at gmail.com (Matt Simpson) Date: Thu, 08 Jan 2009 08:17:22 -0600 Subject: [Tmail-talk] writing out or extracting attachments? In-Reply-To: Message-ID: This is what I've done to extract the attachments. If you'd rather develop it in a rails application you could do something like this. I created a model to manage the attachments specifically, once I did that everything was made much easier and cleaner. I then created a class method called 'extract_attachment' which had an argument of a tmail mail part. The method took the part and extracted and stored the contents and returned it so that it could be assigned to the email. View below for the code, hope it helps. This could work easily with a file system storage as well, instead of Attachment.new you would open a new file, dump the contents into it, then close the file. Reason for the rescues: The I found that not all emails were parsed properly with the TMail class library. So I had to do quite a bit of trial and error on insertion. If there's a better way to do that, please let me know. # == Schema Information # Schema version: 50 # # Table name: attachments # # id :integer(11) not null, primary key # parent_id :integer(11) # message_id :integer(11) # filename :string(255) # content_type :string(255) # size :integer(11) # width :integer(11) # height :integer(11) # thumbnail :string(255) # data :binary # class Attachment < ActiveRecord::Base belongs_to :email def self.extract_attachment part Attachment.new( :filename => safe_filename(part), :content_type => safe_content_type(part), :data => safe_data(part), :disposition => part_disposition(part), :cid => part_cid(part) ) end def self.safe_filename part begin part.filename rescue begin part.original_filename rescue begin part['content-disposition']['filename'] rescue 'Attachment' end end end end def self.safe_content_type part begin part.content_type rescue 'binary' end end def self.safe_data part begin part.read rescue begin part.body rescue 'no content' end end end def self.extract_name part part.original_filename.nil? or part.original_filename == '' ? 'Attachment' : part.original_filename end def self.part_disposition part (part.content_disposition.nil? or part.content_disposition == "inline") ? "inline" : "attachment" end def self.part_cid part (!part.header_string("Content-ID").nil? and !part.header_string("Content-ID").empty?) ? part.header_string("Content-ID") : nil end validates_presence_of :email_id, :filename, :data end Thanks, - Matt On 1/8/09 1:29 AM, "Bj?rn Andersson" wrote: > Hi! > > To write out an attachment you need to fetch the body of the > attachment and write it to a file. > > I've written a script using TMail to extract mime attachments and > uuencoded attachments that you could look at to get an idea. :) > http://cell.sanitarium.se/~ba/tmp/strip-email-attachment.rb.txt > > /Bj?rn > > On Tue, Dec 30, 2008 at 4:59 PM, Sam Luther wrote: >> Hello, >> @email = TMail::Mail.load('/Users/sam/Desktop/test.eml') >> @email.attachments.each do |f| >> # how do i write out the attachment or move it? I tried this, >> # FileUtils.mv f, "/Users/sam/Desktop/processed/#{f.original_filename}" >> end >> >> thanks in advance for any help. >> _______________________________________________ >> Tmail-talk mailing list >> Tmail-talk at rubyforge.org >> http://rubyforge.org/mailman/listinfo/tmail-talk >> > > From jorn at travholt.net Sat Jan 17 12:39:46 2009 From: jorn at travholt.net (=?ISO-8859-1?Q?J=F8rn_St=F8ylen?=) Date: Sat, 17 Jan 2009 18:39:46 +0100 Subject: [Tmail-talk] RFC 822 attachments Message-ID: Hello, TMail-Talk! I'm a hobbyist Ruby scripter, and I'm just starting to get familiar with TMail. In my quest to find some way to decode attachments encoded in RFC 822, I found the fresh discussion on http://www.ruby-forum.com/topic/ 138425. I have searched all over now ... Is there really no way of decoding these attachments in Ruby (in another library, for example)? Regards, J?rn St?ylen, Norway. From mikemondragon at gmail.com Thu Jan 22 23:42:53 2009 From: mikemondragon at gmail.com (Mike Mondragon) Date: Thu, 22 Jan 2009 20:42:53 -0800 Subject: [Tmail-talk] RFC 822 attachments In-Reply-To: References: Message-ID: <967d3b9a0901222042v39a7472av1f0ee4d3a1b3ca94@mail.gmail.com> On Sat, Jan 17, 2009 at 9:39 AM, J?rn St?ylen wrote: > Hello, TMail-Talk! > > I'm a hobbyist Ruby scripter, and I'm just starting to get familiar with > TMail. > > In my quest to find some way to decode attachments encoded in RFC 822, I > found the fresh discussion on http://www.ruby-forum.com/topic/138425. > > I have searched all over now ... Is there really no way of decoding these > attachments in Ruby (in another library, for example)? > > > Regards, > > J?rn St?ylen, Norway. > _______________________________________________ > Tmail-talk mailing list > Tmail-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/tmail-talk > J?rn, I wrote a library called MMS2R that operates on top of TMail. Even though the name leads one to think its only for mobile MMS messages it works with any email. It makes getting at email attachments very simple. http://mms2r.rubyforge.org/ Thanks Mike -- Mike Mondragon Work> http://sas.quat.ch/ Blog> http://blog.mondragon.cc/ From boonedocks at gmail.com Wed Jan 28 15:45:56 2009 From: boonedocks at gmail.com (Mike Boone) Date: Wed, 28 Jan 2009 15:45:56 -0500 Subject: [Tmail-talk] /tmp/ruby_tmail* Files Message-ID: Our /tmp directory is filling up with dated ruby_tmail* directories and files. Is TMail supposed to automatically clean those up after use? Am I not closing the object properly? Or do I just need to clean them up manually? Thanks! Mike Boone. http://boonedocks.net/mike/ -------------- next part -------------- An HTML attachment was scrubbed... URL: