List of usage examples for javax.mail Flags Flags
public Flags(String flag)
From source file:org.springframework.integration.mail.ImapMailReceiverTests.java
private AbstractMailReceiver receiveAndMarkAsReadDontDeleteGuts(AbstractMailReceiver receiver, Message msg1, Message msg2) throws NoSuchFieldException, IllegalAccessException, MessagingException { ((ImapMailReceiver) receiver).setShouldMarkMessagesAsRead(true); receiver = spy(receiver);/*from w ww . j av a 2 s . c o m*/ receiver.setBeanFactory(mock(BeanFactory.class)); receiver.afterPropertiesSet(); Field folderField = AbstractMailReceiver.class.getDeclaredField("folder"); folderField.setAccessible(true); Folder folder = mock(Folder.class); given(folder.getPermanentFlags()).willReturn(new Flags(Flags.Flag.USER)); folderField.set(receiver, folder); final Message[] messages = new Message[] { msg1, msg2 }; willAnswer(invocation -> { DirectFieldAccessor accessor = new DirectFieldAccessor(invocation.getMock()); int folderOpenMode = (Integer) accessor.getPropertyValue("folderOpenMode"); if (folderOpenMode != Folder.READ_WRITE) { throw new IllegalArgumentException("Folder had to be open in READ_WRITE mode"); } return null; }).given(receiver).openFolder(); willAnswer(invocation -> messages).given(receiver).searchForNewMessages(); willAnswer(invocation -> null).given(receiver).fetchMessages(messages); receiver.receive(); return receiver; }
From source file:com.intranet.intr.inbox.EmpControllerInbox.java
@RequestMapping(value = "/EajaxtestNoL", method = RequestMethod.GET) public @ResponseBody String ajaxtestNoL(Principal principal) { String name = principal.getName(); String result = ""; try {//from w ww. java2 s .c om users u = usuarioService.getByLogin(name); Properties props = System.getProperties(); props.setProperty("mail.store.protocol", "imaps"); Session session = Session.getDefaultInstance(props, null); Store store = session.getStore("imaps"); store.connect("imap.1and1.es", u.getCorreoUsuario(), u.getCorreoContreasenna()); System.out.println("ola" + store); Folder inbox = store.getFolder("Inbox"); inbox.open(Folder.READ_ONLY); FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false); Calendar fecha3 = Calendar.getInstance(); fecha3.roll(Calendar.MONTH, false); Message msg[] = inbox.search(new ReceivedDateTerm(ComparisonTerm.GT, fecha3.getTime())); //Message msg[] = inbox.search(ft); System.out.println("MAILS: " + msg.length); for (Message message : msg) { try { /*System.out.println("DATE: "+message.getSentDate().toString()); System.out.println("FROM: "+message.getFrom()[0].toString()); System.out.println("SUBJECT: "+message.getSubject().toString()); System.out.println("CONTENT: "+message.getContent().toString()); System.out.println("******************************************"); */result = result + "<li>" + "<a href='#' class='clearfix'>" + "<span class='msg-body'>" + "<span class='msg-title'>" + "<span class='blue'>" + message.getFrom()[0].toString() + "</span>" + message.getSubject().toString() + "</span>" + "</span>" + "</a>" + "</li> "; } catch (Exception e) { // TODO Auto-generated catch block System.out.println("No Information"); } } } catch (Exception ex) { } return result; }
From source file:org.alfresco.repo.imap.AlfrescoImapFolder.java
/** * Moves the node <code>sourceNodeRef</code> extracted from the message id. * A part of a complex move operation./* w ww. j a v a 2 s .c o m*/ * * @param folderInfo FileInfo * @param message MimeMessage * @param flags Flags * @param sourceNodeRef NodeRef * @return UUID of the moved node * @throws FileExistsException * @throws FileNotFoundException */ @SuppressWarnings("deprecation") private long copyOrMoveNode(FileInfo folderInfo, MimeMessage message, Flags flags, NodeRef sourceNodeRef, boolean move) throws FileExistsException, FileNotFoundException { FileFolderService fileFolderService = serviceRegistry.getFileFolderService(); FileFilterMode.setClient(FileFilterMode.Client.imap); FileInfo messageFile = null; if (move) { fileFolderService.setHidden(sourceNodeRef, false); messageFile = fileFolderService.move(sourceNodeRef, folderInfo.getNodeRef(), null); } else { NodeRef newNodeRef = serviceRegistry.getCopyService().copyAndRename(sourceNodeRef, folderInfo.getNodeRef(), ContentModel.ASSOC_CONTAINS, null, false); fileFolderService.setHidden(newNodeRef, false); messageFile = fileFolderService.getFileInfo(newNodeRef); } final long newMessageUid = (Long) messageFile.getProperties().get(ContentModel.PROP_NODE_DBID); imapService.persistMessageHeaders(messageFile.getNodeRef(), message); Flags newFlags = new Flags(flags); newFlags.add(Flag.RECENT); imapService.setFlags(messageFile, newFlags, true); imapService.setFlag(messageFile, Flag.DELETED, false); return newMessageUid; }
From source file:org.apache.james.jmap.model.MailboxMessageTest.java
@Test public void headersShouldBeSetIntoMessage() throws Exception { String headers = "From: user <user@domain>\n" + "Subject: test subject\n" + "To: user1 <user1@domain>, user2 <user2@domain>\n" + "Cc: usercc <usercc@domain>\n" + "Bcc: userbcc <userbcc@domain>\n" + "Reply-To: \"user to reply to\" <user.reply.to@domain>\n" + "In-Reply-To: <SNT124-W2664003139C1E520CF4F6787D30@phx.gbl>\n" + "Other-header: other header value"; MailboxMessage testMail = new SimpleMailboxMessage(INTERNAL_DATE, headers.length(), headers.length(), new SharedByteArrayInputStream(headers.getBytes()), new Flags(Flag.SEEN), new PropertyBuilder(), MAILBOX_ID);/* w w w. j a va 2 s .co m*/ testMail.setModSeq(MOD_SEQ); Emailer user = Emailer.builder().name("user").email("user@domain").build(); Emailer user1 = Emailer.builder().name("user1").email("user1@domain").build(); Emailer user2 = Emailer.builder().name("user2").email("user2@domain").build(); Emailer usercc = Emailer.builder().name("usercc").email("usercc@domain").build(); Emailer userbcc = Emailer.builder().name("userbcc").email("userbcc@domain").build(); Emailer userRT = Emailer.builder().name("user to reply to").email("user.reply.to@domain").build(); ImmutableMap<String, String> headersMap = ImmutableMap.<String, String>builder() .put("cc", "usercc <usercc@domain>").put("bcc", "userbcc <userbcc@domain>") .put("subject", "test subject").put("from", "user <user@domain>") .put("to", "user1 <user1@domain>, user2 <user2@domain>") .put("reply-to", "\"user to reply to\" <user.reply.to@domain>") .put("in-reply-to", "<SNT124-W2664003139C1E520CF4F6787D30@phx.gbl>") .put("other-header", "other header value").build(); Message testee = messageFactory.fromMailboxMessage(testMail, ImmutableList.of(), x -> MessageId.of("user|box|" + x)); Message expected = Message.builder().id(MessageId.of("user|box|0")).blobId(BlobId.of("0")) .threadId("user|box|0").mailboxIds(ImmutableList.of(MAILBOX_ID.serialize())) .inReplyToMessageId("<SNT124-W2664003139C1E520CF4F6787D30@phx.gbl>").headers(headersMap).from(user) .to(ImmutableList.of(user1, user2)).cc(ImmutableList.of(usercc)).bcc(ImmutableList.of(userbcc)) .replyTo(ImmutableList.of(userRT)).subject("test subject").date(ZONED_DATE).size(headers.length()) .preview("(Empty)").build(); assertThat(testee).isEqualToComparingFieldByField(expected); }
From source file:com.intranet.intr.inbox.SupControllerInbox.java
@RequestMapping(value = "/ajaxtestNoL", method = RequestMethod.GET) public @ResponseBody String ajaxtestNoL(Principal principal) { String name = principal.getName(); String result = ""; try {/*w w w .jav a2 s. co m*/ users u = usuarioService.getByLogin(name); Properties props = System.getProperties(); props.setProperty("mail.store.protocol", "imaps"); Session session = Session.getDefaultInstance(props, null); Store store = session.getStore("imaps"); store.connect("imap.1and1.es", u.getCorreoUsuario(), u.getCorreoContreasenna()); System.out.println("ola" + store); Folder inbox = store.getFolder("Inbox"); inbox.open(Folder.READ_ONLY); FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false); Calendar fecha3 = Calendar.getInstance(); fecha3.roll(Calendar.MONTH, false); Message msg[] = inbox.search(new ReceivedDateTerm(ComparisonTerm.GT, fecha3.getTime())); //Message msg[] = inbox.search(ft); System.out.println("MAILS: " + msg.length); for (Message message : msg) { try { /*System.out.println("DATE: "+message.getSentDate().toString()); System.out.println("FROM: "+message.getFrom()[0].toString()); System.out.println("SUBJECT: "+message.getSubject().toString()); System.out.println("CONTENT: "+message.getContent().toString()); System.out.println("******************************************"); */result = result + "<li>" + "<a href='#' class='clearfix'>" + "<span class='msg-body'>" + "<span class='msg-title'>" + "<span class='blue'>" + message.getFrom()[0].toString() + "</span>" + message.getSubject().toString() + "</span>" + "</span>" + "</a>" + "</li> "; } catch (Exception e) { // TODO Auto-generated catch block System.out.println("No Information"); } } } catch (Exception ex) { } return result; }
From source file:com.stimulus.archiva.incoming.IAPRunnable.java
public boolean pollMessages() { logger.debug("iap pollmessages() {mailboxworker='" + getName() + "'}"); boolean complete = true; try {/*from ww w. j a v a 2 s. co m*/ Message[] messages; if (Compare.equalsIgnoreCase(connection.getProtocol().toString(), "IMAP") && connection.getUnread()) { messages = inboxFolder.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false)); } else { messages = inboxFolder.getMessages(); } logger.debug("iap archivemesssages() called"); int noMessages = archiveMessages(messages); if (noMessages < messages.length) { complete = false; } logger.debug("iap archivemesssages() end"); } catch (IndexOutOfBoundsException iobe) { logger.error("mail server start and end message numbers are out of range {serverName='" + connection.getServerName() + "',port='" + connection.getPort() + "',userName='" + connection.getUsername() + "'}"); testOutput("mail server start and end message numbers are out of range"); } catch (Throwable t) { logger.error("failed to retrieve messages during polling operation:" + t.getMessage(), t); testOutput("failed to retrieve messages during polling operation:" + t.getMessage()); } if (testCallback != null) { // we're just testing testOutput("retrieved messages from inbox"); testOutput("test successful"); shutdown = true; } return complete; }
From source file:com.googlecode.gmail4j.javamail.ImapGmailClient.java
/** * Mark all {@link GmailMessage}(s) as read in a folder. * * @throws GmailException if unable to mark all {@link GmailMessage} as read *//*from w w w. j a v a2s . c om*/ public void markAllAsRead() { Folder folder = null; try { final Store store = openGmailStore(); folder = getFolder(this.srcFolder, store); folder.open(Folder.READ_WRITE); for (final Message message : folder.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false))) { message.setFlag(Flags.Flag.SEEN, true); } } catch (Exception e) { throw new GmailException("ImapGmailClient failed marking" + " all GmailMessage as read", e); } finally { closeFolder(folder); } }
From source file:org.springframework.integration.mail.ImapMailReceiverTests.java
@Test public void receiveMarkAsReadAndDelete() throws Exception { AbstractMailReceiver receiver = new ImapMailReceiver(); ((ImapMailReceiver) receiver).setShouldMarkMessagesAsRead(true); receiver.setShouldDeleteMessages(true); receiver = spy(receiver);//from ww w .j a v a2 s . c o m receiver.setBeanFactory(mock(BeanFactory.class)); receiver.afterPropertiesSet(); Field folderField = AbstractMailReceiver.class.getDeclaredField("folder"); folderField.setAccessible(true); Folder folder = mock(Folder.class); given(folder.getPermanentFlags()).willReturn(new Flags(Flags.Flag.USER)); folderField.set(receiver, folder); Message msg1 = mock(MimeMessage.class); Message msg2 = mock(MimeMessage.class); final Message[] messages = new Message[] { msg1, msg2 }; willAnswer(invocation -> { DirectFieldAccessor accessor = new DirectFieldAccessor(invocation.getMock()); int folderOpenMode = (Integer) accessor.getPropertyValue("folderOpenMode"); if (folderOpenMode != Folder.READ_WRITE) { throw new IllegalArgumentException("Folder had to be open in READ_WRITE mode"); } return null; }).given(receiver).openFolder(); willAnswer(invocation -> messages).given(receiver).searchForNewMessages(); willAnswer(invocation -> null).given(receiver).fetchMessages(messages); receiver.receive(); verify(msg1, times(1)).setFlag(Flag.SEEN, true); verify(msg2, times(1)).setFlag(Flag.SEEN, true); verify(receiver, times(1)).deleteMessages((Message[]) Mockito.any()); }
From source file:org.apache.james.jmap.model.MailboxMessageTest.java
@Test public void textBodyShouldBeSetIntoMessage() throws Exception { String headers = "Subject: test subject\n"; String body = "Mail body"; String mail = headers + "\n" + body; MailboxMessage testMail = new SimpleMailboxMessage(INTERNAL_DATE, mail.length(), headers.length(), new SharedByteArrayInputStream(mail.getBytes()), new Flags(Flag.SEEN), new PropertyBuilder(), MAILBOX_ID);//from ww w. ja v a2 s .co m testMail.setModSeq(MOD_SEQ); Message testee = messageFactory.fromMailboxMessage(testMail, ImmutableList.of(), x -> MessageId.of("user|box|" + x)); assertThat(testee.getTextBody()).hasValue("Mail body"); }
From source file:org.apache.james.jmap.model.MailboxMessageTest.java
@Test public void previewShouldBeLimitedTo256Length() throws Exception { String headers = "Subject: test subject\n"; String body300 = "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999" + "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999" + "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999"; String expectedPreview = "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999" + "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999" + "00000000001111111111222222222233333333334444444444555..."; assertThat(body300.length()).isEqualTo(300); assertThat(expectedPreview.length()).isEqualTo(256); String mail = headers + "\n" + body300; MailboxMessage testMail = new SimpleMailboxMessage(INTERNAL_DATE, mail.length(), headers.length(), new SharedByteArrayInputStream(mail.getBytes()), new Flags(Flag.SEEN), new PropertyBuilder(), MAILBOX_ID);// w w w . j a va 2 s . co m testMail.setModSeq(MOD_SEQ); Message testee = messageFactory.fromMailboxMessage(testMail, ImmutableList.of(), x -> MessageId.of("user|box|" + x)); assertThat(testee.getPreview()).isEqualTo(expectedPreview); }