Decoding "quoted-printable" -- Help needed -- Reopened - Solved 2nd
roland.huettmann at gmail.com
Thu Nov 14 18:12:10 EST 2019
I am very sorry that I am overstressing this list. I keep on answering my
The function needs to address bytes. I found this looking at some similar
# Code snippet from C#
string sHex = input;
sHex = sHex.Substring(i + 1, 2);
int hex = Convert.ToInt32(sHex, 16);
byte b = Convert.ToByte(hex);
i += 3;
I oversaw that the value must be a byte value. Anyway, that is all new to
So, the correct and tested converting to and from "quoted-printable" with
encoded UTF8 in LiveCode >7 is:
set the itemdelimiter to "="
// ENCODE EXAMPLE
put "€" into tChar
put textEncode ( tChar , "UTF-8" ) into tCodedChar
repeat for each codePoint tCodePoint in tCodedChar
put "="& baseConvert ( byteToNum ( tCodePoint ) , 10 , 16 ) after
put tEncoded into msg ---> "=E2=82=AC" - the quoted-printable UFT-8
encoding of the Euro symbol "€"
// DECODE EXAMPLE
put "=E2=82=AC" into tEncoded
delete char 1 of tEncoded
repeat for each item tItem in tEncoded
put numToByte ( BaseConvert ( tItem , 16 , 10 ) ) after tDecoded
put textDecode ( tDecoded , "UTF-8" ) into msg --> the Euro symbol "€"
Thanks to all.
Given a bit of time, I will post a solution for UTF8 quoted-printable
encoded E-Mail blocks of text in the Forum.
Am Do., 14. Nov. 2019 um 20:41 Uhr schrieb R.H. <roland.huettmann at gmail.com
> Oh, sorry, I was too quick declaring a solution.
> Even though the code of the function works fine, the result also converts
back, but the "quoted-printable" or "UTF-8" code expects that each
codepoint is encoded in Hex with just two ASCII letters representing a
> For example, for the Euro symbol "€" we have three codepoints.
> The function below converts to "=E2=201A=AC" while it must be "=E2=82=AC".
> The "=" sign is just a delimiter in quoted-printable.
> Now, I do not know what is wrong in my thinking as I am not getting quite
the same results.
> (The result is ok for other symbols such as 'ü'.)
> put "€" into tChar
> // First encode to UTF-8:
> put textEncode(tChar,"UTF-8") into tCodedChar
> // Repeat for each codepoint in the UTF-8 char
> repeat for each codePoint tCodePoint in tCodedChar
> // Encode each codepoint to its integer expression and convert to
> put "="& BaseConvert ( codePointToNum (tCodePoint) , 10 , 16 )
> end repeat
> put tEncoded into field "Show Codepoints" -- Expected ASCII representing
> -- Result: "=E2=201A=AC" -- Instead of "=E2=82=AC" , but valid and
> The actual "correct" UTF-8 result can be tested here:
> What am I missing?
> Thanks a lot
More information about the use-livecode