コード例 #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
ファイル: MailBoxHelper.java プロジェクト: phcd/TAB
  public static int removeEmails(Account account, String protocol)
      throws MessagingException, UnknownHostException {
    int count = 0;
    Session session =
        Session.getInstance(
            Protocol.POP3.equals(protocol)
                ? getPop3MailProperties(account)
                : getImapMailProperties(account));
    Folder inbox;

    //        store = session.getStore("imap");
    if (account.getLoginName().contains("@yahoo.")) {
      IMAPStore imapstore = (IMAPStore) session.getStore(protocol);
      yahooConnect(account, imapstore, true);
      inbox = imapstore.getFolder("INBOX");
    } else {
      Store store = session.getStore(protocol);
      store.connect(account.getReceiveHost(), account.getLoginName(), account.getPassword());
      inbox = store.getFolder("INBOX");
    }

    inbox.open(Folder.READ_WRITE);

    count = inbox.getMessageCount();
    for (Message message : inbox.getMessages()) {
      message.setFlag(Flags.Flag.DELETED, true);
    }
    inbox.close(true);
    return count;
  }
コード例 #4
0
ファイル: SendMailListener.java プロジェクト: phcd/TAB
 /**
  * @param localFlag
  * @return String
  */
 private String sendMail(HashMap<String, List<EmailPojo>> hashMapMail, boolean localFlag) {
   String failrueId = null;
   String accountName = null;
   String getfailrueId;
   try {
     for (String key : hashMapMail.keySet()) {
       List<EmailPojo> mailPojoList = hashMapMail.get(key);
       Account account = mailPojoList.get(0).getAccount();
       accountName = account.getName();
       Operator operator;
       if (localFlag) {
         operator = (Operator) beanFactory.getBean("localsmtp");
       } else {
         if (beanFactory.containsBean(account.getSendProtocolType())) {
           operator = (Operator) beanFactory.getBean(account.getSendProtocolType());
         } else {
           operator = (Operator) beanFactory.getBean("localsmtp");
         }
       }
       getfailrueId = operator.sendMail(mailPojoList);
       if (failrueId == null) {
         if (getfailrueId != null) {
           failrueId = getfailrueId;
         }
       } else {
         if (getfailrueId != null) {
           failrueId += "," + getfailrueId;
         }
       }
     }
   } catch (Exception e) {
     log.error("sendMail/SendMailListener/Exception: " + "[" + accountName + "]", e);
   }
   return failrueId;
 }
コード例 #5
0
ファイル: MailBoxHelper.java プロジェクト: phcd/TAB
  private static Properties getImapMailProperties(Account account) {
    Properties props = new Properties();

    if (account.getReceiveProtocolType().contains("gmail")) {
      props.put("mail.imap.host", "imap.gmail.com");
      props.put("mail.imap.port", "143");
      props.put("mail.imap.auth", "true");
      props.put("mail.store.protocol", "imap");
      props.put("mail.imap.starttls.enable", "true");
      props.put("mail.imap.socketFactory.port", "993");
      props.put("mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
      props.put("mail.iamp.socketFactory.fallback", "false");
    } else {

      props.setProperty("mail.imap.port", account.getReceivePort());
      props.setProperty("mail.imap.connectiontimeout", "30000");
      if ("ssl".equals(account.getReceiveTs())) {
        Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
        props.setProperty("mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        props.setProperty("mail.imap.socketFactory.fallback", "false");
        props.setProperty("mail.imap.socketFactory.port", account.getReceivePort());
      } else if ("tls".equals(account.getReceiveTs())) {
        props.setProperty("mail.imap.starttls.enable", "true");
        java.security.Security.setProperty(
            "ssl.SocketFactory.provider", "com.archermind.txtbl.mail.DummySSLSocketFactory");
      }
    }

    return props;
  }
コード例 #6
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"));
 }
コード例 #7
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()));
 }
コード例 #8
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);
    }
  }
コード例 #9
0
ファイル: SendMailListener.java プロジェクト: phcd/TAB
  /**
   * Returns the protocol that will be used to send the email.
   *
   * @param hashMapMail
   * @return
   */
  private String getSendProtocolType(HashMap<String, List<EmailPojo>> hashMapMail) {
    String sendProtocolType = null;

    for (String key : hashMapMail.keySet()) {
      List<EmailPojo> mailPojoList = hashMapMail.get(key);
      Account account = mailPojoList.get(0).getAccount();
      sendProtocolType = account.getSendProtocolType();

      break;
    }

    return sendProtocolType;
  }
コード例 #10
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);
    }
  }
コード例 #11
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;
   }
 }
コード例 #12
0
ファイル: MailBoxHelper.java プロジェクト: phcd/TAB
 private static Properties getPop3MailProperties(Account account) {
   Properties props = new Properties();
   props.setProperty("mail.pop3.port", account.getReceivePort());
   props.setProperty("mail.pop3.connectiontimeout", "30000");
   if ("ssl".equals(account.getReceiveTs())) {
     Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
     props.setProperty("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
     props.setProperty("mail.pop3.socketFactory.fallback", "false");
     props.setProperty("mail.pop3.socketFactory.port", account.getReceivePort());
   } else if ("tls".equals(account.getReceiveTs())) {
     props.setProperty("mail.pop3.starttls.enable", "true");
     java.security.Security.setProperty(
         "ssl.SocketFactory.provider", "com.archermind.txtbl.mail.DummySSLSocketFactory");
   }
   return props;
 }
コード例 #13
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;
  }
コード例 #14
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);
  }
コード例 #15
0
ファイル: MailBoxHelper.java プロジェクト: phcd/TAB
  public static void main(String[] args)
      throws MessagingException, NamingException, IOException, InterruptedException {

    Account account = new Account();

    //        account.setLoginName("*****@*****.**");
    //        account.setPassword("p123456");
    //        account.setReceiveHost("imap.aol.com");
    //        account.setReceivePort("143");
    //        removeEmails(account, "imap");

    //        account.setLoginName("*****@*****.**");
    //        account.setPassword("123456");
    //        account.setReceiveHost("pop3.live.com");
    //        account.setReceiveTs("ssl");
    //        account.setReceivePort("995");
    //
    //        removeEmails(account, "pop3");

    account.setLoginName("*****@*****.**");
    account.setPassword("123456");
    account.setReceiveHost("imap.mail.yahoo.com");
    account.setReceivePort("143");
    removeEmails(account, "imap");

    //        account.setLoginName("*****@*****.**");
    //        account.setPassword("passw0rd");
    //        account.setReceiveHost("pop.gmail.com");
    //        account.setReceiveTs("ssl");
    //        account.setReceivePort("995");
    //        removeEmails(account, "pop3");

    //        account.setLoginName("*****@*****.**");
    //        account.setPassword("passw0rd");
    //        account.setReceiveHost("imap.gmail.com");
    //        account.setReceiveTs("ssl");
    //        account.setReceivePort("993");
    //        removeEmails(account, "imap");

    //        account.setLoginName("*****@*****.**");
    //        account.setPassword("123456");
    //        account.setReceiveHost("pop.emailsrvr.com");
    //        account.setReceivePort("110");
    //        removeEmails(account, "pop3");

    //        account.setLoginName("*****@*****.**");
    //        account.setPassword("123456");
    //        account.setReceiveHost("pop.emailsrvr.com");
    //        account.setReceivePort("110");
    //        removeEmails(account, "pop3");

    sendBigEmail(account.getLoginName());
    Thread.sleep(60000);
    sendSimpleEmails(account.getLoginName(), 3);
    sendSimpleEmails(account.getLoginName(), 5);
  }
コード例 #16
0
ファイル: MailBoxHelper.java プロジェクト: phcd/TAB
  /**
   * Special Yahoo connect routines. We resolve hostname IP address and try each one until connected
   *
   * @param account
   * @param store
   * @return
   * @throws java.net.UnknownHostException
   */
  private static int yahooConnect(
      Account account, IMAPStore store, boolean specialYahooConnectEnabled)
      throws UnknownHostException, MessagingException {
    int connectionAttempts = 0;
    store.SetIDCommand(
        "ID (\"vendor\" \"Zimbra\" \"os\" \"Windows XP\" \"os-version\" \"5.1\" \"guid\" \"4062-5711-9195-4050\")");

    if (specialYahooConnectEnabled) {
      InetAddress[] addresses = InetAddress.getAllByName(account.getReceiveHost());

      for (InetAddress address : addresses) {
        try {
          store.connect(address.getHostAddress(), account.getLoginName(), account.getPassword());

          connectionAttempts++;

          break;
        } catch (Throwable t) {
        }
      }
    } else {
      store.connect(account.getReceiveHost(), account.getLoginName(), account.getPassword());

      connectionAttempts++;
    }

    return connectionAttempts;
  }
コード例 #17
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;
 }
コード例 #18
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());
  }
コード例 #19
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;
 }
コード例 #20
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);
    }
  }
コード例 #21
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
 public boolean isFirstTime(Account account) {
   return account.getLast_received_date() == null && account.getLast_mailcheck() == null;
 }
コード例 #22
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
 public boolean isMigratedAccount(Account account) {
   return account.getLast_received_date() == null && account.getLast_mailcheck() != null;
 }
コード例 #23
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
 public boolean exceededMaximumLoginFailures(Account account) {
   return account.getLogin_failures() != null
       && account.getLogin_failures() > maximumLoginFailures;
 }
コード例 #24
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
 private boolean shouldSendAccountLockedNotification(Account account) {
   return account.getLogin_failures() != null
       && (account.getLogin_failures() == maximumLoginFailures + 1);
 }