示例#1
0
  public void updateAccount(
      Account account,
      String newFolderHash,
      int newMessages,
      int folderDepth,
      Date lastMessageReceivedDate)
      throws DALException {
    account.setFolder_hash(newFolderHash);
    // reset login failures - since update account happens on successful mail fetch
    account.setLogin_failures(0);
    account.setLast_login_failure(null);

    account.setMessage_count(account.getMessage_count() + newMessages);

    account.setLast_mailcheck(new Date(System.currentTimeMillis()));

    account.setFolder_depth(folderDepth);

    if (lastMessageReceivedDate == null) {
      DALDominator.updateAccountReceiveInfo(account);
    } else {
      account.setLast_received_date(lastMessageReceivedDate);
      DALDominator.updateAccountReceiveInfoAndReceivedDate(account);
    }
  }
示例#2
0
 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;
   }
 }
示例#3
0
 public boolean isTimeToReconcile(Account account) {
   return account.getLast_reconciliation() == null
       || (System.currentTimeMillis() - account.getLast_reconciliation().getTime())
           > 1000l
               * 60
               * Long.valueOf(
                   SysConfigManager.instance().getValue("reconciliationIntervalInMinutes", "60"));
 }
示例#4
0
  public void handleLoginFailures(String context, Account account) throws DALException {
    account.setLast_mailcheck(new Date(System.currentTimeMillis()));

    if (account.getLogin_failures() == null) {
      account.setLogin_failures(1);
    } else {
      account.setLogin_failures(account.getLogin_failures() + 1);
    }

    account.setLast_login_failure(new Date(System.currentTimeMillis()));

    DALDominator.updateAccountReceiveInfo(account);

    if (shouldSendAccountLockedNotification(account)) {
      notifyAccountLock(account, context);
      sendAccountLockedNotificationEm(account);
    }
  }
示例#5
0
  public Message processMessage(
      Account account,
      String messageStoreBucket,
      Message message,
      int messageNumber,
      String messageId,
      String context,
      StopWatch watch,
      List<MessageValidator> validators,
      EmailProcess emailProcess)
      throws Exception {
    long start = System.nanoTime();

    try {
      StopWatchUtils.newTask(
          watch, String.format("msgNum=%s, storeCheck", messageNumber), context, log);
      log.debug(
          String.format(
              "msgNum=%d, checking if messageId=%s is known for %s",
              messageNumber, messageId, context));
      message =
          valiateAndPrepMessage(
              account, messageStoreBucket, message, messageNumber, messageId, validators);
      if (message != null) {
        log.info(
            String.format(
                "msgNum=%d, messageId=%s, message is new for %s",
                messageNumber, messageId, context));
        boolean result = emailProcess.process(message, messageNumber, messageId);
        if (result) {
          return message;
        }
      }
    } finally {
      if (log.isDebugEnabled())
        log.debug(
            String.format(
                "msgNum=%d, checked if messageId=%s is known in %dms for %s",
                messageNumber, messageId, (System.nanoTime() - start) / 1000000, context));
    }

    return null;
  }
示例#6
0
  public void notifyAccountLock(Account account, String context) {
    PartnerCode partnerCode = account.getPartnerCode();
    String lockedOutMessageBody =
        SysConfigManager.instance()
            .getValue("lockedOutMessageBody", LOCKED_OUT_MESSAGE_BODY, partnerCode);
    String lockedOutMessageSubject =
        SysConfigManager.instance()
            .getValue("lockedOutMessageSubject", LOCKED_OUT_MESSAGE_SUBJECT, partnerCode);
    String lockedOutMessageFrom =
        SysConfigManager.instance()
            .getValue("lockedOutMessageFrom", LOCKED_OUT_MESSAGE_FROM, partnerCode);
    String lockedOutMessageAlias =
        SysConfigManager.instance()
            .getValue("lockedOutMessageAlias", LOCKED_OUT_MESSAGE_ALIAS, partnerCode);

    try {
      Email email = new Email();
      email.setSubject(lockedOutMessageSubject);

      email.setStatus("0");
      email.setUserId(account.getUser_id());
      email.setMessage_type("EMAIL");

      email.setFrom(lockedOutMessageFrom);
      email.setFrom_alias(lockedOutMessageAlias);
      email.setTo(account.getLoginName());
      email.setBodySize(lockedOutMessageBody.length());

      DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      email.setMaildate(dateFormat.format(new Date(System.currentTimeMillis()))); // ugh!

      email.setOriginal_account(account.getLoginName());

      // create the pojgo
      EmailPojo emailPojo = new EmailPojo();
      emailPojo.setEmail(email);

      Body body = new Body();
      body.setData(lockedOutMessageBody.getBytes());

      // note, the email will be encoded to prevent sql-injection. since this email is destined
      // directly for the
      // device, we need to reverse the encoding after the call to newSaveEmail
      new EmailRecievedService().newSaveEmail(account, email, body);

      // Added by Dan so we stop checking accounts that have incorrect passwords
      account.setStatus("0");

    } catch (Throwable t) {
      log.warn(String.format("failed to save locked out message for %s", context), t);
    }
  }