Example #1
0
  /**
   * 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;
  }
Example #2
0
  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;
  }