0

There is a problem parsing the subject in the mail header. For example, the form of the subject is as follows.

subject: =?iso-2022-KR?B?DjlMOC4PIA....gyDzogT?=

My guess is that base64 decoding should include the escape character -SO, SI, ESC$)C-. However, decoding is not included. How can I get a normal string?

I hope the results are as below.

Subject: like this, 안녕하세요.

Please give me a hint how to respond at the code level. in C

Update

sorry. I had a SO, SI, but I missed it. But there was no ESC$)C, The problem is resolved immediately and shared for others.

In the absence of a ESC$)C, the libiconv is a problem, but the gconv(in glibc) was not a problem. What I used was the libiconv. Changing to gconv has solved the problem.

thanks.

Community
  • 1
  • 1
Jay
  • 397
  • 1
  • 5
  • 19
  • The form is: `=?charset?encoding?encoded text?=.` encoding can be either `Q` denoting Q-encoding that is similar to the quoted-printable encoding, or `B` denoting base64 encoding. – Ôrel May 11 '17 at 09:56
  • To get more suggestions it's better if you provide the code and the output that you have so far. – terence hill May 11 '17 at 09:57
  • Thank you, but most of the part about conversion is known. I just wonder how it handles **iso-200-KR**. – Jay May 12 '17 at 00:14

1 Answers1

1

So in =?iso-2022-KR?B?DjlMOC4PIA....gyDzogT?= the Bsandwiched by question marks means base64 encoded. The iso-2022-KR is the character set. The DjlMOC4PIA....gyDzogT is the base64 encoded title.

You first base64 decode the title. It's easy to find a solution for this in C.

This will leave you with an array of binary bytes which is the title encoded in the ISO-2022-KR character set. Presumably you want to convert that to UTF-8 or some other character set your computer can handle. Your best bet for this part is to use a character set conversion utility. If you are on Linux or macOS, you can use the iconv library. See iconv_open, iconv and iconv_close.

Community
  • 1
  • 1
JeremyP
  • 84,577
  • 15
  • 123
  • 161
  • thanks. I've already done base64 decoding and converted it via iconv. However, the result of base64 decoding is the same output in English, not in Hangul, even when converting to something character set. In the mail body, it was necessary to include special characters to convert iso-2022-kr **-SO, SI, ESC$)C-**. However, the base64 decoding result does not include these characters, is it relevant? Does the **subject** differ from the **mail body** in the way it is converted? – Jay May 12 '17 at 00:09