From 0e44acbb2fec928a1606dc60f427a148fff405c9 Mon Sep 17 00:00:00 2001
From: Mohamed Ragab <moragab@gmail.com>
Date: Wed, 02 May 2012 11:15:01 -0400
Subject: [PATCH] Added a script to facilitate setting the proxy host and port and no proxy hosts, and then it concatenates all the java system properties for setting the java proxy configurations and puts the resulting string in an environment variable JAVA_PROXY_CONFIG, modified the scirpts gitblit, gitblit-ubuntu, and gitblit-centos to source the java-proxy-config.sh script and then include the resulting java proxy configuration in the java command
---
src/com/gitblit/MailExecutor.java | 27 +++++++++++++++++++++++----
1 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/src/com/gitblit/MailExecutor.java b/src/com/gitblit/MailExecutor.java
index bfe2232..77dc80b 100644
--- a/src/com/gitblit/MailExecutor.java
+++ b/src/com/gitblit/MailExecutor.java
@@ -15,6 +15,7 @@
*/
package com.gitblit;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
@@ -24,6 +25,7 @@
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.regex.Pattern;
import javax.mail.Authenticator;
import javax.mail.Message;
@@ -152,11 +154,28 @@
InternetAddress from = new InternetAddress(fromAddress, "Gitblit");
message.setFrom(from);
- InternetAddress[] tos = new InternetAddress[toAddresses.size()];
- for (int i = 0; i < toAddresses.size(); i++) {
- tos[i] = new InternetAddress(toAddresses.get(i));
+ // determine unique set of addresses
+ Set<String> uniques = new HashSet<String>();
+ for (String address : toAddresses) {
+ uniques.add(address.toLowerCase());
}
- message.setRecipients(Message.RecipientType.TO, tos);
+
+ Pattern validEmail = Pattern
+ .compile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
+ List<InternetAddress> tos = new ArrayList<InternetAddress>();
+ for (String address : uniques) {
+ if (StringUtils.isEmpty(address)) {
+ continue;
+ }
+ if (validEmail.matcher(address).find()) {
+ try {
+ tos.add(new InternetAddress(address));
+ } catch (Throwable t) {
+ }
+ }
+ }
+ message.setRecipients(Message.RecipientType.BCC,
+ tos.toArray(new InternetAddress[tos.size()]));
message.setSentDate(new Date());
} catch (Exception e) {
logger.error("Failed to properly create message", e);
--
Gitblit v1.9.1