org.apache.mailet.Mail.getSender()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(180)

本文整理了Java中org.apache.mailet.Mail.getSender()方法的一些代码示例,展示了Mail.getSender()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mail.getSender()方法的具体详情如下:
包路径:org.apache.mailet.Mail
类名称:Mail
方法名:getSender

Mail.getSender介绍

[英]Returns the sender of the message, as specified by the SMTP "MAIL FROM" command, or internally defined.
[中]返回SMTP“MAIL FROM”命令指定的或内部定义的邮件发件人。

代码示例

代码示例来源:origin: org.apache.james/james-server-protocols-smtp

@SuppressWarnings("deprecated") // This will be handled in a followup pull request See JAMES-2557
@Override
public MailAddress getSender() {
  return mail.getSender();
}

代码示例来源:origin: org.apache.james/james-server-smtpserver

/**
 * (non-Javadoc)
 * @see org.apache.james.protocols.smtp.MailEnvelope#getSender()
 */
public MailAddress getSender() {
  return mail.getSender();
}

代码示例来源:origin: apache/james-project

/**
 * Returns the sender of the message, as specified by the SMTP "MAIL FROM" command,
 * or internally defined.
 *
 * 'null' or {@link MailAddress#nullSender()} are handled with {@link MaybeSender#nullSender()}.
 *
 * @since Mailet API v3.2.0
 * @return the sender of this message wrapped in an optional
 */
default MaybeSender getMaybeSender() {
  return MaybeSender.of(getSender());
}

代码示例来源:origin: org.apache.james/apache-standard-mailets

public Collection<MailAddress> match(Mail mail) {
    if (mail.getSender() == null) {
      return mail.getRecipients();
    } else {
      return null;
    }
  }
}

代码示例来源:origin: org.apache.james/apache-standard-mailets

public Collection<MailAddress> match(Mail mail) {
    if (senders.contains(mail.getSender())) {
      return mail.getRecipients();
    } else {
      return null;
    }
  }
}

代码示例来源:origin: org.apache.james/apache-mailet-api

/**
 * Returns the sender of the message, as specified by the SMTP "MAIL FROM" command,
 * or internally defined.
 *
 * 'null' or {@link MailAddress#nullSender()} are handled with {@link MaybeSender#nullSender()}.
 *
 * @since Mailet API v3.2.0
 * @return the sender of this message wrapped in an optional
 */
@SuppressWarnings("deprecated")
default MaybeSender getMaybeSender() {
  return MaybeSender.of(getSender());
}

代码示例来源:origin: org.apache.james/apache-standard-mailets

private void logMailInfo(Mail mail) {
  
  // writes the error message to the log
  StringWriter sout = new StringWriter();
  PrintWriter out = new PrintWriter(sout, true);
  
  out.print("Mail details:");
  out.print(" MAIL FROM: " + mail.getSender());
  Iterator<MailAddress> rcptTo = mail.getRecipients().iterator();
  out.print(", RCPT TO: " + rcptTo.next());
  while (rcptTo.hasNext()) {
    out.print(", " + rcptTo.next());
  }
      
  log(sout.toString());
}

代码示例来源:origin: org.apache.james/apache-standard-mailets

public Collection<MailAddress> match(Mail mail) {
    MailAddress mailAddress = mail.getSender();
    if (mailAddress == null) {
      return null;
    }
    String senderString = mailAddress.toString();
    if (pattern.matcher(senderString).matches()) {
      return mail.getRecipients();
    }
    return null;
  }
}

代码示例来源:origin: org.apache.james/apache-standard-mailets

public Collection<MailAddress> match(Mail mail) {
    if (mail.getSender() != null
        && this.getMailetContext().isLocalServer(
            mail.getSender().getDomain().toLowerCase())) {
      return mail.getRecipients();
    }
    return null;

  }
}

代码示例来源:origin: org.apache.james/apache-standard-mailets

/**
   * Takes the message and checks the sender (if there is one) against
   * the vector of host names.
   *
   * Returns the collection of recipients if there's a match.
   *
   * @param mail the mail being processed
   */
  public Collection<MailAddress> match(Mail mail) {
    try {
      if (mail.getSender() != null && senderHosts.contains(mail.getSender().getDomain().toLowerCase(Locale.US))) {
        return mail.getRecipients();
      }
    } catch (Exception e) {
      log(e.getMessage());
    }

    return null;    //No match.
  }
}

代码示例来源:origin: org.apache.james/apache-jsieve-mailet

/**
 * Returns the from.
 * 
 * @return String
 */
public String getEnvelopeFrom()
{
  MailAddress sender = getMail().getSender(); 
  return (null == sender ? "" : sender.toString());
}

代码示例来源:origin: org.apache.james/apache-standard-mailets

/**
 * Standard matcher entrypoint.
 * First of all, checks the sender using {@link #isSenderChecked}.
 * Then, for each recipient checks it using {@link #isRecipientChecked} and
 * {@link #isOverQuota}.
 *
 * @throws MessagingException if either <CODE>isSenderChecked</CODE> or isRecipientChecked throw an exception
 */    
public final Collection<MailAddress> match(Mail mail) throws MessagingException {
  Collection<MailAddress> matching = null;
  if (isSenderChecked(mail.getSender())) {
    matching = new ArrayList<MailAddress>();
    for (Iterator<MailAddress> i = mail.getRecipients().iterator(); i.hasNext(); ) {
      MailAddress recipient = i.next();
      if (isRecipientChecked(recipient) && isOverQuota(recipient, mail)) {
        matching.add(recipient);
      }
    }
  }
  return matching;
}

代码示例来源:origin: org.apache.james/james-server-mailetcontainer-library

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

代码示例来源:origin: org.nhind/gateway

final InternetAddress fromAddr = (mail.getSender() == null) ? null : mail.getSender().toInternetAddress();

代码示例来源:origin: org.apache.james/james-server-smtpserver

.append(mail.getName())
.append(" from ")
.append(mail.getSender())
.append(" on ")
.append(session.getRemoteIPAddress())

代码示例来源:origin: org.apache.james/apache-standard-mailets

/**
 * Sends a message back to the sender indicating what time the server thinks it is.
 *
 * @param mail the mail being processed
 *
 * @throws javax.mail.MessagingException if an error is encountered while formulating the reply message
 */
public void service(Mail mail) throws javax.mail.MessagingException {
  MimeMessage response = (MimeMessage)mail.getMessage().reply(false);
  response.setSubject("The time is now...");
  StringBuffer textBuffer =
    new StringBuffer(128)
        .append("This mail server thinks it's ")
        .append((new java.util.Date()).toString())
        .append(".");
  response.setText(textBuffer.toString());
  // Someone manually checking the server time by hand may send
  // an formatted message, lacking From and To headers.  If the
  // response fields are null, try setting them from the SMTP
  // MAIL FROM/RCPT TO commands used to send the inquiry.
  if (response.getFrom() == null) {
    response.setFrom(((MailAddress)mail.getRecipients().iterator().next()).toInternetAddress());
  }
  if (response.getAllRecipients() == null) {
    response.setRecipients(MimeMessage.RecipientType.TO, mail.getSender().toString());
  }
  response.saveChanges();
  getMailetContext().sendMail(response);
}

代码示例来源:origin: org.apache.james/apache-jsieve-mailet

/**
   * Method execute executes the passed ActionRedirect.
   * 
   * @param anAction not nul
   * @param aMail not null
   * @param context not null
   * @throws MessagingException
   */
  public void execute(ActionRedirect anAction, Mail aMail, ActionContext context) throws MessagingException
  {
    ActionUtils.detectAndHandleLocalLooping(aMail, context, "redirect");
    Collection<MailAddress> recipients = new ArrayList<MailAddress>(1);
    recipients.add(new MailAddress(new InternetAddress(anAction.getAddress())));
    MailAddress sender = aMail.getSender();
    context.post(sender, recipients, aMail.getMessage());
    aMail.setState(Mail.GHOST);
    Log log = context.getLog();
    if (log.isDebugEnabled()) {
      log.debug("Redirected Message ID: "
        + aMail.getMessage().getMessageID() + " to \""
        + anAction.getAddress() + "\"");
    }
  }
}

代码示例来源:origin: org.apache.james/apache-standard-mailets

/**
 * Process an incoming email, removing the currently identified
 * recipients and replacing them with the recipients indicated in
 * the Mail-For, To and Cc headers of the actual email.
 *
 * @param mail incoming email
 */
public void service(Mail mail) throws MessagingException {
  MimeMessage message = mail.getMessage();
  // Utilise features of Set Collections such that they automatically
  // ensure that no two entries are equal using the equality method
  // of the element objects.  MailAddress objects test equality based
  // on equivalent but not necessarily visually identical addresses.
  Collection<MailAddress> recipients = mail.getRecipients();
  // Wipe all the exist recipients
  recipients.clear();
  recipients.addAll(getHeaderMailAddresses(message, "Mail-For"));
  if (recipients.isEmpty()) {
    recipients.addAll(getHeaderMailAddresses(message, "To"));
    recipients.addAll(getHeaderMailAddresses(message, "Cc"));
  }
  if (isDebug) {
    log("All recipients = " + recipients.toString());
    log("Reprocessing mail using recipients in message headers");
  }
  // Return email to the "root" process.
  getMailetContext().sendMail(mail.getSender(), mail.getRecipients(), mail.getMessage());
  mail.setState(Mail.GHOST);
}

代码示例来源:origin: org.apache.james/james-server-core-library

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

代码示例来源:origin: org.apache.james/james-server-jcr

/**
 * Writes the mail message to the given mail node.
 * 
 * @param node
 *            mail node
 * @param mail
 *            mail message
 * @throws MessagingException
 *             if a messaging error occurs
 * @throws RepositoryException
 *             if a repository error occurs
 * @throws IOException
 *             if an IO error occurs
 */
private void setMail(Node node, Mail mail) throws MessagingException, RepositoryException, IOException {
  setState(node, mail.getState());
  setLastUpdated(node, mail.getLastUpdated());
  setError(node, mail.getErrorMessage());
  setRemoteHost(node, mail.getRemoteHost());
  setRemoteAddr(node, mail.getRemoteAddr());
  setSender(node, mail.getSender());
  setRecipients(node, mail.getRecipients());
  setMessage(node, mail.getMessage());
  setAttributes(node, mail);
}

相关文章