本文整理汇总了Java中org.apache.mailet.Mail.getMessage方法的典型用法代码示例。如果您正苦于以下问题:Java Mail.getMessage方法的具体用法?Java Mail.getMessage怎么用?Java Mail.getMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mailet.Mail
的用法示例。
在下文中一共展示了Mail.getMessage方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: service
import org.apache.mailet.Mail; //导入方法依赖的package包/类
/**
* @see org.apache.mailet.base.GenericMailet#service(Mail)
*/
public void service(Mail mail) {
try {
MimeMessage message = mail.getMessage();
// Invoke spamassian connection and scan the message
SpamAssassinInvoker sa = new SpamAssassinInvoker(spamdHost, spamdPort);
sa.scanMail(message);
Iterator<String> headers = sa.getHeadersAsAttribute().keySet().iterator();
// Add headers as attribute to mail object
while (headers.hasNext()) {
String key = headers.next();
mail.setAttribute(key, (String) sa.getHeadersAsAttribute().get(key));
}
message.saveChanges();
} catch (MessagingException e) {
log(e.getMessage());
}
}
示例2: 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;
}
示例3: 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);
}
示例4: 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);
}
示例5: from
import org.apache.mailet.Mail; //导入方法依赖的package包/类
public static ClassificationRequestBody from(Mail mail, UUID messageId) throws MessagingException, IOException {
MimeMessage message = mail.getMessage();
return new ClassificationRequestBody(messageId,
Emailers.from(message.getFrom()),
Recipients.from(message),
ImmutableList.of(Optional.ofNullable(message.getSubject()).orElse("")),
retrieveTextPart(mail),
Optional.ofNullable(message.getSentDate()).map(x -> x.toInstant()));
}
示例6: 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
}
}
}
}
示例7: checkMail
import org.apache.mailet.Mail; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected void checkMail(Mail enqueuedMail, Mail dequeuedMail) throws MessagingException, IOException {
assertEquals(enqueuedMail.getErrorMessage(), dequeuedMail.getErrorMessage());
assertEquals(enqueuedMail.getMessageSize(), dequeuedMail.getMessageSize());
assertEquals(enqueuedMail.getName(), dequeuedMail.getName());
assertEquals(enqueuedMail.getRemoteAddr(), dequeuedMail.getRemoteAddr());
assertEquals(enqueuedMail.getState(), dequeuedMail.getState());
assertEquals(enqueuedMail.getLastUpdated(), dequeuedMail.getLastUpdated());
assertEquals(enqueuedMail.getRemoteHost(), dequeuedMail.getRemoteHost());
assertEquals(enqueuedMail.getSender(), dequeuedMail.getSender());
assertEquals(enqueuedMail.getRecipients().size(), dequeuedMail.getRecipients().size());
Iterator<String> attributes = enqueuedMail.getAttributeNames();
while (attributes.hasNext()) {
String name = attributes.next();
assertNotNull(dequeuedMail.getAttribute(name));
}
MimeMessage enqueuedMsg = enqueuedMail.getMessage();
MimeMessage dequeuedMsg = dequeuedMail.getMessage();
Enumeration<String> enQueuedHeaders = enqueuedMsg.getAllHeaderLines();
Enumeration<String> deQueuedHeaders = dequeuedMsg.getAllHeaderLines();
while (enQueuedHeaders.hasMoreElements()) {
assertEquals(enQueuedHeaders.nextElement(), deQueuedHeaders.nextElement());
}
assertFalse(deQueuedHeaders.hasMoreElements());
assertEquals(enqueuedMsg.getContent(), dequeuedMsg.getContent());
}
示例8: BlueDragonMailWrapper
import org.apache.mailet.Mail; //导入方法依赖的package包/类
public BlueDragonMailWrapper( Mail mail ) throws Exception {
this.mail = mail;
this.message = mail.getMessage();
}
示例9: 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);
}
}
示例10: 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);
}
}
示例11: getMessage
import org.apache.mailet.Mail; //导入方法依赖的package包/类
/**
* @return the full message to append, built from the Mail object
*/
protected String getMessage(Mail originalMail) throws MessagingException {
MimeMessage message = originalMail.getMessage();
StringWriter sout = new StringWriter();
PrintWriter out = new PrintWriter(sout, true);
// First add the "local" notice
// (either from conf or generic error message)
out.println(getMessage());
// And then the message from other mailets
if (originalMail.getErrorMessage() != null) {
out.println();
out.println("Error message below:");
out.println(originalMail.getErrorMessage());
}
out.println();
out.println("Message details:");
if (message.getSubject() != null) {
out.println(" Subject: " + message.getSubject());
}
if (message.getSentDate() != null) {
out.println(" Sent date: " + message.getSentDate());
}
out.println(" MAIL FROM: " + originalMail.getSender());
Iterator rcptTo = originalMail.getRecipients().iterator();
out.println(" RCPT TO: " + rcptTo.next());
while (rcptTo.hasNext()) {
out.println(" " + rcptTo.next());
}
String[] addresses = null;
addresses = message.getHeader(RFC2822Headers.FROM);
if (addresses != null) {
out.print(" From: ");
for (int i = 0; i < addresses.length; i++) {
out.print(addresses[i] + " ");
}
out.println();
}
addresses = message.getHeader(RFC2822Headers.TO);
if (addresses != null) {
out.print(" To: ");
for (int i = 0; i < addresses.length; i++) {
out.print(addresses[i] + " ");
}
out.println();
}
addresses = message.getHeader(RFC2822Headers.CC);
if (addresses != null) {
out.print(" CC: ");
for (int i = 0; i < addresses.length; i++) {
out.print(addresses[i] + " ");
}
out.println();
}
out.println(" Size (in bytes): " + message.getSize());
if (message.getLineCount() >= 0) {
out.println(" Number of lines: " + message.getLineCount());
}
return sout.toString();
}
示例12: 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);
}
}
示例13: writeStream
import org.apache.mailet.Mail; //导入方法依赖的package包/类
/**
* Write the full mail to the stream This can be used by this object or by
* the worker threads.
*
* @param mail
* the Mail used as source
* @param out
* the OutputStream writting the mail to
* @throws IOException
* get thrown if an IO error detected
* @throws MessagingException
* get thrown if an error detected while reading informations of
* the mail
*/
private void writeStream(Mail mail, OutputStream out, boolean update) throws IOException, MessagingException {
MimeMessage msg = mail.getMessage();
if (update) {
if (msg instanceof MimeMessageCopyOnWriteProxy) {
msg = ((MimeMessageCopyOnWriteProxy) msg).getWrappedMessage();
}
if (msg instanceof MimeMessageWrapper) {
MimeMessageWrapper wrapper = (MimeMessageWrapper) msg;
wrapper.loadMessage();
}
}
OutputStream bodyOut = null;
try {
if (streamRep == null) {
// If there is no filestore, use the byte array to store headers
// and the body
bodyOut = out;
} else {
// Store the body in the stream repository
bodyOut = streamRep.put(mail.getName());
}
if (msg instanceof MimeMessageWrapper) {
((MimeMessageWrapper) msg).writeTo(out, bodyOut, null, true);
} else {
// Write the message to the headerOut and bodyOut. bodyOut goes
// straight to the file
MimeMessageUtil.writeTo(mail.getMessage(), out, bodyOut);
}
out.flush();
bodyOut.flush();
} finally {
closeOutputStreams(out, bodyOut);
}
}