B4J Question Encode/Decode Quoted Printable

TomDuncan

Active Member
Licensed User
Longtime User
Hi All,
Is their an easy to to encode or decode Quoted printable data.
This is the body of an email.

Also with this body the body itself is being truncated.
This is how it ends ..
B4X:
</blockquote><blockquote type=3D"cite"><di

where this is what came in..
B4X:
<html><head><meta http-equiv=3D"content-type" content=3D"text/html; charset=3D=
utf-8"></head><body dir=3D"auto"><div>Check it out<br><br>Tom Duncan<div>Sen=
t from my iPad</div></div><div><br>Begin forwarded message:<br><br></div><bl=
ockquote type=3D"cite"><div><b>From:</b> "Google+" &lt;<a href=3D"mailto:nor=
[email protected]">[email protected]</a>&gt;<br><=
b>Date:</b> 15 September 2015 at 9:32:48 PM AEST<br><b>To:</b> <a href=3D"ma=
ilto:[email protected]">[email protected]</a><br><b>Subject:</b> <b>=
Top Google+ Pages suggested for you</b><br><b>Reply-To:</b> "Google+" &lt;<a=
href=3D"mailto:[email protected]">[email protected]=
le.com</a>&gt;<br><br></div></blockquote><blockquote type=3D"cite"><div><!--=
X-Notifications: 1:2cc647e12f000000 --><div style=3D"padding:10px 0;"><tabl=
e style=3D"width:100%" cellpadding=3D"0" cellspacing=3D"0"><tbody><tr><td><a=
href=3D"https://plus.google.com/_/notifications/emlink?emr=3D01313702348586=
381093&amp;emid=3DCIDG_tT4-McCFdOYjAodtJMN9g&amp;path=3D%2Fstream&amp;dt=3D1=

part of it anyway..

Tom
 
Last edited:

Daestrum

Expert
Licensed User
Longtime User
Did you just want it in clean html code ?
<body>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<div>
Check it out
<br>
<br>Tom Duncan
<div>
Sent from my iPad
</div>
</div>
<div>
<br>Begin forwarded message:
<br>
<br>
</div>
<blockquote type="cite">
<div>
<b>From:</b> "Google+"
<a href="mailto:[email protected]">[email protected]</a>
<br>
<b>Date:</b> 15 September 2015 at 9:32:48 PM AEST
<br>
<b>To:</b>
<a href="mailto:***********@gmail.com">***********@gmail.com</a>
<br>
<b>Subject:</b>
<b>Top Google+ Pages suggested for you</b>
<br>
 
Last edited:
Upvote 0

TomDuncan

Active Member
Licensed User
Longtime User
Yes, exactly.
To Display an email in html format.
It does have funny "=" and 3D bits as well.
However, I think their is an error in the mail parse routine which is chopping off the tail of the body.
Might have to ask another question for that.
It is used in the pop email handling.
Tom
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
To clean up the data I just used
B4X:
Dim outstring As String = ""
outstring = s.Replace("="&Chr(10),"").Replace("=3D","=")
outstring = outstring.Replace("&lt;","").Replace("&gt;","").Replace("&amp;","&")
outstring = outstring.Replace("%2F","/").Replace("ahref","a href")
Where s is the input string.
I then used 'jSoup' (from jsoup.org) to parse it into a readable format. (it can also search the document for elements)
B4X:
#if java
import org.jsoup.Jsoup;
import org.jsoup.helper.Validate;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public static String decode(String s){
  Document doc = Jsoup.parseBodyFragment(s);
  Element body = doc.body();
  return body.toString();
}
#end if
 
Last edited:
Upvote 0

TomDuncan

Active Member
Licensed User
Longtime User
That looks nice and easy, thanks will test in the morning.
The code came from the b4j mail program.
It was an e-mail that came to me and looked difficult to parse.

So with jsoup if I used the entire email and used that to grab the body?
Tom
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Yes, or you can specify which parts you want.
eg,
B4X:
// in java code
Element block = doc.select("blockquote[type=cite]).first();
return block.toString();
Will return the first blockquote with a type equal to 'cite'

The truncation could be caused by the buffer being too small if that's how it reads the data from the pop3 server.
 
Upvote 0
Top