gpt4 book ai didi

java - 如何在 Java 中将格式化电子邮件转换为纯文本?

转载 作者:太空宇宙 更新时间:2023-11-04 07:28:40 25 4
gpt4 key购买 nike

我有一个程序,可以将电子邮件作为短信转发给客户。

现在,对邮件正文中写入文本“420”的电子邮件的简单回复将转换为

*

<div dir="ltr">420</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Aug 8, 2013 at 4:14 PM, <span dir="ltr">&lt; 3:50 AM+11111111111: (2/6)<a href="mailto:xxxxxx@gmail.com" target="_blank">xxxxxx@gmail.com</a>&gt;</span> wrote:<br> <blockquote class="gmail_quot 3:50 AM +14411111111: (3/6)e" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">414<div class="HOEnZb"><div class="h5"><br>DO_NOT_REPLY:This i 3:50 AM
: (4/6)s an email notification that you have received a text message from a customer in . If you reply to this email, a text message or 3:50 AM
(5/6)email message will NOT go to the customer. Access the customer text message to send a reply. </div></div></blockquote></div> 3:50 AM
(6/6)<br></div>

*

如何删除文本中的所有格式并仅转发邮件正文?

最佳答案

我建议使用 JSoup 。它使得从 html 中提取文本变得非常容易。一个简单的例子如下。

Document doc = Jsoup.parse("My scores are <strong>good</strong> in <date>2013</date>"); 
String text = doc.body().text();
System.out.println(text);

这会打印

My scores are good in 2013.

关于java - 如何在 Java 中将格式化电子邮件转换为纯文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18125685/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com