Bugs item #2597, was opened at 2005-10-07 12:32
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=2597&group_id=426

Category: Standard Library
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Xinizul Mr (xinizul)
Assigned to: Nobody (None)
Summary: Ruby mail improvement

Initial Comment:
I send this email to the creator of Ruby mail. I'm new to Ruby but I found the following workaround useful when working in windows with the fantastic Ruby Mail library:

-----------------------------------

I'm working with this library to format email messages
and I've found an improvement for developers under
windows OS.

The problem is I can not parse multipart emails (with
attachments) with the library as it is.

I had to include the following lines of code to make
it work.

file: parse.rb

function: parse_header

Modification:  header, rest = data.split(/\n\n/, 2)

modificated by:

 header, rest = data.split(/\n\n/, 2)
 if rest == nil
   header, rest = data.split(/\r\n\r\n/, 2)
 end

I haven't had time to test it in linux OS but I think
it should work also.

Additionally I developed a method to find an
attachment by name, just in case you want to use it in
your lib. The code is something like:


    def findAttach(email, fnameExpr)
      result = []
      if email.multipart?
        i = 0
        email.each_part do |part|
          fname =
part.header.param('Content-Disposition','filename')   
      
          re = Regexp.new(fnameExpr.to_s)
          if re.match(fname)
            result << part.decode
          end          
        end
      end    
      return result
    end


Best regards,

Xinizul

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=2597&group_id=426