gpt4 book ai didi

java - 如何在没有完整源代码的情况下获取邮件内容?

转载 作者:行者123 更新时间:2023-12-01 13:11:03 27 4
gpt4 key购买 nike

我用 javax 读了一些邮件。
然后我想保存消息的内容。

例如,我读了一封内容简单的邮件By: Test
现在我使用 .getContent() 方法读取内容:

Object body = message.getContent();
String content = ((body instanceof String) ? (String) body : "NO STRING CONTENT");

但这里的问题是,By: Test 的简单电子邮件内容由邮件的整个 Outlook 源代码显示:

<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.E-MailFormatvorlage17
{mso-style-type:personal-compose;
font-family:"Arial","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="DE-CH" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">By: Test<o:p></o:p></span></p>
</div>
</body>
</html>

那么如何在不获取整个邮件源代码的情况下读出邮件内容呢?

最佳答案

首先,我将首先提取 <body> 中的内容String 部分。之后,这取决于您的喜好,但您可以删除每个 HTML例如,-tag,但要注意任何格式(换行符!)代码都消失了,您只能得到一大块文本。

关于java - 如何在没有完整源代码的情况下获取邮件内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22866881/

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