java - Checking if a message contains a string -


i have have class check id phrase contained in message, tried matcher , pattern , string.contains(), results returned odd.

here class:

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>0 && this.nboccmotspam<2)             this.confidencelevel = cant_say;         else if (this.nboccmotspam>1 && this.nboccmotspam<3)             this.confidencelevel = 50;         else if (this.nboccmotspam>3 && this.nboccmotspam<4)             this.confidencelevel = 65;         else if (this.nboccmotspam>4 && this.nboccmotspam<5)             this.confidencelevel = 85;         else this.confidencelevel = 90;         return (getconfidencelevel());     }       public void analyze(mimemessage message){         try {             list<string> listechaines = new arraylist<string>();              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);               (int j =0; j<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;     } } 

the results returned checkspam 1 if use matches , 90 if use find, returns 90 when use mail.contains(listechaines.get(j)).

that means message doesn't match of strings in file, there @ least 5 strings in file can found inside message.

matches() checks if whole string matches pattern. not if substring matches it.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -