当前位置: 首页>>代码示例>>Java>>正文


Java Mail类代码示例

本文整理汇总了Java中org.apache.mailet.Mail的典型用法代码示例。如果您正苦于以下问题:Java Mail类的具体用法?Java Mail怎么用?Java Mail使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Mail类属于org.apache.mailet包,在下文中一共展示了Mail类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: service

import org.apache.mailet.Mail; //导入依赖的package包/类
public void service(Mail mail) throws MessagingException {
  long startTime  = System.currentTimeMillis();

	// Create the dummy session
  cfSession tmpSession = ((cfMailSession)(mail.getAttribute("session"))).getSession();

  try {
    // Setup the Application Data
    setApplicationData( tmpSession );

    // Create the CFC we want to call
    ObjectCFC cfc = PluginManager.getPlugInManager().createCFC( tmpSession, cfcMailet );
  	cfc.addArgument( "mail", new BlueDragonMailWrapper( mail ) );
  	cfc.runMethod( tmpSession, cfcMailetMethod );

  	mail25.log( "cfcRan." + cfcMailet + "; Time=" + (System.currentTimeMillis()-startTime) + "ms" );
  } catch (cfmRunTimeException rte) {
    rte.handleException( tmpSession );
    mail25.log( "cfcRan." + cfcMailet + "; Exception @ " + rte.getLogFile().toString() );
  } catch (Exception e) {
  	PluginManager.getPlugInManager().log( "SmtpManager.service.Exception:" + e.getMessage() );
  } finally {
  	tmpSession.pageEnd();
  	tmpSession.close();
  }
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:27,代码来源:SmtpManager.java

示例2: getTo

import org.apache.mailet.Mail; //导入依赖的package包/类
/**
 * Gets the <code>to</code> property, built dynamically using the original
 * Mail object. Its outcome will be the the value the <i>TO:</i> header will
 * be set to, that could be different from the real recipient (see
 * {@link Mail#getRecipients}). Is a "getX(Mail)" method.
 * 
 * @return {@link #replaceInternetAddresses} on {@link #getRecipients()},
 */
protected InternetAddress[] getTo(Mail originalMail) throws MessagingException {
    InternetAddress[] apparentlyTo = (isStatic()) ? this.apparentlyTo : getTo();
    if (apparentlyTo != null) {
        if (apparentlyTo.length == 1 && (apparentlyTo[0].equals(SpecialAddress.UNALTERED.toInternetAddress()) || apparentlyTo[0].equals(SpecialAddress.TO.toInternetAddress()))) {
            apparentlyTo = null;
        } else {
            Collection toList = new ArrayList(apparentlyTo.length);
            for (int i = 0; i < apparentlyTo.length; i++) {
                toList.add(apparentlyTo[i]);
            }
            /*
             * IMPORTANT: setTo() treats null differently from a zero length
             * array, so it's ok to get a zero length array from
             * replaceSpecialAddresses
             */
            apparentlyTo = (InternetAddress[]) replaceInternetAddresses(originalMail, toList).toArray(new InternetAddress[0]);
        }
    }

    return apparentlyTo;
}
 
开发者ID:twachan,项目名称:James,代码行数:30,代码来源:AbstractRedirect.java

示例3: setReplyTo

import org.apache.mailet.Mail; //导入依赖的package包/类
/**
 * <p>
 * Sets the "Reply-To:" header of <i>newMail</i> to <i>replyTo</i>.
 * </p>
 * If the requested value is <code>SpecialAddress.NULL</code> will remove
 * the "Reply-To:" header. If the requested value is null does nothing.</p>
 * Is a "setX(Mail, Tx, Mail)" method.
 */
protected void setReplyTo(Mail newMail, MailAddress replyTo, Mail originalMail) throws MessagingException {
    if (replyTo != null) {
        InternetAddress[] iart = null;
        if (replyTo != SpecialAddress.NULL) {
            iart = new InternetAddress[1];
            iart[0] = replyTo.toInternetAddress();
        }

        // Note: if iart is null will remove the header
        newMail.getMessage().setReplyTo(iart);

        if (isDebug) {
            log("replyTo set to: " + replyTo);
        }
    }
}
 
开发者ID:twachan,项目名称:James,代码行数:25,代码来源:AbstractRedirect.java

示例4: newName

import org.apache.mailet.Mail; //导入依赖的package包/类
/**
 * Create a unique new primary key name for the given MailObject.
 * 
 * @param mail
 *            the mail to use as the basis for the new mail name
 * @return a new name
 */
public static String newName(Mail mail) throws MessagingException {
    String oldName = mail.getName();

    // Checking if the original mail name is too long, perhaps because of a
    // loop caused by a configuration error.
    // it could cause a "null pointer exception" in AvalonMailRepository
    // much
    // harder to understand.
    if (oldName.length() > 76) {
        int count = 0;
        int index = 0;
        while ((index = oldName.indexOf('!', index + 1)) >= 0) {
            count++;
        }
        // It looks like a configuration loop. It's better to stop.
        if (count > 7) {
            throw new MessagingException("Unable to create a new message name: too long." + " Possible loop in config.xml.");
        } else {
            oldName = oldName.substring(0, 76);
        }
    }

    StringBuffer nameBuffer = new StringBuffer(64).append(oldName).append("-!").append(random.nextInt(1048576));
    return nameBuffer.toString();
}
 
开发者ID:twachan,项目名称:James,代码行数:33,代码来源:MailImpl.java

示例5: createAttachedOriginal

import org.apache.mailet.Mail; //导入依赖的package包/类
/**
 * Create a MimeBodyPart with the original Mail as Attachment
 * 
 * @param originalMail
 * @return MimeBodyPart
 * @throws MessagingException
 */
protected MimeBodyPart createAttachedOriginal(Mail originalMail, int attachmentType) throws MessagingException {
    MimeBodyPart part = new MimeBodyPart();
    MimeMessage originalMessage = originalMail.getMessage();

    if (attachmentType == HEADS) {
        part.setContent(getMessageHeaders(originalMessage), "text/plain");
        part.setHeader("Content-Type", "text/rfc822-headers");
    } else {
        part.setContent(originalMessage, "message/rfc822");
    }

    if ((originalMessage.getSubject() != null) && (originalMessage.getSubject().trim().length() > 0)) {
        part.setFileName(originalMessage.getSubject().trim());
    } else {
        part.setFileName("No Subject");
    }
    part.setDisposition("Attachment");
    return part;
}
 
开发者ID:twachan,项目名称:James,代码行数:27,代码来源:DSNBounce.java

示例6: rawBounce

import org.apache.mailet.Mail; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:twachan,项目名称:James,代码行数:29,代码来源:JamesMailetContext.java

示例7: match

import org.apache.mailet.Mail; //导入依赖的package包/类
public Collection<MailAddress> match(Mail mail) {
    String host = mail.getRemoteAddr();
    try {
        // Have to reverse the octets first
        StringBuffer sb = new StringBuffer();
        StringTokenizer st = new StringTokenizer(host, " .", false);

        while (st.hasMoreTokens()) {
            sb.insert(0, st.nextToken() + ".");
        }

        // Add the network prefix for this blacklist
        sb.append(network);

        // Try to look it up
        dnsServer.getByName(sb.toString());

        // If we got here, that's bad... it means the host
        // was found in the blacklist
        return mail.getRecipients();
    } catch (UnknownHostException uhe) {
        // This is good... it's not on the list
        return null;
    }
}
 
开发者ID:twachan,项目名称:James,代码行数:26,代码来源:InSpammerBlacklist.java

示例8: testJames559

import org.apache.mailet.Mail; //导入依赖的package包/类
/**
 * This test has been written as a proof to:
 * http://issues.apache.org/jira/browse/JAMES-559
 */
public void testJames559() throws Exception {
    mailRepository.store(mail);

    Mail m2 = mailRepository.retrieve("mail1");
    m2.getMessage().setHeader("X-Header", "foobar");
    m2.getMessage().saveChanges();

    mailRepository.store(m2);
    // ALWAYS remember to dispose mails!
    LifecycleUtil.dispose(m2);

    m2 = mailRepository.retrieve("mail1");
    assertEquals(mail.getMessage().getContent().toString(), m2.getMessage().getContent().toString());

    LifecycleUtil.dispose(mail);
    mail = null;
    LifecycleUtil.dispose(m2);

    mailRepository.remove("mail1");
}
 
开发者ID:twachan,项目名称:James,代码行数:25,代码来源:AbstractMailRepositoryTest.java

示例9: match

import org.apache.mailet.Mail; //导入依赖的package包/类
/**
 * This is the Not CompositeMatcher - consider what wasn't in the result set
 * of each child matcher. Of course it is easier to understand if it only
 * includes one matcher in the composition, the normal recommended use. @See
 * CompositeMatcher interface.
 * 
 * @return Collectiom of Recipient from the Negated composition of the child
 *         Matcher(s).
 */
public Collection match(Mail mail) throws MessagingException {
    Collection finalResult = mail.getRecipients();
    Matcher matcher = null;
    for (Iterator matcherIter = iterator(); matcherIter.hasNext();) {
        matcher = (Matcher) (matcherIter.next());
        // log("Matching with " +
        // matcher.getMatcherConfig().getMatcherName());
        Collection result = matcher.match(mail);
        if (result == finalResult) {
            // Not is an empty list
            finalResult = null;
        } else if (result != null) {
            finalResult = new ArrayList(finalResult);
            finalResult.removeAll(result);
        }
    }
    return finalResult;
}
 
开发者ID:twachan,项目名称:James,代码行数:28,代码来源:Not.java

示例10: onMessage

import org.apache.mailet.Mail; //导入依赖的package包/类
public HookResult onMessage(SMTPSession session, Mail mail) {
    if (mail instanceof MailImpl) {

        final MailImpl mailImpl = (MailImpl) mail;
        mailImpl.setRemoteHost(session.getRemoteAddress().getHostName());
        mailImpl.setRemoteAddr(session.getRemoteAddress().getAddress().getHostAddress());
        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);
}
 
开发者ID:twachan,项目名称:James,代码行数:17,代码来源:AddDefaultAttributesMessageHook.java

示例11: sendMail

import org.apache.mailet.Mail; //导入依赖的package包/类
/**
 * Method sendMail.
 * 
 * @param mail
 * @throws MessagingException
 */
@SuppressWarnings("unchecked")
protected void sendMail(Mail mail) throws MessagingException {
    // queue the mail
    getMailQueue().enQueue(mail);

    // Update the flags of the received message
    if (!isLeave())
        setMessageDeleted();

    if (isMarkSeen())
        setMessageSeen();

    // Log the status
    StringBuilder messageBuffer = new StringBuilder("Spooled message to recipients: ");
    Iterator recipientIterator = mail.getRecipients().iterator();
    while (recipientIterator.hasNext()) {
        messageBuffer.append(recipientIterator.next());
        messageBuffer.append(' ');
    }
    messageBuffer.append('.');
    logStatusInfo(messageBuffer.toString());
}
 
开发者ID:twachan,项目名称:James,代码行数:29,代码来源:MessageProcessor.java

示例12: onMessage

import org.apache.mailet.Mail; //导入依赖的package包/类
/**
 * Adds header to the message
 * 
 * @see org.apache.james.smtpserver.JamesMessageHook#onMessage(org.apache.james.protocols.smtp.SMTPSession,
 *      org.apache.mailet.Mail)
 */
public HookResult onMessage(SMTPSession session, Mail mail) {
    try {
        MimeMessage message = mail.getMessage();

        // Set the header name and value (supplied at init time).
        if (headerName != null) {
            message.setHeader(headerName, headerValue);
            message.saveChanges();
        }

    } catch (javax.mail.MessagingException me) {
        session.getLogger().error(me.getMessage());
    }

    return new HookResult(HookReturnCode.DECLINED);
}
 
开发者ID:twachan,项目名称:James,代码行数:23,代码来源:SetMimeHeaderHandler.java

示例13: deQueue

import org.apache.mailet.Mail; //导入依赖的package包/类
public MailQueueItem deQueue() throws MailQueueException {
    if (throwException) {
        throwException = false;
        throw new MailQueueException("Mock");
    }
    try {
        final Mail mail = queue.take();
        if (queue.isEmpty())
            lastMail = null;
        return new MailQueueItem() {

            public Mail getMail() {
                return mail;
            }

            public void done(boolean success) throws MailQueueException {
                // do nothing here

            }
        };

    } catch (InterruptedException e) {
        throw new MailQueueException("Mock", e);
    }
}
 
开发者ID:twachan,项目名称:James,代码行数:26,代码来源:MockMailQueue.java

示例14: onMessage

import org.apache.mailet.Mail; //导入依赖的package包/类
/**
 * Adds header to the message
 * 
 * @see org.apache.james.smtpserver#onMessage(SMTPSession)
 */
public HookResult onMessage(SMTPSession session, Mail mail) {
    session.getLogger().debug("sending mail");

    try {
        queue.enQueue(mail);
        Collection<MailAddress> theRecipients = mail.getRecipients();
        String recipientString = "";
        if (theRecipients != null) {
            recipientString = theRecipients.toString();
        }
        if (session.getLogger().isInfoEnabled()) {
            StringBuilder infoBuffer = new StringBuilder(256).append("Successfully spooled mail ").append(mail.getName()).append(" from ").append(mail.getSender()).append(" on ").append(session.getRemoteAddress().getAddress().toString()).append(" for ").append(recipientString);
            session.getLogger().info(infoBuffer.toString());
        }
    } catch (MessagingException me) {
        session.getLogger().error("Unknown error occurred while processing DATA.", me);
        return new HookResult(HookReturnCode.DENYSOFT, DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.UNDEFINED_STATUS) + " Error processing message.");
    }
    return new HookResult(HookReturnCode.OK, DSNStatus.getStatus(DSNStatus.SUCCESS, DSNStatus.CONTENT_OTHER) + " Message received");
}
 
开发者ID:twachan,项目名称:James,代码行数:26,代码来源:SendMailHandler.java

示例15: getAttributes

import org.apache.mailet.Mail; //导入依赖的package包/类
/**
 * Writes the mail attributes from the <code>jamesattr:*</code> property.
 * 
 * @param node
 *            mail node
 * @param mail
 *            mail message
 * @throws RepositoryException
 *             if a repository error occurs
 * @throws IOException
 *             if an IO error occurs
 */
private void getAttributes(Node node, Mail mail) throws RepositoryException, IOException {
    PropertyIterator iterator = node.getProperties("jamesattr:*");
    while (iterator.hasNext()) {
        Property property = iterator.nextProperty();
        String name = Text.unescapeIllegalJcrChars(property.getName().substring("jamesattr:".length()));
        if (property.getType() == PropertyType.BINARY) {
            InputStream input = property.getStream();
            try {
                ObjectInputStream stream = new ObjectInputStream(input);
                mail.setAttribute(name, (Serializable) stream.readObject());
            } catch (ClassNotFoundException e) {
                throw new IOException(e.getMessage());
            } finally {
                input.close();
            }
        } else {
            mail.setAttribute(name, property.getString());
        }
    }
}
 
开发者ID:twachan,项目名称:James,代码行数:33,代码来源:JCRMailRepository.java


注:本文中的org.apache.mailet.Mail类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。