This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository faxtomail. See https://gitlab.nuiton.org/codelutin/faxtomail.git commit 3281552343f9d47e714f53db3570598d5b78b5e1 Author: jcouteau <couteau@codelutin.com> Date: Mon May 13 10:08:30 2019 +0200 fix #10345 et #10346 : Pb de reconnaissance des expéditeurs --- .../faxtomail/services/FaxToMailServiceUtils.java | 13 ++-- .../services/FaxToMailServiceUtilsTest.java | 77 +++++++++++++--------- .../faxtomail/web/job/MailFilterJob.java | 11 +--- 3 files changed, 53 insertions(+), 48 deletions(-) diff --git a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceUtils.java b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceUtils.java index 9f79279b..67079a26 100644 --- a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceUtils.java +++ b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceUtils.java @@ -171,16 +171,15 @@ public class FaxToMailServiceUtils { return subject; } - public static String getDecodedFrom(String from) throws UnsupportedEncodingException { + public static String getDecodedFrom(String from) { Preconditions.checkNotNull(from); - System.setProperty("mail.mime.decodetext.strict", "false"); - if (from.startsWith("=?iso-")) { - //from = from.replaceAll(" ", "=20"); - from = MimeUtility.decodeText(from); - } + // some sender are like "toto tutu<toto.tutu73@gmail.com>" + // some sender are like "toto tutu@ <gmail.com toto.tutu73@gmail.com>" + // the regex is to extract email address from it + from = from.replaceFirst("^.*<(.*\\s)?([\\S]+@[\\S]+)(\\s.*)?>$", "$2"); - return from; + return from.toLowerCase(); } public static String getDomainForEmailAddress(String emailAddress) { diff --git a/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/FaxToMailServiceUtilsTest.java b/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/FaxToMailServiceUtilsTest.java index 9c6a7b2a..9fdfff13 100644 --- a/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/FaxToMailServiceUtilsTest.java +++ b/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/FaxToMailServiceUtilsTest.java @@ -27,14 +27,6 @@ package com.franciaflex.faxtomail.services; import org.junit.Assert; import org.junit.Test; -import java.nio.ByteBuffer; -import java.nio.CharBuffer; -import java.nio.charset.Charset; -import java.nio.charset.CharsetDecoder; -import java.nio.charset.CharsetEncoder; -import java.sql.SQLOutput; -import java.util.Map; - /** * @author Kevin Morin (Code Lutin) * @since 2.0.4 @@ -54,9 +46,8 @@ public class FaxToMailServiceUtilsTest { try { FaxToMailServiceUtils.getDomainForEmailAddress(null); Assert.fail("null email address should throw an excpetion"); - } catch(NullPointerException e) { - // a NPE should be caught + // a NPE should be thrown } } @@ -76,31 +67,55 @@ public class FaxToMailServiceUtilsTest { @Test public void testDecodeFrom() { - try { - String from = "=?iso-8859-1?b?qkfjrsbpvuvtvcbo?= =?iso-8859-1?b?qu5urvmgqkftu0ug?= =?iso-8859-1?b?r09vtefjtku=?= <agence.nantes@baie-ouest.fr>"; - from = "=?iso-8859-1?b?QkFJRSBPVUVTVCBO?= =?iso-8859-1?b?QU5URVMgQkFTU0Ug?= =?iso-8859-1?b?R09VTEFJTkU=?= <agence.nantes@baie-ouest.fr>"; - String test = FaxToMailServiceUtils.getDecodedFrom(from); + String from = "=?iso-8859-1?b?qkfjrsbpvuvtvcbo?= =?iso-8859-1?b?qu5urvmgqkftu0ug?= =?iso-8859-1?b?r09vtefjtku=?= <agence.nantes@baie-ouest.fr>"; + Assert.assertEquals("agence.nantes@baie-ouest.fr", FaxToMailServiceUtils.getDecodedFrom(from)); -// Map<String, Charset> charsetMap = Charset.availableCharsets(); -// for (Map.Entry<String, Charset> entry:charsetMap.entrySet()){ -// if (!"IBM290".equals(entry.getKey()) && !"IBM424".equals(entry.getKey()) && !"x-IBM1364".equals(entry.getKey()) && !"X-UTF-32LE-BOM".equals(entry.getKey()) && !"X-UTF-32BE-BOM".equals(entry.getKey()) && !"x-UTF-16LE-BOM".equals(entry.getKey()) && !"x-JIS0208".equals(entry.getKey()) && !"x-IBM933".equals(entry.getKey()) && !"x-IBM939".equals(entry.getKey()) && !"x-IBM937".equals(entry.getKey()) && !"x-IBM935".equals(entry.getKey()) && !"x-IBM930".equals(entry.g [...] -// CharsetDecoder decoder = entry.getValue().newDecoder(); -// //System.out.println(entry.getKey() + " : " + decoder.decode(ByteBuffer.wrap(test.getBytes()))); -// System.out.println(entry.getKey()); -// System.out.println(decoder.decode(ByteBuffer.wrap(from.getBytes()))); -// } -// } + from = "=?iso-8859-1?b?QkFJRSBPVUVTVCBC?= =?iso-8859-1?b?QVNSBHT1VMQULO?= =?iso-8859-1?b?RQ==?= <agence.nantes@baie-ouest.fr>"; + Assert.assertEquals("agence.nantes@baie-ouest.fr", FaxToMailServiceUtils.getDecodedFrom(from)); - Assert.assertEquals("BAIE OUEST NANTES BASSE GOULAINE <agence.nantes@baie-ouest.fr>", FaxToMailServiceUtils.getDecodedFrom(from)); + from = "=?iso-8859-1?b?u2nhbm7pigrlchvp?= =?iso-8859-1?b?c1rvc2hpymegrxhw?= =?iso-8859-1?b?zxj0ie1lbnvpc2vy?= =?iso-8859-1?b?awu=?= <a.bonnaud@expertmenuiserie.fr>"; + Assert.assertEquals("a.bonnaud@expertmenuiserie.fr", FaxToMailServiceUtils.getDecodedFrom(from)); - from = "=?iso-8859-1?q?henri_seguin__mail_=3a_henri=2eseguin=40homkia=2efr_-_t=e9?= =?iso-8859-1?q?l_=3a_09_84_07_18_47?= <henri.seguin@homkia.fr>"; - Assert.assertEquals("henri seguin mail : henri.seguin@homkia.fr - tél : 09 84 07 18 47 <henri.seguin@homkia.fr>", FaxToMailServiceUtils.getDecodedFrom(from)); + from = "=?iso-8859-1?q?henri_seguin__mail_=3a_henri=2eseguin=40homkia=2efr_-_t=e9?= =?iso-8859-1?q?l_=3a_09_84_07_18_47?= <henri.seguin@homkia.fr>"; + Assert.assertEquals("henri.seguin@homkia.fr", FaxToMailServiceUtils.getDecodedFrom(from)); - from = "Jean Couteau <couteau@codelutin.com>"; - Assert.assertEquals("Jean Couteau <couteau@codelutin.com>", FaxToMailServiceUtils.getDecodedSubject(from)); + from = "=?windows-1252?q?henri_seguin__mail_=3a_henri=2eseguin=40homkia=2efr_-_t?= =?windows-1252?q?=e9l_=3a_09_84_07_18_47?= <henri.seguin@homkia.fr>"; + Assert.assertEquals("henri.seguin@homkia.fr", FaxToMailServiceUtils.getDecodedFrom(from)); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } + from = "=?utf-8?q?secr=c3=a9tariat_-_menuiseries_de_lum?= =?utf-8?q?i=c3=a8re_technal?= <mgivaja@mdl83.fr>"; + Assert.assertEquals("mgivaja@mdl83.fr", FaxToMailServiceUtils.getDecodedFrom(from)); + + from = "=?utf-8?q?6_jrs_=7c_r=c3=a8gles_juridiques_des?= =?utf-8?q?_travaux_de_btp?= <actu@ofib.eu>"; + Assert.assertEquals("actu@ofib.eu", FaxToMailServiceUtils.getDecodedFrom(from)); + + from = "=?utf-8?q?entreprise_on_demand_=2d_comptablilit=c3=a9_fournisseu?= =?utf-8?q?rs?= <comptabilite.fournisseurs@vipplus.com>"; + Assert.assertEquals("comptabilite.fournisseurs@vipplus.com", FaxToMailServiceUtils.getDecodedFrom(from)); + + from = "Jean Couteau <couteau@codelutin.com>"; + Assert.assertEquals("couteau@codelutin.com", FaxToMailServiceUtils.getDecodedFrom(from)); + + from = ""; + Assert.assertEquals("", FaxToMailServiceUtils.getDecodedFrom(from)); + + from = "agence.nantes@baie-ouest.fr"; + Assert.assertEquals("agence.nantes@baie-ouest.fr", FaxToMailServiceUtils.getDecodedFrom(from)); + + from = "<agence.nantes@baie-ouest.fr>"; + Assert.assertEquals("agence.nantes@baie-ouest.fr", FaxToMailServiceUtils.getDecodedFrom(from)); + + from = "BAIE OUEST NANTES BASSE GOULAINE <agence.nantes@baie-ouest.fr>"; + Assert.assertEquals("agence.nantes@baie-ouest.fr", FaxToMailServiceUtils.getDecodedFrom(from)); + + from = "\"mpo.cae.sec@\" <free.fr mpo.cae.sec@free.fr>"; + Assert.assertEquals("mpo.cae.sec@free.fr", FaxToMailServiceUtils.getDecodedFrom(from)); + + from = "\"mpo.cae.sec@\" <mpo.cae.sec@free.fr free.fr>"; + Assert.assertEquals("mpo.cae.sec@free.fr", FaxToMailServiceUtils.getDecodedFrom(from)); + + from = "\"mpo.cae.sec@\" <mpo.cae.sec@free.fr>"; + Assert.assertEquals("mpo.cae.sec@free.fr", FaxToMailServiceUtils.getDecodedFrom(from)); + + from = "<mpo.cae.sec@free.fr>"; + Assert.assertEquals("mpo.cae.sec@free.fr", FaxToMailServiceUtils.getDecodedFrom(from)); } } \ No newline at end of file diff --git a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/job/MailFilterJob.java b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/job/MailFilterJob.java index a3364350..46e62a3b 100644 --- a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/job/MailFilterJob.java +++ b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/job/MailFilterJob.java @@ -247,12 +247,7 @@ public class MailFilterJob extends AbstractFaxToMailJob { Collections2.transform(recipientAddresses, new Function<Address, String>() { @Override public String apply(Address address) { - String recipient = address.toString(); - // some recipient are like "toto tutu<toto.tutu73@gmail.com>" - // the regex is to extract email address from it - recipient = recipient.replaceAll("\\s", "").replaceFirst("^.*<(.*)>$", "$1"); - recipient = recipient.toLowerCase(); - return recipient; + return FaxToMailServiceUtils.getDecodedFrom(address.toString()); } })); @@ -320,10 +315,6 @@ public class MailFilterJob extends AbstractFaxToMailJob { Address[] addresses = message.getFrom(); if (addresses != null && addresses.length > 0) { String sender = FaxToMailServiceUtils.getDecodedFrom(addresses[0].toString()); - // some sender are like "toto tutu<toto.tutu73@gmail.com>" - // the regex is to extract email address from it - sender = sender.replaceFirst("^.*<(.*)>$", "$1"); - sender = sender.toLowerCase(); // Identification du client en fonction du numéro de fax appelant ou de l'adresse e-mail émettrice List<Client> clients = clientService.getClientForEmailAddress(sender, email, company, brands); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.