我使用EWS Java API 1.2從服務器獲取電子郵件。我有一個問題: 我使用性質是這樣的:EWS Java API 1.2 - 解析letter體的最佳方式
PropertySet itemPropertySet = new PropertySet(BasePropertySet.FirstClassProperties);
itemPropertySet.setRequestedBodyType(BodyType.Text);
...
String body = message.getBody().toString();
在這個例子中,我得到的身體爲純文本。但我需要保存正文的格式(例如空行)。當我使用BodyType.HTML時,我得到所有的html標籤,css樣式等。 什麼是通過保存格式和排除html標籤,css樣式等來獲得消息正文的最佳方式。 感謝您的回覆!
更新我的解決方案: 我已停止在this variant。我的問題是在空行,所以現在我在明年函數處理BR和P標籤:
public void handleStartTag(Tag t, MutableAttributeSet a, int pos) //To handle Tag.BODY
public void handleSimpleTag(Tag t, MutableAttributeSet a, int pos) //To handle Tag.BR and adding '\n'
public void handleEndTag(Tag t, int pos) //To handle Tag.P (and adding '\n') and Tag.BODY
public void handleText(char[] data, int pos)
[鏈接](http://stackoverflow.com/questions/18125685/how-do-i-convert-a-formatted-email-into-plain-text-in-java) –