List of usage examples for javax.mail Flags Flags
public Flags(String flag)
From source file:org.apache.james.jmap.model.MessageFactoryTest.java
@Test public void textBodyShouldBeSetIntoMessage() throws Exception { String headers = "Subject: test subject\n"; String body = "Mail body"; String mail = headers + "\n" + body; MetaDataWithContent testMail = MetaDataWithContent.builder().uid(2).flags(new Flags(Flag.SEEN)) .size(mail.length()).internalDate(INTERNAL_DATE) .content(new ByteArrayInputStream(mail.getBytes(Charsets.UTF_8))).attachments(ImmutableList.of()) .mailboxId(MAILBOX_ID).messageId(MessageId.of("user|box|2")).build(); Message testee = messageFactory.fromMetaDataWithContent(testMail); assertThat(testee.getTextBody()).hasValue("Mail body"); }
From source file:org.wso2.esb.integration.common.utils.MailToTransportUtil.java
/** * Delete all unread emails from inbox//from ww w . j a v a 2s. c o m * * @throws ESBMailTransportIntegrationTestException - Is thrown if an error when deleting the emails */ public static void deleteAllUnreadEmailsFromGmail() throws ESBMailTransportIntegrationTestException { Folder inbox = null; Store store = getConnection(); try { inbox = store.getFolder(EMAIL_INBOX); inbox.open(Folder.READ_WRITE); Message[] messages = inbox.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false)); for (Message message : messages) { message.setFlag(Flags.Flag.DELETED, true); log.info("Deleted email Subject : " + message.getSubject()); } } catch (MessagingException e) { log.error("Error when deleting emails from inbox", e); throw new ESBMailTransportIntegrationTestException("Error when deleting emails from inbox ", e); } finally { if (inbox != null) { try { inbox.close(true); } catch (MessagingException e) { log.warn("Error when closing the email folder : ", e); } } if (store != null) { try { store.close(); } catch (MessagingException e) { log.warn("Error when closing the email store : ", e); } } } }
From source file:com.googlecode.gmail4j.javamail.ImapGmailClient.java
@Override public GmailMessageList getMessagesBy(EmailSearchStrategy strategy, String value) { SearchTerm seekStrategy = null;/*w w w . ja va 2 s .c om*/ switch (strategy) { case SUBJECT: seekStrategy = new SubjectTerm(value); LOG.debug("Fetching emails with a subject of \"" + value + "\""); break; case TO: seekStrategy = new RecipientStringTerm(Message.RecipientType.TO, value); LOG.debug("Fetching emails sent to \"" + value + "\""); break; case FROM: seekStrategy = new FromStringTerm(value); LOG.debug("Fetching emails sent from \"" + value + "\""); break; case CC: seekStrategy = new RecipientStringTerm(Message.RecipientType.CC, value); LOG.debug("Fetching emails CC'd to \"" + value + "\""); break; case DATE_GT: seekStrategy = new SentDateTerm(SentDateTerm.GT, parseDate(value)); LOG.debug("Fetching emails with a send date newer than \"" + value + "\""); break; case DATE_LT: seekStrategy = new SentDateTerm(SentDateTerm.LT, parseDate(value)); LOG.debug("Fetching emails with a send date newer than \"" + value + "\""); break; case DATE_EQ: seekStrategy = new SentDateTerm(SentDateTerm.EQ, parseDate(value)); LOG.debug("Fetching emails with a send date newer than \"" + value + "\""); break; case KEYWORD: seekStrategy = new BodyTerm(value); LOG.debug("Fetching emails containing the keyword \"" + value + "\""); break; case UNREAD: seekStrategy = new FlagTerm(new Flags(Flags.Flag.SEEN), false); LOG.debug("Fetching all unread emails"); break; } try { final GmailMessageList found = new GmailMessageList(); final Store store = openGmailStore(); final Folder folder = getFolder(this.srcFolder, store); folder.open(Folder.READ_ONLY); for (final Message msg : folder.search(seekStrategy)) { found.add(new JavaMailGmailMessage(msg)); } LOG.debug("Found " + found.size() + " emails"); return found; } catch (final Exception e) { throw new GmailException("Failed getting unread messages", e); } }
From source file:org.apache.james.jmap.model.MessageFactoryTest.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; MetaDataWithContent testMail = MetaDataWithContent.builder().uid(2).flags(new Flags(Flag.SEEN)) .size(mail.length()).internalDate(INTERNAL_DATE) .content(new ByteArrayInputStream(mail.getBytes(Charsets.UTF_8))).attachments(ImmutableList.of()) .mailboxId(MAILBOX_ID).messageId(MessageId.of("user|box|2")).build(); Message testee = messageFactory.fromMetaDataWithContent(testMail); assertThat(testee.getPreview()).isEqualTo(expectedPreview); }
From source file:org.apache.james.mailbox.store.StoreMessageManager.java
/** * Return {@link Flags} which are permanent stored by the mailbox. By * default this are the following flags: <br> * {@link Flag#ANSWERED}, {@link Flag#DELETED}, {@link Flag#DRAFT}, * {@link Flag#FLAGGED}, {@link Flag#RECENT}, {@link Flag#SEEN} <br> * // www. j a v a2 s.c om * Which in fact does not allow to permanent store user flags / keywords. * * If the sub-class does allow to store "any" user flag / keyword it MUST * override this method and add {@link Flag#USER} to the list of returned * {@link Flags}. If only a special set of user flags / keywords should be * allowed just add them directly. * * @param session * @return flags */ protected Flags getPermanentFlags(MailboxSession session) { // Return a new flags instance to make sure the static declared flags // instance will not get modified later. // // See MAILBOX-109 return new Flags(MINIMAL_PERMANET_FLAGS); }
From source file:org.apache.james.jmap.model.MessageFactoryTest.java
@Test public void attachmentsShouldBeEmptyWhenNone() throws Exception { MetaDataWithContent testMail = MetaDataWithContent.builder().uid(2).flags(new Flags(Flag.SEEN)).size(0) .internalDate(INTERNAL_DATE) .content(new ByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("spamMail.eml")))) .attachments(ImmutableList.of()).mailboxId(MAILBOX_ID).messageId(MessageId.of("user|box|2")) .build();/* w w w . j a v a 2s . c om*/ Message testee = messageFactory.fromMetaDataWithContent(testMail); assertThat(testee.getAttachments()).isEmpty(); }
From source file:org.wso2.carbon.registry.es.utils.EmailUtil.java
/** * This method delete all the sent mails. Can be used after a particular test class * * @throws MessagingException/*from w w w . j ava 2 s . co m*/ * @throws IOException */ public static void deleteSentMails() throws MessagingException, IOException { Properties props = new Properties(); props.load(new FileInputStream(new File(TestConfigurationProvider.getResourceLocation("GREG") + File.separator + "axis2" + File.separator + "smtp.properties"))); Session session = Session.getDefaultInstance(props, null); Store store = session.getStore("imaps"); store.connect("smtp.gmail.com", emailAddress, java.nio.CharBuffer.wrap(emailPassword).toString()); Folder sentMail = store.getFolder("[Gmail]/Sent Mail"); sentMail.open(Folder.READ_WRITE); Message[] messages = sentMail.getMessages(); Flags deleted = new Flags(Flags.Flag.DELETED); sentMail.setFlags(messages, deleted, true); sentMail.close(true); store.close(); }
From source file:org.apache.james.jmap.model.MessageFactoryTest.java
@Test public void attachmentsShouldBeRetrievedWhenSome() throws Exception { String payload = "payload"; BlobId blodId = BlobId.of("id1"); String type = "content"; Attachment expectedAttachment = Attachment.builder().blobId(blodId).size(payload.length()).type(type) .cid("cid").isInline(true).build(); MetaDataWithContent testMail = MetaDataWithContent.builder().uid(2).flags(new Flags(Flag.SEEN)).size(0) .internalDate(INTERNAL_DATE) .content(new ByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("spamMail.eml")))) .attachments(ImmutableList.of(MessageAttachment.builder() .attachment(org.apache.james.mailbox.model.Attachment.builder() .attachmentId(AttachmentId.from(blodId.getRawValue())).bytes(payload.getBytes()) .type(type).build()) .cid(Cid.from("cid")).isInline(true).build())) .mailboxId(MAILBOX_ID).messageId(MessageId.of("user|box|2")).build(); Message testee = messageFactory.fromMetaDataWithContent(testMail); assertThat(testee.getAttachments()).hasSize(1); assertThat(testee.getAttachments().get(0)).isEqualToComparingFieldByField(expectedAttachment); }
From source file:org.apache.james.jmap.model.MailboxMessageTest.java
@Test public void emptyMailShouldBeLoadedIntoMessage() throws Exception { MailboxMessage testMail = new SimpleMailboxMessage(INTERNAL_DATE, 0, 0, new SharedByteArrayInputStream("".getBytes()), new Flags(Flag.SEEN), new PropertyBuilder(), MAILBOX_ID);/*w w w . j av a2s.c om*/ testMail.setModSeq(MOD_SEQ); Message testee = messageFactory.fromMailboxMessage(testMail, ImmutableList.of(), x -> MessageId.of("user|box|" + x)); assertThat(testee).extracting(Message::getPreview, Message::getSize, Message::getSubject, Message::getHeaders, Message::getDate) .containsExactly("(Empty)", 0L, "", ImmutableMap.of(), ZONED_DATE); }
From source file:com.abid_mujtaba.fetchheaders.models.Account.java
public void delete(ArrayList<Email> emails) // Delete emails with the specified ids { if (emails.size() > 0) { Message[] messages = new Message[emails.size()]; try {//from w ww .jav a 2s. c om for (int ii = 0; ii < emails.size(); ii++) { messages[ii] = emails.get(ii).message(); } if (mTrash != null) { mInbox.copyMessages(messages, mTrash); } if (!mUsesLabels) // For Gmail-type accounts (that use Labels rather than folders) copying the message to Trash is enough to carry out deletion. { mInbox.setFlags(messages, new Flags(Flags.Flag.DELETED), true); } mInbox.expunge(); // Forces INBOX to actually delete the emails flagged for deletion } catch (MessagingException e) { Resources.Loge("Exception raised while attempting to delete emails.", e); } } }