test_class.declarator: profileFromMailFromService
test_class.modifier: private
test_class.original_string: private ProfileFromMailFromServiceSensor profileFromMailFromService;
test_class.type: ProfileFromMailFromServiceSensor
test_class.var_name: profileFromMailFromService
test_class.file: eu.alert-project.iccs.stardom.core/eu.alert-project.iccs.stardom.analyzers/eu.alert-project.iccs.stardom.analyzers.mailing/src/test/java/eu/alertproject/iccs/stardom/analyzers/mailing/internal/ProfileFromMailFromServiceSensorTest.java
test_class.identifier: ProfileFromMailFromServiceSensorTest
test_case.body: @Test
      public void getString(){
  
  
          Profile profileQuote = profileFromMailFromService.generate(
                  "lamarque at gmail.com (Lamarque Vieira Souza)"
          );
          Assert.assertEquals(profileQuote.getName(),"Lamarque");
          Assert.assertEquals(profileQuote.getLastname(),"Vieira Souza");
          Assert.assertEquals(profileQuote.getEmail(),"lamarque gmail.com");
  
          Profile profileQuote2 = profileFromMailFromService.generate(
                  "lam_arque at g_mail.com (Lam_arque Vieira Souza)"
          );
          Assert.assertEquals(profileQuote2.getName(),"Lam_arque");
          Assert.assertEquals(profileQuote2.getLastname(),"Vieira Souza");
          Assert.assertEquals(profileQuote2.getEmail(),"lam_arque g_mail.com");
  
  
  
          Profile withQuotes = profileFromMailFromService.generate(
                  "teg at jklm.no (Tom Gundersen)"
          );
          Assert.assertEquals(withQuotes.getName(),"Tom");
          Assert.assertEquals(withQuotes.getLastname(),"Gundersen");
          Assert.assertEquals(withQuotes.getEmail(),"teg jklm.no");
  
  
          Profile withUtf = profileFromMailFromService.generate(
                  "kossebau at kde.org (Friedrich W. H. Kossebau)"
          );
          Assert.assertEquals(withUtf.getName(),"Friedrich");
          Assert.assertEquals(withUtf.getLastname(),"W. H. Kossebau");
          Assert.assertEquals(withUtf.getEmail(),"kossebau kde.org");
  
  
          Profile withUTFNullResult = profileFromMailFromService.generate(
                  "=?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= <zajec5@gmail.com>"
          );
          Assert.assertNull(withUTFNullResult);
  
      }
test_case.class_method_signature: ProfileFromMailFromServiceSensorTest.getString()
test_case.full_signature: @Test public void getString()
test_case.identifier: getString
test_case.invocations: generate assertEquals getName assertEquals getLastname assertEquals getEmail generate assertEquals getName assertEquals getLastname assertEquals getEmail generate assertEquals getName assertEquals getLastname assertEquals getEmail generate assertEquals getName assertEquals getLastname assertEquals getEmail generate assertNull
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void getString()
focal_class.declarator: logger = LoggerFactory.getLogger(ProfileFromMailFromServiceSensor.class)
focal_class.modifier: private
focal_class.original_string: private Logger logger = LoggerFactory.getLogger(ProfileFromMailFromServiceSensor.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.file: eu.alert-project.iccs.stardom.core/eu.alert-project.iccs.stardom.analyzers/eu.alert-project.iccs.stardom.analyzers.mailing/src/main/java/eu/alertproject/iccs/stardom/analyzers/mailing/internal/ProfileFromMailFromServiceSensor.java
focal_class.identifier: ProfileFromMailFromServiceSensor
focal_class.interfaces: implements ProfileFromMailFromService
focal_class.class_method_signature: ProfileFromMailFromServiceSensor.generate(String mailFrom)
focal_class.full_signature: @Override public Profile generate(String mailFrom)
focal_class.identifier: generate
focal_class.modifiers: @Override public
focal_class.parameters: (String mailFrom)
focal_class.return: Profile
focal_class.signature: Profile generate(String mailFrom)
focal_method.body: @Override
      public Profile generate(String mailFrom){
  
          String[] regexes = new String[]{
            "\"?([\\p{L}\\?-_]+)\\s?([\\p{L}\\?\\.\\d=\\\\ _-]+)?\"?\\s*<(.*)>", //  Alex Fiestas <afiestas@kde.org>
            "([\\p{L}\\.\\?-_]+) at ([\\p{L}\\?\\.\\d=\\-_]+) (\\((.*( .*)?)\\))?"
          };
  
          String regex = null;
  
          for(String reg:regexes){
  
              if(mailFrom.matches(reg)){
                  regex = reg;
                  break;
              }
          }
  
          if(regex == null){
              logger.error("Could not find a suitable regular expression for {} ",mailFrom);
              return null;
          }
  
          logger.debug("Found a match for {} ",mailFrom);
  
          /*
          We are making the following assumptions that we have
              1.) Email format Name Lastname <email>
              2.) Names are composed of a single word, the rest is the last name
  
              Alex Fiestas <afiestas@kde.org>
           */
          Pattern p = Pattern.compile(regex);
  
          int i = ArrayUtils.indexOf(regexes, regex);
          Profile profile = new Profile();
  
          Matcher matcher = p.matcher(mailFrom);
          matcher.matches();
  
          switch (i){
              case 0:   //  Alex Fiestas <afiestas@kde.org>
  
                  if(matcher.groupCount() <= 2){
                      //single name
                      profile.setName(matcher.group(1).trim());
                      profile.setEmail(matcher.group(2).trim());
                      profile.setUsername(matcher.group(2).trim());
                  }else if( matcher.groupCount()>2){
                      profile.setName(matcher.group(1).trim());
                      profile.setLastname(StringUtils.trimToEmpty(matcher.group(2)));
                      profile.setEmail(matcher.group(3).trim());
                      profile.setUsername(matcher.group(3).trim());
                  }
                  break;
              case 1:    //  afiestas at kde com
                  profile.setEmail(matcher.group(1).trim()+" "+matcher.group(2).trim());
                  profile.setName(StringUtils.substringBefore(matcher.group(4).trim()," "));
                  profile.setLastname(StringUtils.defaultIfEmpty(StringUtils.substringAfter(matcher.group(4).trim()," ").trim(),""));
                  break;
          }
          return profile;
  
      }
focal_method.class_method_signature: ProfileFromMailFromServiceSensor.generate(String mailFrom)
focal_method.full_signature: @Override public Profile generate(String mailFrom)
focal_method.identifier: generate
focal_method.invocations: matches error debug compile indexOf matcher matches groupCount setName trim group setEmail trim group setUsername trim group groupCount setName trim group setLastname trimToEmpty group setEmail trim group setUsername trim group setEmail trim group trim group setName substringBefore trim group setLastname defaultIfEmpty trim substringAfter trim group
focal_method.modifiers: @Override public
focal_method.parameters: (String mailFrom)
focal_method.return: Profile
focal_method.signature: Profile generate(String mailFrom)