How I can decode TIdMessage from koi8-r to windows-1251? - Printable Version +- Atozed Forums (https://www.atozed.com/forums) +-- Forum: Indy (https://www.atozed.com/forums/forum-8.html) +--- Forum: Indy General Discussion (https://www.atozed.com/forums/forum-9.html) +--- Thread: How I can decode TIdMessage from koi8-r to windows-1251? (/thread-607.html) |
How I can decode TIdMessage from koi8-r to windows-1251? - SergJP - 08-24-2018 I use Embarcadero C++Builder 10.2 Tokyo with Indy 10. The task is to check emails via POP3. I can get emails, but I don't know how to decode their subjects, attachment file name, etc from koi8-r to windows-1251 or UTF-8. Can anybody help me? Code: Return-path: <babichev@meccanosoft.com> RE: How I can decode TIdMessage from koi8-r to windows-1251? - SergJP - 08-24-2018 The problem is solved! Maybe it will be useful for somebody. Need to add #include <IdHeaderCoderPlain.hpp> to the form header. RE: How I can decode TIdMessage from koi8-r to windows-1251? - SergJP - 08-30-2018 Excuse me, but this is not solved completely. #include <IdHeaderCoderPlain.hpp> works fine in test. But in main project it no action. The problem was found by debugger trace into Indy sources. In IdHeaderCoderList.pas: Code: function TIdHeaderCoderList.ByCharSet(const ACharSet: string): TIdHeaderCoderClass; Indy selects a coder that will decode a header's string. In my test application coders are loaded in order: TIdHeaderCoderPlain TIdHeaderCoderIndy TIdHeaderCoder2022JP The letter's headers encoded in KOI-8R. So, when TIdHeaderCoderList.ByCharSet is called, first from end is TIdHeaderCoder2022JP. Its CanHandle returns "false" and next is TIdHeaderCoderIndy. Its CanHandle returns "true" and message decodes by TIdHeaderCoderIndy fine. When I use this in my main project order of coders is other: TIdHeaderCoderIndy TIdHeaderCoder2022JP TIdHeaderCoderPlain First from end is TIdHeaderCoderPlain. It returns "true" and message is not decoded and unreadable. TIdHeaderCoderIndy not used. What can I do? Indy 10.2.6 RE: How I can decode TIdMessage from koi8-r to windows-1251? - rlebeau - 08-30-2018 (08-30-2018, 12:44 PM)SergJP Wrote: In my test application coders are loaded in order: Known issue for C++. If you use only #include <IdAllHeaderCoders.hpp>, rather than #include'ing individual IdHeaderCoderXXX.hpp files, Indy registers the coder classes in this order: TIdHeaderCoderPlain TIdHeaderCoder2022JP TIdHeaderCoderIndy (08-30-2018, 12:44 PM)SergJP Wrote: What can I do? Make sure #include <IdHeaderCoderIndy.hpp> is the last header seen by the compiler. Or use only #include <IdAllHeaderCoders.hpp> instead. Or manually unregister and re-register the coder classes in the desired order at runtime using the UnregisterHeaderCoder() and RegisterHeaderCoder() functions declared in IdHeaderCoderBase.hpp. Also, do note that the entire header coder system is slated to be removed in a future version of Indy (it is already removed in my dev copy), so this won't be an issue for much longer: #44 Remove IdHeaderCoder sub-system RE: How I can decode TIdMessage from koi8-r to windows-1251? - SergJP - 08-31-2018 Remy, thanks for advice. Quote:Make sure #include <IdHeaderCoderIndy.hpp> is the last header seen by the compiler. In main project it is impossible, includes are a lot. Quote:Or use only #include <IdAllHeaderCoders.hpp> instead. No effect both test and main project. Quote:Or manually unregister and re-register the coder classes in the desired order at runtime using the UnregisterHeaderCoder() and RegisterHeaderCoder() functions declared in IdHeaderCoderBase.hpp. Seems it's the best idea. Couldn't you give an example how to call them from C++ builder? Regars, Sergey RE: How I can decode TIdMessage from koi8-r to windows-1251? - rlebeau - 08-31-2018 (08-31-2018, 11:00 AM)SergJP Wrote: Couldn't you give an example how to call them from C++ builder? Like this: Code: #include <IdHeaderCoderBase.hpp> RE: How I can decode TIdMessage from koi8-r to windows-1251? - SergJP - 09-04-2018 Remy, thanks a lot! All works fine. |