Index: messageforums-component-impl/src/java/org/sakaiproject/component/app/messageforums/ui/PrivateMessageManagerImpl.java =================================================================== --- messageforums-component-impl/src/java/org/sakaiproject/component/app/messageforums/ui/PrivateMessageManagerImpl.java (revision 61013) +++ messageforums-component-impl/src/java/org/sakaiproject/component/app/messageforums/ui/PrivateMessageManagerImpl.java (working copy) @@ -29,6 +29,7 @@ import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.HashSet; import org.hibernate.Hibernate; import org.hibernate.HibernateException; @@ -1062,24 +1063,26 @@ pfMap.put(pf1.getOwner(), pf1); } + Set forwardRecipients = new HashSet(); + //this only needs to be done if the message is not being sent for (Iterator i = recipients.iterator(); i.hasNext();) { User u = (User) i.next(); String userId = u.getId(); - - boolean forwardingEnabled = false; String forwardAddress = null; //as this is a hefty overhead only do this if we're not sending as email - if (!asEmail) { /** determine if recipient has forwarding enabled */ PrivateForum pf = null; if (pfMap.containsKey(userId)) - pfMap.get(userId); + pf = (PrivateForum)pfMap.get(userId); + LOG.debug("forwarding: userId: " + userId + ", enabled: " + + pf.getAutoForward().booleanValue() + ", address: " + pf.getAutoForwardEmail() ); + if (pf != null && pf.getAutoForward().booleanValue()){ forwardingEnabled = true; forwardAddress = pf.getAutoForwardEmail(); @@ -1094,29 +1097,27 @@ } } - } /** determine if current user is equal to recipient */ Boolean isRecipientCurrentUser = (currentUserAsString.equals(userId) ? Boolean.TRUE : Boolean.FALSE); - if (!asEmail && forwardingEnabled){ - emailService.send(systemEmail, forwardAddress, message.getTitle(), - bodyString, u.getEmail(), null, additionalHeaders); - - // use forwarded address if set + if (forwardingEnabled){ + forwardRecipients.add(u); + } PrivateMessageRecipientImpl receiver = new PrivateMessageRecipientImpl( userId, typeManager.getReceivedPrivateMessageType(), getContextId(), isRecipientCurrentUser); + recipientList.add(receiver); - } - else { - PrivateMessageRecipientImpl receiver = new PrivateMessageRecipientImpl( - userId, typeManager.getReceivedPrivateMessageType(), getContextId(), - isRecipientCurrentUser); - recipientList.add(receiver); } + + // now send all emails out to auto-forward-requesting users + if (!forwardRecipients.isEmpty()) { + additionalHeaders.add("From: " + systemEmail); + additionalHeaders.add("Subject: " + message.getTitle()); + emailService.sendToUsers(forwardRecipients, additionalHeaders, bodyString); } } else {