/** * @see org.apache.james.mailrepository.api.MailRepository#retrieve(String) */ public Mail retrieve(String key) { loadKeys(); MailImpl res = null; MimeMessage foundMessage = findMessage(key); if (foundMessage == null) { getLogger().error("found message is null!"); return null; } res = new MailImpl(); res.setMessage(foundMessage); res.setName(key); if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) { StringBuffer logBuffer = new StringBuffer(128).append(this.getClass().getName()).append(" Retrieving entry for key ").append(key); getLogger().debug(logBuffer.toString()); } return res; }
/** * @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()); } }
@SuppressWarnings("unchecked") public void sendMail(MailAddress sender, Collection recipients, MimeMessage message, String state) throws MessagingException { MailImpl mail = new MailImpl(mailServer.getId(), sender, recipients, message); try { mail.setState(state); sendMail(mail); } finally { LifecycleUtil.dispose(mail); } }
/** * 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; }
new MailImpl(mailServer.getId(), (MailAddress) session.getState().get(SMTPSession.SENDER), recipientCollection); try { mimeMessageCopyOnWriteProxy = new MimeMessageCopyOnWriteProxy(mmiss); mail.setMessage(mimeMessageCopyOnWriteProxy);
/** * Duplicate the MailImpl, replacing the mail name with the one * passed in as an argument. * * @param newName the name for the duplicated mail * * @return a MailImpl that is a duplicate of this one with a different name */ public Mail duplicate(String newName) { try { return new MailImpl(this, newName); } catch (MessagingException me) { // Ignored. Return null in the case of an error. } return null; } /**
/** * A constructor that creates a MailImpl with the specified name, * sender, recipients, and MimeMessage. * * @param name the name of the MailImpl * @param sender the sender for this MailImpl * @param recipients the collection of recipients of this MailImpl * @param message the MimeMessage associated with this MailImpl */ public MailImpl(String name, MailAddress sender, Collection recipients, MimeMessage message) throws MessagingException { this(name, sender, recipients); this.setMessage(new MimeMessageCopyOnWriteProxy(message)); }
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); }
/** * A constructor that creates a new, uninitialized MailImpl */ public MailImpl() { setState(Mail.DEFAULT); attributes = new HashMap(); } /**
remoteHost = (String) in.readObject(); remoteAddr = (String) in.readObject(); setLastUpdated((Date) in.readObject());
new MailImpl(mailServer.getId(), (MailAddress) session.getState().get(SMTPSession.SENDER), recipientCollection); try { mimeMessageCopyOnWriteProxy = new MimeMessageCopyOnWriteProxy(mmiss); mail.setMessage(mimeMessageCopyOnWriteProxy);
/** * Generates a bounce mail that is a bounce of the original message. * * @param bounceText * the text to be prepended to the message to describe the bounce * condition * * @return the bounce mail * * @throws MessagingException * if the bounce mail could not be created */ private MailImpl rawBounce(Mail mail, String bounceText) throws MessagingException { // This sends a message to the james component that is a bounce of the // sent message MimeMessage original = mail.getMessage(); MimeMessage reply = (MimeMessage) original.reply(false); reply.setSubject("Re: " + original.getSubject()); reply.setSentDate(new Date()); Collection<MailAddress> recipients = new HashSet<MailAddress>(); recipients.add(mail.getSender()); InternetAddress addr[] = { new InternetAddress(mail.getSender().toString()) }; reply.setRecipients(Message.RecipientType.TO, addr); reply.setFrom(new InternetAddress(mail.getRecipients().iterator().next().toString())); reply.setText(bounceText); reply.setHeader(RFC2822Headers.MESSAGE_ID, "replyTo-" + mail.getName()); return new MailImpl("replyTo-" + mail.getName(), new MailAddress(mail.getRecipients().iterator().next().toString()), recipients, reply); }
/** * A constructor that creates a MailImpl with the specified name, * sender, recipients, and message data. * * @param name the name of the MailImpl * @param sender the sender for this MailImpl * @param recipients the collection of recipients of this MailImpl * @param messageIn a stream containing the message source */ public MailImpl(String name, MailAddress sender, Collection recipients, InputStream messageIn) throws MessagingException { this(name, sender, recipients); MimeMessageSource source = new MimeMessageInputStreamSource(name, messageIn); // if MimeMessageCopyOnWriteProxy throws an error in the constructor we // have to manually care disposing our source. try { this.setMessage(new MimeMessageCopyOnWriteProxy(source)); } catch (MessagingException e) { LifecycleUtil.dispose(source); throw e; } }
/** * @see org.apache.james.mailrepository.api.MailRepository#retrieve(String) */ public Mail retrieve(String key) { loadKeys(); MailImpl res = null; MimeMessage foundMessage = findMessage(key); if (foundMessage == null) { getLogger().error("found message is null!"); return null; } res = new MailImpl(); res.setMessage(foundMessage); res.setName(key); if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) { StringBuffer logBuffer = new StringBuffer(128) .append(this.getClass().getName()) .append(" Retrieving entry for key ") .append(key); getLogger().debug(logBuffer.toString()); } return res; }