1

My server (nodejs) receives incoming email in html. Something like this

<div>
I am reply

<div>
On wed 20 <a href="mailto:nn@ni.com">nn@ni.com</a> wrote 
<blockquote>
This is first message
</blockquote>
</div>

</div>

How do I identify the content to be trimmed in that HTML ? Any suggestions would be really helpfull

Nikhil Ponduri
  • 409
  • 9
  • 28
  • There are lots of hide/show answers - does this help? https://stackoverflow.com/questions/4528085/toggle-show-hide-div-with-button – Nathan Dec 28 '20 at 23:32
  • @Nathan I can do hiding and showing But I need a way to find out which content to be trimmed – Nikhil Ponduri Dec 29 '20 at 02:47
  • Did the question change or something? I'm still not sure what you are asking. What's your purpose here, because you could 'trim' anything you want really. – Nathan Dec 29 '20 at 22:57
  • @Nathan The point is how I am going to identify the content that needs to be trimmed. In the above html ```I am reply``` is original message and ```This is first message``` is the previous message that is attached to the current message. So I need to trim the previous messages from the incoming html and show only the reply. How I can achieve this – Nikhil Ponduri Dec 30 '20 at 07:32
  • So you want `div > div` (the direct descendent of the reply div)? I'm not confident regex would be able to parse that, so you might have to consider a headless browser on the server as this answer explains: https://stackoverflow.com/questions/34309557/how-to-access-dom-using-node-js – Nathan Dec 30 '20 at 22:51
  • @NikhilPonduri Have you achieved this? – Bhavin Bhadani Jun 24 '21 at 08:00
  • @NikhilPonduri were you able to achieve this? – Muhammad Abu Bakr Sep 05 '22 at 15:17
  • @MuhammadAbuBakr No. There is no proper way to do this. We just identified the previous message content in the incoming message and marked all the content from that DOM element of HTML as trimmed content – Nikhil Ponduri Sep 06 '22 at 10:28

0 Answers0