List of usage examples for javax.mail Flags getUserFlags
public String[] getUserFlags()
From source file:org.apache.james.mailbox.jcr.mail.model.JCRMailboxMessage.java
@Override public void setFlags(Flags flags) { if (isPersistent()) { try {//from w w w. j ava2 s . c om node.setProperty(ANSWERED_PROPERTY, flags.contains(Flags.Flag.ANSWERED)); node.setProperty(DELETED_PROPERTY, flags.contains(Flags.Flag.DELETED)); node.setProperty(DRAFT_PROPERTY, flags.contains(Flags.Flag.DRAFT)); node.setProperty(FLAGGED_PROPERTY, flags.contains(Flags.Flag.FLAGGED)); node.setProperty(RECENT_PROPERTY, flags.contains(Flags.Flag.RECENT)); node.setProperty(SEEN_PROPERTY, flags.contains(Flags.Flag.SEEN)); node.setProperty(USERFLAGS_PROPERTY, flags.getUserFlags()); } catch (RepositoryException e) { logger.error("Unable to set flags", e); } } else { answered = flags.contains(Flags.Flag.ANSWERED); deleted = flags.contains(Flags.Flag.DELETED); draft = flags.contains(Flags.Flag.DRAFT); flagged = flags.contains(Flags.Flag.FLAGGED); recent = flags.contains(Flags.Flag.RECENT); seen = flags.contains(Flags.Flag.SEEN); userFlags = flags.getUserFlags(); } }
From source file:org.apache.james.mailbox.jcr.mail.model.JCRMessage.java
public void setFlags(Flags flags) { if (isPersistent()) { try {//from ww w .j a va2s . c o m node.setProperty(ANSWERED_PROPERTY, flags.contains(Flags.Flag.ANSWERED)); node.setProperty(DELETED_PROPERTY, flags.contains(Flags.Flag.DELETED)); node.setProperty(DRAFT_PROPERTY, flags.contains(Flags.Flag.DRAFT)); node.setProperty(FLAGGED_PROPERTY, flags.contains(Flags.Flag.FLAGGED)); node.setProperty(RECENT_PROPERTY, flags.contains(Flags.Flag.RECENT)); node.setProperty(SEEN_PROPERTY, flags.contains(Flags.Flag.SEEN)); node.setProperty(USERFLAGS_PROPERTY, flags.getUserFlags()); } catch (RepositoryException e) { logger.error("Unable to set flags", e); } } else { answered = flags.contains(Flags.Flag.ANSWERED); deleted = flags.contains(Flags.Flag.DELETED); draft = flags.contains(Flags.Flag.DRAFT); flagged = flags.contains(Flags.Flag.FLAGGED); recent = flags.contains(Flags.Flag.RECENT); seen = flags.contains(Flags.Flag.SEEN); userFlags = flags.getUserFlags(); } }
From source file:org.apache.james.mailbox.jpa.mail.model.openjpa.AbstractJPAMailboxMessage.java
/** * @see MailboxMessage#setFlags(javax.mail.Flags) *//*w w w. jav a2 s. c om*/ public void setFlags(Flags flags) { answered = flags.contains(Flags.Flag.ANSWERED); deleted = flags.contains(Flags.Flag.DELETED); draft = flags.contains(Flags.Flag.DRAFT); flagged = flags.contains(Flags.Flag.FLAGGED); recent = flags.contains(Flags.Flag.RECENT); seen = flags.contains(Flags.Flag.SEEN); /* // Loop over the user flags and check which of them needs to get added / removed List<String> uFlags = Arrays.asList(flags.getUserFlags()); for (int i = 0; i < userFlags.size(); i++) { JPAUserFlag f = userFlags.get(i); if (uFlags.contains(f.getName()) == false) { userFlags.remove(f); i++; } } for (int i = 0; i < uFlags.size(); i++) { boolean found = false; String uFlag = uFlags.get(i); for (int a = 0; a < userFlags.size(); a++) { String userFlag = userFlags.get(a).getName(); if (userFlag.equals(uFlag)) { found = true; break; } } if (found == false) { userFlags.add(new JPAUserFlag(uFlag)); } } */ String[] userflags = flags.getUserFlags(); userFlags.clear(); for (String userflag : userflags) { userFlags.add(new JPAUserFlag(userflag)); } }
From source file:org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage.java
public SimpleMailboxMessage(Date internalDate, long size, int bodyStartOctet, SharedInputStream content, Flags flags, PropertyBuilder propertyBuilder, MailboxId mailboxId, List<MessageAttachment> attachments) { super(new SimpleMessage(content, size, internalDate, propertyBuilder.getSubType(), propertyBuilder.getMediaType(), bodyStartOctet, propertyBuilder.getTextualLineCount(), propertyBuilder.toProperties(), attachments)); setFlags(flags);/*w ww .j av a2s. c o m*/ this.mailboxId = mailboxId; this.userFlags = flags.getUserFlags(); }
From source file:org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage.java
public synchronized void setFlags(Flags flags) { answered = flags.contains(Flags.Flag.ANSWERED); deleted = flags.contains(Flags.Flag.DELETED); draft = flags.contains(Flags.Flag.DRAFT); flagged = flags.contains(Flags.Flag.FLAGGED); recent = flags.contains(Flags.Flag.RECENT); seen = flags.contains(Flags.Flag.SEEN); userFlags = flags.getUserFlags(); }
From source file:org.apache.james.mailbox.store.StoreMessageManager.java
/** * 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.// w w w .j av a 2 s . c om * * This flag is never removed! * * @param flags * @param session */ 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); } } } }
From source file:org.exist.xquery.modules.mail.MessageListFunctions.java
private Sequence getMessageListAsXML(Sequence[] args, Sequence contextSequence) throws XPathException { Message[] msgList;/* ww w. ja v a 2 s .co m*/ Sequence ret = Sequence.EMPTY_SEQUENCE; // was a msgList handle specified? if (args[0].isEmpty()) { throw (new XPathException(this, "Message List handle not specified")); } // get the MessageList long msgListHandle = ((IntegerValue) args[0].itemAt(0)).getLong(); msgList = MailModule.retrieveMessageList(context, msgListHandle); if (msgList == null) { throw (new XPathException(this, "Invalid Message List handle specified")); } if (msgList.length > 0) { boolean includeHeaders = args[1].effectiveBooleanValue(); MemTreeBuilder builder = context.getDocumentBuilder(); builder.startDocument(); builder.startElement(new QName("messages", MailModule.NAMESPACE_URI, MailModule.PREFIX), null); builder.addAttribute(new QName("count", null, null), String.valueOf(msgList.length)); try { for (int i = 0; i < msgList.length; i++) { Message message = msgList[i]; builder.startElement(new QName("message", MailModule.NAMESPACE_URI, MailModule.PREFIX), null); builder.addAttribute(new QName("number", null, null), String.valueOf(message.getMessageNumber())); // Sent Date if (message.getSentDate() != null) { builder.startElement(new QName("sent", MailModule.NAMESPACE_URI, MailModule.PREFIX), null); builder.characters(formatDate(message.getSentDate())); builder.endElement(); } // Received Date if (message.getReceivedDate() != null) { builder.startElement(new QName("received", MailModule.NAMESPACE_URI, MailModule.PREFIX), null); builder.characters(formatDate(message.getReceivedDate())); builder.endElement(); } // From if (message.getFrom() != null) { builder.startElement(new QName("from", MailModule.NAMESPACE_URI, MailModule.PREFIX), null); builder.characters(message.getFrom()[0].toString()); builder.endElement(); } // Recipients builder.startElement(new QName("recipients", MailModule.NAMESPACE_URI, MailModule.PREFIX), null); // To Recipients Address[] toAddresses = message.getRecipients(Message.RecipientType.TO); if (toAddresses != null) { for (Address to : toAddresses) { builder.startElement( new QName("recipient", MailModule.NAMESPACE_URI, MailModule.PREFIX), null); builder.addAttribute(new QName("type", null, null), "to"); builder.characters(to.toString()); builder.endElement(); } } // cc Recipients Address[] ccAddresses = message.getRecipients(Message.RecipientType.CC); if (ccAddresses != null) { for (Address ccAddress : ccAddresses) { builder.startElement( new QName("recipient", MailModule.NAMESPACE_URI, MailModule.PREFIX), null); builder.addAttribute(new QName("type", null, null), "cc"); builder.characters(ccAddress.toString()); builder.endElement(); } } // bcc Recipients Address[] bccAddresses = message.getRecipients(Message.RecipientType.BCC); if (bccAddresses != null) { for (Address bccAddress : bccAddresses) { builder.startElement( new QName("recipient", MailModule.NAMESPACE_URI, MailModule.PREFIX), null); builder.addAttribute(new QName("type", null, null), "bcc"); builder.characters(bccAddress.toString()); builder.endElement(); } } builder.endElement(); // Flags Flags flags = message.getFlags(); Flags.Flag[] systemFlags = flags.getSystemFlags(); String[] userFlags = flags.getUserFlags(); if (systemFlags.length > 0 || userFlags.length > 0) { builder.startElement(new QName("flags", MailModule.NAMESPACE_URI, MailModule.PREFIX), null); for (Flags.Flag systemFlag : systemFlags) { if (systemFlag == Flags.Flag.ANSWERED) { builder.startElement(new QName("flag", MailModule.NAMESPACE_URI, MailModule.PREFIX), null); builder.addAttribute(new QName("type", null, null), "answered"); builder.endElement(); } else if (systemFlag == Flags.Flag.DELETED) { builder.startElement(new QName("flag", MailModule.NAMESPACE_URI, MailModule.PREFIX), null); builder.addAttribute(new QName("type", null, null), "deleted"); builder.endElement(); } else if (systemFlag == Flags.Flag.DRAFT) { builder.startElement(new QName("flag", MailModule.NAMESPACE_URI, MailModule.PREFIX), null); builder.addAttribute(new QName("type", null, null), "draft"); builder.endElement(); } else if (systemFlag == Flags.Flag.FLAGGED) { builder.startElement(new QName("flag", MailModule.NAMESPACE_URI, MailModule.PREFIX), null); builder.addAttribute(new QName("type", null, null), "flagged"); builder.endElement(); } else if (systemFlag == Flags.Flag.RECENT) { builder.startElement(new QName("flag", MailModule.NAMESPACE_URI, MailModule.PREFIX), null); builder.addAttribute(new QName("type", null, null), "recent"); builder.endElement(); } else if (systemFlag == Flags.Flag.SEEN) { builder.startElement(new QName("flag", MailModule.NAMESPACE_URI, MailModule.PREFIX), null); builder.addAttribute(new QName("type", null, null), "seen"); builder.endElement(); } } for (String userFlag : userFlags) { builder.startElement(new QName("flag", MailModule.NAMESPACE_URI, MailModule.PREFIX), null); builder.addAttribute(new QName("type", null, null), "user"); builder.addAttribute(new QName("value", null, null), userFlag); builder.endElement(); } builder.endElement(); } // Headers if (includeHeaders) { Enumeration headers = message.getAllHeaders(); if (headers.hasMoreElements()) { builder.startElement(new QName("headers", MailModule.NAMESPACE_URI, MailModule.PREFIX), null); while (headers.hasMoreElements()) { Header header = (Header) headers.nextElement(); builder.startElement( new QName("header", MailModule.NAMESPACE_URI, MailModule.PREFIX), null); builder.addAttribute(new QName("name", null, null), header.getName()); builder.addAttribute(new QName("value", null, null), header.getValue()); builder.endElement(); } builder.endElement(); } } // Subject builder.startElement(new QName("subject", MailModule.NAMESPACE_URI, MailModule.PREFIX), null); builder.characters(message.getSubject()); builder.endElement(); builder.endElement(); } } catch (MessagingException me) { throw (new XPathException(this, "Failed to retrieve messages from list", me)); } builder.endElement(); ret = (NodeValue) builder.getDocument().getDocumentElement(); } return (ret); }