Java Code Examples for javax.mail.Flags#getSystemFlags()

The following examples show how to use javax.mail.Flags#getSystemFlags() . 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: LuceneMessageSearchIndex.java    From james-project with Apache License 2.0 6 votes vote down vote up
/**
 * Add the given {@link Flags} to the {@link Document}
 */
private void indexFlags(Document doc, Flags f) {
    List<String> fString = new ArrayList<>();
    Flag[] flags = f.getSystemFlags();
    for (Flag flag : flags) {
        fString.add(toString(flag));
        doc.add(new Field(FLAGS_FIELD, toString(flag), Store.YES, Index.NOT_ANALYZED));
    }
    
    String[] userFlags = f.getUserFlags();
    for (String userFlag : userFlags) {
        doc.add(new Field(FLAGS_FIELD, userFlag, Store.YES, Index.NOT_ANALYZED));
    }
    
    // if no flags are there we just use a empty field
    if (flags.length == 0 && userFlags.length == 0) {
        doc.add(new Field(FLAGS_FIELD, "",Store.NO, Index.NOT_ANALYZED));
    }
    
}
 
Example 2
Source File: StoreMessageManager.java    From james-project with Apache License 2.0 6 votes vote down vote up
/**
 * Check if the given {@link Flags} contains {@link Flags} which are not
 * included in the returned {@link Flags} of
 * {@link #getPermanentFlags(MailboxSession)}. If any are found, these are
 * removed from the given {@link Flags} instance. The only exception is the
 * {@link Flag#RECENT} flag.
 * 
 * This flag is never removed!
 */
private void trimFlags(Flags flags, MailboxSession session) {

    Flags permFlags = getPermanentFlags(session);

    Flag[] systemFlags = flags.getSystemFlags();
    for (Flag f : systemFlags) {
        if (f != Flag.RECENT && permFlags.contains(f) == false) {
            flags.remove(f);
        }
    }
    // if the permFlags contains the special USER flag we can skip this as
    // all user flags are allowed
    if (permFlags.contains(Flags.Flag.USER) == false) {
        String[] uFlags = flags.getUserFlags();
        for (String uFlag : uFlags) {
            if (permFlags.contains(uFlag) == false) {
                flags.remove(uFlag);
            }
        }
    }

}
 
Example 3
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 4
Source File: HumanReadableText.java    From james-project with Apache License 2.0 5 votes vote down vote up
public static HumanReadableText permanentFlags(Flags flags) {
    String text;
    if (flags.getSystemFlags() != null && flags.getSystemFlags().length > 0) {
        text = "Limited";
    } else {
        text = "No permanent flags permitted";
    }
    return new HumanReadableText("org.apache.james.imap.PERMANENT_FLAGS", text);
}
 
Example 5
Source File: UpdatedFlags.java    From james-project with Apache License 2.0 5 votes vote down vote up
public static boolean flagsChanged(Flags flagsOld, Flags flagsNew) {
    Flags modifiedFlags = new Flags();
    addModifiedSystemFlags(flagsOld, flagsNew, modifiedFlags);
    addModifiedUserFlags(flagsOld, flagsNew, modifiedFlags);
    if (modifiedFlags.getSystemFlags().length > 0 || modifiedFlags.getUserFlags().length > 0) {
        return true;
    } else {
        return false;
    }
}
 
Example 6
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
    }
  }
}