Pack('m') and Windows files

Hi all,

first post here, hope to ask things the right way :slight_smile:

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,

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.

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.

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.