# Download files from mail

**URL:** <https://www.ruby-forum.com/t/download-files-from-mail/151959>\
**Category:** Ruby\
**Created:** [October 28, 2008, 1:14pm UTC](https://www.ruby-forum.com/t/download-files-from-mail/151959 "2008-10-28T13:14:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![neia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8dc957/32.png) [@neia](https://www.ruby-forum.com/u/neia)\
**Post date:** [October 28, 2008, 1:14pm UTC](https://www.ruby-forum.com/t/download-files-from-mail/151959/1 "2008-10-28T13:14:21Z")

</div>

Hi,

I’m trying to download a file with net::IMAP from mail count. I can  
download plain texts files using fetch method and unpack’m’, but when i  
try it with an excel file (vnd.ms-excel), the downloaded excel is  
corrupted.

thanks for all

---

<div class="post-metadata">

**Author:** ![neia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8dc957/32.png) [@neia](https://www.ruby-forum.com/u/neia)\
**Post date:** [October 28, 2008, 5:50pm UTC](https://www.ruby-forum.com/t/download-files-from-mail/151959/2 "2008-10-28T17:50:42Z")

</div>

compare the files and detect de differences

bye

Blanca Id wrote:

> Hi,
> 
> I’m trying to download a file with net::IMAP from mail count. I can  
> download plain texts files using fetch method and unpack’m’, but when i  
> try it with an excel file (vnd.ms-excel), the downloaded excel is  
> corrupted.
> 
> thanks for all

---

<div class="post-metadata">

**Author:** ![neia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8dc957/32.png) [@neia](https://www.ruby-forum.com/u/neia)\
**Post date:** [October 28, 2008, 5:56pm UTC](https://www.ruby-forum.com/t/download-files-from-mail/151959/3 "2008-10-28T17:56:23Z")

</div>

Hi Artur,

I have compared the excel file download from mail with the original and  
seems to be the same. I’ve read that can be that the LF character has  
been replaced with CRLF characters, so the download file size is  
diferent.

thanks

Artur Juve wrote:

> compare the files and detect de differences
> 
> bye

---

<div class="post-metadata">

**Author:** ![neia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8dc957/32.png) [@neia](https://www.ruby-forum.com/u/neia)\
**Post date:** [October 28, 2008, 6:34pm UTC](https://www.ruby-forum.com/t/download-files-from-mail/151959/4 "2008-10-28T18:34:50Z")

</div>

Hi,

At last I found the solution, to download correctly excel files I use  
the ‘wb’ instead of ‘w’ on the open parameters.

if body.subtype == “PLAIN”  
File.open(nameFile,‘w’)  
f.write(file)  
end  
else  
File.open(nameFile,‘wb’)  
f.write(file)  
end  
end

bye
