@Test void testComplexExtraction() { assertThat(SearchUtil.getBaseSubject("Re: re:re: fwd:[fwd: \t Test] (fwd) (fwd)(fwd) ")).isEqualTo("Test"); }
public static String getBaseSubject(String subject) { String decodedSubject = MimeUtil.unfold(DecoderUtil.decodeEncodedWords(subject, DecodeMonitor.SILENT)); decodedSubject = new String(decodedSubject.getBytes(UTF8), UTF8); decodedSubject = decodedSubject.replaceAll("\t", " ").replaceAll("( ){2,}", " "); while (true) { int decodedSubjectLength = decodedSubject.length(); while (true) { String subj = removeSubTrailers(decodedSubject); if (decodedSubjectLength > subj.length()) { decodedSubject = subj; decodedSubjectLength = decodedSubject.length(); } else { break; } } while (true) { boolean matchedInner = false; decodedSubjectLength = decodedSubject.length(); decodedSubject = removeSubjLeaders(decodedSubject); if (decodedSubjectLength > decodedSubject.length()) { matchedInner = true; decodedSubjectLength = decodedSubject.length(); } decodedSubjectLength = decodedSubject.length(); String subj = removeBlob(decodedSubject); if (subj.length() > 0) { decodedSubject = subj; if (decodedSubjectLength > decodedSubject.length()) { matchedInner = true; decodedSubjectLength = decodedSubject.length(); } } if (!matchedInner) { break; } } String lowcaseSubject = decodedSubject.toLowerCase(Locale.US); if (lowcaseSubject.startsWith(SUBJ_FWD_HDR) && lowcaseSubject.endsWith(SUBJ_FWD_TRL)) { decodedSubject = decodedSubject.substring(SUBJ_FWD_HDR.length(), decodedSubject.length() - SUBJ_FWD_TRL.length()); decodedSubjectLength = decodedSubject.length(); } else { break; } } return decodedSubject; }
SearchUtil { public static String getBaseSubject(String subject) { String decodedSubject = MimeUtil.unfold(DecoderUtil.decodeEncodedWords(subject, DecodeMonitor.SILENT)); decodedSubject = new String(decodedSubject.getBytes(UTF8), UTF8); decodedSubject = decodedSubject.replaceAll("\t", " ").replaceAll("( ){2,}", " "); while (true) { int decodedSubjectLength = decodedSubject.length(); while (true) { String subj = removeSubTrailers(decodedSubject); if (decodedSubjectLength > subj.length()) { decodedSubject = subj; decodedSubjectLength = decodedSubject.length(); } else { break; } } while (true) { boolean matchedInner = false; decodedSubjectLength = decodedSubject.length(); decodedSubject = removeSubjLeaders(decodedSubject); if (decodedSubjectLength > decodedSubject.length()) { matchedInner = true; decodedSubjectLength = decodedSubject.length(); } decodedSubjectLength = decodedSubject.length(); String subj = removeBlob(decodedSubject); if (subj.length() > 0) { decodedSubject = subj; if (decodedSubjectLength > decodedSubject.length()) { matchedInner = true; decodedSubjectLength = decodedSubject.length(); } } if (!matchedInner) { break; } } String lowcaseSubject = decodedSubject.toLowerCase(Locale.US); if (lowcaseSubject.startsWith(SUBJ_FWD_HDR) && lowcaseSubject.endsWith(SUBJ_FWD_TRL)) { decodedSubject = decodedSubject.substring(SUBJ_FWD_HDR.length(), decodedSubject.length() - SUBJ_FWD_TRL.length()); decodedSubjectLength = decodedSubject.length(); } else { break; } } return decodedSubject; } }
SearchUtil { public static String getBaseSubject(String subject) { String decodedSubject = MimeUtil.unfold(DecoderUtil.decodeEncodedWords(subject, DecodeMonitor.SILENT)); decodedSubject = new String(decodedSubject.getBytes(UTF8), UTF8); decodedSubject = decodedSubject.replaceAll("\t", " ").replaceAll("( ){2,}", " "); while (true) { int decodedSubjectLength = decodedSubject.length(); while (true) { String subj = removeSubTrailers(decodedSubject); if (decodedSubjectLength > subj.length()) { decodedSubject = subj; decodedSubjectLength = decodedSubject.length(); } else { break; } } while (true) { boolean matchedInner = false; decodedSubjectLength = decodedSubject.length(); decodedSubject = removeSubjLeaders(decodedSubject); if (decodedSubjectLength > decodedSubject.length()) { matchedInner = true; decodedSubjectLength = decodedSubject.length(); } decodedSubjectLength = decodedSubject.length(); String subj = removeBlob(decodedSubject); if (subj.length() > 0) { decodedSubject = subj; if (decodedSubjectLength > decodedSubject.length()) { matchedInner = true; decodedSubjectLength = decodedSubject.length(); } } if (!matchedInner) { break; } } String lowcaseSubject = decodedSubject.toLowerCase(Locale.US); if (lowcaseSubject.startsWith(SUBJ_FWD_HDR) && lowcaseSubject.endsWith(SUBJ_FWD_TRL)) { decodedSubject = decodedSubject.substring(SUBJ_FWD_HDR.length(), decodedSubject.length() - SUBJ_FWD_TRL.length()); decodedSubjectLength = decodedSubject.length(); } else { break; } } return decodedSubject; }  }
SearchUtil { public static String getBaseSubject(String subject) { String decodedSubject = MimeUtil.unfold(DecoderUtil.decodeEncodedWords(subject, DecodeMonitor.SILENT)); decodedSubject = new String(decodedSubject.getBytes(UTF8), UTF8); decodedSubject = decodedSubject.replaceAll("\t", " ").replaceAll("( ){2,}", " "); while (true) { int decodedSubjectLength = decodedSubject.length(); while (true) { String subj = removeSubTrailers(decodedSubject); if (decodedSubjectLength > subj.length()) { decodedSubject = subj; decodedSubjectLength = decodedSubject.length(); } else { break; } } while (true) { boolean matchedInner = false; decodedSubjectLength = decodedSubject.length(); decodedSubject = removeSubjLeaders(decodedSubject); if (decodedSubjectLength > decodedSubject.length()) { matchedInner = true; decodedSubjectLength = decodedSubject.length(); } decodedSubjectLength = decodedSubject.length(); String subj = removeBlob(decodedSubject); if (subj.length() > 0) { decodedSubject = subj; if (decodedSubjectLength > decodedSubject.length()) { matchedInner = true; decodedSubjectLength = decodedSubject.length(); } } if (!matchedInner) { break; } } String lowcaseSubject = decodedSubject.toLowerCase(Locale.US); if (lowcaseSubject.startsWith(SUBJ_FWD_HDR) && lowcaseSubject.endsWith(SUBJ_FWD_TRL)) { decodedSubject = decodedSubject.substring(SUBJ_FWD_HDR.length(), decodedSubject.length() - SUBJ_FWD_TRL.length()); decodedSubjectLength = decodedSubject.length(); } else { break; } } return decodedSubject; }  static String getDisplayAddress(Mailbox mailbox); static String getDisplayAddress(String headerValue); static String getMailboxAddress(Mailbox mailbox); static String getMailboxAddress(String headerValue); static String getSerializedMessageIdIfSupportedByUnderlyingStorageOrNull(MailboxMessage mailboxMessage); static String getBaseSubject(String subject); static Predicate<MessageId> distinct(); }
SearchUtil { public static String getBaseSubject(String subject) { String decodedSubject = MimeUtil.unfold(DecoderUtil.decodeEncodedWords(subject, DecodeMonitor.SILENT)); decodedSubject = new String(decodedSubject.getBytes(UTF8), UTF8); decodedSubject = decodedSubject.replaceAll("\t", " ").replaceAll("( ){2,}", " "); while (true) { int decodedSubjectLength = decodedSubject.length(); while (true) { String subj = removeSubTrailers(decodedSubject); if (decodedSubjectLength > subj.length()) { decodedSubject = subj; decodedSubjectLength = decodedSubject.length(); } else { break; } } while (true) { boolean matchedInner = false; decodedSubjectLength = decodedSubject.length(); decodedSubject = removeSubjLeaders(decodedSubject); if (decodedSubjectLength > decodedSubject.length()) { matchedInner = true; decodedSubjectLength = decodedSubject.length(); } decodedSubjectLength = decodedSubject.length(); String subj = removeBlob(decodedSubject); if (subj.length() > 0) { decodedSubject = subj; if (decodedSubjectLength > decodedSubject.length()) { matchedInner = true; decodedSubjectLength = decodedSubject.length(); } } if (!matchedInner) { break; } } String lowcaseSubject = decodedSubject.toLowerCase(Locale.US); if (lowcaseSubject.startsWith(SUBJ_FWD_HDR) && lowcaseSubject.endsWith(SUBJ_FWD_TRL)) { decodedSubject = decodedSubject.substring(SUBJ_FWD_HDR.length(), decodedSubject.length() - SUBJ_FWD_TRL.length()); decodedSubjectLength = decodedSubject.length(); } else { break; } } return decodedSubject; }  static String getDisplayAddress(Mailbox mailbox); static String getDisplayAddress(String headerValue); static String getMailboxAddress(Mailbox mailbox); static String getMailboxAddress(String headerValue); static String getSerializedMessageIdIfSupportedByUnderlyingStorageOrNull(MailboxMessage mailboxMessage); static String getBaseSubject(String subject); static Predicate<MessageId> distinct();  }