james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [5/6] james-project git commit: JAMES-1900 Extract header sanitizing to mime4j
Date Tue, 06 Jun 2017 02:04:28 GMT
JAMES-1900 Extract header sanitizing to mime4j


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/f832b99a
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f832b99a
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f832b99a

Branch: refs/heads/master
Commit: f832b99a7253c45716d0f2a64f6e918fb00e3b8d
Parents: 110db27
Author: benwa <btellier@linagora.com>
Authored: Fri May 5 16:56:30 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Mon Jun 5 20:25:21 2017 +0700

----------------------------------------------------------------------
 .../mailbox/elasticsearch/json/HeaderCollection.java    | 10 +---------
 .../james/mailbox/store/search/MessageSearches.java     | 12 ++----------
 .../standard/src/test/resources/mime/headerFolded.mime  |  4 ++--
 .../org/apache/james/jmap/model/MessageFactory.java     | 10 +---------
 4 files changed, 6 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f832b99a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/HeaderCollection.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/HeaderCollection.java
b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/HeaderCollection.java
index eef245c..3db1c9a 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/HeaderCollection.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/HeaderCollection.java
@@ -31,8 +31,6 @@ import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
 import org.apache.james.mailbox.store.search.SearchUtil;
-import org.apache.james.mime4j.codec.DecodeMonitor;
-import org.apache.james.mime4j.codec.DecoderUtil;
 import org.apache.james.mime4j.dom.address.Address;
 import org.apache.james.mime4j.dom.address.Group;
 import org.apache.james.mime4j.dom.address.Mailbox;
@@ -51,12 +49,6 @@ import com.google.common.collect.Multimap;
 
 public class HeaderCollection {
 
-    private static String sanitizeHeaderField(String headerName) {
-        return DecoderUtil.decodeEncodedWords(
-            MimeUtil.unfold(headerName),
-            DecodeMonitor.SILENT);
-    }
-
     public static class Builder {
 
         // Some sent e-mail have this form : Wed,  3 Jun 2015 09:05:46 +0000 (UTC)
@@ -90,7 +82,7 @@ public class HeaderCollection {
         public Builder add(Field field) {
             Preconditions.checkNotNull(field);
             String headerName = field.getName().toLowerCase(Locale.US);
-            String sanitizedValue = sanitizeHeaderField(field.getBody());
+            String sanitizedValue = MimeUtil.unscrambleHeaderValue(field.getBody());
 
             headers.put(headerName, sanitizedValue);
             handleSpecificHeader(headerName, sanitizedValue);

http://git-wip-us.apache.org/repos/asf/james-project/blob/f832b99a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
index 7bb255c..9516717 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
@@ -51,8 +51,6 @@ import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
 import org.apache.james.mailbox.store.search.comparator.CombinedComparator;
 import org.apache.james.mime4j.MimeException;
 import org.apache.james.mime4j.MimeIOException;
-import org.apache.james.mime4j.codec.DecodeMonitor;
-import org.apache.james.mime4j.codec.DecoderUtil;
 import org.apache.james.mime4j.dom.Message;
 import org.apache.james.mime4j.dom.address.Address;
 import org.apache.james.mime4j.dom.address.AddressList;
@@ -91,12 +89,6 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
         .setMaxLineLen(-1)
         .build();
 
-    private static String sanitizeHeaderField(String headerValue) {
-        return DecoderUtil.decodeEncodedWords(
-            MimeUtil.unfold(headerValue),
-            DecodeMonitor.SILENT);
-    }
-
     private Iterator<MailboxMessage> messages;
     private SearchQuery query;
     private MailboxSession session;
@@ -479,7 +471,7 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
         for (Header header : headers) {
             String name = header.getName();
             if (headerName.equalsIgnoreCase(name)) {
-                String value = sanitizeHeaderField(header.getValue());
+                String value = MimeUtil.unscrambleHeaderValue(header.getValue());
                 if (value != null) {
                     if (value.toUpperCase(Locale.US).contains(text)) {
                         result = true;
@@ -529,7 +521,7 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
         for (Header header : headers) {
             String name = header.getName();
             if (headerName.equalsIgnoreCase(name)) {
-                value = sanitizeHeaderField(header.getValue());
+                value = MimeUtil.unscrambleHeaderValue(header.getValue());
                 break;
             }
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f832b99a/mailet/standard/src/test/resources/mime/headerFolded.mime
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/resources/mime/headerFolded.mime b/mailet/standard/src/test/resources/mime/headerFolded.mime
index f8f44ce..409bb0c 100644
--- a/mailet/standard/src/test/resources/mime/headerFolded.mime
+++ b/mailet/standard/src/test/resources/mime/headerFolded.mime
@@ -1,6 +1,6 @@
-Return-Path: <aduprat@linagora.com>
+Return-Path: <duprat@linagora.com>
 Subject: Fwd: Invitation: (Aucun objet) - ven. 20 janv. 2017 14:00 - 15:00
- (CET) (aduprat@linagora.com)
+ (CET) (duprat@linagora.com)
 To: =?UTF-8?Q?Beno=c3=aet_TELLIER?= <tellier@linagora.com>
 From: aduprat
  <duprat@linagora.com>

http://git-wip-us.apache.org/repos/asf/james-project/blob/f832b99a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
index e0eb1c9..e39e78e 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
@@ -44,8 +44,6 @@ import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MessageAttachment;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.MessageResult;
-import org.apache.james.mime4j.codec.DecodeMonitor;
-import org.apache.james.mime4j.codec.DecoderUtil;
 import org.apache.james.mime4j.dom.address.AddressList;
 import org.apache.james.mime4j.dom.address.Mailbox;
 import org.apache.james.mime4j.dom.address.MailboxList;
@@ -73,12 +71,6 @@ public class MessageFactory {
         .setMaxLineLen(-1)
         .build();
 
-    private static String sanitizeHeaderField(String headerValue) {
-        return DecoderUtil.decodeEncodedWords(
-            MimeUtil.unfold(headerValue),
-            DecodeMonitor.SILENT);
-    }
-
     private static final ZoneId UTC_ZONE_ID = ZoneId.of("Z");
 
     private final MessagePreviewGenerator messagePreview;
@@ -204,7 +196,7 @@ public class MessageFactory {
         Function<Entry<String, Collection<Field>>, String> bodyConcatenator
= fieldListEntry -> fieldListEntry.getValue()
                 .stream()
                 .map(Field::getBody)
-                .map(MessageFactory::sanitizeHeaderField)
+                .map(MimeUtil::unscrambleHeaderValue)
                 .collect(Collectors.toList())
                 .stream()
                 .collect(Collectors.joining(","));


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message