public static String getSubject(Message msg) { try { return Str.decodeQuotedPrintable(msg.getSubject()); } catch (MessagingException ex) { throw new RuntimeException(ex); } }
public static String getHeaderFieldValue(Message msg, String fieldName) { String[] header; try { header = msg.getHeader(fieldName); } catch (MessagingException ex) { throw new RuntimeException(ex); } if (header == null) return null; return Str.decodeQuotedPrintable(header[0]); }
public static String getReplyTo(Message msg) { Address[] aa; try { aa = msg.getReplyTo(); } catch (MessagingException ex) { throw new RuntimeException(ex); } if (aa == null) return null; if (aa.length > 0) { return Str.decodeQuotedPrintable(aa[0].toString()); } return null; }
public static Set<String> getRecipientsFormated( Message msg, javax.mail.Message.RecipientType type) { Address[] aa; try { aa = msg.getRecipients(type); } catch (MessagingException ex) { throw new RuntimeException(ex); } Set<String> result = new HashSet<String>(); if (aa != null) { for (Address a : aa) { result.add(Str.decodeQuotedPrintable(a.toString())); } } return result; }
public static String getFromFormated(Message msg) { StringBuffer sb = new StringBuffer(); Address[] aa; try { aa = msg.getFrom(); } catch (MessagingException ex) { throw new RuntimeException(ex); } if (aa == null) { sb.append("<Kein Absender>"); } else { for (int i = 0; i < aa.length; i++) { sb.append(Str.decodeQuotedPrintable(aa[i].toString())); if (i < aa.length - 1) sb.append(", "); } } return sb.toString(); }
public static InputStream getAttachment(Part part, String filename) { try { if (filename.equals(Str.decodeQuotedPrintable(part.getFileName()))) return part.getInputStream(); if (part.getContentType().toLowerCase().startsWith("multipart")) { MimeMultipart multipart; multipart = (MimeMultipart) part.getContent(); int count = multipart.getCount(); for (int i = 0; i < count; i++) { InputStream in = getAttachment(multipart.getBodyPart(i), filename); if (in != null) return in; } } } catch (Throwable ex) { throw new RuntimeException(ex); } return null; }
public static Set<String> getAttachmentFilenames(Part part) { try { Set<String> result = new HashSet<String>(); if (part.getContentType().toLowerCase().startsWith("multipart")) { MimeMultipart multipart; try { multipart = (MimeMultipart) part.getContent(); int count = multipart.getCount(); for (int i = 0; i < count; i++) { result.addAll(getAttachmentFilenames(multipart.getBodyPart(i))); } } catch (NullPointerException ex) { // part.getContent() throws NullPointerException LOG.info(ex); } } else { String filename = part.getFileName(); if (filename != null) result.add(Str.decodeQuotedPrintable(filename)); } return result; } catch (Exception ex) { throw new RuntimeException(ex); } }