/** * @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()); } }