javax.mail.Flags.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(11.9k)|赞(0)|评价(0)|浏览(155)

本文整理了Java中javax.mail.Flags.<init>()方法的一些代码示例,展示了Flags.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flags.<init>()方法的具体详情如下:
包路径:javax.mail.Flags
类名称:Flags
方法名:<init>

Flags.<init>介绍

[英]Construct an empty Flags object.
[中]构造一个空的Flags对象。

代码示例

代码示例来源:origin: spring-projects/spring-integration

@Test
public void validateSearchTermsWhenShouldNotMarkAsReadNoExistingFlags() throws Exception {
  ImapMailReceiver receiver = new ImapMailReceiver();
  receiver.setShouldMarkMessagesAsRead(false);
  receiver.setBeanFactory(mock(BeanFactory.class));
  receiver.afterPropertiesSet();
  Field folderField = AbstractMailReceiver.class.getDeclaredField("folder");
  folderField.setAccessible(true);
  Folder folder = mock(Folder.class);
  when(folder.getPermanentFlags()).thenReturn(new Flags(Flags.Flag.USER));
  folderField.set(receiver, folder);
  Method compileSearchTerms = ReflectionUtils.findMethod(receiver.getClass(), "compileSearchTerms", Flags.class);
  compileSearchTerms.setAccessible(true);
  Flags flags = new Flags();
  SearchTerm searchTerms = (SearchTerm) compileSearchTerms.invoke(receiver, flags);
  assertTrue(searchTerms instanceof NotTerm);
}

代码示例来源:origin: org.apache.james/james-server-jmap-integration-testing

@Test
public void fromFlagListShouldConvertInvalidJMAPFlag() {
  assertThat(StringListToFlags.fromFlagList(ImmutableList.of("op§")))
    .isEqualTo(new Flags("op§"));
}

代码示例来源:origin: org.apache.james/apache-james-mailbox-cassandra

@Test
void updateIndexOnAddShouldUpdateFirstUnseenWhenUnseen() {
  MailboxMessage message = mock(MailboxMessage.class);
  when(message.createFlags()).thenReturn(new Flags());
  when(message.getUid()).thenReturn(MESSAGE_UID);
  testee.updateIndexOnAdd(message, MAILBOX_ID).join();
  Optional<MessageUid> actual = firstUnseenDAO.retrieveFirstUnread(MAILBOX_ID).join();
  assertThat(actual.isPresent()).isTrue();
  assertThat(actual.get()).isEqualTo(MESSAGE_UID);
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Test
public void asFlagsShouldReturnFlagsWhenSystemFlag() throws Exception {
  assertThat(Keyword.DELETED.asFlags())
    .isEqualTo(new Flags(Flags.Flag.DELETED));
}

代码示例来源:origin: spring-projects/spring-integration

@Test
public void testIdleWithServerCustomSearch() throws Exception {
  ImapMailReceiver receiver =
      new ImapMailReceiver("imap://user:pw@localhost:" + this.imapIdleServer.getPort() + "/INBOX");
  receiver.setSearchTermStrategy((supportedFlags, folder) -> {
    try {
      FromTerm fromTerm = new FromTerm(new InternetAddress("bar@baz"));
      return new AndTerm(fromTerm, new FlagTerm(new Flags(Flag.SEEN), false));
    }
    catch (AddressException e) {
      throw new RuntimeException(e);
    }
  });
  testIdleWithServerGuts(receiver, false);
}

代码示例来源:origin: org.apache.james/apache-james-mailbox-cassandra

@Test
void updateIndexOnAddShouldIncrementUnseenMessageCountWhenUnseen() throws Exception {
  MailboxMessage message = mock(MailboxMessage.class);
  when(message.createFlags()).thenReturn(new Flags());
  when(message.getUid()).thenReturn(MESSAGE_UID);
  testee.updateIndexOnAdd(message, MAILBOX_ID).join();
  Optional<Long> actual = mailboxCounterDAO.countUnseenMessagesInMailbox(mailbox).join();
  assertThat(actual.isPresent()).isTrue();
  assertThat(actual.get()).isEqualTo(1);
}

代码示例来源:origin: org.apache.james/james-server-jmap-integration-testing

@Test
public void fromFlagListShouldConvertValidJMAPFlag() {
  assertThat(StringListToFlags.fromFlagList(ImmutableList.of("$Any")))
    .isEqualTo(new Flags("$Any"));
}

代码示例来源:origin: spring-projects/spring-integration

@Test
public void receiveAndDontSetDeleteWithUrl() throws Exception {
  AbstractMailReceiver receiver = new Pop3MailReceiver("pop3://some.host");
  receiver = spy(receiver);
  receiver.setBeanFactory(mock(BeanFactory.class));
  receiver.afterPropertiesSet();
  Field folderField = AbstractMailReceiver.class.getDeclaredField("folder");
  folderField.setAccessible(true);
  Folder folder = mock(Folder.class);
  when(folder.getPermanentFlags()).thenReturn(new Flags(Flags.Flag.USER));
  folderField.set(receiver, folder);
  Message msg1 = mock(MimeMessage.class);
  Message msg2 = mock(MimeMessage.class);
  final Message[] messages = new Message[] { msg1, msg2 };
  doAnswer(invocation -> null).when(receiver).openFolder();
  doAnswer(invocation -> messages).when(receiver).searchForNewMessages();
  doAnswer(invocation -> null).when(receiver).fetchMessages(messages);
  receiver.afterPropertiesSet();
  receiver.receive();
  verify(msg1, times(0)).setFlag(Flag.DELETED, true);
  verify(msg2, times(0)).setFlag(Flag.DELETED, true);
}

代码示例来源:origin: org.apache.james/apache-james-mailbox-cassandra

@Test
void updateIndexOnAddShouldNotIncrementUnseenMessageCountWhenSeen() throws Exception {
  MailboxMessage message = mock(MailboxMessage.class);
  when(message.createFlags()).thenReturn(new Flags(Flags.Flag.SEEN));
  when(message.getUid()).thenReturn(MESSAGE_UID);
  testee.updateIndexOnAdd(message, MAILBOX_ID).join();
  Optional<Long> actual = mailboxCounterDAO.countUnseenMessagesInMailbox(mailbox).join();
  assertThat(actual.isPresent()).isTrue();
  assertThat(actual.get()).isEqualTo(0);
}

代码示例来源:origin: org.apache.james/james-server-jmap-integration-testing

@Test
public void fromFlagListShouldConvertDeletedFlag() {
  assertThat(StringListToFlags.fromFlagList(ImmutableList.of(Keyword.DELETED.getFlagName())))
    .isEqualTo(new Flags(Flag.DELETED));
}

代码示例来源:origin: spring-projects/spring-integration

@Test
public void receiveAndDontSetDeleteWithoutUrl() throws Exception {
  AbstractMailReceiver receiver = new Pop3MailReceiver();
  receiver = spy(receiver);
  receiver.setBeanFactory(mock(BeanFactory.class));
  receiver.afterPropertiesSet();
  Field folderField = AbstractMailReceiver.class.getDeclaredField("folder");
  folderField.setAccessible(true);
  Folder folder = mock(Folder.class);
  when(folder.getPermanentFlags()).thenReturn(new Flags(Flags.Flag.USER));
  folderField.set(receiver, folder);
  Message msg1 = mock(MimeMessage.class);
  Message msg2 = mock(MimeMessage.class);
  final Message[] messages = new Message[] { msg1, msg2 };
  doAnswer(invocation -> null).when(receiver).openFolder();
  doAnswer(invocation -> messages).when(receiver).searchForNewMessages();
  doAnswer(invocation -> null).when(receiver).fetchMessages(messages);
  receiver.afterPropertiesSet();
  receiver.receive();
  verify(msg1, times(0)).setFlag(Flag.DELETED, true);
  verify(msg2, times(0)).setFlag(Flag.DELETED, true);
}

代码示例来源:origin: org.apache.james/apache-james-mailbox-cassandra

@Test
void updateIndexOnAddShouldIncrementMessageCount() throws Exception {
  MailboxMessage message = mock(MailboxMessage.class);
  when(message.createFlags()).thenReturn(new Flags());
  when(message.getUid()).thenReturn(MESSAGE_UID);
  testee.updateIndexOnAdd(message, MAILBOX_ID).join();
  Optional<Long> actual = mailboxCounterDAO.countMessagesInMailbox(mailbox).join();
  assertThat(actual.isPresent()).isTrue();
  assertThat(actual.get()).isEqualTo(1);
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Test
public void asFlagsShouldReturnFlagsWhenUserFlagContainsUnderscore() throws Exception {
  String userFlag = "$has_cal";
  Keyword keyword = new Keyword(userFlag);
  assertThat(keyword.asFlags())
    .isEqualTo(new Flags(userFlag));
}

代码示例来源:origin: spring-projects/spring-integration

@Test
public void receiveAndDontDelete() throws Exception {
  AbstractMailReceiver receiver = new Pop3MailReceiver();
  receiver.setShouldDeleteMessages(false);
  receiver = spy(receiver);
  receiver.setBeanFactory(mock(BeanFactory.class));
  receiver.afterPropertiesSet();
  Field folderField = AbstractMailReceiver.class.getDeclaredField("folder");
  folderField.setAccessible(true);
  Folder folder = mock(Folder.class);
  when(folder.getPermanentFlags()).thenReturn(new Flags(Flags.Flag.USER));
  folderField.set(receiver, folder);
  Message msg1 = mock(MimeMessage.class);
  Message msg2 = mock(MimeMessage.class);
  final Message[] messages = new Message[] { msg1, msg2 };
  doAnswer(invocation -> null).when(receiver).openFolder();
  doAnswer(invocation -> messages).when(receiver).searchForNewMessages();
  doAnswer(invocation -> null).when(receiver).fetchMessages(messages);
  receiver.afterPropertiesSet();
  receiver.receive();
  verify(msg1, times(0)).setFlag(Flag.DELETED, true);
  verify(msg2, times(0)).setFlag(Flag.DELETED, true);
}

代码示例来源:origin: org.apache.james/apache-james-mailbox-cassandra

@Test
void updateIndexOnAddShouldUpdateApplicableFlag() {
  Flags customFlags = new Flags("custom");
  MailboxMessage message = mock(MailboxMessage.class);
  when(message.createFlags()).thenReturn(customFlags);
  when(message.getUid()).thenReturn(MESSAGE_UID);
  testee.updateIndexOnAdd(message, MAILBOX_ID).join();
  Flags applicableFlag = applicableFlagDAO.retrieveApplicableFlag(MAILBOX_ID).join().get();
  assertThat(applicableFlag).isEqualTo(customFlags);
}

代码示例来源:origin: org.apache.james/james-server-jmap-integration-testing

@Test
public void fromFlagListShouldConvertAnwseredFlag() {
  assertThat(StringListToFlags.fromFlagList(ImmutableList.of(Keyword.ANSWERED.getFlagName())))
    .isEqualTo(new Flags(Flag.ANSWERED));
}

代码示例来源:origin: spring-projects/spring-integration

@Test
public void receiveAndDelete() throws Exception {
  AbstractMailReceiver receiver = new Pop3MailReceiver();
  receiver.setShouldDeleteMessages(true);
  receiver = spy(receiver);
  receiver.setBeanFactory(mock(BeanFactory.class));
  receiver.afterPropertiesSet();
  Field folderField = AbstractMailReceiver.class.getDeclaredField("folder");
  folderField.setAccessible(true);
  Folder folder = mock(Folder.class);
  when(folder.getPermanentFlags()).thenReturn(new Flags(Flags.Flag.USER));
  folderField.set(receiver, folder);
  Message msg1 = mock(MimeMessage.class);
  Message msg2 = mock(MimeMessage.class);
  final Message[] messages = new Message[] { msg1, msg2 };
  doAnswer(invocation -> {
    DirectFieldAccessor accessor = new DirectFieldAccessor(invocation.getMock());
    int folderOpenMode = (Integer) accessor.getPropertyValue("folderOpenMode");
    if (folderOpenMode != Folder.READ_WRITE) {
      throw new IllegalArgumentException("Folder had to be open in READ_WRITE mode");
    }
    return null;
  }).when(receiver).openFolder();
  doAnswer(invocation -> messages).when(receiver).searchForNewMessages();
  doAnswer(invocation -> null).when(receiver).fetchMessages(messages);
  receiver.afterPropertiesSet();
  receiver.receive();
  verify(msg1, times(1)).setFlag(Flag.DELETED, true);
  verify(msg2, times(1)).setFlag(Flag.DELETED, true);
}

代码示例来源:origin: org.apache.james/apache-james-mailbox-cassandra

@Test
void updateIndexOnAddShouldNotUpdateFirstUnseenWhenSeen() {
  MailboxMessage message = mock(MailboxMessage.class);
  when(message.createFlags()).thenReturn(new Flags(Flags.Flag.SEEN));
  when(message.getUid()).thenReturn(MESSAGE_UID);
  testee.updateIndexOnAdd(message, MAILBOX_ID).join();
  Optional<MessageUid> actual = firstUnseenDAO.retrieveFirstUnread(MAILBOX_ID).join();
  assertThat(actual.isPresent()).isFalse();
}

代码示例来源:origin: org.apache.james/james-server-jmap-integration-testing

@Test
public void fromFlagListShouldConvertRecentFlag() {
  assertThat(StringListToFlags.fromFlagList(ImmutableList.of(Keyword.RECENT.getFlagName())))
    .isEqualTo(new Flags(Flag.RECENT));
}

代码示例来源:origin: spring-projects/spring-integration

@Test
public void validateSearchTermsWhenShouldMarkAsReadWithExistingFlags() throws Exception {
  ImapMailReceiver receiver = new ImapMailReceiver();
  receiver.setShouldMarkMessagesAsRead(true);
  receiver.setBeanFactory(mock(BeanFactory.class));
  receiver.afterPropertiesSet();
  Field folderField = AbstractMailReceiver.class.getDeclaredField("folder");
  folderField.setAccessible(true);
  Folder folder = mock(Folder.class);
  when(folder.getPermanentFlags()).thenReturn(new Flags(Flags.Flag.USER));
  folderField.set(receiver, folder);
  Method compileSearchTerms = ReflectionUtils.findMethod(receiver.getClass(), "compileSearchTerms", Flags.class);
  compileSearchTerms.setAccessible(true);
  Flags flags = new Flags();
  flags.add(Flag.ANSWERED);
  SearchTerm searchTerms = (SearchTerm) compileSearchTerms.invoke(receiver, flags);
  assertTrue(searchTerms instanceof AndTerm);
  AndTerm andTerm = (AndTerm) searchTerms;
  SearchTerm[] terms = andTerm.getTerms();
  assertEquals(2, terms.length);
  NotTerm notTerm = (NotTerm) terms[0];
  assertTrue(((FlagTerm) notTerm.getTerm()).getFlags().contains(Flag.ANSWERED));
  notTerm = (NotTerm) terms[1];
  Flags siFlags = new Flags();
  siFlags.add(AbstractMailReceiver.DEFAULT_SI_USER_FLAG);
  assertTrue(((FlagTerm) notTerm.getTerm()).getFlags().contains(siFlags));
}

相关文章