public void testSetFlags() throws Exception {
    NavigableMap<Long, FileInfo> fis =
        imapService.getFolderStatus(
                authenticationService.getCurrentUserName(),
                testImapFolderNodeRef,
                ImapViewMode.ARCHIVE)
            .search;
    if (fis != null && fis.size() > 0) {
      FileInfo messageFileInfo = fis.firstEntry().getValue();
      try {
        setFlags(messageFileInfo);
        fail("Can't set flags");
      } catch (Exception e) {
        if (e instanceof AccessDeniedException) {
          // expected
        } else {
          throw e;
        }
      }

      reauthenticate(USER_NAME, USER_PASSWORD);

      permissionService.setPermission(
          testImapFolderNodeRef, anotherUserName, PermissionService.WRITE, true);

      reauthenticate(anotherUserName, anotherUserName);

      setFlags(messageFileInfo);
    }
  }
  protected void runAs(String userName) {
    authenticationService.authenticate(userName, userName.toCharArray());
    assertNotNull(authenticationService.getCurrentUserName());
    // for(GrantedAuthority authority : woof.getAuthorities())
    // {
    // System.out.println("Auth = "+authority.getAuthority());
    // }

  }
  public void testGetFlags() throws Exception {
    NavigableMap<Long, FileInfo> fis =
        imapService.getFolderStatus(
                authenticationService.getCurrentUserName(),
                testImapFolderNodeRef,
                ImapViewMode.ARCHIVE)
            .search;
    if (fis != null && fis.size() > 0) {
      FileInfo messageFileInfo = fis.firstEntry().getValue();

      reauthenticate(USER_NAME, USER_PASSWORD);

      permissionService.setPermission(
          testImapFolderNodeRef, anotherUserName, PermissionService.WRITE, true);

      imapService.setFlags(messageFileInfo, flags, true);

      reauthenticate(anotherUserName, anotherUserName);

      Flags fl = imapService.getFlags(messageFileInfo);
      assertTrue(fl.contains(flags));
    }
  }
  public void testSetFlag() throws Exception {
    NavigableMap<Long, FileInfo> fis =
        imapService.getFolderStatus(
                authenticationService.getCurrentUserName(),
                testImapFolderNodeRef,
                ImapViewMode.ARCHIVE)
            .search;
    if (fis != null && fis.size() > 0) {
      FileInfo messageFileInfo = fis.firstEntry().getValue();

      reauthenticate(USER_NAME, USER_PASSWORD);

      permissionService.setPermission(
          testImapFolderNodeRef, anotherUserName, PermissionService.WRITE, true);

      reauthenticate(anotherUserName, anotherUserName);

      imapService.setFlag(messageFileInfo, Flags.Flag.RECENT, true);

      Serializable prop =
          nodeService.getProperty(messageFileInfo.getNodeRef(), ImapModel.PROP_FLAG_RECENT);
      assertNotNull("Can't set RECENT flag", prop);
    }
  }