I'm currently testing the libcurl library on macOS. The received messages contain characters instead of e.g. german umlauts as in the following example (Memory Viewer):
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
...
Dies ist eine Testnachricht mit </span><b><span =[CR]
[LF]
style=3D'font-size:10.0pt;font-family:"Arial","sans-serif";color:red'>rot=[CR]
[LF]
em</span></b><span =[CR]
[LF]
style=3D'font-size:10.0pt;font-family:"Arial","sans-serif";color:red'> =[CR]
[LF]
</span><span =[CR]
[LF]
style=3D'font-size:10.0pt;font-family:"Arial","sans-serif";color:#002060'=[CR]
[LF]
>und <b>fetten</b> Text.<br><br>Mit freundlichen =[CR]
[LF]
Gr=FC=DFen<br><br><o:p></o:p></span></p></div></body></html>
As you can see there are special chars (=E4, 3D, =F6, =09, 0, ...)
Any ideas how to decode the received message ? I think its not the right way to replace strings such as:
msg_html = ReplaceString(msg_html, "=E4", "ä" )
msg_html = ReplaceString(msg_html, "=FC", "ü" )
thx in advance !
libcurl - how to decode special chars im mail
Re: libcurl - how to decode special chars im mail
Im on phone but there are two functions you can use Urldecode() and
Esacpehtml() or is that escapehtmlstring()
Esacpehtml() or is that escapehtmlstring()
Re: libcurl - how to decode special chars im mail
If you look in the header fields, you can see:
https://en.wikipedia.org/wiki/Quoted-printable
https://de.wikipedia.org/wiki/Quoted-Pr ... -Kodierung
Such a decoder is not implemented in PB. You have to write it on your own.
Look here:Content-Transfer-Encoding: quoted-printable
https://en.wikipedia.org/wiki/Quoted-printable
https://de.wikipedia.org/wiki/Quoted-Pr ... -Kodierung
Such a decoder is not implemented in PB. You have to write it on your own.
Re: libcurl - how to decode special chars im mail
A first try:
Code: Select all
Procedure.s Quotedprintable_Decoder(*Text.Character)
Protected Result$, *Start
*Start = *Text
While *Text\c
If *Text\c = '='
Result$ + PeekS(*Start, (*Text - *Start) / SizeOf(Character))
*Text + SizeOf(Character)
Result$ + Chr(Val("$" + PeekS(*Text, 2)))
*Text + 2 * SizeOf(Character)
*Start = *Text
Else
*Text + SizeOf(Character)
EndIf
Wend
If *Start < *Text
Result$ + PeekS(*Start, (*Text - *Start) / SizeOf(Character))
EndIf
ProcedureReturn Result$
EndProcedure
QPText$ = ~"Dies ist eine Testnachricht mit </span><b><span =0Dstyle=3D'font-size:10.0pt;font-family:\"Arial\",\"sans-serif\";color:red'>rot=0Dem</span></b><span =0D"
QPText$ + ~"style=3D'font-size:10.0pt;font-family:\"Arial\",\"sans-serif\";color:red'> =0D</span><span =0Dstyle=3D'font-size:10.0pt;font-family:\"Arial\",\"sans-serif\";color:#002060'=0D"
QPText$ + ~">und <b>fetten</b> Text.<br><br>Mit freundlichen =0DGr=FC=DFen<br><br><o:p></o:p></span></p></div></body></html>"
Debug Quotedprintable_Decoder(@QPText$)
Re: libcurl - how to decode special chars im mail
... wow, that's a great solution. Thank you!
Using your code the converted HTML code is now formatted correctly on MAC and Windows (related to special characters like "3D", "=E4", ...)
Here some more test results using MAC OS:
content-Type: text/html; charset="iso-8859-1"
-> german umlauts are displayed correct in debugger and web gadget.
content="text/html; charset=utf-8"
-> Umlauts are displayed incorrectly in the debugger and web gadget (e.g. "ö" = "ö", "ü" instead of "ü")
-> I used a function to convert asccii to utf8 (see func below) -> ok for web gadget and debugger
Test results using Windows 7:
content-Type: text/html; charset="iso-8859-1"
-> german umlauts are displayed correct in debugger but NOT in web gadget (e.g. "Mit freundlichen Grüßen")
content="text/html; charset=utf-8"
-> german umlauts are NOT displayed correct in debugger and web gadget ("ü" instead of "ü", "ä" instead of "ä",..)
-> Using my function converts not all of german umlauts (e.g. "ß", big "Ü")
Her my function to convert ascii:
Using your code the converted HTML code is now formatted correctly on MAC and Windows (related to special characters like "3D", "=E4", ...)
Here some more test results using MAC OS:
content-Type: text/html; charset="iso-8859-1"
-> german umlauts are displayed correct in debugger and web gadget.
content="text/html; charset=utf-8"
-> Umlauts are displayed incorrectly in the debugger and web gadget (e.g. "ö" = "ö", "ü" instead of "ü")
-> I used a function to convert asccii to utf8 (see func below) -> ok for web gadget and debugger
Test results using Windows 7:
content-Type: text/html; charset="iso-8859-1"
-> german umlauts are displayed correct in debugger but NOT in web gadget (e.g. "Mit freundlichen Grüßen")
content="text/html; charset=utf-8"
-> german umlauts are NOT displayed correct in debugger and web gadget ("ü" instead of "ü", "ä" instead of "ä",..)
-> Using my function converts not all of german umlauts (e.g. "ß", big "Ü")
Her my function to convert ascii:
Code: Select all
Procedure.s AsciiToUTF8(String$)
Protected Buffer$
Buffer$ = Space(Len(String$))
PokeS(@Buffer$, String$, -1, #PB_Ascii)
String$ = PeekS(@Buffer$, -1, #PB_UTF8)
ProcedureReturn String$
EndProcedure

