Email attachment


I’m quite new to Ruby and Rails. Now I’m stuck on a problem with
receiving emails. Everything but attachments work just fine. I try to
save the attached file (jpeg) in a file.

I use a Windows XP system and use Outlook to send the mails.

My receive function looks like this:
class Receiver < ActionMailer::Base
def receive(email)
Post.create(:title => email.subject, :body => email.body, :created_at
=> do |part|
filename = “#{RAILS_ROOT}/public/post/image/test.jpg”,File::CREAT|File::TRUNC|File::WRONLY,0644){ |f|

The problem is that the saved file is not an exact copy of the original
file. I see the pattern below:
Original: … 07 08 09 0A 0B FF …
Saved: … 07 08 09 0D 0A 0B FF …
(All 0A are replaced with 0D 0A)

So, there is a problem with “line feeds” in the image data. But what and
why? What can I do about it?


Problem solved. Need a “file.binmode”