コード例 #1
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
  public boolean isAccountBeingUsed(Account account) {
    if (log.isDebugEnabled())
      log.debug(
          String.format(
              "Checking account %s, user_id %s for last registration with location service",
              account.getId(), account.getUser_id()));

    IPeekLocationService locationService = new PeekLocationService();
    Date lastUpdated = null;
    try {
      lastUpdated = locationService.getLastUpdatedTimestamp(account.getUser_id());
    } catch (DALException e) {
      log.error(UtilsTools.getExceptionStackTrace(e));
    }
    if (lastUpdated == null) {
      log.debug("Last updated value not found, so we should still check this account");
      return true;
    }
    Date now = new Date();
    Long interval = dayMultiplier * mailcheckDisableIntervalInHours;
    Long sinceLastConnection = now.getTime() - lastUpdated.getTime();
    if (sinceLastConnection > interval) {
      if (log.isDebugEnabled())
        log.debug(
            String.format(
                "Last mail check was %s hours ago, > %s hour interval , we will not check this account",
                sinceLastConnection / dayMultiplier, interval / dayMultiplier));
      return false;
    }

    return true;
  }
コード例 #2
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));
  }
コード例 #3
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
 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
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
 protected boolean isMessageAlreadyProcessed(
     String messageId, Account account, String storeBucket, Set<String> storeMessageIds)
     throws MessageStoreException {
   return messageId != null
       && (storeMessageIds.contains(messageId)
           || messageIdStore.hasMessage(
               account.getId(), storeBucket, messageId, account.getCountry()));
 }
コード例 #5
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
  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);
    }
  }
コード例 #6
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
  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);
    }
  }
コード例 #7
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;
   }
 }
コード例 #8
0
  public ArrayList<Account> getAccountList() {
    Connection connect = null;

    try {
      ArrayList<Account> accounts = new ArrayList<>();
      connect = DBConnection.getConnection();

      String sql = "SELECT * FROM account" + "ORDER BY name desc";

      ResultSet result = Utility.queryOperation(connect, sql);
      Account temp = new Account();
      while (result.next()) {
        temp.setName(result.getString("name"));
        temp.setEmail(result.getString("email"));
        temp.setSecondaryEmail(result.getString("secondaryEmail"));
        temp.setTypeAccount(result.getString("typeAccount"));
        temp.setPassword(result.getString("password"));
        temp.setAdmin(result.getBoolean("isAdministrator"));
        accounts.add(temp);
      }
      return accounts;

    } catch (SQLException ex) {
      Logger.getLogger(AccountManager.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
      DBConnection.releaseConnection(connect);
    }
    return null;
  }
コード例 #9
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;
  }
コード例 #10
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
  protected String getEmailDroppedMessage(
      Account account, Date sentDate, int reportedSize, String from) throws MessagingException {
    String time = new SimpleDateFormat("hh:mm a").format(sentDate);
    String date = new SimpleDateFormat("MMMMM dd, yyyy").format(sentDate);

    String emailDroppedMessage =
        SysConfigManager.instance()
            .getValue("emailDroppedMessage", EMAIL_DROPPED_MESSAGE, account.getPartnerCode());

    return String.format(emailDroppedMessage, time, date, from, reportedSize);
  }
コード例 #11
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;
 }
コード例 #12
0
  public void updateProfile(String key, Account pAccount)
      throws SQLException, ConnectionException, MissingDataException, NullAccountException,
          ProfileException, PasswordException, EmailException {
    try (Connection connect = DBConnection.getConnection()) {
      pAccount = testAccount(pAccount);

      String sql =
          "UPDATE account"
              + "set name = '"
              + Utility.Replace(testProfileData(pAccount.getName()))
              + "', surname = '"
              + Utility.Replace(testProfileData(pAccount.getSurname()))
              + "', password = '******', secondaryEmail = '"
              + testEmail(pAccount.getSecondaryEmail())
              + "WHERE email = '"
              + key
              + "'";

      String sql2 = "UPDATE " + pAccount.getTypeAccount();

      if (pAccount instanceof PhdStudent) {
        sql2 +=
            " set telephone = '"
                + testProfileData(((PhdStudent) pAccount).getTelephone())
                + "', link =  '"
                + testProfileData(((PhdStudent) pAccount).getLink())
                + "', deparment = '"
                + testProfileData(((PhdStudent) pAccount).getDepartment())
                + "', researchInterest = '"
                + testProfileData(((PhdStudent) pAccount).getResearchInterest())
                + "' WHERE fkAccount = '"
                + testProfileData(((PhdStudent) pAccount).getSecondaryEmail());
      }

      if (pAccount instanceof Professor) {
        sql2 +=
            " set link = '"
                + ((Professor) pAccount).getLink()
                + "', set department = '"
                + ((Professor) pAccount).getDepartment()
                + "' WHERE fkAccount = '"
                + ((Professor) pAccount).getSecondaryEmail()
                + "'";
      }

      if (pAccount.getTypeAccount().equals("basic")) // aggiorna solo info base
      Utility.executeOperation(connect, sql);
      else {
        Utility.executeOperation(connect, sql);
        Utility.executeOperation(connect, sql2);
      }

      connect.commit();
    }
  }
コード例 #13
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
 boolean isMessageTooBig(Folder folder, Account account, Message message, int messageNumber)
     throws Exception {
   int messageSize =
       (folder instanceof POP3Folder)
           ? ((POP3Folder) folder).getMessageSize(messageNumber)
           : getMessageSize(message, account);
   boolean messageTooBig = messageSize > maximumMessageSize;
   if (messageTooBig) {
     log.warn(
         String.format(
             "msgNum=%d, message is too big %d bytes, discarding for %s",
             messageNumber, messageSize, account.getName()));
     saveMessageDroppedNotification(account, messageNumber, message, messageSize);
   }
   return messageTooBig;
 }
コード例 #14
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
  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);
    }
  }
コード例 #15
0
  public ArrayList<Account> searchUser(String search, String type) throws SQLException {
    Connection connect = null;
    ArrayList<Account> accounts;

    String sql =
        "SELECT * from account WHERE "
            + "name LIKE '%"
            + search
            + "%'"
            + "AND typeAccount = '"
            + type
            + "'";
    String sql2 = "SELECT * from account WHERE " + "typeAccount ='" + type + "'";
    try {
      connect = DBConnection.getConnection();
      accounts = new ArrayList<>();
      if (search.isEmpty()) {
        ResultSet result = Utility.queryOperation(connect, sql2);
        Account temp = new Account();
        while (result.next()) {
          temp.setName(result.getString("name"));
          temp.setEmail(result.getString("email"));
          temp.setSecondaryEmail(result.getString("secondaryEmail"));
          temp.setTypeAccount(result.getString("typeAccount"));
          temp.setPassword(result.getString("password"));
          temp.setAdmin(result.getBoolean("isAdministrator"));
          accounts.add(temp);
        }
      } else {
        ResultSet result = Utility.queryOperation(connect, sql);
        Account temp = new Account();
        while (result.next()) {
          temp.setName(result.getString("name"));
          temp.setEmail(result.getString("email"));
          temp.setSecondaryEmail(result.getString("secondaryEmail"));
          temp.setTypeAccount(result.getString("typeAccount"));
          temp.setPassword(result.getString("password"));
          temp.setAdmin(result.getBoolean("isAdministrator"));
          accounts.add(temp);
        }
      }

    } finally {
      DBConnection.releaseConnection(connect);
    }
    return accounts;
  }
コード例 #16
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
 private boolean shouldSendAccountLockedNotification(Account account) {
   return account.getLogin_failures() != null
       && (account.getLogin_failures() == maximumLoginFailures + 1);
 }
コード例 #17
0
  public void changeType(Account pAccount, String newType)
      throws SQLException, ConnectionException, NullAccountException, EmailException {
    String demotionSql =
        "DELETE FROM " // cancella vecchie info
            + pAccount.getTypeAccount()
            + "WHERE fkAccount = '"
            + testEmail(pAccount.getSecondaryEmail())
            + "'";

    String toProfessorSql =
        "INSERT INTO professor " // se nuovo professor
            + "(fkAccount,link,department)"
            + "VALUES ('"
            + testEmail(pAccount.getSecondaryEmail())
            + "',"
            + "'"
            + "null"
            + "',"
            + "'"
            + "null"
            + "'";

    String toPhdSql =
        "INSERT INTO phdstudent "
            + "(fkAccount,telephone,link,deparment,researchInterest,fkCycle"
            + "fkCurriculum, fkProfessor )" // nuovo dottorando
            + "VALUES ('"
            + testEmail(pAccount.getSecondaryEmail())
            + "',"
            + "'"
            + "null"
            + "',"
            + "'"
            + "null"
            + "',"
            + "'"
            + "null"
            + "',"
            + "'"
            + "null"
            + "',"
            + "'"
            + "null"
            + "',"
            + "'"
            + "null"
            + "',"
            + "'"
            + "null"
            + "'";

    String changeTypeSql =
        "UPDATE account" // aggiorna il tipo
            + "set typeAccount = '"
            + newType
            + "' WHERE email = '"
            + pAccount.getEmail();

    Connection connect = null;
    try {
      connect = DBConnection.getConnection();
      pAccount = testAccount(pAccount);

      if (newType.equals("phdstudent") && pAccount.getTypeAccount().equals("basic")) {
        Utility.executeOperation(connect, toPhdSql); // diventa un dottorando
        Utility.executeOperation(connect, changeTypeSql); // cambia tipo in account
      } else if (newType.equals("phdstudent") && pAccount.getTypeAccount().equals("professor")) {
        Utility.executeOperation(connect, demotionSql); // perde info phd
        Utility.executeOperation(connect, toPhdSql); // nuove info prof
        Utility.executeOperation(connect, changeTypeSql);
      } else if (newType.equals("professor") && pAccount.getTypeAccount().equals("basic")) {
        Utility.executeOperation(connect, toProfessorSql);
        Utility.executeOperation(connect, changeTypeSql);
      } else if (newType.equals("professor") && pAccount.getTypeAccount().equals("phdstudent")) {
        Utility.executeOperation(connect, demotionSql);
        Utility.executeOperation(connect, toProfessorSql);
        Utility.executeOperation(connect, changeTypeSql);
      } else if (newType.equals("basic")) {
        Utility.executeOperation(connect, demotionSql);
        Utility.executeOperation(connect, changeTypeSql);
      }

    } finally {
      DBConnection.releaseConnection(connect);
    }
  }
コード例 #18
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
 public boolean exceededMaximumLoginFailures(Account account) {
   return account.getLogin_failures() != null
       && account.getLogin_failures() > maximumLoginFailures;
 }
コード例 #19
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
 public boolean isFirstTime(Account account) {
   return account.getLast_received_date() == null && account.getLast_mailcheck() == null;
 }
コード例 #20
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
 public boolean isMigratedAccount(Account account) {
   return account.getLast_received_date() == null && account.getLast_mailcheck() != null;
 }