コード例 #1
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
 public boolean isMessageTooOld(Account account, Message message, String context)
     throws MessagingException {
   if (message.getSentDate() == null) {
     log.warn(
         String.format("we have a message with no sent date for %s, allowing message", context));
     return false;
   } else if (account.getRegister_time() == null) {
     log.warn(
         String.format(
             "we are process an account with no register time. this behavior is not understood yet %s, we will accept this message",
             context));
     return false;
   } else {
     boolean messageTooOld =
         (System.currentTimeMillis() - message.getSentDate().getTime())
             > 1000l * 60 * 60 * 24 * emailDaysCutoff;
     if (messageTooOld) {
       log.warn(
           String.format(
               "msgNum=%d, message is too old, sentDate=%s, discarding, for %s",
               message.getMessageNumber(), message.getSentDate(), context));
     }
     return messageTooOld;
   }
 }
コード例 #2
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
 public Date getMessageDate(Message message) throws MessagingException {
   Date messageDate = message.getReceivedDate();
   if (message.getReceivedDate() == null) {
     if (message.getSentDate() != null) {
       messageDate = message.getSentDate();
     }
   }
   return messageDate;
 }
コード例 #3
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
  public int handleFirstTime(
      Account account,
      FolderHelper folderHelper,
      int folderDepth,
      String messageStoreBucket,
      Set<String> storedMessageIds,
      String context,
      StopWatch watch)
      throws Exception {
    int newMessages = 0;
    Date lastMessageReceivedDate = null;
    log.info(String.format("handling first mailcheck for %s", context));

    Folder folder;
    while ((folder = folderHelper.next()) != null) {
      String folderContext = context + " ,folderName=" + folder.getFullName();
      IMAPFolder imapFolder = (IMAPFolder) folder;

      Collection<Integer> messages = getFirstTimeMessages(imapFolder, folderContext);

      if (messages.size() > 0) {
        storedMessageIds = new HashSet<String>();

        for (Integer messageNumber : messages) {
          Message message = imapFolder.getMessage(messageNumber);

          if (lastMessageReceivedDate == null
              || lastMessageReceivedDate.before(message.getReceivedDate())) {
            lastMessageReceivedDate = message.getReceivedDate();
          }

          String messageId = getId(account, imapFolder, message);

          if (processMessage(
              account,
              message,
              messageNumber,
              messageId,
              imapFolder,
              storedMessageIds,
              messageStoreBucket,
              folderContext,
              watch,
              folderHelper)) {
            newMessages++;
          }
        }
      }
    }
    updateAccount(account, null, 0, folderDepth, lastMessageReceivedDate);
    return newMessages;
  }
コード例 #4
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
 protected int getMessageSize(Message message, Account account)
     throws IOException, MessagingException {
   int count = 0;
   if (account.getLoginName().contains("aol.com") && message.getContent() instanceof Multipart) {
     Multipart multipart = (Multipart) message.getContent();
     for (int i = 0; i < multipart.getCount(); i++) {
       count += multipart.getBodyPart(i).getSize();
     }
   } else {
     count = message.getSize();
   }
   return count;
 }
コード例 #5
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
  /**
   * Deliveres notification to the user that an email has been dropped. Typically due to size
   * restriction
   *
   * @param account
   * @param messageNumber
   * @param message
   * @throws Exception
   */
  public void saveMessageDroppedNotification(
      Account account, int messageNumber, Message message, int reportedSize) throws Exception {
    MessageParser parser = new MessageParser();

    Email email = new Email();
    email.setSubject(
        "Your email"); // ReceiverUtilsTools.subSubject(parser.parseMsgSubject(message),
                       // subjectSize));
    email.setFrom(parser.parseMsgAddress(message, "FROM", false));
    email.setTo(ReceiverUtilsTools.subAddress(parser.parseMsgAddress(message, "TO", true)));
    email.setCc(ReceiverUtilsTools.subAddress(parser.parseMsgAddress(message, "CC", true)));
    email.setBcc(ReceiverUtilsTools.subAddress(parser.parseMsgAddress(message, "BCC", true)));
    email.setMaildate(ReceiverUtilsTools.dateToStr(message.getSentDate()));
    email.setStatus("0");
    email.setUserId(account.getUser_id());
    email.setMessage_type("EMAIL");

    Body body = new Body();

    String droppedMessage =
        getEmailDroppedMessage(account, getMessageDate(message), reportedSize, email.getFrom());

    body.setData(droppedMessage.getBytes());
    email.setBodySize(droppedMessage.length());

    int saveStatus = DALDominator.newSaveMail(account, email, body);

    if (log.isDebugEnabled())
      log.debug(
          String.format(
              "[%s] msgNum=%d, saving completed for dropped message with status %s",
              account.getName(), messageNumber, saveStatus));
  }
コード例 #6
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
  private boolean isRead(Message msg, String context) {
    boolean readFlag = false;
    try {
      if (msg.isExpunged()) {
        readFlag = true;
      } else {
        Flags flags = msg.getFlags();
        Flags.Flag[] flag = flags.getSystemFlags();
        for (Flags.Flag aFlag : flag) {
          if (aFlag == Flags.Flag.SEEN) {
            readFlag = true;
            break;
          }
        }
      }
    } catch (MessagingException e) {
      log.debug(String.format("failed to get SEEN FLAG for %s", context), e);
    }

    return readFlag;
  }
コード例 #7
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
  /**
   * It so happens Gmail sends us sent messages as well as received once
   *
   * @param account
   * @param message
   * @return
   * @throws Exception
   */
  protected boolean isSentMessage(Account account, Message message) throws Exception {
    MessageParser parser = new MessageParser();

    if (EmailUtil.isFromSameAsAccount(account, message)) {
      String to = parser.parseMsgAddress(message, "TO", true);
      String cc = parser.parseMsgAddress(message, "CC", true);

      if (!to.contains(account.getName()) && !cc.contains(account.getName())) {
        log.warn(
            String.format(
                "msgNum=%d, message is 'sent' not 'received' discarding, for %s",
                message.getMessageNumber(), account.getName()));
        return true;
      }
    }

    return false;
  }
コード例 #8
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
  protected Message getFullyLoad(Message message, Folder folder, String context)
      throws MessagingException {

    // use the copy constructor to try and copy the email over and work with it locally
    boolean read = isRead(message, context);

    MimeMessage msg = new MimeMessage((MimeMessage) message);
    // BUG: was marking IMAP emails as read: test account of aircel to verify

    try {
      if (!read && (folder instanceof IMAPFolder)) {
        message.setFlag(Flags.Flag.SEEN, false);
      }
    } catch (MessagingException me) {
      // Not all providers allow for setting of flags
      log.debug(String.format("failed to SEEN flag %s", context), me);
    }
    return msg;
  }
コード例 #9
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
 private Date getDateToDetermineOrder(Message message) throws MessagingException {
   return message instanceof IMAPMessage ? message.getReceivedDate() : message.getSentDate();
 }