Quoted-printable is also one of the common encoding methods in mime mail. Like base64, it also encodes the input string or data into printable ASCII strings.
Quoted-printable: the input data is in the range of 33-60 and 62-126 and is directly output; others must be encoded as "=" plus two bytes of hex code (uppercase ). To ensure that the output line does not exceed the specified length, you can add the "=/R/N" sequence at the end of the line as the soft carriage return.
Int encodequoted (const unsigned char * psrc, char * pdst, int nsclen, int nmaxlinelen) {int ndstlen; // The output character count int nlinelen; // The output row length count ndstlen = 0; nlinelen = 0; For (INT I = 0; I <nsclen; I ++, psrc ++) {// ASCII 33-60, 62-126 is output, and the rest must be encoded if (* psrc> = '! ') & (* Psrc '~ ') & (* Psrc! = ') {* Pdst ++ = (char) * psrc; ndstlen ++; nlinelen ++;} else {sprintf (pdst, "= % 02x ", * psrc); pdst + = 3; ndstlen + = 3; nlinelen + = 3;} // output line feed? If (nlinelen> = nmaxlinelen-3) {sprintf (pdst, "=/R/N"); pdst + = 3; ndstlen + = 3; nlinelen = 0 ;}} // Add the end character * pdst = '/0' to the output; return ndstlen ;}
Quoted-printable decoding is simple, and the encoding process can be reversed.
Int decodequoted (const char * psrc, unsigned char * pdst, int nsclen) {int ndstlen; // count the output characters int I; I = 0; ndstlen = 0; while (I <nsclen) {If (strncmp (psrc, "=/R/N", 3) = 0) // press enter to skip {psrc + = 3; I + = 3;} else {If (* psrc = ') // The encoded byte {sscanf (psrc, "= % 02x", pdst ); pdst ++; psrc + = 3; I + = 3;} else // unencoded byte {* pdst ++ = (unsigned char) * psrc ++; I ++ ;}ndstlen ++ ;}// the output end character * pdst = '/0'; return ndstlen ;}
[Related resources]
RFC/STD documentation: Internet FAQ Archives
Bhw98 columns: http://www.csdn.net/develop/author/netauthor/bhw98/
First Release: 2003-06-23
Last revised: