本文整理汇总了Java中org.apache.mailet.Mail.getSender方法的典型用法代码示例。如果您正苦于以下问题:Java Mail.getSender方法的具体用法?Java Mail.getSender怎么用?Java Mail.getSender使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mailet.Mail
的用法示例。
在下文中一共展示了Mail.getSender方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: service
import org.apache.mailet.Mail; //导入方法依赖的package包/类
/**
* Service does the hard work,and redirects the originalMail in the form
* specified. Checks that the original return path is not empty, and then
* calls super.service(originalMail), otherwise just returns.
*
* @param originalMail
* the mail to process and redirect
* @throws MessagingException
* if a problem arises formulating the redirected mail
*/
public void service(Mail originalMail) throws MessagingException {
if (originalMail.getSender() == null) {
if (isDebug)
log("Processing a bounce request for a message with an empty reverse-path. No bounce will be sent.");
if (!getPassThrough(originalMail)) {
originalMail.setState(Mail.GHOST);
}
return;
}
if (isDebug)
log("Processing a bounce request for a message with a reverse path. The bounce will be sent to " + originalMail.getSender().toString());
super.service(originalMail);
}
示例2: getReplyTo
import org.apache.mailet.Mail; //导入方法依赖的package包/类
/**
* Gets the <code>replyTo</code> property, built dynamically using the
* original Mail object. Is a "getX(Mail)" method.
*
* @return {@link #getReplyTo()} replacing
* <code>SpecialAddress.UNALTERED</code> if applicable with null and
* <code>SpecialAddress.SENDER</code> with the original mail sender
*/
protected MailAddress getReplyTo(Mail originalMail) throws MessagingException {
MailAddress replyTo = (isStatic()) ? this.replyTo : getReplyTo();
if (replyTo != null) {
if (replyTo == SpecialAddress.UNALTERED) {
replyTo = null;
} else if (replyTo == SpecialAddress.SENDER) {
replyTo = originalMail.getSender();
}
}
return replyTo;
}
示例3: 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 {
String sender = null;
MailAddress senderAddr = mail.getSender();
String remoteAddr = mail.getRemoteAddr();
String helo = mail.getRemoteHost();
if (remoteAddr.equals("127.0.0.1") == false) {
if (senderAddr != null) {
sender = senderAddr.toString();
} else {
sender = "";
}
SPFResult result = spf.checkSPF(remoteAddr, sender, helo);
mail.setAttribute(EXPLANATION_ATTRIBUTE, result.getExplanation());
mail.setAttribute(RESULT_ATTRIBUTE, result.getResult());
log("ip:" + remoteAddr + " from:" + sender + " helo:" + helo + " = " + result.getResult());
if (addHeader) {
try {
MimeMessage msg = mail.getMessage();
msg.addHeader(result.getHeaderName(), result.getHeaderText());
msg.saveChanges();
} catch (MessagingException e) {
// Ignore not be able to add headers
}
}
}
}
示例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;
}
}
示例5: service
import org.apache.mailet.Mail; //导入方法依赖的package包/类
/**
* Scans the mail and determines the spam probability.
*
* @param mail
* The Mail message to be scanned.
* @throws MessagingException
* if a problem arises
*/
public void service(Mail mail) throws MessagingException {
try {
MimeMessage message = mail.getMessage();
if (ignoreLocalSender) {
// ignore the message if the sender is local
if (mail.getSender() != null && getMailetContext().isLocalServer(mail.getSender().getDomain())) {
return;
}
}
String[] headerArray = message.getHeader(headerName);
// ignore the message if already analyzed
if (headerArray != null && headerArray.length > 0) {
return;
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
double probability;
if (message.getSize() < getMaxSize()) {
message.writeTo(baos);
probability = analyzer.computeSpamProbability(new BufferedReader(new StringReader(baos.toString())));
} else {
probability = 0.0;
}
mail.setAttribute(MAIL_ATTRIBUTE_NAME, new Double(probability));
message.setHeader(headerName, Double.toString(probability));
DecimalFormat probabilityForm = (DecimalFormat) DecimalFormat.getInstance();
probabilityForm.applyPattern("##0.##%");
String probabilityString = probabilityForm.format(probability);
String senderString;
if (mail.getSender() == null) {
senderString = "null";
} else {
senderString = mail.getSender().toString();
}
if (probability > 0.1) {
log(headerName + ": " + probabilityString + "; From: " + senderString + "; Recipient(s): " + getAddressesString(mail.getRecipients()));
// Check if we should tag the subject
if (tagSubject) {
appendToSubject(message, " [" + probabilityString + (probability > 0.9 ? " SPAM" : " spam") + "]");
}
}
saveChanges(message);
} catch (Exception e) {
log("Exception: " + e.getMessage(), e);
throw new MessagingException("Exception thrown", e);
}
}
示例6: 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);
}
}
示例7: manageDisplayRequest
import org.apache.mailet.Mail; //导入方法依赖的package包/类
/**
* Manages a display request.
*/
private void manageDisplayRequest(Mail mail) throws MessagingException {
MailAddress senderMailAddress = mail.getSender();
String senderUser = senderMailAddress.getLocalPart().toLowerCase(Locale.US);
String senderHost = senderMailAddress.getDomain().toLowerCase(Locale.US);
senderUser = getPrimaryName(senderUser);
Connection conn = null;
PreparedStatement selectStmt = null;
ResultSet selectRS = null;
StringWriter sout = new StringWriter();
PrintWriter out = new PrintWriter(sout, true);
try {
out.println("Answering on behalf of: " + whitelistManagerAddress);
out.println("Displaying white list of " + (new MailAddress(senderUser, senderHost)) + ":");
out.println();
conn = datasource.getConnection();
selectStmt = conn.prepareStatement(selectBySender);
selectStmt.setString(1, senderUser);
selectStmt.setString(2, senderHost);
selectRS = selectStmt.executeQuery();
while (selectRS.next()) {
MailAddress mailAddress = new MailAddress(selectRS.getString(1), selectRS.getString(2));
out.println(mailAddress.toInternetAddress().toString());
}
out.println();
out.println("Finished");
sendReplyFromPostmaster(mail, sout.toString());
} catch (SQLException sqle) {
out.println("Error accessing the database");
sendReplyFromPostmaster(mail, sout.toString());
throw new MessagingException("Error accessing database", sqle);
} finally {
theJDBCUtil.closeJDBCResultSet(selectRS);
theJDBCUtil.closeJDBCStatement(selectStmt);
theJDBCUtil.closeJDBCConnection(conn);
}
}
示例8: sendReplyFromPostmaster
import org.apache.mailet.Mail; //导入方法依赖的package包/类
private void sendReplyFromPostmaster(Mail mail, String stringContent) throws MessagingException {
try {
MailAddress notifier = getMailetContext().getPostmaster();
MailAddress senderMailAddress = mail.getSender();
MimeMessage message = mail.getMessage();
// Create the reply message
MimeMessage reply = new MimeMessage(Session.getDefaultInstance(System.getProperties(), null));
// Create the list of recipients in the Address[] format
InternetAddress[] rcptAddr = new InternetAddress[1];
rcptAddr[0] = senderMailAddress.toInternetAddress();
reply.setRecipients(Message.RecipientType.TO, rcptAddr);
// Set the sender...
reply.setFrom(notifier.toInternetAddress());
// Create the message body
MimeMultipart multipart = new MimeMultipart();
// Add message as the first mime body part
MimeBodyPart part = new MimeBodyPart();
part.setContent(stringContent, "text/plain");
part.setHeader(RFC2822Headers.CONTENT_TYPE, "text/plain");
multipart.addBodyPart(part);
reply.setContent(multipart);
reply.setHeader(RFC2822Headers.CONTENT_TYPE, multipart.getContentType());
// Create the list of recipients in our MailAddress format
Set<MailAddress> recipients = new HashSet<MailAddress>();
recipients.add(senderMailAddress);
// Set additional headers
if (reply.getHeader(RFC2822Headers.DATE) == null) {
reply.setHeader(RFC2822Headers.DATE, rfc822DateFormat.format(new java.util.Date()));
}
String subject = message.getSubject();
if (subject == null) {
subject = "";
}
if (subject.indexOf("Re:") == 0) {
reply.setSubject(subject);
} else {
reply.setSubject("Re:" + subject);
}
reply.setHeader(RFC2822Headers.IN_REPLY_TO, message.getMessageID());
// Send it off...
getMailetContext().sendMail(notifier, recipients, reply);
} catch (Exception e) {
log("Exception found sending reply", e);
}
}
示例9: matchedWhitelist
import org.apache.mailet.Mail; //导入方法依赖的package包/类
/**
* @see org.apache.james.transport.matchers.AbstractSQLWhitelistMatcher
* #matchedWhitelist(org.apache.mailet.MailAddress, org.apache.mailet.Mail)
*/
protected boolean matchedWhitelist(MailAddress recipientMailAddress, Mail mail) throws MessagingException {
MailAddress senderMailAddress = mail.getSender();
String senderUser = senderMailAddress.getLocalPart().toLowerCase(Locale.US);
String senderHost = senderMailAddress.getDomain().toLowerCase(Locale.US);
Connection conn = null;
PreparedStatement selectStmt = null;
ResultSet selectRS = null;
try {
String recipientUser = recipientMailAddress.getLocalPart().toLowerCase(Locale.US);
String recipientHost = recipientMailAddress.getDomain().toLowerCase(Locale.US);
if (conn == null) {
conn = datasource.getConnection();
}
if (selectStmt == null) {
selectStmt = conn.prepareStatement(selectByPK);
}
selectStmt.setString(1, recipientUser);
selectStmt.setString(2, recipientHost);
selectStmt.setString(3, senderUser);
selectStmt.setString(4, senderHost);
selectRS = selectStmt.executeQuery();
if (selectRS.next()) {
// This address was already in the list
return true;
}
// check for wildcard domain entries
selectStmt = conn.prepareStatement(selectByPK);
selectStmt.setString(1, recipientUser);
selectStmt.setString(2, recipientHost);
selectStmt.setString(3, "*");
selectStmt.setString(4, senderHost);
selectRS = selectStmt.executeQuery();
if (selectRS.next()) {
// This address was already in the list
return true;
}
// check for wildcard recipient domain entries
selectStmt = conn.prepareStatement(selectByPK);
selectStmt.setString(1, "*");
selectStmt.setString(2, recipientHost);
selectStmt.setString(3, senderUser);
selectStmt.setString(4, senderHost);
selectRS = selectStmt.executeQuery();
if (selectRS.next()) {
// This address was already in the list
return true;
}
// check for wildcard domain entries on both
selectStmt = conn.prepareStatement(selectByPK);
selectStmt.setString(1, "*");
selectStmt.setString(2, recipientHost);
selectStmt.setString(3, "*");
selectStmt.setString(4, senderHost);
selectRS = selectStmt.executeQuery();
if (selectRS.next()) {
// This address was already in the list
return true;
}
} catch (SQLException sqle) {
log("Error accessing database", sqle);
throw new MessagingException("Exception thrown", sqle);
} finally {
theJDBCUtil.closeJDBCResultSet(selectRS);
theJDBCUtil.closeJDBCStatement(selectStmt);
theJDBCUtil.closeJDBCConnection(conn);
}
return false;
}
示例10: 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;
}
示例11: getJMSProperties
import org.apache.mailet.Mail; //导入方法依赖的package包/类
/**
* Get JMS Message properties with values
*
* @param mail
* @param delayInMillis
* @throws JMSException
* @throws MessagingException
*/
@SuppressWarnings("unchecked")
protected Map<String, Object> getJMSProperties(Mail mail, long delayInMillis) throws JMSException, MessagingException {
Map<String, Object> props = new HashMap<String, Object>();
long nextDelivery = -1;
if (delayInMillis > 0) {
nextDelivery = System.currentTimeMillis() + delayInMillis;
}
props.put(JAMES_NEXT_DELIVERY, nextDelivery);
props.put(JAMES_MAIL_ERROR_MESSAGE, mail.getErrorMessage());
props.put(JAMES_MAIL_LAST_UPDATED, mail.getLastUpdated().getTime());
props.put(JAMES_MAIL_MESSAGE_SIZE, mail.getMessageSize());
props.put(JAMES_MAIL_NAME, mail.getName());
StringBuilder recipientsBuilder = new StringBuilder();
Iterator<MailAddress> recipients = mail.getRecipients().iterator();
while (recipients.hasNext()) {
String recipient = recipients.next().toString();
recipientsBuilder.append(recipient.trim());
if (recipients.hasNext()) {
recipientsBuilder.append(JAMES_MAIL_SEPARATOR);
}
}
props.put(JAMES_MAIL_RECIPIENTS, recipientsBuilder.toString());
props.put(JAMES_MAIL_REMOTEADDR, mail.getRemoteAddr());
props.put(JAMES_MAIL_REMOTEHOST, mail.getRemoteHost());
String sender;
MailAddress s = mail.getSender();
if (s == null) {
sender = "";
} else {
sender = mail.getSender().toString();
}
StringBuilder attrsBuilder = new StringBuilder();
Iterator<String> attrs = mail.getAttributeNames();
while (attrs.hasNext()) {
String attrName = attrs.next();
attrsBuilder.append(attrName);
Object value = convertAttributeValue(mail.getAttribute(attrName));
props.put(attrName, value);
if (attrs.hasNext()) {
attrsBuilder.append(JAMES_MAIL_SEPARATOR);
}
}
props.put(JAMES_MAIL_ATTRIBUTE_NAMES, attrsBuilder.toString());
props.put(JAMES_MAIL_SENDER, sender);
props.put(JAMES_MAIL_STATE, mail.getState());
return props;
}
示例12: 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;
}
示例13: bounce
import org.apache.mailet.Mail; //导入方法依赖的package包/类
/**
* <p>
* This generates a response to the Return-Path address, or the address of
* the message's sender if the Return-Path is not available. Note that this
* is different than a mail-client's reply, which would use the Reply-To or
* From header.
* </p>
* <p>
* Bounced messages are attached in their entirety (headers and content) and
* the resulting MIME part type is "message/rfc822".
* </p>
* <p>
* The attachment to the subject of the original message (or "No Subject" if
* there is no subject in the original message)
* </p>
* <p>
* There are outstanding issues with this implementation revolving around
* handling of the return-path header.
* </p>
* <p>
* MIME layout of the bounce message:
* </p>
* <p>
* multipart (mixed)/ contentPartRoot (body) = mpContent (alternative)/ part
* (body) = message part (body) = original
* </p>
*
* @see org.apache.mailet.MailetContext#bounce(Mail, String, MailAddress)
*/
public void bounce(Mail mail, String message, MailAddress bouncer) throws MessagingException {
if (mail.getSender() == null) {
if (log.isInfoEnabled())
log.info("Mail to be bounced contains a null (<>) reverse path. No bounce will be sent.");
return;
} else {
// Bounce message goes to the reverse path, not to the Reply-To
// address
if (log.isInfoEnabled())
log.info("Processing a bounce request for a message with a reverse path of " + mail.getSender().toString());
}
MailImpl reply = rawBounce(mail, message);
// Change the sender...
reply.getMessage().setFrom(bouncer.toInternetAddress());
reply.getMessage().saveChanges();
// Send it off ... with null reverse-path
reply.setSender(null);
sendMail(reply);
LifecycleUtil.dispose(reply);
}
示例14: senderDomainIsValid
import org.apache.mailet.Mail; //导入方法依赖的package包/类
/**
* <p>
* Checks if a sender domain of <i>mail</i> is valid.
* </p>
* <p>
* If we do not do this check, and someone uses a redirection mailet in a
* processor initiated by SenderInFakeDomain, then a fake sender domain will
* cause an infinite loop (the forwarded e-mail still appears to come from a
* fake domain).<br>
* Although this can be viewed as a configuration error, the consequences of
* such a mis-configuration are severe enough to warrant protecting against
* the infinite loop.
* </p>
* <p>
* This check can be skipped if {@link #getFakeDomainCheck(Mail)} returns
* true.
* </p>
*
* @param mail
* the mail object to check
* @return true if the if the sender is null or
* {@link org.apache.mailet.MailetContext#getMailServers} returns
* true for the sender host part
*/
protected final boolean senderDomainIsValid(Mail mail) throws MessagingException {
if (getFakeDomainCheck(mail)) {
return mail.getSender() == null || getMailetContext().getMailServers(mail.getSender().getDomain()).size() != 0;
} else
return true;
}