package com.kescoode.xmail.domain.internal; import com.fsck.k9.mail.Part; import java.util.List; /** * {@link com.kescoode.xmail.domain.LocalEmail}对应的页面显示逻辑对象 * * @author Kesco Lin */ public class UiMessageContent { public final String text; public final String html; public final List<Part> attachments; public UiMessageContent(String text, String html, List<Part> attachments) { this.text = text; this.html = html; this.attachments = attachments; } public String calculateContentPreview(String text) { if (text == null) { return null; } // Only look at the first 8k of a message when calculating // the preview. This should avoid unnecessary // memory usage on large messages if (text.length() > 8192) { text = text.substring(0, 8192); } // Remove (correctly delimited by '-- \n') signatures text = text.replaceAll("(?ms)^-- [\\r\\n]+.*", ""); // try to remove lines of dashes in the preview text = text.replaceAll("(?m)^----.*?$", ""); // remove quoted text from the preview text = text.replaceAll("(?m)^[#>].*$", ""); // Remove a common quote header from the preview text = text.replaceAll("(?m)^On .*wrote.?$", ""); // Remove a more generic quote header from the preview text = text.replaceAll("(?m)^.*\\w+:$", ""); // Remove horizontal rules. text = text.replaceAll("\\s*([-=_]{30,}+)\\s*", " "); // URLs in the preview should just be shown as "..." - They're not // clickable and they usually overwhelm the preview text = text.replaceAll("https?://\\S+", "..."); // Don't show newlines in the preview text = text.replaceAll("(\\r|\\n)+", " "); // Collapse whitespace in the preview text = text.replaceAll("\\s+", " "); // Remove any whitespace at the beginning and end of the string. text = text.trim(); return (text.length() <= 512) ? text : text.substring(0, 512); } }