B4J Question Wrong Format Message Body In Email Server

Hello All
I use EmailServer for get new emails from email but message body will be in wrong format if the message is Persian.

The correct format should be like this :

<div style="line-height:2.5!important;font:normal 10pt tahoma;direction:rtl"><div class="adM">
</div><span style="font-weight:bold;color:#9e2558"> با سلام </span>
<br><b>قیمت 0075 Bandar - پلی اتیلن سبک فیلم 0075 بندر امام</b>، در تاریخ دوشنبه ۱۷ شهریور ۱۳۹۹ ۱۲:۱۵ به روز رسانی شد.<br> <b>آخرین قیمت: 228,000 ریال</b><br><a href="https://wkpl.ir/mp59" style="font-weight:bold;color:#9e2558;text-decoration:none" target="_blank" data-saferedirecturl="https://www.google.com/url?q=https://wkpl.ir/mp59&amp;source=gmail&amp;ust=1599553157782000&amp;usg=AFQjCNH8RGJk6yv8OpjPZ6cf8IpvDQZy8g">برای مشاهده نمودار قیمت این گرید اینجا کلیک کنید</a><br><a href="https://wkpl.ir/g59" style="font-weight:bold;color:#9e2558;text-decoration:none" target="_blank" data-saferedirecturl="https://www.google.com/url?q=https://wkpl.ir/g59&amp;source=gmail&amp;ust=1599553157782000&amp;usg=AFQjCNFcoFUXnkbO5XS9uNUGKK5JBoQ0jQ">برای مشاهده صفحه اختصاصی این گرید اینجا کلیک کنید</a><br><a href="https://wikiplast.ir/prices" style="font-weight:bold;color:#9e2558;text-decoration:none" target="_blank" data-saferedirecturl="https://www.google.com/url?q=https://wikiplast.ir/prices&amp;source=gmail&amp;ust=1599553157782000&amp;usg=AFQjCNHsUfhHqGuinSJVOYt0bSIQWRol0g">برای مشاهده آرشیو قیمت ها اینجا کلیک کنید</a><br> با احترام</div>
But Message will be like this :

<br/><b>ÙÛÙت 020 Bandar - Ù¾ÙÛ Ø§ØªÛÙ٠سبک ÙÛÙÙ 020 بÙدراÙاÙ</b>Ø Ø¯Ø± تارÛØ® دÙØ´Ùب٠۱۷ Ø´ÙرÛÙر Û±Û³Û¹Û¹ Û±Û²:Û±Û¶ ب٠رÙز رساÙÛ Ø´Ø¯.<br /> <b>آخرÛÙ ÙÛÙت: 225,000 رÛاÙ</b><br /><a href='https://wkpl.ir/mp78' style='font-weight:bold;color:#9E2558;text-decoration:none;'>Ø¨Ø±Ø§Û ÙشاÙد٠ÙÙÙدار ÙÛÙت اÛ٠گرÛد اÛÙجا Ú©ÙÛÚ© Ú©ÙÛد</a><br/><a href='https://wkpl.ir/g78' style='font-weight:bold;color:#9E2558;text-decoration:none;'>Ø¨Ø±Ø§Û ÙشاÙد٠صÙØÙ Ø§Ø®ØªØµØ§ØµÛ Ø§Û٠گرÛد اÛÙجا Ú©ÙÛÚ© Ú©ÙÛد</a><br/><a href='https://wikiplast.ir/prices' style='font-weight:bold;color:#9E2558;text-decoration:none;'>Ø¨Ø±Ø§Û ÙشاÙد٠آرشÛÙ ÙÛÙت Ùا اÛÙجا Ú©ÙÛÚ© Ú©ÙÛد</a><br /> با اØتراÙ</div>
 

behnam_tr

Active Member
Licensed User
Longtime User
check this :

B4X:
dim su as stringutils
dim st as string
st = su.EncodeUrl(your string, "UTF8")
log(s)

lib : jstringutils
 
Upvote 0
I don't send the emails.
Actually somebody sends some emails to my gmail daily and i wanna download that emails and analyze them.
Also they contains Persian text.
Now What should I do?
 
Upvote 0
Don't use MailParser. What is the output of Log(Message) in DownloadCompleted event?

Delivered-To: [email protected]
Received: by 2002:a9d:8a7:0:0:0:0:0 with SMTP id 36csp3255119otf;
Mon, 7 Sep 2020 00:46:27 -0700 (PDT)
X-Google-Smtp-Source: ABdhPJyAewZimU5wgBbibes3hJyX56xSzviMrQWiMGyhpMlg9oYIpLyCbOHyRDMkMGfJLyEHg932
X-Received: by 2002:a7b:c1d3:: with SMTP id a19mr13318356wmj.19.1599464787054;
Mon, 07 Sep 2020 00:46:27 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1599464787; cv=none;
d=google.com; s=arc-20160816;
b=QNqpfWmRoIYA8E4M608oPuR7Wc9WlztoqAuvRGOgEwUt5InrY89seCsrQYttpaxmPJ
1PNy0nXGYzjcUY1jmbHuWf26YjVZSryxkM2dE836A1Zg28FIC2X0BQ8R4enXkq1SqrZX
wl2s6xXZ0do5zGk8Z2v1M9FYKBrzGPyozwsPPdDeJk6W60BRgORI18dFqq+9zaZeadjf
r9NP1/nSXk0aY6cGSwCLPX4/O8mlfrWPcAMplYSCheqqNpfoIoT17AXGf+1bSUGIGWb7
tfLSTAIygwzN6WJg+Y4a62ihB1nSv7wYDd3GURa1kMvtNq8RK+Ai5a1wMgucKeUPiiCh
h3kw==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
h=mime-version:message-id:subject:reply-to:from:to:date
:dkim-signature;
bh=7rny+2GEt+nSE+mcI94FkqkWSNw2vqvJRjsLYsITXNk=;
b=b8afPhAmb8EP+eVgtCLAZuFf9y9ZnXHcm6nvcKOtls5dW0nDDMeys7Id9HTAFBDKec
Z4Kirqvajz0Bn6u7R6BPMtrKUL6YGDe/iB67AyAyjmOCJv3Ygz3n/iOMrpE1f7hS8bRo
jLYA+sGFvHNlR+sM9hf8neY0cyGMyqaAe3/Ls6o6cusU/N5zyhUnQ8c6bU89OBTY2W8U
hDSrRurf/AnMq2KDKYHwtaBRlMWpiKsvA0jl28HjIovTFk+ybqOnhJdlFFP+bqGTJ7Gm
OJ32FL8LSAoDwGactQLTO2onMcBZl0x6V138dtIeJQ5RvFpsTt6DKzKbB8MNx1heocUN
gHmw==
ARC-Authentication-Results: i=1; mx.google.com;
dkim=pass [email protected] header.s=default header.b="C8/OaLZ7";
spf=pass (google.com: domain of [email protected] designates 87.236.210.127 as permitted sender) smtp.mailfrom=[email protected]
Return-Path: <[email protected]>
Received: from pvir127.mizbanwp.com ([87.236.210.127])
by mx.google.com with ESMTPS id 32si10555808wri.480.2020.09.07.00.46.26
(version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
Mon, 07 Sep 2020 00:46:26 -0700 (PDT)
Received-SPF: pass (google.com: domain of [email protected] designates 87.236.210.127 as permitted sender) client-ip=87.236.210.127;
Authentication-Results: mx.google.com;
dkim=pass [email protected] header.s=default header.b="C8/OaLZ7";
spf=pass (google.com: domain of [email protected] designates 87.236.210.127 as permitted sender) smtp.mailfrom=[email protected]
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
d=wikiplast.ir; s=default; h=Content-Type:MIME-Version:Message-ID:Subject:
Reply-To:From:To:Date:Sender:Cc:Content-Transfer-Encoding:Content-ID:
Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc
:Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:
List-Subscribe:List-Post:List-Owner:List-Archive;
bh=7rny+2GEt+nSE+mcI94FkqkWSNw2vqvJRjsLYsITXNk=; b=C8/OaLZ7nDAngtBfb7+EmVJmy8
8Zju7ICTbBUG21Sk/+zKaTniF4Iir9+SCTl5K4iwtR5ODaHzRZI37IhOwUZzNXeoi8r3Is5Z0TJBP
TkPvfJe4UajhIKnF5+MXKkzujBPbsa55C3xA7inLhpdoeCdmahhOotsmrKhjNia176zTfEC1GMd+v
c1soo8Ke8yzQcfVUWeZhTIpsOkTwzzFtqckC2gOdTSVDIYiyC3VERIx+q9kguYnpcFeqSdxQRxByi
r3fgev4PWwJ/EysU37onEUYmos2Zu14fQObHuM2GVHWJLGtbw/zhRvT333J8GvBGkSeeN0D9oBskc
4hbEzoTA==;
Received: from [::1] (port=37564 helo=wikiplast.ir)
by pvir127.mizbanwp.com with esmtpa (Exim 4.93)
(envelope-from <[email protected]>)
id 1kFBr0-0003Bs-F8; Mon, 07 Sep 2020 12:16:18 +0430
Date: Mon, 7 Sep 2020 12:16:18 +0430
To: =?UTF-8?B?2YjbjNqp24wg2b7ZhNin2LPYqg==?= <[email protected]>
From: =?UTF-8?B?2YjbjNqp24wg2b7ZhNin2LPYqg==?= <[email protected]>
Reply-To: =?UTF-8?B?2YjbjNqp24wg2b7ZhNin2LPYqg==?= <[email protected]>
Subject: =?UTF-8?B?2KjZhyDYsdmI2LIg2LHYs9in2YbbjCDZgtuM2YXYqiDar9ix24zYryAyNDIw?=
=?UTF-8?B?RTAyLWtvcmRlc3RhbiAtINm+2YTbjCDYp9iq24zZhNmGINiz2KjaqQ==?=
=?UTF-8?B?INmB24zZhNmFIDI0MjBFMDIg2qnYsdiv2LPYqtin2YYg2K/YsSDYqtin2LE=?=
=?UTF-8?B?24zYriDYr9mI2LTZhtio2Ycg27HbtyDYtNmH2LHbjNmI2LEg27Hbs9u527kg?=
=?UTF-8?B?27Hbsjrbsdu2?=
Message-ID: <[email protected]>
X-Priority: 3
X-Mailer: PHPMailer 5.2.1 (http://code.google.com/a/apache-extras.org/p/phpmailer/)
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="b1_5580b6a8d445e4f3a3a4da4f2b3ff94c"
X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
X-AntiAbuse: Primary Hostname - pvir127.mizbanwp.com
X-AntiAbuse: Original Domain - gmail.com
X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse: Sender Address Domain - wikiplast.ir
X-Get-Message-Sender-Via: pvir127.mizbanwp.com: authenticated_id: [email protected]
X-Authenticated-Sender: pvir127.mizbanwp.com: [email protected]
X-Source:
X-Source-Args:
X-Source-Dir:
X-From-Rewrite: unmodified, already matched
--b1_5580b6a8d445e4f3a3a4da4f2b3ff94c
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8bit
برÙاÙÙ Ø´Ùا از اÛ٠اÛÙÛ٠پشتÛباÙÛ ÙÙÛ Ú©ÙØ¯Ø Ø¨Ø±Ø§Û Ø¯Ûد٠آÙØ ÙØ·Ùا از برÙاÙ٠دÛÚ¯Ø±Û Ø§Ø³ØªÙاد٠ÙÙائÛد
--b1_5580b6a8d445e4f3a3a4da4f2b3ff94c
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: 8bit
<div style='line-height:2.5 !important;font:normal 10pt tahoma;direction:rtl;'>
<span style='font-weight:bold;color:#9E2558;'> با سÙا٠</span>
<br/><b>ÙÛÙت 2420E02-kordestan - Ù¾ÙÛ Ø§ØªÛÙ٠سبک ÙÛÙÙ 2420E02 کردستاÙ</b>Ø Ø¯Ø± تارÛØ® دÙØ´Ùب٠۱۷ Ø´ÙرÛÙر Û±Û³Û¹Û¹ Û±Û²:Û±Û¶ ب٠رÙز رساÙÛ Ø´Ø¯.<br /> <b>آخرÛÙ ÙÛÙت: 216,000 رÛاÙ</b><br /><a href='https://wkpl.ir/mp277' style='font-weight:bold;color:#9E2558;text-decoration:none;'>Ø¨Ø±Ø§Û ÙشاÙد٠ÙÙÙدار ÙÛÙت اÛ٠گرÛد اÛÙجا Ú©ÙÛÚ© Ú©ÙÛد</a><br/><a href='https://wkpl.ir/g277' style='font-weight:bold;color:#9E2558;text-decoration:none;'>Ø¨Ø±Ø§Û ÙشاÙد٠صÙØÙ Ø§Ø®ØªØµØ§ØµÛ Ø§Û٠گرÛد اÛÙجا Ú©ÙÛÚ© Ú©ÙÛد</a><br/><a href='https://wikiplast.ir/prices' style='font-weight:bold;color:#9E2558;text-decoration:none;'>Ø¨Ø±Ø§Û ÙشاÙد٠آرشÛÙ ÙÛÙت Ùا اÛÙجا Ú©ÙÛÚ© Ú©ÙÛد</a><br /> با اØتراÙ</div>
--b1_5580b6a8d445e4f3a3a4da4f2b3ff94c--

It's the MessageText in DownloadCompleted event
 
Upvote 0
Try this untested code:
B4X:
Dim r As Reflector
r.Target = POP3 'your object
Dim client As JavaObject = r.GetField("client")
client.SetField("encoding", "UTF8")
I tested this and write it just after initializing the pop and before the pop.DownloadMessage(id, False) and in the DownloadCompleted event but it gave Error in every condition :

Waiting for debugger to connect...
Program started.
Checking mails
java.lang.NoClassDefFoundError: javafx/event/EventHandler
at b4j.example.main._mailtimer_tick(main.java:108)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
at b4j.example.main.main(main.java:29)
Caused by: java.lang.ClassNotFoundException: javafx.event.EventHandler
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 16 more
java.lang.RuntimeException: java.lang.NoClassDefFoundError: javafx/event/EventHandler
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:120)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
at b4j.example.main.main(main.java:29)
Caused by: java.lang.NoClassDefFoundError: javafx/event/EventHandler
at b4j.example.main._mailtimer_tick(main.java:108)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
... 3 more
Caused by: java.lang.ClassNotFoundException: javafx.event.EventHandler
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 16 more
Program terminated (StartMessageLoop was not called).
 
Last edited:
Upvote 0

MicroDrie

Well-Known Member
Licensed User
but message body will be in wrong format if the message is Persian.
Unfortunately, I do not speak the Persian language. That makes reading the text incomprehensible to me. What strikes me is that the involved email clients use all kinds of encrypting protocols. The site concerned appears to offer a variety of products. The text message may be encrypted. The question is what happens if you send a message to the email server yourself? If that is readable, your program is correct, but cannot read the encrypted message.
 
Upvote 0
Unfortunately, I do not speak the Persian language. That makes reading the text incomprehensible to me. What strikes me is that the involved email clients use all kinds of encrypting protocols. The site concerned appears to offer a variety of products. The text message may be encrypted. The question is what happens if you send a message to the email server yourself? If that is readable, your program is correct, but cannot read the encrypted message.

Hello MicroDrie and thanks for your answer

I tested what you said and when I send my own persian text to email it will good in the email and its format doesn't change So I thought if I send the wrong format text to email it will convert to correct format but when i send , it didn't change and stayed in wrong format.

So according to your answer my program is correct and message (Not wrong format text) will be readable if i send it to email
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top