title: In selenium webdrive how to login in gmail and get activation code by using mail subject
body: <pre><code>public String getAuthorizationCode(String account) throws Exception {
      Message email = getMessagesBySubject("Email Subject "+ account, true, 5)[0];
      BufferedReader reader = new BufferedReader(new InputStreamReader(email.getInputStream()));
  
      String line;
      String prefix = "userId:";
  
      while ((line = reader.readLine()) != null) {
        if(line.startsWith(prefix)) {
          return line.substring(line.indexOf(":") + 1);
        }
      }
      return null;
    }
  </code></pre>
  
  <p>//  public Message[] getMessagesBySubject(String subject, boolean unreadOnly, int maxToSearch) throws Exception{
      Map indices = getStartAndEndIndices(maxToSearch);</p>
  
  <pre><code>Message messages[] = folder.search(
      new SubjectTerm(subject),
      folder.getMessages(indices.get("startIndex"), indices.get("endIndex")));
  
  if(unreadOnly){
    List&lt;Message&gt; unreadMessages = new ArrayList&lt;Message&gt;();
    for (Message message : messages) {
      if(isMessageUnread(message)) {
        unreadMessages.add(message);
      }
    }
    messages = unreadMessages.toArray(new Message[]{});
  }
  
  return messages;
  </code></pre>
  
  <p>}</p>