[jbpm-commits] JBoss JBPM SVN: r4427 - jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/service.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Apr 3 13:37:31 EDT 2009
Author: bradsdavis
Date: 2009-04-03 13:37:31 -0400 (Fri, 03 Apr 2009)
New Revision: 4427
Modified:
jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/service/SynchronousMailService.java
Log:
Added code to split out the to/cc/bcc over the filter.
Modified: jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/service/SynchronousMailService.java
===================================================================
--- jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/service/SynchronousMailService.java 2009-04-03 17:19:24 UTC (rev 4426)
+++ jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/service/SynchronousMailService.java 2009-04-03 17:37:31 UTC (rev 4427)
@@ -1,8 +1,16 @@
package org.jbpm.pvm.internal.email.service;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import javax.mail.Address;
+import javax.mail.MessagingException;
import javax.mail.Session;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMessage.RecipientType;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
@@ -16,13 +24,48 @@
@Override
public void send(Collection<Email> emails) {
-
+
//Emails need to have the sessions populated.
for(Email email : emails)
{
+ Collection<InternetAddress> to = new HashSet<InternetAddress>();
+ Collection<InternetAddress> cc = new HashSet<InternetAddress>();
+ Collection<InternetAddress> bcc = new HashSet<InternetAddress>();
+
+ MimeMessage message = email.getMimeMessage();
+ try {
+ for(Address addr : Arrays.asList(message.getRecipients(RecipientType.TO)))
+ {
+ if(addr instanceof InternetAddress)
+ {
+ to.add((InternetAddress)addr);
+ }
+ }
+ for(Address addr : Arrays.asList(message.getRecipients(RecipientType.CC)))
+ {
+ if(addr instanceof InternetAddress)
+ {
+ cc.add((InternetAddress)addr);
+ }
+ }
+ for(Address addr : Arrays.asList(message.getRecipients(RecipientType.BCC)))
+ {
+ if(addr instanceof InternetAddress)
+ {
+ bcc.add((InternetAddress)addr);
+ }
+ }
+
+ }
+ catch(MessagingException e)
+ {
+
+ }
+
+
for(MailServerConfiguration config : serverConfigs)
{
- AddressFilter filter = config.getFilter();
+ AddressFilter addressFilter = config.getFilter();
SmtpServer server = config.getServer();
if(server!=null)
@@ -32,7 +75,22 @@
//Need to apply filter.
try {
- email.send();
+ Collection<InternetAddress> toFiltered = addressFilter.filter(to);
+ Collection<InternetAddress> ccFiltered = addressFilter.filter(cc);
+ Collection<InternetAddress> bccFiltered = addressFilter.filter(bcc);
+
+ //Set the email with the new filtered addresses.
+ email.setTo(toFiltered);
+ email.setCc(ccFiltered);
+ email.setBcc(bccFiltered);
+
+ //If there is someone to send it to, then send it.
+ if((toFiltered!=null&&!toFiltered.isEmpty())||
+ (ccFiltered!=null&&!ccFiltered.isEmpty())||
+ (bccFiltered!=null&&!bccFiltered.isEmpty()))
+ {
+ email.send();
+ }
}
catch(EmailException e)
{
More information about the jbpm-commits
mailing list