public void openConnection(
     final String userName,
     final String passWord,
     final String host,
     final int port,
     final boolean useSSL) {
   eventQueue.push(new EmailLoginCommand(host, port, useSSL, userName, passWord));
 }
  public void work() {

    try {
      EmailCommand command = (EmailCommand) eventQueue.pop();
      if (command == null) {
        // ignore
      } else {
        // #debug debug
        System.out.println("Process " + command);

        try {
          if (command instanceof EmailLoginCommand) {
            try {
              connection =
                  (StreamConnection)
                      Connector.open(
                          ((EmailLoginCommand) command).getUrl(), Connector.READ_WRITE, true);
              inbound = connection.openInputStream();
              outbound = connection.openOutputStream();
            } catch (IOException e) {
              // #debug error
              System.out.println("Failed to open connection to email server." + e);
            }
            process(command);
          } else if (command instanceof EmailCloseCommand) {
            try {
              connection.close();
            } catch (IOException e) {
              // #debug error
              System.out.println("Failed to close connection to email server." + e);
            }
            connection = null;
            inbound = null;
            outbound = null;
          } else {
            process(command);
          }
        } catch (IOException e) {
          // #debug error
          System.out.println("Failed sending/receiving command to/from server." + e);

          passResponseToListeners(command.createResponse("IOE"));
        }
      }
    } catch (InterruptedException e) {
      thread.stop();
    }
  }
 public void fetchFolders() {
   eventQueue.push(new EmailFetchFoldersCommand());
 }
 public void closeConnection() {
   eventQueue.push(new EmailCloseCommand());
 }
 public void appendMessage(final String mailbox, final EmailMessage message) {
   eventQueue.push(new EmailAppendMessageCommand(mailbox, message));
 }
 public void fetchMessage(final String emailNumber, final boolean useUids) {
   eventQueue.push(new EmailFetchMessagesCommand(emailNumber, "body[1]", useUids));
 }
 public void fetchMessages(final String emailNumbers, final boolean useUids) {
   eventQueue.push(new EmailFetchMessagesCommand(emailNumbers, "all", useUids));
 }
 public void useFolder(final String folder) {
   eventQueue.push(new EmailUseFolderCommand(folder));
 }