/** * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTable#mapAddressInternal(java.lang.String, * java.lang.String) */ protected String mapAddressInternal(String user, String domain) throws RecipientRewriteTableException { if (mappings == null) { return null; } else { return RecipientRewriteTableUtil.getTargetString(user, domain, mappings); } }
@Override public void init() throws MessagingException { String mapping = getInitParameter("mapping"); if (mapping != null) { mappings = RecipientRewriteTableUtil.getXMLMappings(mapping); } }
/** * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTable#getUserDomainMappingsInternal(java.lang.String, * java.lang.String) */ protected Collection<String> getUserDomainMappingsInternal(String user, String domain) throws RecipientRewriteTableException { if (mappings == null) { return null; } else { String maps = mappings.get(user + "@" + domain); if (maps != null) { return RecipientRewriteTableUtil.mappingToCollection(maps); } else { return null; } } }
/** * @throws RecipientRewriteTableException * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTable#addMappingInternal(String, * String, String) */ protected void addMappingInternal(String user, String domain, String regex) throws RecipientRewriteTableException { String newUser = getUserString(user); String newDomain = getDomainString(domain); Collection<String> map = getUserDomainMappings(newUser, newDomain); if (map != null && map.size() != 0) { map.add(regex); updateMapping(newUser, newDomain, RecipientRewriteTableUtil.CollectionToMapping(map)); } else { addRawMapping(newUser, newDomain, regex); } }
/** * @throws RecipientRewriteTableException * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTable#removeMappingInternal(String, * String, String) */ protected void removeMappingInternal(String user, String domain, String mapping) throws RecipientRewriteTableException { String newUser = getUserString(user); String newDomain = getDomainString(domain); Collection<String> map = getUserDomainMappings(newUser, newDomain); if (map != null && map.size() > 1) { map.remove(mapping); updateMapping(newUser, newDomain, RecipientRewriteTableUtil.CollectionToMapping(map)); } else { removeRawMapping(newUser, newDomain, mapping); } }
/** * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTable#getAllMappingsInternal() */ protected Map<String, Collection<String>> getAllMappingsInternal() throws RecipientRewriteTableException { if (mappings != null && mappings.size() > 0) { Map<String, Collection<String>> mappingsNew = new HashMap<String, Collection<String>>(); Iterator<String> maps = mappings.keySet().iterator(); while (maps.hasNext()) { String key = maps.next(); mappingsNew.put(key, RecipientRewriteTableUtil.mappingToCollection(mappings.get(key).toString())); } return mappingsNew; } else { return null; } }
/** * Map any virtual recipients to real recipients using the configured * mapping. * * @param recipientsMap * the mapping of virtual to real recipients */ @Override protected void mapRecipients(Map<MailAddress, String> recipientsMap) { Collection<MailAddress> recipients = recipientsMap.keySet(); for (MailAddress source : recipients) { String user = source.getLocalPart().toLowerCase(Locale.US); Domain domain = source.getDomain(); String targetString = RecipientRewriteTableUtil.getTargetString(user, domain, mappings); if (targetString != null) { recipientsMap.put(source, targetString); } } }
/** * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTable#doConfigure(org.apache.commons.configuration.HierarchicalConfiguration) */ @SuppressWarnings("unchecked") protected void doConfigure(HierarchicalConfiguration arg0) throws ConfigurationException { List<String> mapConf = arg0.getList("mapping"); mappings = new HashMap<String, String>(); if (mapConf != null && mapConf.size() > 0) { for (int i = 0; i < mapConf.size(); i++) { mappings.putAll(RecipientRewriteTableUtil.getXMLMappings(mapConf.get(i))); } } else { throw new ConfigurationException("No mapping configured"); } }
/** * @throws RecipientRewriteTableException * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTable#mapAddress(java.lang.String, * java.lang.String) */ protected Collection<String> getUserDomainMappingsInternal(String user, String domain) throws RecipientRewriteTableException { EntityManager entityManager = entityManagerFactory.createEntityManager(); final EntityTransaction transaction = entityManager.getTransaction(); try { transaction.begin(); List<JPARecipientRewrite> virtualUsers = entityManager.createNamedQuery("selectUserDomainMapping").setParameter("user", user).setParameter("domain", domain).getResultList(); transaction.commit(); if (virtualUsers.size() > 0) { return RecipientRewriteTableUtil.mappingToCollection(virtualUsers.get(0).getTargetAddress()); } } catch (PersistenceException e) { getLogger().debug("Failed to get user domain mappings", e); if (transaction.isActive()) { transaction.rollback(); } throw new RecipientRewriteTableException("Error while retrieve mappings", e); } finally { entityManager.close(); } return null; }
/** * @throws RecipientRewriteTableException * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTable#getAllMappingsInternal() */ protected Map<String, Collection<String>> getAllMappingsInternal() throws RecipientRewriteTableException { EntityManager entityManager = entityManagerFactory.createEntityManager(); final EntityTransaction transaction = entityManager.getTransaction(); Map<String, Collection<String>> mapping = new HashMap<String, Collection<String>>(); try { transaction.begin(); List<JPARecipientRewrite> virtualUsers = entityManager.createNamedQuery("selectAllMappings").getResultList(); transaction.commit(); for (JPARecipientRewrite virtualUser : virtualUsers) { mapping.put(virtualUser.getUser() + "@" + virtualUser.getDomain(), RecipientRewriteTableUtil.mappingToCollection(virtualUser.getTargetAddress())); } if (mapping.size() > 0) return mapping; } catch (PersistenceException e) { getLogger().debug("Failed to get all mappings", e); if (transaction.isActive()) { transaction.rollback(); } throw new RecipientRewriteTableException("Error while retrieve mappings", e); } finally { entityManager.close(); } return null; }