List of usage examples for javax.mail Flags Flags
public Flags()
From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java
@Test public void getUpdatedJsonMessagePartShouldBehaveWellOnEmptyFlags() throws Exception { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES); 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 setMessagesShouldDeleteMatchingMessagesWhenMixed() throws Exception { // Given//w ww. j a v a 2s. 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()); jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags()); jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), new ByteArrayInputStream("Subject: test3\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\", \"" + username + "|mailbox|4\", \"" + username + "|mailbox|3\"]}, \"#0\"]]") .when().post("/jmap").then().log().ifValidationFails().statusCode(200); // Then given().header("Authorization", accessToken.serialize()) .body("[[\"getMessages\", {\"ids\": [\"" + username + "|mailbox|1\", \"" + username + "|mailbox|2\", \"" + username + "|mailbox|3\"]}, \"#0\"]]") .when().post("/jmap").then().log().ifValidationFails().statusCode(200) .body(NAME, equalTo("messages")).body(ARGUMENTS + ".list", hasSize(1)); }
From source file:org.apache.james.mailbox.store.StoreMessageManager.java
/** * @see org.apache.james.mailbox.MessageManager#appendMessage(java.io.InputStream, * java.util.Date, org.apache.james.mailbox.MailboxSession, boolean, * javax.mail.Flags)/*from w w w .jav a2s . com*/ */ public long appendMessage(InputStream msgIn, Date internalDate, final MailboxSession mailboxSession, boolean isRecent, Flags flagsToBeSet) throws MailboxException { File file = null; TeeInputStream tmpMsgIn = null; BodyOffsetInputStream bIn = null; FileOutputStream out = null; SharedFileInputStream contentIn = null; if (!isWriteable(mailboxSession)) { throw new ReadOnlyException(getMailboxPath(), mailboxSession.getPathDelimiter()); } try { // Create a temporary file and copy the message to it. We will work // with the file as // source for the InputStream file = File.createTempFile("imap", ".msg"); out = new FileOutputStream(file); tmpMsgIn = new TeeInputStream(msgIn, out); bIn = new BodyOffsetInputStream(tmpMsgIn); // Disable line length... This should be handled by the smtp server // component and not the parser itself // https://issues.apache.org/jira/browse/IMAP-122 MimeConfig config = MimeConfig.custom().setMaxLineLen(-1).setMaxHeaderLen(-1).build(); final MimeTokenStream parser = new MimeTokenStream(config, new DefaultBodyDescriptorBuilder()); parser.setRecursionMode(RecursionMode.M_NO_RECURSE); parser.parse(bIn); final HeaderImpl header = new HeaderImpl(); EntityState next = parser.next(); while (next != EntityState.T_BODY && next != EntityState.T_END_OF_STREAM && next != EntityState.T_START_MULTIPART) { if (next == EntityState.T_FIELD) { header.addField(parser.getField()); } next = parser.next(); } final MaximalBodyDescriptor descriptor = (MaximalBodyDescriptor) parser.getBodyDescriptor(); final PropertyBuilder propertyBuilder = new PropertyBuilder(); final String mediaType; final String mediaTypeFromHeader = descriptor.getMediaType(); final String subType; if (mediaTypeFromHeader == null) { mediaType = "text"; subType = "plain"; } else { mediaType = mediaTypeFromHeader; subType = descriptor.getSubType(); } propertyBuilder.setMediaType(mediaType); propertyBuilder.setSubType(subType); propertyBuilder.setContentID(descriptor.getContentId()); propertyBuilder.setContentDescription(descriptor.getContentDescription()); propertyBuilder.setContentLocation(descriptor.getContentLocation()); propertyBuilder.setContentMD5(descriptor.getContentMD5Raw()); propertyBuilder.setContentTransferEncoding(descriptor.getTransferEncoding()); propertyBuilder.setContentLanguage(descriptor.getContentLanguage()); propertyBuilder.setContentDispositionType(descriptor.getContentDispositionType()); propertyBuilder.setContentDispositionParameters(descriptor.getContentDispositionParameters()); propertyBuilder.setContentTypeParameters(descriptor.getContentTypeParameters()); // Add missing types final String codeset = descriptor.getCharset(); if (codeset == null) { if ("TEXT".equalsIgnoreCase(mediaType)) { propertyBuilder.setCharset("us-ascii"); } } else { propertyBuilder.setCharset(codeset); } final String boundary = descriptor.getBoundary(); if (boundary != null) { propertyBuilder.setBoundary(boundary); } if ("text".equalsIgnoreCase(mediaType)) { final CountingInputStream bodyStream = new CountingInputStream(parser.getInputStream()); bodyStream.readAll(); long lines = bodyStream.getLineCount(); bodyStream.close(); next = parser.next(); if (next == EntityState.T_EPILOGUE) { final CountingInputStream epilogueStream = new CountingInputStream(parser.getInputStream()); epilogueStream.readAll(); lines += epilogueStream.getLineCount(); epilogueStream.close(); } propertyBuilder.setTextualLineCount(lines); } final Flags flags; if (flagsToBeSet == null) { flags = new Flags(); } else { flags = flagsToBeSet; // Check if we need to trim the flags trimFlags(flags, mailboxSession); } if (isRecent) { flags.add(Flags.Flag.RECENT); } if (internalDate == null) { internalDate = new Date(); } byte[] discard = new byte[4096]; while (tmpMsgIn.read(discard) != -1) { // consume the rest of the stream so everything get copied to // the file now // via the TeeInputStream } int bodyStartOctet = (int) bIn.getBodyStartOffset(); if (bodyStartOctet == -1) { bodyStartOctet = 0; } contentIn = new SharedFileInputStream(file); final int size = (int) file.length(); final List<MessageAttachment> attachments = extractAttachments(contentIn); final MailboxMessage message = createMessage(internalDate, size, bodyStartOctet, contentIn, flags, propertyBuilder, attachments); new QuotaChecker(quotaManager, quotaRootResolver, mailbox).tryAddition(1, size); return locker.executeWithLock(mailboxSession, getMailboxPath(), new MailboxPathLocker.LockAwareExecution<Long>() { @Override public Long execute() throws MailboxException { MessageMetaData data = appendMessageToStore(message, attachments, mailboxSession); SortedMap<Long, MessageMetaData> uids = new TreeMap<Long, MessageMetaData>(); uids.put(data.getUid(), data); dispatcher.added(mailboxSession, uids, getMailboxEntity()); return data.getUid(); } }, true); } catch (IOException e) { throw new MailboxException("Unable to parse message", e); } catch (MimeException e) { throw new MailboxException("Unable to parse message", e); } finally { IOUtils.closeQuietly(bIn); IOUtils.closeQuietly(tmpMsgIn); IOUtils.closeQuietly(out); IOUtils.closeQuietly(contentIn); // delete the temporary file if one was specified if (file != null) { if (!file.delete()) { // Don't throw an IOException. The message could be appended // and the temporary file // will be deleted hopefully some day } } } }
From source file:org.apache.james.jmap.methods.integration.GetMessageListMethodTest.java
@Test public void getMessageListUnsetAnsweredFilterShouldWork() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); ComposedMessageId messageNotAnswered = 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 messageAnswered = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ClassLoader.getSystemResourceAsStream("eml/twoAttachments.eml"), new Date(), false, new Flags(Flags.Flag.ANSWERED)); await();/* ww w .ja v a 2s . c o m*/ given().header("Authorization", accessToken.serialize()) .body("[[\"getMessageList\", {\"filter\":{\"isAnswered\":\"false\"}}, \"#0\"]]").when() .post("/jmap").then().statusCode(200).body(NAME, equalTo("messageList")) .body(ARGUMENTS + ".messageIds", allOf(containsInAnyOrder(messageNotAnswered.getMessageId().serialize()), not(containsInAnyOrder(messageAnswered.getMessageId().serialize())))); }
From source file:org.apache.james.pop3server.POP3ServerTest.java
/** * Test for JAMES-1202 - This was failing before as the more then one connection to the same * mailbox was not handled the right way *///from www. jav a 2s.com @Test @Ignore public void testStatUidlListTwoConnections() throws Exception { finishSetUp(pop3Configuration); pop3Client = new POP3Client(); pop3Client.connect("127.0.0.1", pop3Port); usersRepository.addUser("foo2", "bar2"); MailboxPath mailboxPath = new MailboxPath(MailboxConstants.USER_NAMESPACE, "foo2", "INBOX"); MailboxSession session = mailboxManager.login("foo2", "bar2", LoggerFactory.getLogger("Test")); if (!mailboxManager.mailboxExists(mailboxPath, session)) { mailboxManager.createMailbox(mailboxPath, session); } int msgCount = 100; for (int i = 0; i < msgCount; i++) { mailboxManager.getMailbox(mailboxPath, session).appendMessage( new ByteArrayInputStream(("Subject: test\r\n\r\n" + i).getBytes()), new Date(), session, true, new Flags()); } pop3Client.login("foo2", "bar2"); assertEquals(1, pop3Client.getState()); POP3MessageInfo[] listEntries = pop3Client.listMessages(); POP3MessageInfo[] uidlEntries = pop3Client.listUniqueIdentifiers(); POP3MessageInfo statInfo = pop3Client.status(); assertEquals(msgCount, listEntries.length); assertEquals(msgCount, uidlEntries.length); assertEquals(msgCount, statInfo.number); POP3Client m_pop3Protocol2 = new POP3Client(); m_pop3Protocol2.connect("127.0.0.1", pop3Port); m_pop3Protocol2.login("foo2", "bar2"); assertEquals(1, m_pop3Protocol2.getState()); POP3MessageInfo[] listEntries2 = m_pop3Protocol2.listMessages(); POP3MessageInfo[] uidlEntries2 = m_pop3Protocol2.listUniqueIdentifiers(); POP3MessageInfo statInfo2 = m_pop3Protocol2.status(); assertEquals(msgCount, listEntries2.length); assertEquals(msgCount, uidlEntries2.length); assertEquals(msgCount, statInfo2.number); pop3Client.deleteMessage(1); listEntries = pop3Client.listMessages(); uidlEntries = pop3Client.listUniqueIdentifiers(); statInfo = pop3Client.status(); assertEquals(msgCount - 1, listEntries.length); assertEquals(msgCount - 1, uidlEntries.length); assertEquals(msgCount - 1, statInfo.number); // even after the message was deleted it should get displayed in the // second connection listEntries2 = m_pop3Protocol2.listMessages(); uidlEntries2 = m_pop3Protocol2.listUniqueIdentifiers(); statInfo2 = m_pop3Protocol2.status(); assertEquals(msgCount, listEntries2.length); assertEquals(msgCount, uidlEntries2.length); assertEquals(msgCount, statInfo2.number); assertTrue(pop3Client.logout()); pop3Client.disconnect(); // even after the message was deleted and the session was quit it should // get displayed in the second connection listEntries2 = m_pop3Protocol2.listMessages(); uidlEntries2 = m_pop3Protocol2.listUniqueIdentifiers(); statInfo2 = m_pop3Protocol2.status(); assertEquals(msgCount, listEntries2.length); assertEquals(msgCount, uidlEntries2.length); assertEquals(msgCount, statInfo2.number); // This both should error and so return null assertNull(m_pop3Protocol2.retrieveMessageTop(1, 100)); assertNull(m_pop3Protocol2.retrieveMessage(1)); m_pop3Protocol2.sendCommand("quit"); m_pop3Protocol2.disconnect(); mailboxManager.deleteMailbox(mailboxPath, session); }
From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java
@Test public void spamEmailShouldBeWellConvertedToJsonWithApacheTika() throws IOException { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new TikaTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES); MailboxMessage spamMail = new SimpleMailboxMessage(MESSAGE_ID, date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/nonTextual.eml"))), new Flags(), propertyBuilder, MAILBOX_ID); spamMail.setUid(UID);/* w ww .j av a 2 s . c o m*/ spamMail.setModSeq(MOD_SEQ); assertThatJson(messageToElasticSearchJson.convertToJson(spamMail, ImmutableList.of(new MockMailboxSession("username").getUser()))).when(IGNORING_ARRAY_ORDER) .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/nonTextual.json"), CHARSET)); }
From source file:org.apache.james.jmap.methods.integration.SetMessagesMethodTest.java
@Test public void setMessagesShouldReturnUpdatedIdAndNoErrorWhenIsUnreadPassedToFalse() throws MailboxException { // Given//from w w w.java 2s . 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(); String presumedMessageId = username + "|mailbox|1"; // When given().header("Authorization", accessToken.serialize()) .body(String.format( "[[\"setMessages\", {\"update\": {\"%s\" : { \"isUnread\" : false } } }, \"#0\"]]", presumedMessageId)) .when().post("/jmap") // Then .then().log().ifValidationFails().spec(getSetMessagesUpdateOKResponseAssertions(presumedMessageId)); }
From source file:org.apache.james.jmap.methods.integration.GetMessageListMethodTest.java
@Test public void getMessageListANDOperatorShouldWork() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); ComposedMessageId messageNotSeenNotFlagged = 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 messageNotSeenFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ClassLoader.getSystemResourceAsStream("eml/twoAttachments.eml"), new Date(), false, new Flags(Flags.Flag.FLAGGED)); ComposedMessageId messageSeenNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ClassLoader.getSystemResourceAsStream("eml/oneInlinedImage.eml"), new Date(), false, new Flags(Flags.Flag.SEEN)); ComposedMessageId messageSeenFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ClassLoader.getSystemResourceAsStream("eml/oneInlinedImage.eml"), new Date(), false, FlagsBuilder.builder().add(Flags.Flag.SEEN, Flags.Flag.FLAGGED).build()); await();// w ww . j a va 2s . co m given().header("Authorization", accessToken.serialize()).body( "[[\"getMessageList\", {\"filter\":{\"operator\":\"AND\",\"conditions\":[{\"isFlagged\":\"true\"},{\"isUnread\":\"true\"}]}}, \"#0\"]]") .when().post("/jmap").then().statusCode(200).body(NAME, equalTo("messageList")) .body(ARGUMENTS + ".messageIds", allOf(containsInAnyOrder(messageNotSeenFlagged.getMessageId().serialize()), not(containsInAnyOrder(messageNotSeenNotFlagged.getMessageId().serialize(), messageSeenNotFlagged.getMessageId().serialize(), messageSeenFlagged.getMessageId().serialize())))); }
From source file:org.apache.james.jmap.methods.integration.SetMessagesMethodTest.java
@Test public void setMessagesShouldMarkAsReadWhenIsUnreadPassedToFalse() throws MailboxException { // Given//www.j a v a2s . 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(); String presumedMessageId = username + "|mailbox|1"; given().header("Authorization", accessToken.serialize()) .body(String.format( "[[\"setMessages\", {\"update\": {\"%s\" : { \"isUnread\" : false } } }, \"#0\"]]", presumedMessageId)) // When .when().post("/jmap"); // Then with().header("Authorization", accessToken.serialize()) .body("[[\"getMessages\", {\"ids\": [\"" + presumedMessageId + "\"]}, \"#0\"]]").post("/jmap") .then().log().ifValidationFails().statusCode(200).body(NAME, equalTo("messages")) .body(ARGUMENTS + ".list", hasSize(1)).body(ARGUMENTS + ".list[0].isUnread", equalTo(false)); }
From source file:org.apache.james.jmap.methods.integration.GetMessageListMethodTest.java
@Test public void getMessageListOROperatorShouldWork() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); ComposedMessageId messageNotSeenNotFlagged = 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 messageNotSeenFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ClassLoader.getSystemResourceAsStream("eml/twoAttachments.eml"), new Date(), false, new Flags(Flags.Flag.FLAGGED)); ComposedMessageId messageSeenNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ClassLoader.getSystemResourceAsStream("eml/oneInlinedImage.eml"), new Date(), false, new Flags(Flags.Flag.SEEN)); ComposedMessageId messageSeenFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ClassLoader.getSystemResourceAsStream("eml/oneInlinedImage.eml"), new Date(), false, FlagsBuilder.builder().add(Flags.Flag.SEEN, Flags.Flag.FLAGGED).build()); await();//from w w w . ja va 2 s .co m given().header("Authorization", accessToken.serialize()).body( "[[\"getMessageList\", {\"filter\":{\"operator\":\"OR\",\"conditions\":[{\"isFlagged\":\"true\"},{\"isUnread\":\"true\"}]}}, \"#0\"]]") .when().post("/jmap").then().statusCode(200).body(NAME, equalTo("messageList")) .body(ARGUMENTS + ".messageIds", allOf(containsInAnyOrder(messageNotSeenFlagged.getMessageId().serialize(), messageSeenFlagged.getMessageId().serialize(), messageNotSeenNotFlagged.getMessageId().serialize()), not(containsInAnyOrder(messageSeenNotFlagged.getMessageId().serialize())))); }