本文整理汇总了Java中org.apache.mailet.Mail.setState方法的典型用法代码示例。如果您正苦于以下问题:Java Mail.setState方法的具体用法?Java Mail.setState怎么用?Java Mail.setState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mailet.Mail
的用法示例。
在下文中一共展示了Mail.setState方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: handleException
import org.apache.mailet.Mail; //导入方法依赖的package包/类
/**
* This is a helper method that updates the state of the mail object to
* Mail.ERROR as well as recording the exception to the log
*
* @param me
* the exception to be handled
* @param mail
* the mail being processed when the exception was generated
* @param offendersName
* the matcher or mailet than generated the exception
* @param nextState
* the next state to set
*
* @throws MessagingException
* thrown always, rethrowing the passed in exception
*/
public static void handleException(MessagingException me, Mail mail, String offendersName, String nextState, Logger logger) throws MessagingException {
mail.setState(nextState);
StringWriter sout = new StringWriter();
PrintWriter out = new PrintWriter(sout, true);
StringBuffer exceptionBuffer = new StringBuffer(128).append("Exception calling ").append(offendersName).append(": ").append(me.getMessage());
out.println(exceptionBuffer.toString());
Exception e = me;
while (e != null) {
e.printStackTrace(out);
if (e instanceof MessagingException) {
e = ((MessagingException) e).getNextException();
} else {
e = null;
}
}
String errorString = sout.toString();
mail.setErrorMessage(errorString);
logger.error(errorString);
throw me;
}
示例3: service
import org.apache.mailet.Mail; //导入方法依赖的package包/类
/**
* Store a mail in a particular repository.
*
* @param mail
* the mail to process
*/
public void service(Mail mail) throws javax.mail.MessagingException {
StringBuffer logBuffer = new StringBuffer(160).append("Storing mail ").append(mail.getName()).append(" in ").append(repositoryPath);
log(logBuffer.toString());
repository.store(mail);
if (!passThrough) {
mail.setState(Mail.GHOST);
}
}
示例4: service
import org.apache.mailet.Mail; //导入方法依赖的package包/类
/**
* Delivers a mail to a local mailbox in a given folder.
*
* @see org.apache.mailet.base.GenericMailet#service(org.apache.mailet.Mail)
*/
@Override
public void service(Mail mail) throws MessagingException {
if (mail.getState() != Mail.GHOST) {
doService(mail);
if (consume) {
mail.setState(Mail.GHOST);
}
}
}
示例5: handleBouncing
import org.apache.mailet.Mail; //导入方法依赖的package包/类
/**
* Method handleBouncing sets the Mail state to ERROR and delete from the
* message store.
*
* @param mail
*/
protected void handleBouncing(Mail mail) throws MessagingException {
mail.setState(Mail.ERROR);
setMessageDeleted();
mail.setErrorMessage("This mail from FetchMail task " + getFetchTaskName() + " seems to be bouncing!");
logStatusError("Message is bouncing! Deleted from message store and moved to the Error repository.");
}
示例6: service
import org.apache.mailet.Mail; //导入方法依赖的package包/类
public void service(Mail mail) throws MessagingException {
if (shouldThrow) {
throw new MessagingException();
} else {
mail.setState(newState);
}
}
示例7: service
import org.apache.mailet.Mail; //导入方法依赖的package包/类
/**
* @see
* org.apache.mailet.base.GenericMailet#service(org.apache.mailet.Mail)
*/
public void service(Mail mail) {
if (!(Mail.ERROR.equals(mail.getState()))) {
// Don't complain if we fall off the end of the
// error processor. That is currently the
// normal situation for James, and the message
// will show up in the error store.
StringBuffer warnBuffer = new StringBuffer(256).append("Message ").append(mail.getName()).append(" reached the end of this processor, and is automatically deleted. This may indicate a configuration error.");
logger.warn(warnBuffer.toString());
}
// Set the mail to ghost state
mail.setState(Mail.GHOST);
}
示例8: service
import org.apache.mailet.Mail; //导入方法依赖的package包/类
public void service(Mail mail) throws MessagingException {
mail.setState( Mail.GHOST );
}
示例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包/类
/**
* 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());
}
}
}
示例11: 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);
}
}
示例12: service
import org.apache.mailet.Mail; //导入方法依赖的package包/类
public void service(Mail mail) throws MessagingException {
String state = config.getInitParameter("state");
mail.setState(state);
}
示例13: testChooseRightProcessor
import org.apache.mailet.Mail; //导入方法依赖的package包/类
public void testChooseRightProcessor() throws Exception {
AbstractStateCompositeProcessor processor = new AbstractStateCompositeProcessor() {
@Override
protected MailProcessor createMailProcessor(final String state, HierarchicalConfiguration config) throws Exception {
return new MockMailProcessor("") {
@Override
public void service(Mail mail) throws MessagingException {
// check if the right processor was selected depending on the state
assertEquals(state, mail.getState());
super.service(mail);
}
};
}
};
Logger log = LoggerFactory.getLogger("MockLog");
// slf4j can't set programmatically any log level. It's just a facade
// log.setLevel(SimpleLog.LOG_LEVEL_DEBUG);
processor.setLog(log);
processor.configure(createConfig(Arrays.asList("root","error","test")));
processor.init();
try {
Mail mail1 = new MailImpl();
mail1.setState(Mail.DEFAULT);
Mail mail2 = new MailImpl();
mail2.setState(Mail.ERROR);
Mail mail3 = new MailImpl();
mail3.setState("test");
Mail mail4 = new MailImpl();
mail4.setState("invalid");
processor.service(mail1);
processor.service(mail2);
processor.service(mail3);
try {
processor.service(mail4);
fail("should fail because of no mapping to a processor for this state");
} catch (MessagingException e) {
}
} finally {
processor.dispose();
}
}