List of usage examples for javax.mail.internet InternetAddress getGroup
public InternetAddress[] getGroup(boolean strict) throws AddressException
From source file:msgshow.java
public static void dumpEnvelope(Message m) throws Exception { pr("This is the message envelope"); pr("---------------------------"); Address[] a;/*from w ww. ja v a2 s . c o m*/ // FROM if ((a = m.getFrom()) != null) { for (int j = 0; j < a.length; j++) pr("FROM: " + a[j].toString()); } // REPLY TO if ((a = m.getReplyTo()) != null) { for (int j = 0; j < a.length; j++) pr("REPLY TO: " + a[j].toString()); } // TO if ((a = m.getRecipients(Message.RecipientType.TO)) != null) { for (int j = 0; j < a.length; j++) { pr("TO: " + a[j].toString()); InternetAddress ia = (InternetAddress) a[j]; if (ia.isGroup()) { InternetAddress[] aa = ia.getGroup(false); for (int k = 0; k < aa.length; k++) pr(" GROUP: " + aa[k].toString()); } } } // SUBJECT pr("SUBJECT: " + m.getSubject()); // DATE Date d = m.getSentDate(); pr("SendDate: " + (d != null ? d.toString() : "UNKNOWN")); // FLAGS Flags flags = m.getFlags(); StringBuffer sb = new StringBuffer(); Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags boolean first = true; for (int i = 0; i < sf.length; i++) { String s; Flags.Flag f = sf[i]; if (f == Flags.Flag.ANSWERED) s = "\\Answered"; else if (f == Flags.Flag.DELETED) s = "\\Deleted"; else if (f == Flags.Flag.DRAFT) s = "\\Draft"; else if (f == Flags.Flag.FLAGGED) s = "\\Flagged"; else if (f == Flags.Flag.RECENT) s = "\\Recent"; else if (f == Flags.Flag.SEEN) s = "\\Seen"; else continue; // skip it if (first) first = false; else sb.append(' '); sb.append(s); } String[] uf = flags.getUserFlags(); // get the user flag strings for (int i = 0; i < uf.length; i++) { if (first) first = false; else sb.append(' '); sb.append(uf[i]); } pr("FLAGS: " + sb.toString()); // X-MAILER String[] hdrs = m.getHeader("X-Mailer"); if (hdrs != null) pr("X-Mailer: " + hdrs[0]); else pr("X-Mailer NOT available"); }
From source file:MainClass.java
public static void dumpEnvelope(Message m) throws Exception { pr("This is the message envelope"); pr("---------------------------"); Address[] a;// ww w . j a v a2 s .c om // FROM if ((a = m.getFrom()) != null) { for (int j = 0; j < a.length; j++) pr("FROM: " + a[j].toString()); } // TO if ((a = m.getRecipients(Message.RecipientType.TO)) != null) { for (int j = 0; j < a.length; j++) { pr("TO: " + a[j].toString()); InternetAddress ia = (InternetAddress) a[j]; if (ia.isGroup()) { InternetAddress[] aa = ia.getGroup(false); for (int k = 0; k < aa.length; k++) pr(" GROUP: " + aa[k].toString()); } } } // SUBJECT pr("SUBJECT: " + m.getSubject()); // DATE Date d = m.getSentDate(); pr("SendDate: " + (d != null ? d.toString() : "UNKNOWN")); // FLAGS Flags flags = m.getFlags(); StringBuffer sb = new StringBuffer(); Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags boolean first = true; for (int i = 0; i < sf.length; i++) { String s; Flags.Flag f = sf[i]; if (f == Flags.Flag.ANSWERED) s = "\\Answered"; else if (f == Flags.Flag.DELETED) s = "\\Deleted"; else if (f == Flags.Flag.DRAFT) s = "\\Draft"; else if (f == Flags.Flag.FLAGGED) s = "\\Flagged"; else if (f == Flags.Flag.RECENT) s = "\\Recent"; else if (f == Flags.Flag.SEEN) s = "\\Seen"; else continue; // skip it if (first) first = false; else sb.append(' '); sb.append(s); } String[] uf = flags.getUserFlags(); // get the user flag strings for (int i = 0; i < uf.length; i++) { if (first) first = false; else sb.append(' '); sb.append(uf[i]); } pr("FLAGS: " + sb.toString()); // X-MAILER String[] hdrs = m.getHeader("X-Mailer"); if (hdrs != null) pr("X-Mailer: " + hdrs[0]); else pr("X-Mailer NOT available"); }
From source file:com.zimbra.cs.imap.ImapMessage.java
private static void naddresses(PrintStream ps, InternetAddress[] addrs) { int count = 0; if (addrs != null && addrs.length > 0) { for (InternetAddress addr : addrs) { if (addr.isGroup()) { // 7.4.2: "[RFC-2822] group syntax is indicated by a special form of address // structure in which the host name field is NIL. If the mailbox name // field is also NIL, this is an end of group marker (semi-colon in RFC // 822 syntax). If the mailbox name field is non-NIL, this is a start of // group marker, and the mailbox name field holds the group name phrase." try { String serialized = addr.getAddress(); int colon = serialized.indexOf(':'); String name = colon == -1 ? serialized : serialized.substring(0, colon); InternetAddress[] members = addr.getGroup(false); if (count++ == 0) { ps.write('('); }//from ww w. j av a 2 s .c o m ps.print("(NIL NIL "); nstring(ps, name); ps.print(" NIL)"); if (members != null) { for (InternetAddress member : members) { address(ps, member); } } ps.print("(NIL NIL NIL NIL)"); } catch (ParseException e) { } } else if (addr.getAddress() == null) { continue; } else { // 7.4.2: "The fields of an address structure are in the following order: personal // name, [SMTP] at-domain-list (source route), mailbox name, and host name." if (count++ == 0) { ps.write('('); } address(ps, addr); } } } if (count == 0) { ps.write(NIL, 0, 3); } else { ps.write(')'); } }
From source file:com.zimbra.cs.mime.Mime.java
public static InternetAddress[] parseAddressHeader(String header, boolean expandGroups) { if (header == null || header.trim().isEmpty()) return NO_ADDRESSES; header = header.trim();/* w w w . j a v a 2 s . com*/ InternetAddress[] addresses; try { addresses = JavaMailInternetAddress.parseHeader(header, false); } catch (Throwable e) { // Catch everything in case MIME parser was not robust enough to handle a malformed header. if (e instanceof OutOfMemoryError) { Zimbra.halt("MIME parser failed: " + header, e); } else if (!(e instanceof AddressException)) { sLog.error("MIME parser failed: " + header, e); } try { return new InternetAddress[] { new JavaMailInternetAddress(null, header, MimeConstants.P_CHARSET_UTF8) }; } catch (UnsupportedEncodingException e1) { return NO_ADDRESSES; } } if (!expandGroups) return addresses; boolean hasGroups = false; for (InternetAddress addr : addresses) { if (addr.isGroup()) { hasGroups = true; break; } } if (!hasGroups) return addresses; // if we're here, we need to expand at least one group... List<InternetAddress> expanded = new ArrayList<InternetAddress>(); for (InternetAddress addr : addresses) { if (!addr.isGroup()) { expanded.add(addr); } else { try { InternetAddress[] members = addr.getGroup(false); if (members == null) expanded.add(addr); else for (InternetAddress member : members) expanded.add(member); } catch (AddressException e) { expanded.add(addr); } } } return expanded.toArray(new InternetAddress[expanded.size()]); }
From source file:org.apache.solr.handler.dataimport.FsMailEntityProcessor.java
private void addAddressToList(Address[] adresses, List<String> to) throws AddressException { for (Address address : adresses) { to.add(address.toString());// w ww .j a va 2 s . c o m InternetAddress ia = (InternetAddress) address; if (ia.isGroup()) { InternetAddress[] group = ia.getGroup(false); for (InternetAddress member : group) { to.add(member.toString()); } } } }