Exemplo n.º 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);
    }
  }
Exemplo n.º 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;
   }
 }
Exemplo n.º 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"));
 }
Exemplo n.º 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);
    }
  }
Exemplo n.º 5
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);
    }
  }
Exemplo n.º 6
0
  /**
   * checks message sent date againsts a predefined email days cutoff
   *
   * @param message
   * @param migratedAccount
   * @return
   * @throws javax.mail.MessagingException
   */
  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;
    }

    // This should handle the first login case, we want to take up to x days worth of old emails and
    // not be rejected
    // by the Too Old check
    if (account.getLast_received_date() == 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 (System.currentTimeMillis() - message.getSentDate().getTime())
          > 1000l * 60 * 60 * 24 * emailDaysCutoff;
    }

    return isOlder(message.getSentDate(), account.getLast_received_date());
  }
Exemplo n.º 7
0
  public static String send(Email2Send email, Server server) throws Exception {
    Session session;

    if (server.isAuth()) {
      Authenticator auth = new PopAuthenticator(server.getUser(), server.getPwd());
      session = Session.getInstance(getProperties(server), auth);
    } else {
      session = Session.getInstance(getProperties(server), null);
    }
    MyMessage mailMsg = new MyMessage(session); // a new email message
    InternetAddress[] addresses = null;
    try {
      if (email.getDestinatari() != null && email.getDestinatari().size() > 0) {
        addresses = InternetAddress.parse(email.getDestinatariToString(), false);
        mailMsg.setRecipients(Message.RecipientType.TO, addresses);
      } else {
        throw new MessagingException("The mail message requires a 'To' address.");
      }
      if (email.getCc() != null && email.getCc().size() > 0) {
        addresses = InternetAddress.parse(email.getCcToString(), false);
        mailMsg.setRecipients(Message.RecipientType.CC, addresses);
      }
      if (email.getBcc() != null && email.getBcc().size() > 0) {
        addresses = InternetAddress.parse(email.getBccToString(), false);
        mailMsg.setRecipients(Message.RecipientType.BCC, addresses);
      }
      if (email.getMittente() != null) {
        mailMsg.setFrom(new InternetAddress(email.getMittente()));
      } else {
        throw new MessagingException("The mail message requires a valid 'From' address.");
      }
      //
      if (email.getOggetto() != null) mailMsg.setSubject(email.getOggetto());
      // corpo e attachment
      if (email.getAllegati() != null && email.getAllegati().size() > 0) {
        BodyPart messageBodyPart = new MimeBodyPart();
        if (email.getCorpo() != null) messageBodyPart.setText(email.getCorpo());
        Multipart multipart = new MimeMultipart();
        multipart.addBodyPart(messageBodyPart);
        // attachment
        for (File allegato : email.getAllegati()) {
          messageBodyPart = new MimeBodyPart();
          DataSource source = new FileDataSource(allegato.getCanonicalPath());
          DataHandler dataH = new DataHandler(source);
          messageBodyPart.setDataHandler(dataH);
          messageBodyPart.setFileName(allegato.getName());
          multipart.addBodyPart(messageBodyPart);
        }
        mailMsg.setContent(multipart);
      } else {
        mailMsg.setContent(email.getCorpo(), "text/plain;charset=\"UTF-8\"");
      }

      mailMsg.setId("<CN" + System.currentTimeMillis() + "@giava.by/giavacms>");
      // mailMsg.addHeader("Message-ID",
      // "111111.11199295388525.provaProvaProva");

      mailMsg.setSentDate(new Date());
      mailMsg.saveChanges();
      // Finally, send the mail message; throws a 'SendFailedException'
      // if any of the message's recipients have an invalid address
      Transport.send(mailMsg);
    } catch (MessagingException e) {
      logger.error(e.toString());
      e.printStackTrace();
      return "";
    } catch (Exception exc) {
      logger.error(exc.toString());
      exc.printStackTrace();
      return "";
    }
    return mailMsg.getMessageID();
  }