Java Code Examples for javax.mail.Flags#Flag

The following examples show how to use javax.mail.Flags#Flag . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: cfImapConnection.java    From openbd-core with GNU General Public License v3.0 6 votes vote down vote up
public void changeStatus( String folderName, long mailIDs[], Flags.Flag newFlag, boolean value ){
  try{
  
    Folder folderToUse = mailStore.getFolder(folderName);
    folderToUse.open( Folder.READ_WRITE );
    
    Flags f = new Flags();
    f.add( newFlag );
	
	Message mlist[];
	if ( folderToUse instanceof UIDFolder )
		mlist = ((UIDFolder)folderToUse).getMessagesByUID( mailIDs );
	else
		mlist = folderToUse.getMessages( returnToInts(mailIDs) );
	
	for ( int x=0; x < mlist.length; x++ )
		mlist[x].setFlags( f, value );
    
    folderToUse.close( true );
	setData( "succeeded", 	cfBooleanData.TRUE );
  
  } catch (Exception E ){
	setData( "errortext", 	new cfStringData( E.getMessage() ) );
	setData( "succeeded", 	cfBooleanData.FALSE );
  }
}
 
Example 2
Source File: MessageSearches.java    From james-project with Apache License 2.0 6 votes vote down vote up
private boolean matches(SearchQuery.FlagCriterion criterion, MailboxMessage message,
                        Collection<MessageUid> recentMessageUids) {
    SearchQuery.BooleanOperator operator = criterion.getOperator();
    boolean isSet = operator.isSet();
    Flags.Flag flag = criterion.getFlag();
    if (flag == Flags.Flag.ANSWERED) {
        return isSet == message.isAnswered();
    } else if (flag == Flags.Flag.SEEN) {
        return isSet == message.isSeen();
    } else if (flag == Flags.Flag.DRAFT) {
        return isSet == message.isDraft();
    } else if (flag == Flags.Flag.FLAGGED) {
        return isSet == message.isFlagged();
    } else if (flag == Flags.Flag.RECENT) {
        final MessageUid uid = message.getUid();
        return isSet == recentMessageUids.contains(uid);
    } else if (flag == Flags.Flag.DELETED) {
        return isSet == message.isDeleted();
    } else {
        return false;
    }
}
 
Example 3
Source File: FlagsFactory.java    From james-project with Apache License 2.0 6 votes vote down vote up
public Flags build() {
    FlagsFilter flagsFilter = this.flagsFilter.orElse(FlagsFilter.noFilter());
    Flags flagsOrEmpty = this.flags.orElse(new Flags());

    Stream<Flags.Flag> flagStream =
        toFlagStream(flagsOrEmpty)
            .filter(flagsFilter.getSystemFlagFilter());
    Stream<String> userFlagsStream =
        Stream
            .concat(
                toUserFlagStream(flagsOrEmpty),
                userFlags.stream())
            .distinct()
            .filter(s -> !Strings.isNullOrEmpty(s))
            .filter(flagsFilter.getUserFlagFilter());

    final Flags result = new Flags();
    flagStream.forEach(result::add);
    userFlagsStream.forEach(result::add);
    return result;
}
 
Example 4
Source File: CriterionConverter.java    From james-project with Apache License 2.0 6 votes vote down vote up
private QueryBuilder convertFlag(SearchQuery.FlagCriterion flagCriterion) {
    SearchQuery.BooleanOperator operator = flagCriterion.getOperator();
    Flags.Flag flag = flagCriterion.getFlag();
    if (flag.equals(Flags.Flag.DELETED)) {
        return boolQuery().filter(termQuery(JsonMessageConstants.IS_DELETED, operator.isSet()));
    }
    if (flag.equals(Flags.Flag.ANSWERED)) {
        return boolQuery().filter(termQuery(JsonMessageConstants.IS_ANSWERED, operator.isSet()));
    }
    if (flag.equals(Flags.Flag.DRAFT)) {
        return boolQuery().filter(termQuery(JsonMessageConstants.IS_DRAFT, operator.isSet()));
    }
    if (flag.equals(Flags.Flag.SEEN)) {
        return boolQuery().filter(termQuery(JsonMessageConstants.IS_UNREAD, !operator.isSet()));
    }
    if (flag.equals(Flags.Flag.RECENT)) {
        return boolQuery().filter(termQuery(JsonMessageConstants.IS_RECENT, operator.isSet()));
    }
    if (flag.equals(Flags.Flag.FLAGGED)) {
        return boolQuery().filter(termQuery(JsonMessageConstants.IS_FLAGGED, operator.isSet()));
    }
    throw new RuntimeException("Unknown flag used in Flag search criterion");
}
 
Example 5
Source File: FlagsExtraField.java    From james-project with Apache License 2.0 6 votes vote down vote up
private static String systemFlagToString(Flags.Flag flag) throws RuntimeException {
    if (flag == Flags.Flag.ANSWERED) {
        return "\\ANSWERED";
    } else if (flag == Flags.Flag.DELETED) {
        return "\\DELETED";
    } else if (flag == Flags.Flag.DRAFT) {
        return "\\DRAFT";
    } else if (flag == Flags.Flag.FLAGGED) {
        return "\\FLAGGED";
    } else if (flag == Flags.Flag.RECENT) {
        return "\\RECENT";
    } else if (flag == Flags.Flag.SEEN) {
        return "\\SEEN";
    }
    throw new RuntimeException("Unknown system flag");
}
 
Example 6
Source File: StoredMessage.java    From greenmail with Apache License 2.0 5 votes vote down vote up
public boolean isSet(Flags.Flag flag) {
    try {
        return getMimeMessage().isSet(flag);
    } catch (MessagingException e) {
        throw new IllegalStateException("Can not access flag " + flag, e);
    }
}
 
Example 7
Source File: MimeMessageEx.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
@Override
public synchronized boolean isSet(Flags.Flag flag) throws MessagingException {
    if (original == null)
        return super.isSet(flag);
    else
        return original.isSet(flag);
}
 
Example 8
Source File: StoredMessage.java    From greenmail with Apache License 2.0 5 votes vote down vote up
public void setFlag(Flags.Flag flag, boolean value) {
    try {
        getMimeMessage().setFlag(flag, value);
    } catch (MessagingException e) {
        throw new IllegalStateException("Can not set flag " + flag + " to " + value, e);
    }
}
 
Example 9
Source File: SearchTermBuilder.java    From greenmail with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 10
Source File: JavaxMailMessage.java    From mail-importer with Apache License 2.0 5 votes vote down vote up
@Override
public void setFlag(Flags.Flag flag, boolean set)
    throws RuntimeMessagingException {
  try {
    delegate.setFlag(flag, set);
  } catch (MessagingException e) {
    throw new RuntimeMessagingException(e);
  }
}
 
Example 11
Source File: JavaxMailMessage.java    From mail-importer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isSet(Flags.Flag flag) throws RuntimeMessagingException {
  try {
    return delegate.isSet(flag);
  } catch (MessagingException e) {
    throw new RuntimeMessagingException(e);
  }
}
 
Example 12
Source File: ImapServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Set flags to the specified imapFolder.
 * 
 * @param messageInfo FileInfo of imap Folder.
 * @param flags flags to set.
 * @param value value to set.
 */
public void setFlags(FileInfo messageInfo, Flags flags, boolean value)
{
    checkForFlaggableAspect(messageInfo.getNodeRef());
    

    for (Flags.Flag flag : flags.getSystemFlags())
    {
        setFlag(messageInfo, flag, value);
    }
}
 
Example 13
Source File: UpdatedFlags.java    From james-project with Apache License 2.0 4 votes vote down vote up
public boolean isModifiedToUnset(Flags.Flag flag) {
    return !newFlags.contains(flag) && oldFlags.contains(flag);
}
 
Example 14
Source File: UpdatedFlags.java    From james-project with Apache License 2.0 4 votes vote down vote up
public boolean isUnchanged(Flags.Flag flag) {
    return !isModifiedToSet(flag) && !isModifiedToUnset(flag);
}
 
Example 15
Source File: FlagsBuilder.java    From james-project with Apache License 2.0 4 votes vote down vote up
public FlagsBuilder add(Flags.Flag... flags) {
    for (Flags.Flag flag : flags) {
        internalFlags.add(flag);
    }
    return this;
}
 
Example 16
Source File: UpdatedFlags.java    From james-project with Apache License 2.0 4 votes vote down vote up
private static boolean isChanged(Flags original, Flags updated, Flags.Flag flag) {
    return original != null && updated != null && (original.contains(flag) ^ updated.contains(flag));
}
 
Example 17
Source File: MailAccount.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
protected void setEnvelope(final Mail mail, final Message message) throws javax.mail.MessagingException
{
  mail.setMessage(message);
  Address[] addr;
  // ID
  mail.setMessageNumber(message.getMessageNumber());

  // FROM
  StringBuffer buf = new StringBuffer();
  addr = message.getFrom();
  if (addr != null) {
    for (int j = 0; j < addr.length; j++) {
      if (j > 0)
        buf.append(",");
      buf.append(addr[j].toString());
    }
  }
  mail.setFrom(buf.toString());

  // TO
  addr = message.getRecipients(Message.RecipientType.TO);
  buf = new StringBuffer();
  if (addr != null) {
    for (int j = 0; j < addr.length; j++) {
      if (j > 0)
        buf.append(",");
      buf.append(addr[j].toString());
    }
  }
  mail.setTo(buf.toString());

  // SUBJECT
  mail.setSubject(message.getSubject());

  // DATE
  final Date date = message.getSentDate();
  if (date != null) {
    mail.setDate(date);
  } else { // Needed for compareTo (assume 1.1.1970)
    mail.setDate(new Date(0));
  } // FLAGS
  final Flags flags = message.getFlags();
  final Flags.Flag[] systemFlags = flags.getSystemFlags(); // get the system flags

  for (int i = 0; i < systemFlags.length; i++) {
    final Flags.Flag flag = systemFlags[i];
    if (flag == Flags.Flag.ANSWERED) {
      // Ignore this flag
    } else if (flag == Flags.Flag.DELETED) {
      mail.setDeleted(true);
    } else if (flag == Flags.Flag.DRAFT) {
      // Ignore this flag
    } else if (flag == Flags.Flag.FLAGGED) {
      // Ignore this flag
    } else if (flag == Flags.Flag.RECENT) {
      mail.setRecent(true);
    } else if (flag == Flags.Flag.SEEN) {
      mail.setSeen(true);
    } else {
      // skip it
    }
  }
}
 
Example 18
Source File: FlagsFactory.java    From james-project with Apache License 2.0 4 votes vote down vote up
private Stream<Flags.Flag> toFlagStream(Flags flags) {
    return Arrays.stream(flags.getSystemFlags());
}
 
Example 19
Source File: Keyword.java    From james-project with Apache License 2.0 4 votes vote down vote up
public static Keyword fromFlag(Flags.Flag flag) {
    return IMAP_SYSTEM_FLAGS.get(flag);
}
 
Example 20
Source File: Keyword.java    From james-project with Apache License 2.0 4 votes vote down vote up
public Optional<Flags.Flag> asSystemFlag() {
    return Optional.ofNullable(IMAP_SYSTEM_FLAGS.inverse()
        .get(this));
}