List of usage examples for javax.mail Flags Flags
public Flags()
From source file:com.sun.mail.pop3.POP3Folder.java
/** * Always returns an empty <code>Flags</code> object because * the POP3 protocol doesn't support any permanent flags. * * @return empty Flags object/* w w w .j a va 2 s . co m*/ */ public Flags getPermanentFlags() { return new Flags(); // empty flags object }
From source file:com.hs.mail.imap.dao.MySqlMessageDao.java
public Flags getFlags(long messageID) { Flags flags = getSystemFlags(messageID); if (flags == null) { flags = new Flags(); }/* w w w .j a va 2 s . c om*/ List<String> ufs = getUserFlags(messageID); if (CollectionUtils.isNotEmpty(ufs)) { for (String uf : ufs) { flags.add(uf); } } return flags; }
From source file:org.springframework.integration.mail.AbstractMailReceiver.java
private void setMessageFlags(Message[] filteredMessages) throws MessagingException { boolean recentFlagSupported = false; Flags flags = this.getFolder().getPermanentFlags(); if (flags != null) { recentFlagSupported = flags.contains(Flags.Flag.RECENT); }//from w ww . j a va 2 s . c o m for (Message message : filteredMessages) { if (!recentFlagSupported) { if (flags != null && flags.contains(Flags.Flag.USER)) { if (logger.isDebugEnabled()) { logger.debug("USER flags are supported by this mail server. Flagging message with '" + SI_USER_FLAG + "' user flag"); } Flags siFlags = new Flags(); siFlags.add(SI_USER_FLAG); message.setFlags(siFlags, true); } else { if (logger.isDebugEnabled()) { logger.debug( "USER flags are not supported by this mail server. Flagging message with system flag"); } message.setFlag(Flags.Flag.FLAGGED, true); } } this.setAdditionalFlags(message); } }
From source file:org.apache.james.jmap.methods.integration.SetMessagesMethodTest.java
@Test public void setMessagesShouldReturnDestroyedWhenMatchingMessage() throws Exception { // Given/*from w w w . j ava 2 s . com*/ jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags()); await(); given().header("Authorization", accessToken.serialize()) .body("[[\"setMessages\", {\"destroy\": [\"" + username + "|mailbox|1\"]}, \"#0\"]]").when() .post("/jmap").then().log().ifValidationFails().statusCode(200).body(NAME, equalTo("messagesSet")) .body(ARGUMENTS + ".notDestroyed", anEmptyMap()).body(ARGUMENTS + ".destroyed", hasSize(1)) .body(ARGUMENTS + ".destroyed", contains(username + "|mailbox|1")); }
From source file:org.apache.james.jmap.methods.integration.GetMessageListMethodTest.java
@Test public void getMessageListUnreadFilterShouldWork() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); ComposedMessageId messageNotRead = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); ComposedMessageId messageRead = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ClassLoader.getSystemResourceAsStream("eml/twoAttachments.eml"), new Date(), false, new Flags(Flags.Flag.SEEN)); await();/*from w w w . ja va 2 s . com*/ given().header("Authorization", accessToken.serialize()) .body("[[\"getMessageList\", {\"filter\":{\"isUnread\":\"true\"}}, \"#0\"]]").when().post("/jmap") .then().statusCode(200).body(NAME, equalTo("messageList")).body(ARGUMENTS + ".messageIds", allOf(containsInAnyOrder(messageNotRead.getMessageId().serialize()), not(containsInAnyOrder(messageRead.getMessageId().serialize())))); }
From source file:org.nuxeo.ecm.platform.mail.utils.MailCoreHelper.java
protected static void doCheckMail(DocumentModel currentMailFolder, CoreSession coreSession) throws MessagingException { String email = (String) currentMailFolder.getPropertyValue(EMAIL_PROPERTY_NAME); String password = (String) currentMailFolder.getPropertyValue(PASSWORD_PROPERTY_NAME); if (!StringUtils.isEmpty(email) && !StringUtils.isEmpty(password)) { mailService = getMailService();//from w ww .ja v a2s. co m MessageActionPipe pipe = mailService.getPipe(PIPE_NAME); Visitor visitor = new Visitor(pipe); Thread.currentThread().setContextClassLoader(Framework.class.getClassLoader()); // initialize context ExecutionContext initialExecutionContext = new ExecutionContext(); initialExecutionContext.put(MIMETYPE_SERVICE_KEY, getMimeService()); initialExecutionContext.put(PARENT_PATH_KEY, currentMailFolder.getPathAsString()); initialExecutionContext.put(CORE_SESSION_KEY, coreSession); initialExecutionContext.put(LEAVE_ON_SERVER_KEY, Boolean.TRUE); // TODO should be an attribute in 'protocol' // schema Folder rootFolder = null; Store store = null; try { String protocolType = (String) currentMailFolder.getPropertyValue(PROTOCOL_TYPE_PROPERTY_NAME); initialExecutionContext.put(PROTOCOL_TYPE_KEY, protocolType); // log.debug(PROTOCOL_TYPE_KEY + ": " + (String) initialExecutionContext.get(PROTOCOL_TYPE_KEY)); String host = (String) currentMailFolder.getPropertyValue(HOST_PROPERTY_NAME); String port = (String) currentMailFolder.getPropertyValue(PORT_PROPERTY_NAME); Boolean socketFactoryFallback = (Boolean) currentMailFolder .getPropertyValue(SOCKET_FACTORY_FALLBACK_PROPERTY_NAME); String socketFactoryPort = (String) currentMailFolder .getPropertyValue(SOCKET_FACTORY_PORT_PROPERTY_NAME); Boolean starttlsEnable = (Boolean) currentMailFolder .getPropertyValue(STARTTLS_ENABLE_PROPERTY_NAME); String sslProtocols = (String) currentMailFolder.getPropertyValue(SSL_PROTOCOLS_PROPERTY_NAME); Long emailsLimit = (Long) currentMailFolder.getPropertyValue(EMAILS_LIMIT_PROPERTY_NAME); long emailsLimitLongValue = emailsLimit == null ? EMAILS_LIMIT_DEFAULT : emailsLimit.longValue(); String imapDebug = Framework.getProperty(IMAP_DEBUG, "false"); Properties properties = new Properties(); properties.put("mail.store.protocol", protocolType); // properties.put("mail.host", host); // Is IMAP connection if (IMAP.equals(protocolType)) { properties.put("mail.imap.host", host); properties.put("mail.imap.port", port); properties.put("mail.imap.starttls.enable", starttlsEnable.toString()); properties.put("mail.imap.debug", imapDebug); properties.put("mail.imap.partialfetch", "false"); } else if (IMAPS.equals(protocolType)) { properties.put("mail.imaps.host", host); properties.put("mail.imaps.port", port); properties.put("mail.imaps.starttls.enable", starttlsEnable.toString()); properties.put("mail.imaps.ssl.protocols", sslProtocols); properties.put("mail.imaps.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); properties.put("mail.imaps.socketFactory.fallback", socketFactoryFallback.toString()); properties.put("mail.imaps.socketFactory.port", socketFactoryPort); properties.put("mail.imap.partialfetch", "false"); properties.put("mail.imaps.partialfetch", "false"); } else if (POP3S.equals(protocolType)) { properties.put("mail.pop3s.host", host); properties.put("mail.pop3s.port", port); properties.put("mail.pop3s.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); properties.put("mail.pop3s.socketFactory.fallback", socketFactoryFallback.toString()); properties.put("mail.pop3s.socketFactory.port", socketFactoryPort); properties.put("mail.pop3s.ssl.protocols", sslProtocols); } else { // Is POP3 connection properties.put("mail.pop3.host", host); properties.put("mail.pop3.port", port); } properties.put("user", email); properties.put("password", password); Session session = Session.getInstance(properties); store = session.getStore(); store.connect(email, password); String folderName = INBOX; // TODO should be an attribute in 'protocol' schema rootFolder = store.getFolder(folderName); // need RW access to update message flags rootFolder.open(Folder.READ_WRITE); Message[] allMessages = rootFolder.getMessages(); // VDU log.debug("nbr of messages in folder:" + allMessages.length); FetchProfile fetchProfile = new FetchProfile(); fetchProfile.add(FetchProfile.Item.FLAGS); fetchProfile.add(FetchProfile.Item.ENVELOPE); fetchProfile.add(FetchProfile.Item.CONTENT_INFO); fetchProfile.add("Message-ID"); fetchProfile.add("Content-Transfer-Encoding"); rootFolder.fetch(allMessages, fetchProfile); if (rootFolder instanceof IMAPFolder) { // ((IMAPFolder)rootFolder).doCommand(FetchProfile) } List<Message> unreadMessagesList = new ArrayList<Message>(); for (Message message : allMessages) { Flags flags = message.getFlags(); int unreadMessagesListSize = unreadMessagesList.size(); if (flags != null && !flags.contains(Flag.SEEN) && unreadMessagesListSize < emailsLimitLongValue) { unreadMessagesList.add(message); if (unreadMessagesListSize == emailsLimitLongValue - 1) { break; } } } Message[] unreadMessagesArray = unreadMessagesList.toArray(new Message[unreadMessagesList.size()]); // perform email import visitor.visit(unreadMessagesArray, initialExecutionContext); // perform flag update globally Flags flags = new Flags(); flags.add(Flag.SEEN); boolean leaveOnServer = (Boolean) initialExecutionContext.get(LEAVE_ON_SERVER_KEY); if ((IMAP.equals(protocolType) || IMAPS.equals(protocolType)) && leaveOnServer) { flags.add(Flag.SEEN); } else { flags.add(Flag.DELETED); } rootFolder.setFlags(unreadMessagesArray, flags, true); } finally { if (rootFolder != null && rootFolder.isOpen()) { rootFolder.close(true); } if (store != null) { store.close(); } } } }
From source file:org.apache.james.jmap.model.MailboxMessageTest.java
@Test public void flagsShouldBeSetIntoMessage() throws Exception { Flags flags = new Flags(); flags.add(Flag.ANSWERED);// w w w .j a v a 2 s .c o m flags.add(Flag.FLAGGED); flags.add(Flag.DRAFT); MailboxMessage testMail = new SimpleMailboxMessage(INTERNAL_DATE, 0, 0, new SharedByteArrayInputStream("".getBytes()), flags, new PropertyBuilder(), MAILBOX_ID); testMail.setModSeq(MOD_SEQ); Message testee = messageFactory.fromMailboxMessage(testMail, ImmutableList.of(), x -> MessageId.of("user|box|" + x)); assertThat(testee) .extracting(Message::isIsUnread, Message::isIsFlagged, Message::isIsAnswered, Message::isIsDraft) .containsExactly(true, true, true, true); }
From source file:org.apache.james.mailbox.elasticsearch.json.MailboxMessageToElasticSearchJsonTest.java
@Test public void getUpdatedJsonMessagePartShouldBehaveWellOnEmptyFlags() throws Exception { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris")); assertThatJson(messageToElasticSearchJson.getUpdatedJsonMessagePart(new Flags(), MOD_SEQ)).isEqualTo( "{\"modSeq\":42,\"isAnswered\":false,\"isDeleted\":false,\"isDraft\":false,\"isFlagged\":false,\"isRecent\":false,\"userFlags\":[],\"isUnread\":true}"); }
From source file:org.apache.james.jmap.methods.integration.SetMessagesMethodTest.java
@Test public void setMessagesShouldDeleteMessageWhenMatchingMessage() throws Exception { // Given/* ww w . j a v a 2 s. c o m*/ jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags()); await(); // When given().header("Authorization", accessToken.serialize()) .body("[[\"setMessages\", {\"destroy\": [\"" + username + "|mailbox|1\"]}, \"#0\"]]").when() .post("/jmap").then().log().ifValidationFails().statusCode(200); // Then given().header("Authorization", accessToken.serialize()) .body("[[\"getMessages\", {\"ids\": [\"" + username + "|mailbox|1\"]}, \"#0\"]]").when() .post("/jmap").then().log().ifValidationFails().statusCode(200).body(NAME, equalTo("messages")) .body(ARGUMENTS + ".list", empty()); }
From source file:org.apache.james.jmap.methods.integration.GetMessageListMethodTest.java
@Test public void getMessageListSetDraftFilterShouldWork() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); ComposedMessageId messageNotDraft = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); ComposedMessageId messageDraft = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ClassLoader.getSystemResourceAsStream("eml/twoAttachments.eml"), new Date(), false, new Flags(Flags.Flag.DRAFT)); await();/*from w w w . j a v a 2 s .c o m*/ given().header("Authorization", accessToken.serialize()) .body("[[\"getMessageList\", {\"filter\":{\"isDraft\":\"true\"}}, \"#0\"]]").when().post("/jmap") .then().statusCode(200).body(NAME, equalTo("messageList")) .body(ARGUMENTS + ".messageIds", allOf(containsInAnyOrder(messageDraft.getMessageId().serialize()), not(containsInAnyOrder(messageNotDraft.getMessageId().serialize())))); }