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


Java Mail.getRecipients方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: match

import org.apache.mailet.Mail; //导入方法依赖的package包/类
public Collection<MailAddress> match(Mail mail) {
    if (mail.getSender() == null) {
        return null;
    }
    String domain = mail.getSender().getDomain();
    // DNS Lookup for this domain
    Collection<String> servers = getMailetContext().getMailServers(domain);
    if (servers.size() == 0) {
        // No records...could not deliver to this domain, so matches
        // criteria.
        log("No MX, A, or CNAME record found for domain: " + domain);
        return mail.getRecipients();
    } else if (matchNetwork(servers.iterator().next().toString())) {
        /*
         * It could be a wildcard address like these:
         *
         * 64.55.105.9/32          # Allegiance Telecom Companies Worldwide (.nu)
         * 64.94.110.11/32         # VeriSign (.com .net)
         * 194.205.62.122/32       # Network Information Center - Ascension Island (.ac)
         * 194.205.62.62/32        # Internet Computer Bureau (.sh)
         * 195.7.77.20/32          # Fredrik Reutersward Data (.museum)
         * 206.253.214.102/32      # Internap Network Services (.cc)
         * 212.181.91.6/32         # .NU Domain Ltd. (.nu)
         * 219.88.106.80/32        # Telecom Online Solutions (.cx)
         * 194.205.62.42/32        # Internet Computer Bureau (.tm)
         * 216.35.187.246/32       # Cable & Wireless (.ws)
         * 203.119.4.6/32          # .PH TLD (.ph)
         *
         */
        log("Banned IP found for domain: " + domain);
        log(" --> :" + servers.iterator().next());
        return mail.getRecipients();
    } else {
        // Some servers were found... the domain is not fake.

        return null;
    }
}
 
开发者ID:twachan,项目名称:James,代码行数:39,代码来源:SenderInFakeDomain.java

示例5: match

import org.apache.mailet.Mail; //导入方法依赖的package包/类
public Collection match(Mail inMail) throws MessagingException {
  return inMail.getRecipients();
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:4,代码来源:All.java

示例6: service

import org.apache.mailet.Mail; //导入方法依赖的package包/类
public void service(Mail mail) throws MessagingException {
    // Then loop through each address in the recipient list and try to map
    // it according to the alias table

    Connection conn = null;
    PreparedStatement mappingStmt = null;
    ResultSet mappingRS = null;

    Collection<MailAddress> recipients = mail.getRecipients();
    Collection<MailAddress> recipientsToRemove = new Vector<MailAddress>();
    Collection<MailAddress> recipientsToAdd = new Vector<MailAddress>();
    try {
        conn = datasource.getConnection();
        mappingStmt = conn.prepareStatement(query);

        for (Iterator<MailAddress> i = recipients.iterator(); i.hasNext();) {
            try {
                MailAddress source = i.next();
                mappingStmt.setString(1, source.toString());
                mappingRS = mappingStmt.executeQuery();
                if (!mappingRS.next()) {
                    // This address was not found
                    continue;
                }
                try {
                    String targetString = mappingRS.getString(1);
                    MailAddress target = new MailAddress(targetString);

                    // Mark this source address as an address to remove from
                    // the recipient list
                    recipientsToRemove.add(source);
                    recipientsToAdd.add(target);
                } catch (ParseException pe) {
                    // Don't alias this address... there's an invalid
                    // address mapping here
                    StringBuffer exceptionBuffer = new StringBuffer(128).append("There is an invalid alias from ").append(source).append(" to ").append(mappingRS.getString(1));
                    log(exceptionBuffer.toString());
                    continue;
                }
            } finally {
                ResultSet localRS = mappingRS;
                // Clear reference to result set
                mappingRS = null;
                theJDBCUtil.closeJDBCResultSet(localRS);
            }
        }
    } catch (SQLException sqle) {
        throw new MessagingException("Error accessing database", sqle);
    } finally {
        theJDBCUtil.closeJDBCStatement(mappingStmt);
        theJDBCUtil.closeJDBCConnection(conn);
    }

    recipients.removeAll(recipientsToRemove);
    recipients.addAll(recipientsToAdd);
}
 
开发者ID:twachan,项目名称:James,代码行数:57,代码来源:JDBCAlias.java

示例7: service

import org.apache.mailet.Mail; //导入方法依赖的package包/类
/**
 * @see org.apache.mailet.base.GenericMailet#service(org.apache.mailet.Mail)
 */
public void service(Mail mail) throws MessagingException {
    Collection<MailAddress> recipients = mail.getRecipients();
    Collection<MailAddress> errors = new Vector<MailAddress>();

    MimeMessage message = mail.getMessage();

    // Set Return-Path and remove all other Return-Path headers from the
    // message
    // This only works because there is a placeholder inserted by
    // MimeMessageWrapper
    message.setHeader(RFC2822Headers.RETURN_PATH, (mail.getSender() == null ? "<>" : "<" + mail.getSender() + ">"));

    Collection<MailAddress> newRecipients = new LinkedList<MailAddress>();
    for (Iterator<MailAddress> i = recipients.iterator(); i.hasNext();) {
        MailAddress recipient = (MailAddress) i.next();
        try {
            Collection<MailAddress> usernames = processMail(mail.getSender(), recipient, message);

            // if the username is null or changed we remove it from the
            // remaining recipients
            if (usernames == null) {
                i.remove();
            } else {
                i.remove();
                // if the username has been changed we add a new recipient
                // with the new name.
                newRecipients.addAll(usernames);
            }

        } catch (Exception ex) {
            getMailetContext().log("Error while storing mail.", ex);
            errors.add(recipient);
        }
    }

    if (newRecipients.size() > 0) {
        recipients.addAll(newRecipients);
    }

    if (!errors.isEmpty()) {
        // If there were errors, we redirect the email to the ERROR
        // processor.
        // In order for this server to meet the requirements of the SMTP
        // specification, mails on the ERROR processor must be returned to
        // the sender. Note that this email doesn't include any details
        // regarding the details of the failure(s).
        // In the future we may wish to address this.
        getMailetContext().sendMail(mail.getSender(), errors, message, Mail.ERROR);
    }

    if (recipients.size() == 0) {
        // We always consume this message
        mail.setState(Mail.GHOST);
    }
}
 
开发者ID:twachan,项目名称:James,代码行数:59,代码来源:AbstractRecipientRewriteTableMailet.java

示例8: service

import org.apache.mailet.Mail; //导入方法依赖的package包/类
/**
 * Spool mail from a particular repository.
 * 
 * @param trigger
 *            triggering e-mail (eventually parameterize via the trigger
 *            message)
 */
public void service(Mail trigger) throws MessagingException {
    trigger.setState(Mail.GHOST);
    java.util.Collection processed = new java.util.ArrayList();
    Iterator list = repository.list();
    while (list.hasNext()) {
        String key = (String) list.next();
        try {
            Mail mail = repository.retrieve(key);
            if (mail != null && mail.getRecipients() != null) {
                log((new StringBuffer(160).append("Spooling mail ").append(mail.getName()).append(" from ").append(repositoryPath)).toString());

                /*
                 * log("Return-Path: " +
                 * mail.getMessage().getHeader(RFC2822Headers.RETURN_PATH,
                 * ", ")); log("Sender: " + mail.getSender()); log("To: " +
                 * mail.getMessage().getHeader(RFC2822Headers.TO, ", "));
                 * log("Recipients: "); for (Iterator i =
                 * mail.getRecipients().iterator(); i.hasNext(); ) {
                 * log("    " + ((MailAddress)i.next()).toString()); };
                 */

                mail.setAttribute("FromRepository", Boolean.TRUE);
                mail.setState(processor);
                getMailetContext().sendMail(mail);
                if (delete)
                    processed.add(key);
                LifecycleUtil.dispose(mail);
            }
        } catch (MessagingException e) {
            log((new StringBuffer(160).append("Unable to re-spool mail ").append(key).append(" from ").append(repositoryPath)).toString(), e);
        }
    }

    if (delete) {
        Iterator delList = processed.iterator();
        while (delList.hasNext()) {
            repository.remove((String) delList.next());
        }
    }
}
 
开发者ID:twachan,项目名称:James,代码行数:48,代码来源:FromRepository.java

示例9: service

import org.apache.mailet.Mail; //导入方法依赖的package包/类
/**
 * Services the mailet.
 */
public void service(Mail mail) throws MessagingException {

    // check if it's a local sender
    MailAddress senderMailAddress = mail.getSender();
    if (senderMailAddress == null) {
        return;
    }
    if (!getMailetContext().isLocalEmail(senderMailAddress)) {
        // not a local sender, so return
        return;
    }

    Collection<MailAddress> recipients = mail.getRecipients();

    if (recipients.size() == 1 && whitelistManagerAddress != null && whitelistManagerAddress.equals(recipients.toArray()[0])) {

        mail.setState(Mail.GHOST);

        String subject = mail.getMessage().getSubject();
        if (displayFlag != null && displayFlag.equals(subject)) {
            manageDisplayRequest(mail);
        } else if (insertFlag != null && insertFlag.equals(subject)) {
            manageInsertRequest(mail);
        } else if (removeFlag != null && removeFlag.equals(subject)) {
            manageRemoveRequest(mail);
        } else {
            StringWriter sout = new StringWriter();
            PrintWriter out = new PrintWriter(sout, true);
            out.println("Answering on behalf of: " + whitelistManagerAddress);
            out.println("ERROR: Unknown command in the subject line: " + subject);
            sendReplyFromPostmaster(mail, sout.toString());
        }
        return;
    }

    if (automaticInsert) {
        checkAndInsert(senderMailAddress, recipients);
    }

}
 
开发者ID:twachan,项目名称:James,代码行数:44,代码来源:WhiteListManager.java

示例10: match

import org.apache.mailet.Mail; //导入方法依赖的package包/类
public Collection<MailAddress> match(Mail mail) {
    return matchNetwork(mail.getRemoteAddr()) ? mail.getRecipients() : null;
}
 
开发者ID:twachan,项目名称:James,代码行数:4,代码来源:RemoteAddrInNetwork.java

示例11: match

import org.apache.mailet.Mail; //导入方法依赖的package包/类
public Collection<MailAddress> match(Mail mail) throws MessagingException {
    // check if it's a local sender
    MailAddress senderMailAddress = mail.getSender();
    if (senderMailAddress == null) {
        return null;
    }
    if (getMailetContext().isLocalEmail(senderMailAddress)) {
        // is a local sender, so return
        return null;
    }

    String senderUser = senderMailAddress.getLocalPart();
    String senderHost = senderMailAddress.getDomain();

    senderUser = senderUser.toLowerCase(Locale.US);
    senderHost = senderHost.toLowerCase(Locale.US);

    Collection<MailAddress> recipients = mail.getRecipients();

    Collection<MailAddress> inWhiteList = new java.util.HashSet<MailAddress>();

    for (Iterator<MailAddress> i = recipients.iterator(); i.hasNext();) {
        MailAddress recipientMailAddress = i.next();
        String recipientUser = recipientMailAddress.getLocalPart().toLowerCase(Locale.US);
        String recipientHost = recipientMailAddress.getDomain().toLowerCase(Locale.US);

        if (!getMailetContext().isLocalServer(recipientHost)) {
            // not a local recipient, so skip
            continue;
        }

        recipientUser = getPrimaryName(recipientUser);

        if (matchedWhitelist(recipientMailAddress, mail)) {
            // This address was already in the list
            inWhiteList.add(recipientMailAddress);
        }

    }

    return inWhiteList;

}
 
开发者ID:twachan,项目名称:James,代码行数:44,代码来源:AbstractSQLWhitelistMatcher.java

示例12: match

import org.apache.mailet.Mail; //导入方法依赖的package包/类
public Collection<MailAddress> match(Mail mail) {
    return matchNetwork(mail.getRemoteAddr()) ? null : mail.getRecipients();
}
 
开发者ID:twachan,项目名称:James,代码行数:4,代码来源:RemoteAddrNotInNetwork.java

示例13: browse

import org.apache.mailet.Mail; //导入方法依赖的package包/类
/**
 * @see org.apache.james.queue.api.MailQueueManagementMBean#browse()
 */
@SuppressWarnings("unchecked")
public List<CompositeData> browse() throws Exception {
    MailQueueIterator it = queue.browse();
    List<CompositeData> data = new ArrayList<CompositeData>();
    String[] names = new String[] { "name", "sender", "state", "recipients", "size", "lastUpdated", "remoteAddress", "remoteHost", "errorMessage", "attributes", "nextDelivery" };
    String[] descs = new String[] { "Unique name", "Sender", "Current state", "Recipients", "Size in bytes", "Timestamp of last update", "IPAddress of the sender", "Hostname of the sender", "Errormessage if any", "Attributes stored", "Timestamp of when the next delivery attempt will be make" };
    OpenType[] types = new OpenType[] { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.LONG, SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.LONG };

    while (it.hasNext()) {

        MailQueueItemView mView = it.next();
        Mail m = mView.getMail();
        long nextDelivery = mView.getNextDelivery();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(names[0], m.getName());
        String sender = null;
        MailAddress senderAddress = m.getSender();
        if (senderAddress != null) {
            sender = senderAddress.toString();
        }
        map.put(names[1], sender);
        map.put(names[2], m.getState());

        StringBuilder rcptsBuilder = new StringBuilder();
        Collection<MailAddress> rcpts = m.getRecipients();
        if (rcpts != null) {
            Iterator<MailAddress> rcptsIt = rcpts.iterator();
            while (rcptsIt.hasNext()) {
                rcptsBuilder.append(rcptsIt.next().toString());
                if (rcptsIt.hasNext()) {
                    rcptsBuilder.append(",");
                }
            }
        }
        map.put(names[3], rcptsBuilder.toString());
        map.put(names[4], m.getMessageSize());
        map.put(names[5], m.getLastUpdated().getTime());
        map.put(names[6], m.getRemoteAddr());
        map.put(names[7], m.getRemoteHost());
        map.put(names[8], m.getErrorMessage());
        Map<String, String> attrs = new HashMap<String, String>();
        Iterator<String> attrNames = m.getAttributeNames();
        while (attrNames.hasNext()) {
            String attrName = attrNames.next();
            String attrValueString = null;
            Serializable attrValue = m.getAttribute(attrName);
            if (attrValue != null) {
                attrValueString = attrValue.toString();
            }
            attrs.put(attrName, attrValueString);
        }
        map.put(names[9], attrs.toString());
        map.put(names[10], nextDelivery);
        CompositeDataSupport c = new CompositeDataSupport(new CompositeType(Mail.class.getName(), "Queue Mail", names, descs, types), map);
        data.add(c);
    }
    it.close();
    return data;
}
 
开发者ID:twachan,项目名称:James,代码行数:63,代码来源:MailQueueManagement.java


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