Update of /var/cvs/applications/email/src/org/mmbase/applications/email
In directory
james.mmbase.org:/tmp/cvs-serv11452/src/org/mmbase/applications/email
Modified Files:
SendMail.java
Log Message:
added an option to be able to disable mailing excetp to certain addresses (for
testing with production data..)
See also:
http://cvs.mmbase.org/viewcvs/applications/email/src/org/mmbase/applications/email
Index: SendMail.java
===================================================================
RCS file:
/var/cvs/applications/email/src/org/mmbase/applications/email/SendMail.java,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -b -r1.44 -r1.45
--- SendMail.java 12 Jun 2008 14:17:42 -0000 1.44
+++ SendMail.java 1 Aug 2008 11:23:09 -0000 1.45
@@ -16,6 +16,7 @@
import javax.naming.*;
import javax.mail.util.ByteArrayDataSource;
import javax.activation.*;
+import java.util.regex.*;
import org.mmbase.module.smtp.*;
import org.mmbase.bridge.*;
@@ -30,7 +31,7 @@
* @author Daniel Ockeloen
* @author Johannes Verelst <[EMAIL PROTECTED]>
* @since MMBase-1.6
- * @version $Id: SendMail.java,v 1.44 2008/06/12 14:17:42 michiel Exp $
+ * @version $Id: SendMail.java,v 1.45 2008/08/01 11:23:09 michiel Exp $
*/
public class SendMail extends AbstractSendMail {
private static final Logger log =
Logging.getLoggerInstance(SendMail.class);
@@ -42,6 +43,8 @@
public static long emailSent = 0;
public static long emailFailed = 0;
+ private Pattern onlyToPattern = Pattern.compile(".*");
+
/**
public SendMail(String name) {
super(name);
@@ -214,6 +217,7 @@
}
}
+ if (onlyToPattern.matcher(to).matches()) {
try {
MimeMessage msg = constructMessage(from, to, headers);
@@ -230,6 +234,10 @@
log.debug(e.getMessage(), e);
throw e;
}
+ } else {
+ log.service("Not sending mail to " + to + " because it does not
match " + onlyToPattern);
+ return false;
+ }
}
/**
@@ -265,6 +273,13 @@
String dataSource = getInitParameter("datasource");
if ("".equals(dataSource)) dataSource = null;
+ {
+ String only = getInitParameter("onlyto");
+ if (only != null && ! "".equals(only)) {
+ onlyToPattern = Pattern.compile(only);
+ }
+ }
+
//java.security.Security.addProvider(new
com.sun.net.ssl.internal.ssl.Provider());
session = null;
@@ -401,6 +416,7 @@
if (log.isServiceEnabled()) {
log.service("Sending mail to " + to + " Headers " + headers + " "
+ session);
}
+ if (onlyToPattern.matcher(to).matches()) {
try {
MimeMessage msg = constructMessage(from, to, headers);
msg.setText(data, mailEncoding);
@@ -413,6 +429,9 @@
log.debug("because: ", new Exception());
}
}
+ } else {
+ log.service("not sending mail to " + to + " because it does not
match " + onlyToPattern);
+ }
return false;
}
@@ -433,7 +452,7 @@
* (see rfc 822 4.4.4)
* @since MMBase-1.9
*/
- protected void sendRemoteMail(InternetAddress[] onlyto, Address sender,
Node n) {
+ protected void sendRemoteMail(final InternetAddress[] onlyto, Address
sender, Node n) {
if (log.isDebugEnabled()) {
log.debug("Sending node {" + n + "} to addresses {" +
Arrays.asList(onlyto) + "}");
log.trace("Because ", new Exception());
@@ -466,7 +485,13 @@
msg.setHeader("X-mmbase-node", n.getNodeManager().getName() + "/"
+ n.getNumber());
try {
InternetAddress[] toRecipients = InternetAddress.parse(to);
- msg.addRecipients(Message.RecipientType.TO, toRecipients);
+ for (InternetAddress toRecipient : toRecipients) {
+ if
(onlyToPattern.matcher(toRecipient.getAddress()).matches()) {
+ msg.addRecipient(Message.RecipientType.TO,
toRecipient);
+ } else {
+ log.service("Not sending to " + toRecipient + "
because it does not match " + onlyToPattern);
+ }
+ }
} catch (javax.mail.internet.AddressException ae) {
log.warn(ae);
errors.append("\nTo: " + to + ": " + ae.getMessage());
@@ -475,7 +500,13 @@
if (cc != null) {
try {
InternetAddress[] ccRecipients = InternetAddress.parse(cc);
- msg.addRecipients(Message.RecipientType.CC, ccRecipients);
+ for (InternetAddress ccRecipient : ccRecipients) {
+ if
(onlyToPattern.matcher(ccRecipient.getAddress()).matches()) {
+ msg.addRecipient(Message.RecipientType.CC,
ccRecipient);
+ } else {
+ log.service("Not cc-sending to " + ccRecipient + "
because it does not match " + onlyToPattern);
+ }
+ }
} catch (javax.mail.internet.AddressException ae) {
log.warn(ae);
errors.append("\nCc: " + cc + " " + ae.getMessage());
@@ -485,7 +516,13 @@
if (bcc != null) {
try {
InternetAddress[] bccRecipients =
InternetAddress.parse(bcc);
+ for (InternetAddress bccRecipient : bccRecipients) {
+ if
(onlyToPattern.matcher(bccRecipient.getAddress()).matches()) {
msg.addRecipients(Message.RecipientType.BCC,
bccRecipients);
+ } else {
+ log.service("Not cc-sending to " + bccRecipient +
" because it does not match " + onlyToPattern);
+ }
+ }
} catch (javax.mail.internet.AddressException ae) {
log.warn(ae);
errors.append("\nBcc: " + bcc + " " + ae.getMessage());
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs