I am using gmail api to get latest messages. Unfortunately while fetching messages, it is also chaining previous message chain to the bottom. I want to prevent or remove that. Is there a way to do this?
Message message = service.users().messages().get(user, messageId).setFormat("raw").execute();
getAttachments(service, user, messageId);
Base64 base64Url = new Base64(true);
byte[] emailBytes = base64Url.decodeBase64(message.getRaw());
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
MimeMessage email = new MimeMessage(session, new ByteArrayInputStream(emailBytes));
MimeMessageParser parser = new MimeMessageParser(email); //org.apache.commons.mail.util
parser.parse();
String content = parser.getHtmlContent();
How do we remove this chain that you see above?
Can the api only return current message without returning the entire chain?
One solution I found was that we can remove div with class name gmail_quote from parsed data but this seems less than ideal solution.
<div dir="auto">Current Content<div dir="auto"><br></div></div><br>
<!--
Below html content can be removed to hide chain
-->
<div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 26 Aug 2020, 10:26 pm Ranju Machhi, <<a href="mailto:test@gmail.com">test@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">Previous Content</div><div dir="auto"><br></div><div dir="auto"><br></div>
</blockquote></div>