Delete everything after first signature header

pull/162/head
M66B 5 years ago
parent cc6baa172f
commit 11a1f29ad0

@ -114,6 +114,8 @@ import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node; import org.jsoup.nodes.Node;
import org.jsoup.nodes.TextNode; import org.jsoup.nodes.TextNode;
import org.jsoup.select.NodeTraversor;
import org.jsoup.select.NodeVisitor;
import org.openintents.openpgp.OpenPgpError; import org.openintents.openpgp.OpenPgpError;
import org.openintents.openpgp.util.OpenPgpApi; import org.openintents.openpgp.util.OpenPgpApi;
import org.openintents.openpgp.util.OpenPgpServiceConnection; import org.openintents.openpgp.util.OpenPgpServiceConnection;
@ -2235,30 +2237,31 @@ public class FragmentCompose extends FragmentBase {
if (usenet) { if (usenet) {
Document rdoc = Jsoup.parse(refText); Document rdoc = Jsoup.parse(refText);
Node signature = null; List<Node> tbd = new ArrayList<>();
for (Element e : rdoc.select("*"))
for (Node node : e.childNodes()) NodeTraversor.traverse(new NodeVisitor() {
boolean found = false;
public void head(Node node, int depth) {
if (node instanceof TextNode && if (node instanceof TextNode &&
"--".equals(((TextNode) node).text().trim()) && "-- ".equals(((TextNode) node).getWholeText()) &&
node.nextSibling() != null && node.nextSibling() != null &&
"br".equals(node.nextSibling().nodeName())) "br".equals(node.nextSibling().nodeName()))
signature = node; found = true;
if (found)
if (signature != null) { tbd.add(node);
List<Node> tbd = new ArrayList<>(); }
tbd.add(signature);
Node next = signature.nextSibling(); public void tail(Node node, int depth) {
while (next != null) { // Do nothing
tbd.add(0, next);
next = next.nextSibling();
} }
}, rdoc);
for (Node n : tbd) if (tbd.size() > 0) {
n.remove(); for (Node node : tbd)
node.remove();
if (rdoc.body() != null) refText = (rdoc.body() == null ? "" : rdoc.body().html());
refText = rdoc.body().html();
} }
} }

Loading…
Cancel
Save