/** * @param mail * @param newName * @throws MessagingException */ public MailImpl(Mail mail, String newName) throws MessagingException { this(newName, mail.getSender(), mail.getRecipients(), mail.getMessage()); setRemoteHost(mail.getRemoteHost()); setRemoteAddr(mail.getRemoteAddr()); setLastUpdated(mail.getLastUpdated()); try { if (mail instanceof MailImpl) { setAttributesRaw((HashMap) cloneSerializableObject(((MailImpl) mail).getAttributesRaw())); } else { HashMap attribs = new HashMap(); for (Iterator i = mail.getAttributeNames(); i.hasNext(); ) { String hashKey = (String) i.next(); attribs.put(hashKey,cloneSerializableObject(mail.getAttribute(hashKey))); } setAttributesRaw(attribs); } } catch (IOException e) { // should never happen for in memory streams setAttributesRaw(new HashMap()); } catch (ClassNotFoundException e) { // should never happen as we just serialized it setAttributesRaw(new HashMap()); } }
public HookResult onMessage(SMTPSession session, Mail mail) { if (mail instanceof MailImpl) { final MailImpl mailImpl = (MailImpl) mail; mailImpl.setRemoteHost(session.getRemoteHost()); mailImpl.setRemoteAddr(session.getRemoteIPAddress()); if (session.getUser() != null) { mail.setAttribute(SMTP_AUTH_USER_ATTRIBUTE_NAME, session.getUser()); } if (session.isRelayingAllowed()) { mail.setAttribute(SMTP_AUTH_NETWORK_NAME,"true"); } } return new HookResult(HookReturnCode.DECLINED); }
/** * Reads a mail message from the given mail node. * * @param node * mail node * @return mail message * @throws MessagingException * if a messaging error occurs * @throws RepositoryException * if a repository error occurs * @throws IOException * if an IO error occurs */ private Mail getMail(Node node) throws MessagingException, RepositoryException, IOException { String name = Text.unescapeIllegalJcrChars(node.getName()); MailImpl mail = new MailImpl(name, getSender(node), getRecipients(node), getMessage(node)); mail.setState(getState(node)); mail.setLastUpdated(getLastUpdated(node)); mail.setErrorMessage(getError(node)); mail.setRemoteHost(getRemoteHost(node)); mail.setRemoteAddr(getRemoteAddr(node)); getAttributes(node, mail); return mail; }