JSIEVE-107 Decode headers before returning back
authorDaniele Depetrini <daniele.depetrini@infocert.it>
Mon, 6 Jun 2016 13:40:52 +0000 (15:40 +0200)
committerbenwa <btellier@linagora.com>
Tue, 22 Aug 2017 08:53:23 +0000 (15:53 +0700)
util/src/main/java/org/apache/jsieve/util/check/ScriptCheckMailAdapter.java

index fbb71c9..6a06c5c 100644 (file)
@@ -34,6 +34,7 @@ import javax.mail.MessagingException;
 import java.io.IOException;
 import java.util.*;
 import javax.mail.internet.MimeUtility;
+import java.io.UnsupportedEncodingException;
 
 /**
  * Checks script execution for an email. The wrapped email is set by called
@@ -141,10 +142,12 @@ public class ScriptCheckMailAdapter implements MailAdapter {
                     //We need to do unfold headers here
                     result = new LinkedList<String>();
                     for (String value: values)
-                        result.add(MimeUtility.unfold(value));
+                        result.add(MimeUtility.decodeText(MimeUtility.unfold(value)));
                 }
             } catch (MessagingException e) {
                 throw new SieveMailException(e);
+            } catch (UnsupportedEncodingException e) {
+                throw new SieveMailException(e);
             }
         }
         return result;
@@ -265,7 +268,7 @@ public class ScriptCheckMailAdapter implements MailAdapter {
                 final Header header = (Header) en.nextElement();
                 final String name = header.getName();
                 if (name.trim().equalsIgnoreCase(headerName)) {
-                    builder.addAddresses(MimeUtility.unfold(header.getValue()));
+                    builder.addAddresses(MimeUtility.decodeText(MimeUtility.unfold(header.getValue())));
                 }
             }
 
@@ -274,6 +277,8 @@ public class ScriptCheckMailAdapter implements MailAdapter {
 
         } catch (MessagingException ex) {
             throw new SieveMailException(ex);
+        } catch (UnsupportedEncodingException ex) {
+            throw new SieveMailException(ex);
         } catch (ParseException ex) {
             throw new SieveMailException(ex);
         }