Пример #1
0
  public String getMessageThread(String threadId) {
    String returnVal = "";
    JSONObject threadDetails = new JSONObject();
    try {

      Gmail service =
          new Gmail.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
              .setApplicationName("Gmail Quickstart")
              .build();
      com.google.api.services.gmail.model.Thread thread =
          service.users().threads().get("me", threadId).execute();
      System.out.println("Thread id: " + thread.getId());
      System.out.println("No. of messages in this thread: " + thread.getMessages().size());
      List<Message> messages = thread.getMessages();
      if (messages != null) {
        for (Message message : messages) {
          Message msg1 = service.users().messages().get("me", message.getId()).execute();
          // returnVal = returnVal + getMessage(message.getId());
          returnVal = returnVal + getMessageDetails(message.getId()).get("body");
        }

        System.out.println(thread.toPrettyString());
      }
      threadDetails.put("message", returnVal);
      return threadDetails.toJSONString();
    } catch (IOException ex) {
      Logger.getLogger(GoogleAuthHelper.class.getName()).log(Level.SEVERE, null, ex);
      return "error";
    }
  }
Пример #2
0
 public Thread execute() {
   try {
     Thread thread = new Thread();
     thread.setMessages(MockGmail.this.expectedThreadList.get(this.threadId));
     return thread;
   } catch (NullPointerException e) {
     return null;
   }
 }