You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2009/11/12 19:17:41 UTC
svn commit: r835481 - in /james/hupa/trunk/server/src:
main/java/org/apache/hupa/server/guice/
main/java/org/apache/hupa/server/handler/
test/java/org/apache/hupa/server/handler/
Author: norman
Date: Thu Nov 12 18:17:40 2009
New Revision: 835481
URL: http://svn.apache.org/viewvc?rev=835481&view=rev
Log:
Fix regex bug and configuration file load order (HUPA-48). Thx to Manuel Carrasco again..
Modified:
james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/ServerModul.java
james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/GetMessageDetailsHandler.java
james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/GetMessageDetailsHandlerTest.java
Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/ServerModul.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/ServerModul.java?rev=835481&r1=835480&r2=835481&view=diff
==============================================================================
--- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/ServerModul.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/ServerModul.java Thu Nov 12 18:17:40 2009
@@ -128,21 +128,22 @@
protected Properties loadProperties() throws Exception {
Properties properties = null;
- properties = loadProperties(configDir + CONFIG_FILE_NAME);
+
+ String fileName = System.getProperty(SYS_PROP_CONFIG_FILE);
+ if (fileName != null) {
+ properties = loadProperties(fileName);
+ }
if (properties == null) {
- String fileName = System.getProperty(SYS_PROP_CONFIG_FILE);
- if (fileName != null) {
- properties = loadProperties(fileName);
+ for (String name : CONFIG_PROPERTIES) {
+ properties = loadProperties(name);
+ if (properties != null)
+ break;
}
+ }
- if (properties == null) {
- for (String name : CONFIG_PROPERTIES) {
- properties = loadProperties(name);
- if (properties != null)
- break;
- }
- }
+ if (properties == null) {
+ properties = loadProperties(configDir + CONFIG_FILE_NAME);
}
// Configure default parameters for Hupa in demo mode
Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/GetMessageDetailsHandler.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/GetMessageDetailsHandler.java?rev=835481&r1=835480&r2=835481&view=diff
==============================================================================
--- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/GetMessageDetailsHandler.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/GetMessageDetailsHandler.java Thu Nov 12 18:17:40 2009
@@ -269,14 +269,14 @@
static Pattern regex_badAttrs = Pattern.compile("(?si)(<)(\\w+)(\\s.+?)onClick=(\".+?\"|'.+?')(.*?</)(\\2)(\\s*>)");
static String repl_badAttrs = "$1$2$3 $5$6$7";
- static Pattern regex_orphandHttpLinks = Pattern.compile("(?si)(?!.*<a\\s?[^>]*?>.+</a\\s*>.*)(>[^<>]*)" + HTML_LINK_REGEXP + "([^<>]*<)");
+ static Pattern regex_orphandHttpLinks = Pattern.compile("(?si)(?!.*<a\\s?[^>]*?>.+</a\\s*>.*)(<[^<]*?>[^<>]*)" + HTML_LINK_REGEXP + "([^<>]*<[^>]*?>)");
static String repl_orphandHttpLinks = "$1<a href=\"$2\">$2</a>$3";
static Pattern regex_existingHttpLinks = Pattern.compile("(?si)<a\\s[^>]*?href=[\"']?" + HTML_LINK_REGEXP + "[\"']?");
static String repl_existingHttpLinks = "<a onClick=\"openLink('$1');return false;\" href=\"$1\"";
- static Pattern regex_orphandEmailLinks = Pattern.compile("(?si)(?!.*<a\\s?[^>]*?>.+</a\\s*>.*)<([A-z]+?)(.*?)>(.*[\\s>])" + EMAIL_REGEXP + "(.*)</\\1>");
- static String repl_orphandEmailLinks = "<$1$2>$3<a href=\"mailto:$4\">$4</a>$5</$1>";
+ static Pattern regex_orphandEmailLinks = Pattern.compile("(?si)(?!.*<a\\s?[^>]*?>.+</a\\s*>.*)(<[^<]*?>[^<>]*)" + EMAIL_REGEXP + "([^<>]*<[^>]*?>)");
+ static String repl_orphandEmailLinks = "$1<a href=\"mailto:$2\">$2</a>$3";
static Pattern regex_existingEmailLinks = Pattern.compile("(?si)<a\\s[^>]*?href=[\"']*mailto:[\"']?([^\"]+)[\"']?");
static String repl_existngEmailLinks = "<a onClick=\"mailTo('$1');return false;\" href=\"mailto:$1\"";
Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/GetMessageDetailsHandlerTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/GetMessageDetailsHandlerTest.java?rev=835481&r1=835480&r2=835481&view=diff
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/GetMessageDetailsHandlerTest.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/GetMessageDetailsHandlerTest.java Thu Nov 12 18:17:40 2009
@@ -80,9 +80,10 @@
assertEquals("-- <div> .. \"<a onClick=\"openLink('http://whatever');return false;\" href=\"http://whatever\">http://whatever</a>\" .. </div>", res);
}
-
+
public void testRegexEmailLinks() {
String txt, res;
+
txt = ".. <a href=\"mailTo:someone@somedomain.com\">..</a> ..";
res = handler.replaceAll(txt, GetMessageDetailsHandler.regex_existingEmailLinks, GetMessageDetailsHandler.repl_existngEmailLinks);
assertEquals(".. <a onClick=\"mailTo('someone@somedomain.com');return false;\" href=\"mailto:someone@somedomain.com\">..</a> ..", res);
@@ -120,6 +121,10 @@
res = handler.txtDocumentToHtml("", "aFolder", 9999l);
assertTrue(res.length()==0);
+ // TODO: test this
+ //http://accounts.myspace.com.deaaaf.me.uk/msp/index.php?fuseaction=update&code=78E2BL6-EKY5L893K4MHSA-74ESO-D743U41GYB18J-FA18EI698V4M&email=postmaster@hotelsearch.com
+
+
}
public void testFilterHtmlDocument() throws Exception {
@@ -165,6 +170,23 @@
}
+ public void testRegexEmailsInsideTagAttributes() {
+ String msg, res;
+ msg = ".. <a href=\"http://whatever?param1=whatever&email= dock@example.com¶m3\">..</a> ..";
+ res = handler.filterHtmlDocument(msg, "aFolder", 9999l);
+ assertFalse(res.contains("mailTo("));
+
+ msg = ".. <a href=bla > http://whatever?param1=whatever&email=dock@example.com¶m3 </a> ..";
+ res = handler.filterHtmlDocument(msg, "aFolder", 9999l);
+ assertFalse(res.contains("mailTo("));
+ assertFalse(res.contains("openLink("));
+
+ msg = ".. <div > http://whatever?param1=whatever&email=dock@example.com¶m3 <p> ..";
+ res = handler.filterHtmlDocument(msg, "aFolder", 9999l);
+ assertFalse(res.contains("mailTo("));
+ assertTrue(res.contains("openLink("));
+ }
+
private MessageDetails loadMessageDetails(String msgFile) throws Exception {
return handler.mimeToDetails(loadMessage(msgFile), "theFolder", 9999l);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org