Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > mailto URL fails with "�"

mailto URL fails with "�"
Thread Tools
Brass
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Nov 5, 2003, 10:04 PM
 
I'm using the NSWorkspace openURL method and a "mailto:..." URL in my application to send an email message using the default email application (usually Mail.app).

Usually it works fine, however I've figured out that if the body part of the email message in the URL contains a "�" (degrees) character, the body of the email ends up being empty!

I've checked that the "CFURLCreateStringByAddingPercentEscapes" funtion is not doing anything bizarre, but it is translating the "�" into a "%B0" (which I assume is correct - even if it's not, why would it cause the entire message to be empty?).

The relevant bit's of my code are below. Does anyone have any idea why this is happening or how I can work around the problem?

Code:
subject = (NSString *)CFURLCreateStringByAddingPercentEscapes (NULL, (CFStringRef)subject, NULL, NULL, kCFStringEncodingISOLatin1); body = (NSString *)CFURLCreateStringByAddingPercentEscapes (NULL, (CFStringRef)mutableBody, NULL, NULL, kCFStringEncodingISOLatin1); escapedURLString = [NSString stringWithFormat:@"mailto:?subject=%@&body=%@", subject, body ]; [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:escapedURLString]];
     
Brass  (op)
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Nov 5, 2003, 10:08 PM
 
Just a quick follow up. I've just tried entering the following URL into Camino's URL field:

mailto:?subject=blah&body=blah�blah

and it works fine, including the "�". So why doesn't my code work?
     
Brass  (op)
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Nov 6, 2003, 05:22 PM
 
Okay, I've solved the initial problem by using UTF8 encoding instead of Latin encoding. This works fine for most characters. Along the way, I also changed to using NSString's "stringByAddingPercentEscapesUsingEncoding:" method instead of the core foundation function (because it's a lot easier to read).

However, I've now got a problem with "&" characters. It simply does not translate them.

I guess this is because "&" is perfectly legal in URL's (as GET argument seperators). I'll have to manually translate them to %-escapes myself.
( Last edited by Brass; Nov 6, 2003 at 07:33 PM. )
     
Wevah
Senior User
Join Date: Nov 2001
Location: State of Denial
Status: Offline
Reply With Quote
Nov 8, 2003, 09:38 PM
 
Baleeted: screwed up on an entity, and then realized I didn't properly understand the problem! D'oh!
( Last edited by Wevah; Nov 8, 2003 at 09:44 PM. )
[Wevah setPostCount:[Wevah postCount] + 1];
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 06:09 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,