Phew! Panicked too soon i guess, i figured what was wrong!
Since the attachments were binary files, the mode should have been
"wb".
After changing the mode, it works perfectly fine.
File.open(base_dir+"\\"+filename,"wb")
/Ramya
On Sep 5, 4:30 pm, Ramya Addanki
<ramya.adda...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I read the attachments in an email in the following manner:
>
> def receive(email)
> base_dir="d:\\temp\\attachments"
> if email.has_attachments?
> email.attachments.each do |a|
> filename=a.original_filename
>
File.open(base_dir+"\\"+filename,"w+") { |f|
> puts f.syswrite(a.read) # i tried f.write also
> }
> end # end of attachments
> end # end if
> end # end def
>
> The attachments are pdf files,images,.doc,.xls files.
> The problem now is the size of the files stored on the file system is
> the same as that of the attachment. But the data that gets written to
> the file is junk. Obviously i need to decode the content of the
> attachment. Any suggestion.
>
> I did try to read the parts of the mail as described in the
post:http://blog.mondragon.cc/articles/2006/12/30/decoding-email-attachmen...
> but in this case, only 2 kb of data gets written
>
> Any suggestions?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---