How can I use unicode in the mailto protocol?

I want to run the default email client application through the ShellExecute function.

those. I am writing something like this:

ShellExecute (0, 'mailto: example@example.com ? Subject = example & body = example', ...);

How can I encode non-American characters in the subject and body?

I can’t use the default ANSI codepage because the characters can be anything: Chinese characters, Cyrillic or something else.

PS notes:

  • I am using ShellExecuteW function.
  • Leaving the object and body "as is" will not work (tested with the Windows Live Mail client on Win7 and Outlook Express on WinXP).
  • An encoding object like URLEncode (UTF8Encode (Subject)) will work for Windows Live Mail, but will not work in Outlook Express.
  • URLEncode (UTF8Encode (Body)) will not work for both clients.
+3
source share
2 answers

Email:? Example@example.com Headline = Example & body =% E5% 85% of ad

The short answer is no. Symbols must be percent encoded as defined by RFC 3986 and its predecessors. RFC 2368 defines the structure of a mailto URI.

#include "windows.h"

int main() {
  ShellExecute(0, TEXT("open"),
    TEXT("mailto:example@example.com?subject=example&body=%e5%85%ad"),
    TEXT(""), NULL, SW_SHOWNORMAL);

  return 0;
}

The body in this case is the CJK character U+516D (ε…­) encoded as UTF-8 (E5 85 AD). This works correctly with Mozilla Thunderbird (you may need to install additional fonts if it does not).

, ( ) URI. RFC 3986 UTF-8, . , RFC 3986, .

: URLEncode HTML application/x-www-form-urlencoded. , , .

2: IRI Windows, , , . .

+6

. Unicode ( ). . ANSI ( ?), URLEncoded ..

3-4 , . , .

+2

Source: https://habr.com/ru/post/1730869/


All Articles