/** * 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; } /**
/** * @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; }
/** * @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; }
/** * 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); }
@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); } }
new MailImpl(mailServer.getId(), (MailAddress) session.getState().get(SMTPSession.SENDER), recipientCollection);
new MailImpl(mailServer.getId(), (MailAddress) session.getState().get(SMTPSession.SENDER), recipientCollection);
/** * 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; }