IMAP Search command & unicode in Synapse lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Rebell · 2023-10-02 17:39 Hello, I’m using Synapse, and I can’t figure out how to use Japanese, German, and Russian characters for the search command in IMAP.  I tried playing with UTF8Encode, but in socket logs i see that in anyway characters are not recognized correctly. At best I get the error  "Error in IMAP command SEARCH: Invalid search key". So, for example. How to use a such requests ? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Imap.SearchMess('SUBJECT  möglich'); In this case, socket log appear : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 03896AA0-> S8 SEARCH SUBJECT "moglich" so "ö" symbol looks in other way. Another symbols like "ß" just change to "?" . Please explain to me how to deal with this. What encoding should I use? ---------------------------------------------------------------------- rvk · 2023-10-02 18:02 Have you tried mime encoding the string.  ś would become =B6 etc. You can use EncodeQuotedPrintable() in synacode. ---------------------------------------------------------------------- Rebell · 2023-10-02 19:14 For some reason this function does not work for me and does not convert the string. I tried to specify an already encoded value as a constant. There was no error in the server’s response, but he didn’t see the letter either. I'm not sure that the IMAP server automatically decrypts this encoding. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 20231003-030521.547 030D6AA0-> S7 SEARCH FROM "abzuschlie=C3=9Fen" 20231003-030521.547 030D6AA0HR_WriteCount: 3720231003-030521.764 030D6AA0HR_CanRead: 20231003-030521.764 030D6AA0HR_ReadCount: 6420231003-030521.764 030D6AA0<- * SEARCHS7 OK Search completed (0.004 + 0.000 + 0.003 secs). ---------------------------------------------------------------------- rvk · 2023-10-02 19:26 Quote from: Rebell on October 02, 2023, 09:14:44 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 20231003-030521.547 030D6AA0-> S7 SEARCH FROM "abzuschlie=C3=9Fen" You are searching FROM there. Does subject give the same empty result? Does it return the mime encoding when you ask for a list with subjects? Something like a1 FETCH 1:* (FLAGS BODY.PEEK[HEADER.FIELDS (SUBJECT)]) (Not sure if that's the exact correct notation for a list) ---------------------------------------------------------------------- Rebell · 2023-10-02 19:31 Quote from: Rebell on October 02, 2023, 09:14:44 pmFor some reason this function does not work for me and does not convert the string. I tried to specify an already encoded value as a constant. There was no error in the server’s response, but he didn’t see the letter either. I'm not sure that the IMAP server automatically decrypts this encoding. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 20231003-030521.547 030D6AA0-> S7 SEARCH FROM "abzuschlie=C3=9Fen" 20231003-030521.547 030D6AA0HR_WriteCount: 3720231003-030521.764 030D6AA0HR_CanRead: 20231003-030521.764 030D6AA0HR_ReadCount: 6420231003-030521.764 030D6AA0<- * SEARCHS7 OK Search completed (0.004 + 0.000 + 0.003 secs). yes, same results, also with message part.. It's just do not see this keyword neither in the headers nor in the body of the letter ---------------------------------------------------------------------- rvk · 2023-10-02 19:34 I meant how does the encoding of those characters look when you retrieve the mail without converting the raw message in imap? Do you see real utf-8 or encoded characters with = ? ---------------------------------------------------------------------- Rebell · 2023-10-02 19:36 Quote from: Rebell on October 02, 2023, 09:31:02 pmQuote from: Rebell on October 02, 2023, 09:14:44 pmFor some reason this function does not work for me and does not convert the string. I tried to specify an already encoded value as a constant. There was no error in the server’s response, but he didn’t see the letter either. I'm not sure that the IMAP server automatically decrypts this encoding. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 20231003-030521.547 030D6AA0-> S7 SEARCH FROM "abzuschlie=C3=9Fen" 20231003-030521.547 030D6AA0HR_WriteCount: 3720231003-030521.764 030D6AA0HR_CanRead: 20231003-030521.764 030D6AA0HR_ReadCount: 6420231003-030521.764 030D6AA0<- * SEARCHS7 OK Search completed (0.004 + 0.000 + 0.003 secs). yes, same results, also with message part.. It's just do not see this keyword neither in the headers nor in the body of the letter For example, full log : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 20231003-033423.642 03766AA0HR_Connect: secureimap.t-online.de:99320231003-033424.549 03766AA0HR_ReadCount: 12020231003-033424.549 03766AA0<- * OK [CAPABILITY IMAP4 IMAP4rev1 QUOTA LITERAL+ NAMESPACE UIDPLUS IDLE SORT] IMAP Proxy ready (secureimap.t-online.de) 20231003-033424.549 03766AA0-> S1 CAPABILITY 20231003-033424.549 03766AA0HR_WriteCount: 1520231003-033424.734 03766AA0HR_CanRead: 20231003-033424.734 03766AA0HR_ReadCount: 14520231003-033424.734 03766AA0<- * CAPABILITY IMAP4 IMAP4rev1 QUOTA LITERAL+ NAMESPACE UIDPLUS IDLE SORTS1 OK Pre- login capabilities listed, post-login capabilities have more 20231003-033424.734 03766AA0-> S2 LOGIN "myemail@t-online.de" "mypassword" 20231003-033424.734 03766AA0HR_WriteCount: 4520231003-033424.951 03766AA0HR_CanRead: 20231003-033424.951 03766AA0HR_ReadCount: 45720231003-033424.951 03766AA0<- S2 OK [CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS BINARY MOVE SNIPPET=FUZZY PREVIEW=FUZZY PREVIEW STATUS=SIZE SAVEDATE LITERAL+ NOTIFY METADATA SPECIAL-USE COMPRESS=DEFLATE XEXPIRE QUOTA] Logged in 20231003-033424.951 03766AA0-> S3 LIST "" * 20231003-033424.951 03766AA0HR_WriteCount: 1420231003-033425.168 03766AA0HR_CanRead: 20231003-033425.168 03766AA0HR_ReadCount: 36720231003-033425.168 03766AA0<- * LIST (\HasChildren) "." INBOX* LIST (\HasNoChildren \UnMarked \Junk) "." INBOX.Spam* LIST (\HasNoChildren \UnMarked \Trash) "." INBOX.Trash* LIST (\HasNoChildren \UnMarked \Sent) "." INBOX.Sent* LIST (\HasNoChildren \UnMarked) "." INBOX.Schule* LIST (\HasNoChildren \UnMarked \Drafts) "." INBOX.DraftsS3 OK List completed (0.003 + 0.000 + 0.002 secs). 20231003-033425.168 03766AA0-> S4 SELECT "INBOX" 20231003-033425.168 03766AA0HR_WriteCount: 1920231003-033425.438 03766AA0HR_CanRead: 20231003-033425.438 03766AA0HR_ReadCount: 49520231003-033425.438 03766AA0<- * FLAGS (\Answered \Flagged \Deleted \Seen \Draft DTAG_document DTAG_image $HasNoAttachment $HasAttachment)* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft DTAG_document DTAG_image $HasNoAttachment $HasAttachment \*)] Flags permitted.* 6021 EXISTS* 0 RECENT* OK [UNSEEN 2] First unseen.* OK [UIDVALIDITY 1440249986] UIDs valid* OK [UIDNEXT 8647] Predicted next UID* OK [HIGHESTMODSEQ 17827] HighestS4 OK [READ-WRITE] Select completed (0.001 + 0.000 + 0.001 secs). 20231003-033425.438 03766AA0-> S5 SEARCH SUBJECT "f=c3=bcr sie" 20231003-033425.438 03766AA0HR_WriteCount: 3420231003-033425.707 03766AA0HR_CanRead: 20231003-033425.707 03766AA0HR_ReadCount: 6420231003-033425.707 03766AA0<- * SEARCHS5 OK Search completed (0.019 + 0.000 + 0.018 secs). 20231003-033425.707 03766AA0-> S6 SELECT "INBOX.Trash" ---------------------------------------------------------------------- Rebell · 2023-10-02 19:54 Quote from: rvk on October 02, 2023, 09:34:42 pmI meant how does the encoding of those characters look when you retrieve the mail without converting the raw message in imap? Do you see real utf-8 or encoded characters with = ? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Imap.FetchH eader(ID,MimeMess)MimeMess.MessagePart.TargetCharset:=UTF_8;MimeMess.M essagePart.ConvertCharset:=true;MimeMess.DecodeMessage;  So after decoding MimeMess.Header.Subject  Gives me :                   Wichtige Hinweise f_r Sie Have to be : Wichtige Hinweise für Sie ---------------------------------------------------------------------- rvk · 2023-10-02 19:56 Does the full log of Imap.FetchHeader show the raw headers? ---------------------------------------------------------------------- Rebell · 2023-10-02 20:02 Quote from: rvk on October 02, 2023, 09:56:23 pmDoes the full log of Imap.FetchHeader show the raw headers? Yes it is. Here is subject in raw:  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Subject: =?utf-8?q?Wichtige_Hinweise_f=C3=BCr_Sie?= ---------------------------------------------------------------------- rvk · 2023-10-02 20:09 Try to search with passing the encoding too. So search =?utf-8?q?f=C3=BCr_Sie?= Also in that exact case (case sensitive). ---------------------------------------------------------------------- rvk · 2023-10-02 20:22 Actually, for me the unencoded utf8 does seem to work in my imap. Quotea1 FETCH 1:* (FLAGS BODY.PEEK[HEADER.FIELDS (SUBJECT)]) * 1 FETCH (FLAGS (\Seen) BODY[HEADER.FIELDS (SUBJECT)] {106} Subject: Topic reply: Direct use of OpenSSL without using intermediate libraries (LNet, Indy, Synapse) ) * 20 FETCH (FLAGS (\Seen \Recent) BODY[HEADER.FIELDS (SUBJECT)] {66} Subject: Topic reply: IMAP Search command & unicode in Synapse ) * 21 FETCH (FLAGS (\Seen) BODY[HEADER.FIELDS (SUBJECT)] {41} Subject: =?UTF-8?Q?Test_=C3=BC_test?= * 22 FETCH (FLAGS (\Recent) BODY[HEADER.FIELDS (SUBJECT)] {41} Subject: =?UTF-8?Q?Test_=C3=BC_test?= ) a1 OK Fetch completed (0.002 + 0.000 + 0.001 secs). a2 search subject "ü" * SEARCH 21 22 a2 OK Search completed (0.002 + 0.000 + 0.001 secs). Done directly via telnet. ---------------------------------------------------------------------- Rebell · 2023-10-02 20:26 Quote from: rvk on October 02, 2023, 10:09:01 pmTry to search with passing the encoding too. So search =?utf-8?q?f=C3=BCr_Sie?= Also in that exact case (case sensitive). Nope, it doesn't find it. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 20231003-041635.133 03676AA0-> S5 SEARCH SUBJECT "=?utf-8?q?f=C3=BCr_Sie?=" 20231003-041635.133 03676AA0HR_WriteCount: 4620231003-041635.350 03676AA0HR_CanRead: 20231003-041635.350 03676AA0HR_ReadCount: 6420231003-041635.350 03676AA0<- * SEARCHS5 OK Search completed (0.032 + 0.000 + 0.031 secs). But it finds the letter if you specify the part without a special character Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 20231003-042331.400 030A6AA0-> S5 SEARCH SUBJECT "Wichtige Hinweise" 20231003-042331.400 030A6AA0HR_WriteCount: 3920231003-042331.663 030A6AA0HR_CanRead: 20231003-042331.663 030A6AA0HR_ReadCount: 6920231003-042331.663 030A6AA0<- * SEARCH 6012S5 OK Search completed (0.050 + 0.000 + 0.049 secs). ---------------------------------------------------------------------- paweld · 2023-10-03 06:36 With me it finds messages without any problem, there is only a problem with decoding messages - there are ? instead of non-ascii characters.Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button8Click(Sender: TObject);var  imap: TIMAPSend;  MessageList, Message: TStringList;  MimeMess: TMimeMess;  i: Integer;begin  Memo1.Lines.Clear;  MessageList := TStringList.Create;  imap := TIMAPSend.Create;  imap.FullSSL := True;  imap.AutoTLS := True;  imap.Username := maillogin;  imap.Password := mailpasswd;  imap.TargetHost := mailhost;  imap.TargetPort := mailport;  if imap.Login then  begin    if imap.SelectFolder('INBOX') then    begin      if imap.SearchMess('SUBJECT "möglich"', MessageList) then      begin        Memo1.Lines.Add('Number of messages found: ' + IntToStr(MessageList.Count));        Memo1.Lines.Add('Mesaage list:');        Message := TStringList.Create;        MimeMess := TMimeMess.Create;        for i := 0 to MessageList.Count - 1 do      begin          Message.Clear;          imap.FetchMess(StrToInt(MessageList[i]), Message);          MimeMess.Lines.Text := Message.Text;          MimeMess.DecodeMessage;          Memo1.Lines.Add('---------');          Memo1.Lines.Add('Subject: ' + MimeMess.Header.Subject);          Memo1.Lines.Add('From: ' + MimeMess.Header.From);          Memo1.Lines.Add('Date: ' + FormatDateTime('yyyy-mm-dd hh:nn:ss', MimeMess.Header.Date));        end;        Message.Free;        MimeMess.Free;      end      else        ShowMessage('Message not found!')    end    else      ShowMessage('IMAP CHANGE FOLDER ERROR: ' + imap.ResultString);    imap.Logout;  end  else    ShowMessage('IMAP LOGIN ERROR: ' + imap.ResultString);  imap.Free;  MessageList.Free;end; ---------------------------------------------------------------------- rvk · 2023-10-03 07:59 Quote from: paweld on October 03, 2023, 08:36:50 amWith me it finds messages without any problem, there is only a problem with decoding messages - there are ? instead of non-ascii characters.That worked for me too. I got a string with #$FC for ü back. Throwing the string through WinCPToUTF8 (from LazUtf8) did fix that. ---------------------------------------------------------------------- paweld · 2023-10-03 08:17 @rvk: Thank for the trick, hadn't thought of that. ---------------------------------------------------------------------- rvk · 2023-10-03 08:22 Quote from: paweld on October 03, 2023, 10:17:56 am@rvk: Thank for the trick, hadn't thought of that. I only wonder if that also works for real other (extended) utf-8 characters. The #$FC (as in ü) seems to be just ascii (1 character) encoding. https://www.garykessler.net/library/ascii.html So what would happen with other real utf-8 characters. (guess I need to type some Chinese characters to test this  ) ---------------------------------------------------------------------- rvk · 2023-10-03 08:38 Quote from: paweld on October 03, 2023, 10:17:56 am@rvk: Thank for the trick, hadn't thought of that. I've got a better method. I noticed the Charset for Header class was set to cp1252 on my system. Forcing it to UTF-8, before the DecodeMessage, will give you the result directly in UTF-8  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i           imap.FetchMess(StrToInt(MessageList[i]), Message);          MimeMess.Lines.Text := Message.Text;          MimeMess.Header.CharsetCode := UTF_8;  // was cp1252          MimeMess.DecodeMessage;          Memo1.Lines.Add('---------');        Memo1.Lines.Add('Subject: ' + MimeMess.Header.Subject);          Memo1.Lines.Add('From: ' + MimeMess.Header.From);          Memo1.Lines.Add('Date: ' + FormatDateTime('yyyy-mm-dd hh:nn:ss', MimeMess.Header.Date)); In that case extended UTF-8 characters are translated correctly too. Internally mime encoding is used, but first translating it to cp1252 and then to Utf-8 will loose characters. Letting it directly translate to utf-8 will fix that. ---------------------------------------------------------------------- paweld · 2023-10-03 08:48 @rvk Thank you very much. When sending an email, I always set the charset to UTF8, but I didn't think that when reading it, you have to too. That's the trick to solve the problem. ---------------------------------------------------------------------- Rebell · 2023-10-03 09:05 Quote from: paweld on October 03, 2023, 08:36:50 amWith me it finds messages without any problem, there is only a problem with decoding messages - there are ? instead of non-ascii characters.Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button8Click(Sender: TObject);var  imap: TIMAPSend;  MessageList, Message: TStringList;  MimeMess: TMimeMess;  i: Integer;begin  Memo1.Lines.Clear;  MessageList := TStringList.Create;  imap := TIMAPSend.Create;  imap.FullSSL := True;  imap.AutoTLS := True;  imap.Username := maillogin;  imap.Password := mailpasswd;  imap.TargetHost := mailhost;  imap.TargetPort := mailport;  if imap.Login then  begin    if imap.SelectFolder('INBOX') then    begin      if imap.SearchMess('SUBJECT "möglich"', MessageList) then      begin        Memo1.Lines.Add('Number of messages found: ' + IntToStr(MessageList.Count));        Memo1.Lines.Add('Mesaage list:');        Message := TStringList.Create;        MimeMess := TMimeMess.Create;        for i := 0 to MessageList.Count - 1 do      begin          Message.Clear;          imap.FetchMess(StrToInt(MessageList[i]), Message);          MimeMess.Lines.Text := Message.Text;          MimeMess.DecodeMessage;          Memo1.Lines.Add('---------');          Memo1.Lines.Add('Subject: ' + MimeMess.Header.Subject);          Memo1.Lines.Add('From: ' + MimeMess.Header.From);          Memo1.Lines.Add('Date: ' + FormatDateTime('yyyy-mm-dd hh:nn:ss', MimeMess.Header.Date));        end;        Message.Free;        MimeMess.Free;      end      else        ShowMessage('Message not found!')    end    else      ShowMessage('IMAP CHANGE FOLDER ERROR: ' + imap.ResultString);    imap.Logout;  end  else    ShowMessage('IMAP LOGIN ERROR: ' + imap.ResultString);  imap.Free;  MessageList.Free;end;     Your code give me same results, Nothing found ( Maybe something in My Synapse version , but i tried few ones.. And now using the latest one from trunk. Can you share me your Synapse files please ? I will try ---------------------------------------------------------------------- rvk · 2023-10-03 09:08 Quote from: Rebell on October 03, 2023, 11:05:03 amYour code give me same results, Nothing found ( Maybe something in My Synapse version , but i tried few ones.. And now using the latest one from trunk. Can you share me your Synapse files please ? I will try I've just used the synapse 40.1 from the Online Package Manager in Lazarus. It could also be that you imap server is configured differently. What happens if you just use "lich" as search term? Does it find something? And if it does, how is the encoding you get back (if you look in the debugger)? ---------------------------------------------------------------------- Rebell · 2023-10-03 09:24 Quote from: rvk on October 03, 2023, 11:08:10 amQuote from: Rebell on October 03, 2023, 11:05:03 amYour code give me same results, Nothing found ( Maybe something in My Synapse version , but i tried few ones.. And now using the latest one from trunk. Can you share me your Synapse files please ? I will try I've just used the synapse 40.1 from the Online Package Manager in Lazarus. It could also be that you imap server is configured differently. What happens if you just use "lich" as search term? Does it find something? And if it does, how is the encoding you get back (if you look in the debugger)? Yes, it finds.. It do not find only when special chars in request. Moreover, i see that it change this chars in requests in anyway... "ü" it change to "u" "ß" it change to "?" ---------------------------------------------------------------------- Rebell · 2023-10-03 09:28 So i think trouble on my side, on Synapse side, that Synapse cant send normal request in UTF-8 ---------------------------------------------------------------------- rvk · 2023-10-03 09:29 Quote from: Rebell on October 03, 2023, 11:24:43 amMoreover, i see that it change this chars in requests in anyway... "ü" it change to "u" "ß" it change to "?" Yeah, then it's not going to find anything  What version of Lazarus and OS are you using? If I look in Synapse I don't see it is changing the UTF-8 characters anywhere. Not in TIMAPSend.SearchMess and not in SendString. Quote from: Rebell on October 03, 2023, 11:28:26 amSo i think trouble on my side, on Synapse side, that Synapse cant send normal request in UTF-8 For us it does (same version). So my guess is that it is your Lazarus version. ---------------------------------------------------------------------- Rebell · 2023-10-03 09:33 Quote from: rvk on October 03, 2023, 11:29:10 amQuote from: Rebell on October 03, 2023, 11:24:43 amMoreover, i see that it change this chars in requests in anyway... "ü" it change to "u" "ß" it change to "?" Yeah, then it's not going to find anything  What version of Lazarus and OS are you using? If I look in Synapse I don't see it is changing the UTF-8 characters anywhere. Not in TIMAPSend.SearchMess and not in SendString. Quote from: Rebell on October 03, 2023, 11:28:26 amSo i think trouble on my side, on Synapse side, that Synapse cant send normal request in UTF-8 For us it does (same version). So my guess is that it is your Lazarus version. I'm using Rad Studio 11 ---------------------------------------------------------------------- rvk · 2023-10-03 09:39 Quote from: Rebell on October 03, 2023, 11:33:05 amI'm using Rad Studio 11 That's Delphi  You are on a Lazarus/FPC forum here  Delphi doesn't do UTF-8. It does unicode/widestring/UTF-16 or something. ---------------------------------------------------------------------- Rebell · 2023-10-03 09:49 Understand. Thank you very much ! I will continue my search ) ---------------------------------------------------------------------- rvk · 2023-10-03 09:58 In TIMAPSend.IMAPcommand there is a call to FSock.SendString. In FSock.SendString it expects an AnsiString. For Lazarus/FPC this can contain a UTF-8 string and it will send it just fine. For Delphi (in which Value is a Unicodestring/Widestring, so 2 bytes per char) it will convert automatically to ansistring (NOT UTF-8) where you will loose characters. You might want to try to convert to utf-8 before the call but I'm not sure how imapsend.pas will handle that (because there it is still a "string"). You can also hack imapsend.pas TIMAPSend.IMAPcommand to convert the value there from unicode to utf-8 in the expected ansistring. ---------------------------------------------------------------------- rvk · 2023-10-03 10:16 I've just tried this in Delphi and it seems to work: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  S: AnsiString;//...  S := Utf8Encode('┴'); // upside T  if imap.SearchMess('SUBJECT "' +S + '"', MessageList) then So converting your Widestring to a UTF-8 in AnsiString and passing it back to SearchMess should work. (The AnsiString is again translated to Widestring, but the characters stay in the 255 range and are passed as such to the AnsiString again in SendString.) ---------------------------------------------------------------------- Rebell · 2023-10-03 10:24 Quote from: rvk on October 03, 2023, 12:16:34 pmI've just tried this in Delphi and it seems to work: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  S: AnsiString;//...  S := Utf8Encode('┴'); // upside T  if imap.SearchMess('SUBJECT "' +S + '"', MessageList) then So converting your Widestring to a UTF-8 in AnsiString and passing it back to SearchMess should work. (The AnsiString is again translated to Widestring, but the characters stay in the 255 range and are passed as such to the AnsiString again in SendString.) Uhuhuh ! It works ! Thank you so much !