<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
I honestly don't know why I thought that there wasn't a list_to_binary function...I suppose thats what you get for programming late into the night. I believe it was on How I Met Your Mother that I heard the phrase "Nothing good ever happens after 2am." I should probably take that to heart when it comes to coding.<br><br>> Date: Sat, 14 May 2011 23:28:12 -0300<br>> Subject: Re: [erlang-questions] Odd behavior when sending emails via SMTP when messages are converted to/from binaries<br>> From: juanjo@comellas.org<br>> To: silent_vendetta@hotmail.com<br>> CC: erlang-questions@erlang.org<br>> <br>> Yes, the correct thing to do would be to use list_to_binary/1 and<br>> binary_to_list/1.<br>> <br>> It might be possible to avoid the conversion altogether if you're<br>> writing the result of the conversion to a socket or a file. If so, you<br>> could just build an iolist and parse what you receive directly as a<br>> binary.<br>> <br>> Juanjo<br>> <br>> <br>> On Sat, May 14, 2011 at 11:19 PM, Chris Hicks<br>> <silent_vendetta@hotmail.com> wrote:<br>> > With some additional testing finally figured it out. I'm not sure how I<br>> > missed it before, hard to keep track of all the tests you run after a while,<br>> > but using term_to_binary then binary_to_list ends up leaving 4 extra<br>> > elements in the list prior to the text which was first turned into a binary<br>> > in the first place.<br>> > Chris Hicks.<br>> ><br>> > ________________________________<br>> > From: silent_vendetta@hotmail.com<br>> > To: erlang-questions@erlang.org<br>> > Date: Sat, 14 May 2011 17:18:06 -0700<br>> > Subject: [erlang-questions] Odd behavior when sending emails via SMTP when<br>> > messages are converted to/from binaries<br>> ><br>> > In the system I'm building I am working with all my strings as binaries. I'm<br>> > doing this because I'll be deploying on a 64 bit platform and don't need all<br>> > the text I'm working with blowing up in size when there isn't any need for<br>> > it. However I'm noticing an odd behavior when constructing emails to send<br>> > over SMTP.<br>> > Basically what I'm doing is this:<br>> > ...<br>> > Message_body = "This is a message body", <-- This part is actually more<br>> > complex in that variables are being used along with string literals to form<br>> > the entire body, which is why I initially create it as a string.<br>> > Binary_message = erlang:term_to_binary(Message_body),<br>> > email:send(Binary_message).<br>> ><br>> > The other module then does this:<br>> > ...<br>> > Header = "From: xxx <xxx>\rTo: yyy<yyy>\rSubject: This is the subject\r",<br>> > Full_message = Header ++ erlang:binary_to_list(Binary_message),<br>> > send_email(Full_message).<br>> ><br>> > Now the message sends just fine and shows up in my email. However in front<br>> > of the Message_body text are three extra characters "ƒk Ő" and if I change<br>> > the second module to this:<br>> > ...<br>> > Header = "From: xxx <xxx>\rTo: yyy<yyy>\rSubject: This is the subject\r",<br>> > Body = erlang:binary_to_list(Binary_message),<br>> > Full_message = Header ++ Body,<br>> > send_email(Full_message).<br>> ><br>> > Then the three characters change to these"ƒk ×" and I simply can't figure<br>> > out what is going on. Now I'm not building a mail server and I don't expect<br>> > to be sending thousands of emails so working around this by simply treating<br>> > all email text as strings (not converting to/from binary) is certainly not a<br>> > problem. I am just curious if anyone can explain or help me figure out what<br>> > is going on.<br>> > Chris Hicks.<br>> ><br>> > _______________________________________________ erlang-questions mailing<br>> > list erlang-questions@erlang.org<br>> > http://erlang.org/mailman/listinfo/erlang-questions<br>> > _______________________________________________<br>> > erlang-questions mailing list<br>> > erlang-questions@erlang.org<br>> > http://erlang.org/mailman/listinfo/erlang-questions<br>> ><br>> ><br>                                       </body>
</html>