# Pack('m') and Windows files

**URL:** <https://www.ruby-forum.com/t/pack-m-and-windows-files/189686>\
**Category:** Ruby\
**Created:** [June 5, 2010, 3:33am UTC](https://www.ruby-forum.com/t/pack-m-and-windows-files/189686 "2010-06-05T03:33:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![syntaxerrormmm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5e925/32.png) [@syntaxerrormmm](https://www.ruby-forum.com/u/syntaxerrormmm)\
**Post date:** [June 5, 2010, 3:33am UTC](https://www.ruby-forum.com/t/pack-m-and-windows-files/189686/1 "2010-06-05T03:33:27Z")

</div>

Hi all,

first post here, hope to ask things the right way 🙂

I’m using Ruby from RubyInstaller, 1.9.1-p243. I’m trying to send a .txt  
file (which notepad++ says it’s Dos/Windows with ANSI encoding) via  
email using something like:  
content = File.read(filename)  
enccont = [content].pack(‘m’)

Then inserting enccont inside a heredoc containing the whole mail to  
send, like:  
message =\<\<EOMESS  
…  
#{enccont}  
…  
EOMESS

The results are that I receive a mail that lacks of the ‘end of lines’,  
in which place there are little squares (one per each line, to be fair).  
Also, filetype is Unix (and not Dos/Windows).

I tried previously to substitute \n with \r\n:  
content = File.read(filename).gsub(/\n/, ‘\r\n’)

but the results are worse than before (\r\n appears also in the  
attachment).

I would like to obtain the same file also via email. Is that possible?  
Is there someone which has some ideas on how to achieve that?

Thanks, regards,

---

<div class="post-metadata">

**Author:** ![syntaxerrormmm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5e925/32.png) [@syntaxerrormmm](https://www.ruby-forum.com/u/syntaxerrormmm)\
**Post date:** [June 5, 2010, 3:41am UTC](https://www.ruby-forum.com/t/pack-m-and-windows-files/189686/2 "2010-06-05T03:41:00Z")

</div>

> The results are that I receive a mail that lacks of the ‘end of lines’,  
> in which place there are little squares (one per each line, to be fair).  
> Also, filetype is Unix (and not Dos/Windows).
> 
> I tried previously to substitute \n with \r\n:  
> content = File.read(filename).gsub(/\n/, ‘\r\n’)

Make sure you’re using double-quotes for “\r\n” and not single-quotes.

Aaron out.

---

<div class="post-metadata">

**Author:** ![syntaxerrormmm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5e925/32.png) [@syntaxerrormmm](https://www.ruby-forum.com/u/syntaxerrormmm)\
**Post date:** [June 5, 2010, 3:46am UTC](https://www.ruby-forum.com/t/pack-m-and-windows-files/189686/3 "2010-06-05T03:46:17Z")

</div>

Emiliano wrote:

> > The results are that I receive a mail that lacks of the ‘end of lines’,  
> > in which place there are little squares (one per each line, to be fair).  
> > Also, filetype is Unix (and not Dos/Windows).
> > 
> > I tried previously to substitute \n with \r\n:  
> > content = File.read(filename).gsub(/\n/, ‘\r\n’)

To which I responded:

> Make sure you’re using double-quotes for “\r\n” and not single-quotes.

I suppose I should have elaborated:

irb(main):001:0\> ‘\n’  
=\> “\n”  
irb(main):002:0\> “\n”  
=\> “\n”

Notice how encapsulating the backslash within single quotes results in  
the string “\n”? Backslashes inside single-quoted strings escape the  
backslash itself, and also single quotes, but not \r\n CR+LF escape  
sequences:

irb(main):001:0\> ‘This is a backslash: \’  
=\> “This is a backslash: \”  
irb(main):002:0\> “This is a backslash: \”  
=\> “This is a backslash: \”  
irb(main):003:0\> 'This is a single-quote: ‘’  
=\> “This is a single-quote: '”  
irb(main):004:0\> ‘But other escape sequences do not work: \r\n\t\b’  
=\> “But other escape sequences do not work: \r\n\t\b”  
irb(main):005:0\> “They do within double quotes: \r\n\t\b”  
=\> “They do within double quotes: \r\n\t\b”

Aaron out.

---

<div class="post-metadata">

**Author:** ![syntaxerrormmm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5e925/32.png) [@syntaxerrormmm](https://www.ruby-forum.com/u/syntaxerrormmm)\
**Post date:** [June 5, 2010, 4:02am UTC](https://www.ruby-forum.com/t/pack-m-and-windows-files/189686/4 "2010-06-05T04:02:44Z")

</div>

Aaron D. Gifford wrote:

> To which I responded:
> 
> > Make sure you’re using double-quotes for “\r\n” and not single-quotes.
> 
> I suppose I should have elaborated:

To be honest, you put me on the right way with the first message indeed,  
but thank you very much for the clear elaboration.

Obviously, the problem is solved. Thanks again.
