コード例 #1
0
ファイル: Message.java プロジェクト: stee11/newsgroups
 public String[] getEmail() {
   LinkedSet<String> ls = new LinkedSet<String>();
   int counter = 0;
   String bod = this.getBody();
   String from = this.getFrom();
   Scanner f = new Scanner(from);
   Scanner b = new Scanner(bod);
   String pattern =
       "^[A-Za-z0-9]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
   while (b.hasNext()) {
     String newString = b.next();
     String finalString = newString.replaceAll(pattern, "");
     if (newString.matches(pattern)) {
       ls.add(newString);
       counter++;
     }
   }
   while (f.hasNext()) {
     String newString = f.next();
     String finalString = newString.replaceAll(pattern, "");
     if (newString.matches(pattern)) {
       ls.add(newString);
       counter++;
     }
   }
   String[] Lastemails = new String[ls.size()];
   if (ls.size() > 0) {
     for (int i = 0; i < ls.size(); i++) {
       Lastemails[i] = ls.get(i + 1);
     }
   }
   return Lastemails;
 }