From a5019812fbdaf57096b8483778b610fd3b0d1887 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Thu, 21 Feb 2019 19:45:12 +0100 Subject: show file too large instead of generic delivery failed --- .../de/pixart/messenger/parser/AbstractParser.java | 34 ++++++++++++++++++---- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'src/main/java/de/pixart/messenger/parser/AbstractParser.java') diff --git a/src/main/java/de/pixart/messenger/parser/AbstractParser.java b/src/main/java/de/pixart/messenger/parser/AbstractParser.java index e0a26c18d..0b94102a5 100644 --- a/src/main/java/de/pixart/messenger/parser/AbstractParser.java +++ b/src/main/java/de/pixart/messenger/parser/AbstractParser.java @@ -2,6 +2,8 @@ package de.pixart.messenger.parser; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; import java.util.Locale; import de.pixart.messenger.entities.Account; @@ -126,14 +128,36 @@ public abstract class AbstractParser { public static String extractErrorMessage(Element packet) { final Element error = packet.findChild("error"); if (error != null && error.getChildren().size() > 0) { + final List errorNames = orderedElementNames(error.getChildren()); final String text = error.findChildContent("text"); if (text != null && !text.trim().isEmpty()) { - return text; - } else { - return error.getChildren().get(0).getName().replace("-", " "); + return prefixError(errorNames) + text; + } else if (errorNames.size() > 0) { + return prefixError(errorNames) + errorNames.get(0).replace("-", " "); + } + } + return null; + } + + private static String prefixError(List errorNames) { + if (errorNames.size() > 0) { + return errorNames.get(0) + '\u001f'; + } + return ""; + } + + private static List orderedElementNames(List children) { + List names = new ArrayList<>(); + for (Element child : children) { + final String name = child.getName(); + if (name != null && !name.equals("text")) { + if ("urn:ietf:params:xml:ns:xmpp-stanzas".equals(child.getNamespace())) { + names.add(name); + } else { + names.add(0, name); + } } - } else { - return null; } + return names; } } -- cgit v1.2.3