Note that there are some explanatory texts on larger screens.

plurals
  1. POChecking if a message contains a string
    primarykey
    data
    text
    <p>I have have a class that check id a phrase is contained in a message, I tried to do it with <code>Matcher</code> and <code>Pattern</code> and with <code>String.contains()</code>, but the results returned are odd.</p> <p>Here is the class:</p> <pre><code>public class MotsClesFilter implements EmailFilter { final String NAME = "Filtrage par mots cles"; /*private Pattern chaineSpam; private Matcher chaineCourriel;*/ private int nbOccMotSpam; private byte confidenceLevel; @Override public String getFilterName() { return this.NAME; } @Override public byte checkSpam(MimeMessage message) { analyze(message); if(this.nbOccMotSpam==0) this.confidenceLevel = 1; else if (this.nbOccMotSpam&gt;0 &amp;&amp; this.nbOccMotSpam&lt;2) this.confidenceLevel = CANT_SAY; else if (this.nbOccMotSpam&gt;1 &amp;&amp; this.nbOccMotSpam&lt;3) this.confidenceLevel = 50; else if (this.nbOccMotSpam&gt;3 &amp;&amp; this.nbOccMotSpam&lt;4) this.confidenceLevel = 65; else if (this.nbOccMotSpam&gt;4 &amp;&amp; this.nbOccMotSpam&lt;5) this.confidenceLevel = 85; else this.confidenceLevel = 90; return (getConfidenceLevel()); } public void analyze(MimeMessage message){ try { List&lt;String&gt; listeChaines = new ArrayList&lt;String&gt;(); BufferedReader bis = new BufferedReader(new InputStreamReader(new FileInputStream(new File("SpamWords.txt")))); while(bis.ready()){ String ligne = bis.readLine(); listeChaines.add(ligne); } String mail = ((String.valueOf(message.getContent()))); //System.out.println(mail); for (int j =0; j&lt;listeChaines.size();j++){ //System.out.println(listeChaines.get(j)); Pattern chaineSpam = Pattern.compile(listeChaines.get(j),Pattern.CASE_INSENSITIVE); Matcher chaineCourriel = chaineSpam.matcher(mail); if (chaineCourriel.matches()) this.nbOccMotSpam++; } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MessagingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public byte getConfidenceLevel() { // TODO Auto-generated method stub return this.confidenceLevel; } @Override public boolean enabled() { // TODO Auto-generated method stub return true; } } </code></pre> <p>The results returned by <code>checkSpam</code> are always 1 if use matches and 90 if I use find, it also returns 90 when I use <code>mail.contains(listeChaines.get(j))</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload