How to decode q encoding in C?

Is there a library for q-coding? I need to decode some q-encoded text, for example:

**Subject: =?iso-8859-1?Q?=A1Hola,_se=F1or!?=** 
+4
source share
3 answers

GNU Mailutils libmailutils is one example of such a library.

The “Q” coding is defined by RFC 2047 , so using it as a search query yields other relevant results.

+2
source

The email subject is encoded in accordance with RFC 2047. We can decode it using the mu_rfc2047_decode() function provided by GNU mailutils. Example:

 #include <stdio.h> #include <stdlib.h> #include <mailutils/mailutils.h> #include <mailutils/mime.h> ... char cipher[] = "=?GB2312?B?UmWjujEy1MK8xruuse0=?="; char *plaintext; int rc = mu_rfc2047_decode("utf-8", cipher, &plaintext); if (rc) { fprintf(stderr, "Fail to decode '%s'\n", cipher); } else { puts(plaintext); free(plaintext); } 

To download GNU mailutils, visit https://mailutils.org/

To understand RFC 2047, read https://www.ietf.org/rfc/rfc2047.txt

Test result:

 Cipher: **Subject: =?iso-8859-1?Q?=A1Hola,_se=F1or!?=** Plaintext: **Subject: ¡Hola, señor!** Cipher: =?Big5?Q?=AE=F8=B6O=BA=A18=A4d=BFW=AEa?= Plaintext:消費滿8千獨家Cipher: =?GB2312?B?UmWjujEy1MK8xruuse0=?= Plaintext: Re:12月计划表 
+1
source

I do not know about Q-coding libraries, could not be found.

Please note that your last example is not like a Q-encoding, note that the character after the encoding ("UTF-8") is not "Q", but "B". This means that base64 encoding, for which there are many libraries, glib is one example.

See MIME on Wikipedia for how to determine which encoding is used.

0
source

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


All Articles