Пример #1
0
  @Test
  public void testRetr() throws IOException {
    initAccount();

    Integer labelId = ReservedLabels.POP3.getId();
    RestV2IT.addMessage(EMAIL_SIMPLE, labelId);

    // initialize POP3 client
    POP3Client client = new POP3Client();
    client.connect(POP3_HOST, POP3_PORT);

    // Login
    boolean loginSuccess = client.login(TEST_ACCOUNT, TEST_PASSWORD);
    assertThat(loginSuccess, is(true));

    // RETR message
    Reader retrMessage = client.retrieveMessage(1);
    assertThat(retrMessage, notNullValue());

    checkMessage(EMAIL_SIMPLE, retrMessage);
    retrMessage.close();

    // RETR non-existing message
    retrMessage = client.retrieveMessage(10);
    assertThat(retrMessage, nullValue());

    // Delete and RETR the message again
    boolean deleteResult = client.deleteMessage(1);
    assertThat(deleteResult, is(true));

    retrMessage = client.retrieveMessage(1);
    assertThat(retrMessage, nullValue());
  }
Пример #2
0
  @Test
  public void testStat() throws IOException {
    initAccount();

    // load messages with POP3 label
    long mailSizeRegular = getResourceSize(EMAIL_REGULAR);
    long mailSizeAttach = getResourceSize(EMAIL_LARGE_ATT);

    Integer labelId = ReservedLabels.POP3.getId();
    RestV2IT.addMessage(EMAIL_REGULAR, labelId);
    RestV2IT.addMessage(EMAIL_LARGE_ATT, labelId);

    // initialize POP3 client
    POP3Client client = new POP3Client();
    client.connect(POP3_HOST, POP3_PORT);

    boolean loginSuccess = client.login(TEST_ACCOUNT, TEST_PASSWORD);
    assertThat(loginSuccess, is(true));

    POP3MessageInfo info = client.status();
    assertThat(info.size, equalTo((int) (mailSizeRegular + mailSizeAttach)));
    assertThat(info.number, equalTo(2));

    // Logout
    boolean logoutSuccess = client.logout();
    assertThat(logoutSuccess, is(true));
  }
Пример #3
0
  @Test
  public void testListUidl() throws IOException {
    initAccount();

    // load messages with POP3 label
    long mailSizeRegular = getResourceSize(EMAIL_REGULAR);
    long mailSizeAttach = getResourceSize(EMAIL_LARGE_ATT);

    Map<String, UUID> messages = new HashMap<String, UUID>(2);
    Integer labelId = ReservedLabels.POP3.getId();

    messages.put("headers", RestV2IT.addMessage(EMAIL_REGULAR, labelId));
    messages.put("attach", RestV2IT.addMessage(EMAIL_LARGE_ATT, labelId));

    // initialize POP3 client
    POP3Client client = new POP3Client();
    client.connect(POP3_HOST, POP3_PORT);

    boolean loginSuccess = client.login(TEST_ACCOUNT, TEST_PASSWORD);
    assertThat(loginSuccess, is(true));

    // LIST all messages
    POP3MessageInfo[] info = client.listMessages();
    assertThat(info.length, equalTo(2));
    assertThat((int) mailSizeAttach, equalTo(info[0].size));
    assertThat((int) mailSizeRegular, equalTo(info[1].size));
    assertThat(info[0].number, equalTo(1));
    assertThat(info[1].number, equalTo(2));

    // LIST one message
    POP3MessageInfo msgInfo = client.listMessage(1);
    assertThat((int) mailSizeAttach, equalTo(msgInfo.size));
    assertThat(msgInfo.number, equalTo(1));

    // LIST message that does not exist
    msgInfo = client.listMessage(10);
    assertThat(msgInfo, nullValue());

    // UIDL all messages
    info = client.listUniqueIdentifiers();
    assertThat(info.length, equalTo(2));
    assertThat(info[0].identifier, equalTo(Base64UUIDUtils.encode(messages.get("attach"))));
    assertThat(info[1].identifier, equalTo(Base64UUIDUtils.encode(messages.get("headers"))));
    assertThat(info[0].number, equalTo(1));
    assertThat(info[1].number, equalTo(2));

    // UIDL one message
    msgInfo = client.listUniqueIdentifier(1);
    assertThat(msgInfo.identifier, equalTo(Base64UUIDUtils.encode(messages.get("attach"))));
    assertThat(msgInfo.number, equalTo(1));

    // UIDL message that does not exist
    msgInfo = client.listUniqueIdentifier(10);
    assertThat(msgInfo, nullValue());

    boolean logoutSuccess = client.logout();
    assertThat(logoutSuccess, is(true));
  }
Пример #4
0
  @Test
  public void testRset() throws IOException {
    initAccount();

    Integer labelId = ReservedLabels.POP3.getId();
    RestV2IT.addMessage(EMAIL_REGULAR, labelId);

    // initialize POP3 client
    POP3Client client = new POP3Client();
    client.connect(POP3_HOST, POP3_PORT);

    // Login
    boolean loginSuccess = client.login(TEST_ACCOUNT, TEST_PASSWORD);
    assertThat(loginSuccess, is(true));

    // LIST all messages
    POP3MessageInfo[] info = client.listMessages();
    assertThat(info.length, equalTo(1));

    // DELE message 1
    boolean deleteResult = client.deleteMessage(1);
    assertThat(deleteResult, is(true));

    // LIST remaining
    info = client.listMessages();
    assertThat(info.length, equalTo(0));

    // RSET. After this the deleted mark should be removed again
    boolean resetRestult = client.reset();
    assertThat(resetRestult, is(true));

    // LIST all messages
    info = client.listMessages();
    assertThat(info.length, equalTo(1));

    // Logout
    boolean logoutSuccess = client.logout();
    assertThat(logoutSuccess, is(true));
  }
Пример #5
0
  @Test
  public void testDele() throws IOException {
    initAccount();

    Map<String, UUID> messages = new HashMap<String, UUID>(2);
    Integer labelId = ReservedLabels.POP3.getId();

    messages.put("headers", RestV2IT.addMessage(EMAIL_REGULAR, labelId));
    messages.put("attach", RestV2IT.addMessage(EMAIL_LARGE_ATT, labelId));

    // initialize POP3 client
    POP3Client client = new POP3Client();
    client.connect(POP3_HOST, POP3_PORT);

    // Login
    boolean loginSuccess = client.login(TEST_ACCOUNT, TEST_PASSWORD);
    assertThat(loginSuccess, is(true));

    // LIST all messages
    POP3MessageInfo[] info = client.listMessages();
    assertThat(info.length, equalTo(2));

    // DELE message 1
    boolean deleteResult = client.deleteMessage(1);
    assertThat(deleteResult, is(true));

    // LIST remaining
    info = client.listMessages();
    assertThat(info.length, equalTo(1));

    // DELE message 1 again
    deleteResult = client.deleteMessage(1);
    assertThat(deleteResult, is(false));

    // LIST remaining
    info = client.listMessages();
    assertThat(info.length, equalTo(1));

    // DELE message 2
    deleteResult = client.deleteMessage(2);
    assertThat(deleteResult, is(true));

    info = client.listMessages();
    assertThat(info.length, equalTo(0));

    // QUIT so the messages get expunged
    boolean logoutSuccess = client.logout();
    assertThat(logoutSuccess, is(true));

    // reconnect
    client.connect(POP3_HOST, POP3_PORT);

    // Login
    loginSuccess = client.login(TEST_ACCOUNT, TEST_PASSWORD);
    assertThat(loginSuccess, is(true));

    info = client.listMessages();
    assertThat(info.length, equalTo(0));

    logoutSuccess = client.logout();
    assertThat(logoutSuccess, is(true));
  }