Collapse numbered re/fwd

pull/194/merge
M66B 3 years ago
parent e8487db1ff
commit d94c662870

@ -48,6 +48,8 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.mail.Address; import javax.mail.Address;
import javax.mail.internet.InternetAddress; import javax.mail.internet.InternetAddress;
@ -329,19 +331,27 @@ public class EntityMessage implements Serializable {
for (String fwd : Helper.getStrings(context, language, R.string.title_subject_forward_alt, "")) for (String fwd : Helper.getStrings(context, language, R.string.title_subject_forward_alt, ""))
prefixes.add(new Pair<>(fwd.trim().toLowerCase(), true)); prefixes.add(new Pair<>(fwd.trim().toLowerCase(), true));
String counts = "((\\[\\d+\\])|(\\(\\d+\\)))?";
List<Boolean> scanned = new ArrayList<>(); List<Boolean> scanned = new ArrayList<>();
subject = subject.trim(); subject = subject.trim();
while (true) { while (true) {
boolean found = false; boolean found = false;
for (Pair<String, Boolean> prefix : prefixes) for (Pair<String, Boolean> prefix : prefixes) {
if (subject.toLowerCase().startsWith(prefix.first)) { String pre = prefix.first.endsWith(":")
? "(^" + Pattern.quote(prefix.first.substring(0, prefix.first.length() - 1)) + counts + ":)"
: "(^" + Pattern.quote(prefix.first) + ")";
Pattern p = Pattern.compile(pre + "(\\s*)(.*)", Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(subject);
if (m.matches()) {
found = true; found = true;
int count = scanned.size(); int count = scanned.size();
if (!prefix.second.equals(count == 0 ? forward : scanned.get(count - 1))) if (!prefix.second.equals(count == 0 ? forward : scanned.get(count - 1)))
scanned.add(prefix.second); scanned.add(prefix.second);
subject = subject.substring(prefix.first.length()).trim(); subject = m.group(m.groupCount());
break; break;
} }
}
if (!found) if (!found)
break; break;
} }

Loading…
Cancel
Save