Пример #1
0
 private Date getSentDate(List<MessagePartHeader> headers) {
   for (MessagePartHeader header : headers) {
     if ("Date".equals(header.getName())) {
       try {
         return emailDateFormat.parse(header.getValue());
       } catch (ParseException e) {
         LOGGER.log(Level.WARNING, "Failed to parse date " + header.getValue(), e);
       }
     }
   }
   return new Date();
 }
Пример #2
0
 private String getSender(List<MessagePartHeader> headers) {
   for (MessagePartHeader header : headers) {
     if ("From".equals(header.getName())) {
       String sender = header.getValue();
       int addressIndex = sender.indexOf('<');
       if (addressIndex > 0) {
         sender = sender.substring(0, addressIndex).trim();
       }
       return sender;
     }
   }
   return "Unknown Gmail Source";
 }
Пример #3
0
  public Map getBareGmailMessageDetails(String messageId) {
    Map<String, Object> messageDetails = new HashMap<String, Object>();
    try {
      Gmail service =
          new Gmail.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
              .setApplicationName("Gmail Quickstart")
              .build();
      Message message =
          service
              .users()
              .messages()
              .get("me", messageId)
              .setFormat("full")
              .setFields("id,payload,sizeEstimate,snippet,threadId")
              .execute();
      List<MessagePartHeader> headers = message.getPayload().getHeaders();
      for (MessagePartHeader header : headers) {
        if (header.getName().equals("From")
            || header.getName().equals("Date")
            || header.getName().equals("Subject")
            || header.getName().equals("To")
            || header.getName().equals("CC")) {
          messageDetails.put(header.getName().toLowerCase(), header.getValue());
        }
      }
      messageDetails.put("snippet", message.getSnippet());
      messageDetails.put("threadId", message.getThreadId());
      messageDetails.put("id", message.getId());
      // messageDetails.put("body",message.getPayload().getBody().getData());

    } catch (IOException ex) {
      Logger.getLogger(GoogleAuthHelper.class.getName()).log(Level.SEVERE, null, ex);
    }
    return messageDetails;
  }