Linefeeds getting stripped in Windows, MacOS is fine

I have the following code that I’m using to open up the default email client on the system and the line feeds are not making it to the email client. It’s just one long line in the body. I checked the string, body and it’s fine. Once this line of code is run the issue occurs.

System.GotoURL(“mailto:”+recipient+“?cc=”+iv_cc+“&subject=” + subject + “&body=”+body)

Any ideas?

The end of line is different between Windows and MacOS, so my guess it depends on how you create ‘body’ or how is URL encoded?
https://documentation.xojo.com/api/text/endofline.html#endofline

I know it’s different. The body text is a string straight from a TextArea control typed in by the user. Before putting it in the URL, I displayed it in a MessageBox and it looked fine. That has me scratching my head.

You need to use EncodeURIComponent on each of your 4 parameters.

3 Likes

On Windows I discovered that the textarea can display ASCII 11 as a linefeed.

You might try:

System.GotoURL("mailto:"+recipient+"?cc="+iv_cc+"&subject=" + subject + "&body=" _ 
+ body.ReplaceAll(Chr(11), EndOfLine).ReplaceLineEndings(EndOfLine.Native))

Even on Windows, TextArea uses the Mac end of line. Use ReplaceLineEndings to set the correct EOL.

1 Like

? Why ?

Wow, my mind is blown right now. Just verified for myself. This really should not be. 0D between the lines instead of 0A0D.

I still stand by what I said above though. If the user presses Shift+Return on Windows it will create an endofline character with ASCII 11.

No idea, but it’s been that way for the last 20 years.

That does not make it better :wink:

This is strange. I do need to use the EncodeURLComponent to prevent one big line and that’s fine. I’ve tried replacing the Endofline characters and it looks right in the new email created, but when it sends, there’s only a single line between each line even if I’d hit CR a few times. Frustrating!

Any ideas? The test email is from windows is using Thunderbird as the email client. When my code sends the email text to the Thunderbird client and creates the new email to be sent, all looks fine. When the email arrives at the recipient’s email the email there’s only 1 linefeed even when there should be more.

For example:

Test

1

2

3

Will end up:

Test
1
2
3

Email clients tend to change the data they get. As you don’t send as html you don’t have much control anyways.

Show us the raw data of the email.

1 Like

It actually wasn’t the email client that was the issue. I found some mistakes in my code after trying to implement the recommended changes. I have it working now.

After much tinkering and fixing some mistakes in my code. I have it fixed with using 2 suggestions made.

  1. I had to search my string and make sure properly change the EndOfLine value to that used by windows.

  2. I had to use the EncodeURLComponent. I did find that in my situation, this works for Windows and Linux, but is not needed for MacOS and actually screws it up on MacOS.

In any case, it’s all working now for all 3 Desktop OSs.

You absolutely need EncodeURIComponent even on macOS. If the user types an &, for example, the result will be messed up.

2 Likes

That’s what I thought, it’s been working for me without out it on MacOS. When I tried it on MacOS, it screwed it up. I don’t understand that, but it’s working fine now without it on the Mac.