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

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

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

Flags.add介绍

[英]Add the specified user flag to this Flags object.
[中]将指定的用户标志添加到此标志对象。

代码示例

代码示例来源:origin: oblac/jodd

/**
 * Marks messages as seen after receiving them.
 */
public ReceiverBuilder markSeen() {
  this.flagsToSet.add(Flags.Flag.SEEN);
  return this;
}

代码示例来源:origin: oblac/jodd

/**
 * Deletes messages upon receiving.
 */
public ReceiverBuilder markDeleted() {
  this.flagsToSet.add(Flags.Flag.DELETED);
  return this;
}

代码示例来源:origin: oblac/jodd

/**
 * Marks message with given flag.
 */
public ReceiverBuilder mark(final Flags.Flag flagToSet) {
  this.flagsToSet.add(flagToSet);
  return this;
}

代码示例来源:origin: oblac/jodd

/**
 * Unmarks a message with given flag.
 */
public ReceiverBuilder unmark(final Flags.Flag flagToUnset) {
  this.flagsToUnset.add(flagToUnset);
  return this;
}

代码示例来源:origin: oblac/jodd

/**
 * Receives all emails that matches given {@link EmailFilter} and
 * mark all messages as 'seen' and 'deleted'.
 *
 * @param filter {@link EmailFilter}
 * @return array of {@link ReceivedEmail}s.
 */
public ReceivedEmail[] receiveEmailAndDelete(final EmailFilter filter) {
  final Flags flags = new Flags();
  flags.add(Flags.Flag.SEEN);
  flags.add(Flags.Flag.DELETED);
  return receiveMessages(filter, flags, null, false, null);
}

代码示例来源:origin: oblac/jodd

/**
 * Defines filter for single flag.
 *
 * @param flag  The flag to filter on.
 * @param value The {@link Flag} setting to check for.
 * @return this
 */
public EmailFilter flag(final Flag flag, final boolean value) {
  final Flags flags = new Flags();
  flags.add(flag);
  return flags(flags, value);
}

代码示例来源:origin: oblac/jodd

/**
 * Receives all emails that matches given {@link EmailFilter}
 * and mark them as 'seen' (ie 'read').
 *
 * @param filter {@link EmailFilter}
 * @return array of {@link ReceivedEmail}s.
 */
public ReceivedEmail[] receiveEmailAndMarkSeen(final EmailFilter filter) {
  final Flags flagsToSet = new Flags();
  flagsToSet.add(Flags.Flag.SEEN);
  return receiveMessages(filter, flagsToSet, null, false, null);
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * Set the flags for this message. <p>
 *
 * This implementation modifies the <code>flags</code> field.
 *
 * @exception    IllegalWriteException if the underlying
 *            implementation does not support modification
 * @exception    IllegalStateException if this message is
 *            obtained from a READ_ONLY folder.
 * @exception      MessagingException for other failures
 */
public synchronized void setFlags(Flags flag, boolean set)
    throws MessagingException {
if (set)
  flags.add(flag);
else
  flags.remove(flag);
}

代码示例来源:origin: com.sun.mail/javax.mail

/**
 * Set the flags for this message. <p>
 *
 * This implementation modifies the <code>flags</code> field.
 *
 * @exception    IllegalWriteException if the underlying
 *            implementation does not support modification
 * @exception    IllegalStateException if this message is
 *            obtained from a READ_ONLY folder.
 * @exception      MessagingException for other failures
 */
@Override
public synchronized void setFlags(Flags flag, boolean set)
    throws MessagingException {
if (set)
  flags.add(flag);
else
  flags.remove(flag);
}

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

private void setMessageFlags(Message[] filteredMessages) throws MessagingException {
  boolean recentFlagSupported = false;
  Flags flags = getFolder().getPermanentFlags();
  if (flags != null) {
    recentFlagSupported = flags.contains(Flags.Flag.RECENT);
  }
  for (Message message : filteredMessages) {
    if (!recentFlagSupported) {
      if (flags != null && flags.contains(Flags.Flag.USER)) {
        if (this.logger.isDebugEnabled()) {
          this.logger.debug("USER flags are supported by this mail server. Flagging message with '"
              + this.userFlag + "' user flag");
        }
        Flags siFlags = new Flags();
        siFlags.add(this.userFlag);
        message.setFlags(siFlags, true);
      }
      else {
        this.logger.debug("USER flags are not supported by this mail server. " +
            "Flagging message with system flag");
        message.setFlag(Flags.Flag.FLAGGED, true);
      }
    }
    setAdditionalFlags(message);
  }
}

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

public void validateSearchTermsWhenShouldMarkAsReadNoExistingFlagsGuts(String userFlag, ImapMailReceiver receiver)
    throws NoSuchFieldException, IllegalAccessException, InvocationTargetException {
  receiver.setShouldMarkMessagesAsRead(true);
  receiver.setBeanFactory(mock(BeanFactory.class));
  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);
  NotTerm notTerm = (NotTerm) searchTerms;
  Flags siFlags = new Flags();
  siFlags.add(userFlag);
  assertEquals(siFlags, ((FlagTerm) notTerm.getTerm()).getFlags());
}

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

private SearchTerm applyTermsWhenNoRecentFlag(Folder folder, SearchTerm searchTerm) {
  NotTerm notFlagged = null;
  if (folder.getPermanentFlags().contains(Flag.USER)) {
    if (logger.isDebugEnabled()) {
      logger.debug("This email server does not support RECENT flag, but it does support " +
          "USER flags which will be used to prevent duplicates during email fetch." +
          " This receiver instance uses flag: " + getUserFlag());
    }
    Flags siFlags = new Flags();
    siFlags.add(getUserFlag());
    notFlagged = new NotTerm(new FlagTerm(siFlags, true));
  }
  else {
    logger.debug("This email server does not support RECENT or USER flags. " +
        "System flag 'Flag.FLAGGED' will be used to prevent duplicates during email fetch.");
    notFlagged = new NotTerm(new FlagTerm(new Flags(Flag.FLAGGED), true));
  }
  if (searchTerm == null) {
    return notFlagged;
  }
  else {
    return new AndTerm(searchTerm, notFlagged);
  }
}

代码示例来源:origin: org.jodd/jodd-mail

/**
 * Unmarks a message with given flag.
 */
public ReceiverBuilder unmark(final Flags.Flag flagToUnset) {
  this.flagsToUnset.add(flagToUnset);
  return this;
}

代码示例来源:origin: apache/james-project

public FlagsBuilder add(Flags.Flag... flags) {
  for (Flags.Flag flag : flags) {
    internalFlags.add(flag);
  }
  return this;
}

代码示例来源: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));
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * Get the deleted message count.
 */
public synchronized int getDeletedMessageCount()
    throws MessagingException {
if (!opened) {
  checkExists();
  // no way to do this on closed folders
  return -1;
}
// if opened, issue server-side search for messages that do
// have the DELETED flag.
Flags f = new Flags();
f.add(Flags.Flag.DELETED);
try {
  synchronized(messageCacheLock) {
  int[] matches = getProtocol().search(new FlagTerm(f, true));
  return matches.length; // NOTE: 'matches' is never null
  }
} catch (ConnectionException cex) {
  throw new FolderClosedException(this, cex.getMessage());
} catch (ProtocolException pex) {
  // Shouldn't happen
  throw new MessagingException(pex.getMessage(), pex);
}
}

代码示例来源:origin: com.sun.mail/javax.mail

/**
 * Get the deleted message count.
 */
@Override
public synchronized int getDeletedMessageCount()
    throws MessagingException {
if (!opened) {
  checkExists();
  // no way to do this on closed folders
  return -1;
}
// if opened, issue server-side search for messages that do
// have the DELETED flag.
Flags f = new Flags();
f.add(Flags.Flag.DELETED);
try {
  synchronized(messageCacheLock) {
  int[] matches = getProtocol().search(new FlagTerm(f, true));
  return matches.length; // NOTE: 'matches' is never null
  }
} catch (ConnectionException cex) {
  throw new FolderClosedException(this, cex.getMessage());
} catch (ProtocolException pex) {
  // Shouldn't happen
  throw new MessagingException(pex.getMessage(), pex);
}
}

代码示例来源:origin: camunda/camunda-bpm-platform

f.add(Flags.Flag.SEEN);
try {
  synchronized(messageCacheLock) {

代码示例来源:origin: com.sun.mail/javax.mail

f.add(Flags.Flag.SEEN);
try {
  synchronized(messageCacheLock) {

代码示例来源:origin: greenmail-mail-test/greenmail

private static SearchTerm createFlagSearchTerm(String pFlagName, boolean pValue) {
  Flags.Flag flag = toFlag(pFlagName);
  Flags flags = new javax.mail.Flags();
  if (null == flag) { // user flags
    flags.add(pFlagName);
  } else {
    flags.add(flag);
  }
  return new FlagTerm(flags, pValue);
}

相关文章