001 package de.deepamehta.plugins.mail; 002 003 import java.io.UnsupportedEncodingException; 004 import java.util.ArrayList; 005 import java.util.HashMap; 006 import java.util.List; 007 008 import javax.mail.internet.AddressException; 009 import javax.mail.internet.InternetAddress; 010 011 /** 012 * Hash recipient lists by type. 013 */ 014 @SuppressWarnings("serial") 015 class RecipientsByType extends HashMap<RecipientType, List<InternetAddress>> { 016 017 private Integer count = 0; 018 019 public void add(String typeUri, String address, String personal) 020 throws UnsupportedEncodingException, AddressException { 021 InternetAddress internetAddress = new InternetAddress(address, personal); 022 internetAddress.validate(); 023 getTypeList(RecipientType.fromUri(typeUri)).add(internetAddress); 024 count++; 025 } 026 027 private List<InternetAddress> getTypeList(RecipientType type) { 028 if (get(type) == null) { 029 put(type, new ArrayList<InternetAddress>()); 030 } 031 return get(type); 032 } 033 034 public Integer getCount() { 035 return count; 036 } 037 }