com.sun.mail.pop3.POP3Folder Java Examples
The following examples show how to use
com.sun.mail.pop3.POP3Folder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Pop3ServerTest.java From greenmail with Apache License 2.0 | 6 votes |
@Test public void testRetrieve() throws Exception { assertNotNull(greenMail.getPop3()); final String subject = GreenMailUtil.random(); final String body = GreenMailUtil.random() + "\r\n" + GreenMailUtil.random() + "\r\n" + GreenMailUtil.random(); String to = "[email protected]"; GreenMailUtil.sendTextEmailTest(to, "[email protected]", subject, body); greenMail.waitForIncomingEmail(5000, 1); try (Retriever retriever = new Retriever(greenMail.getPop3())) { Message[] messages = retriever.getMessages(to); assertEquals(1, messages.length); assertEquals(subject, messages[0].getSubject()); assertEquals(body, GreenMailUtil.getBody(messages[0]).trim()); // UID POP3Folder f = (POP3Folder) messages[0].getFolder(); assertNotEquals("UNKNOWN", f.getUID(messages[0])); } }
Example #2
Source File: Core.java From FairEmail with GNU General Public License v3.0 | 5 votes |
private static void onSeen(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, POP3Folder ifolder) throws JSONException { // Mark message (un)seen DB db = DB.getInstance(context); boolean seen = jargs.getBoolean(0); db.message().setMessageUiSeen(folder.id, seen); }
Example #3
Source File: Core.java From FairEmail with GNU General Public License v3.0 | 5 votes |
private static void onFlag(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, POP3Folder ifolder) throws MessagingException, JSONException { // Star/unstar message DB db = DB.getInstance(context); boolean flagged = jargs.getBoolean(0); db.message().setMessageFlagged(message.id, flagged); }
Example #4
Source File: POP3TestCase.java From javamail-mock2 with Apache License 2.0 | 5 votes |
@Test public void testAddMessages() throws Exception { final MockMailbox mb = MockMailbox.get("[email protected]"); final MailboxFolder mf = mb.getInbox(); final MimeMessage msg = new MimeMessage((Session) null); msg.setSubject("Test"); msg.setFrom("[email protected]"); msg.setText("Some text here ..."); msg.setRecipient(RecipientType.TO, new InternetAddress("[email protected]")); mf.add(msg); // 11 mf.add(msg); // 12 mf.add(msg); // 13 final Store store = session.getStore(); store.connect("[email protected]", null); final Folder inbox = store.getFolder("INBOX"); inbox.open(Folder.READ_ONLY); Assert.assertEquals(3, inbox.getMessageCount()); Assert.assertNotNull(inbox.getMessage(1)); inbox.close(true); Assert.assertEquals(3, inbox.getMessageCount()); inbox.open(Folder.READ_ONLY); inbox.getMessage(1).setFlag(Flag.DELETED, true); inbox.close(true); inbox.open(Folder.READ_ONLY); Assert.assertEquals(2, inbox.getMessageCount()); Assert.assertTrue(inbox instanceof POP3Folder); Assert.assertEquals("12", ((POP3Folder) inbox).getUID(inbox.getMessage(1))); inbox.close(true); }
Example #5
Source File: MailAccountServlet.java From document-management-system with GNU General Public License v2.0 | 4 votes |
/** * List server mails */ private void serverList(String userId, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DatabaseException, MessagingException { log.debug("serverList({}, {}, {})", new Object[]{userId, request, response}); int maId = WebUtils.getInt(request, "ma_id"); String ma_user = WebUtils.getString(request, "ma_user"); int start = WebUtils.getInt(request, "start", 1); Session session = Session.getDefaultInstance(MailUtils.getProperties()); List<Map<String, Object>> serverMails = new ArrayList<Map<String, Object>>(); // Open connection MailAccount ma = MailAccountDAO.findByPk(maId); Store store = session.getStore(ma.getMailProtocol()); store.connect(ma.getMailHost(), ma.getMailUser(), ma.getMailPassword()); Folder folder = store.getFolder(ma.getMailFolder()); folder.open(Folder.READ_ONLY); int max = folder.getMessageCount(); // Get messages int end = start + PAGINATION_LIMIT - 1; Message[] messages = folder.getMessages(start, end < max ? end : max); FetchProfile fp = new FetchProfile(); fp.add(FetchProfile.Item.CONTENT_INFO); fp.add(FetchProfile.Item.ENVELOPE); fp.add(FetchProfile.Item.FLAGS); folder.fetch(messages, fp); // Read mails for (Message msg : messages) { Map<String, Object> mail = new HashMap<String, Object>(); mail.put("receivedDate", msg.getReceivedDate()); mail.put("sentDate", msg.getSentDate()); mail.put("subject", (msg.getSubject() == null || msg.getSubject().isEmpty()) ? MailUtils.NO_SUBJECT : msg.getSubject()); mail.put("from", msg.getFrom().length > 0 ? MailUtils.addressToString(msg.getFrom()[0]) : ""); mail.put("seen", msg.isSet(Flags.Flag.SEEN)); mail.put("msgNumber", msg.getMessageNumber()); if (folder instanceof POP3Folder) { mail.put("uid", msg.getMessageNumber()); } else if (folder instanceof IMAPFolder) { mail.put("uid", ((IMAPFolder) folder).getUID(msg)); } serverMails.add(mail); } // Close connection folder.close(false); store.close(); ServletContext sc = getServletContext(); sc.setAttribute("ma_id", maId); sc.setAttribute("ma_user", ma_user); sc.setAttribute("max", max); sc.setAttribute("start", start); sc.setAttribute("end", end < max ? end : max); sc.setAttribute("limit", PAGINATION_LIMIT); sc.setAttribute("serverMails", serverMails); sc.getRequestDispatcher("/admin/mail_server_list.jsp").forward(request, response); log.debug("serverList: void"); }
Example #6
Source File: POP3TestCase.java From javamail-mock2 with Apache License 2.0 | 4 votes |
@Test public void testDefaultFolder() throws Exception { final MockMailbox mb = MockMailbox.get("[email protected]"); final MailboxFolder mf = mb.getInbox(); final MimeMessage msg = new MimeMessage((Session) null); msg.setSubject("Test"); msg.setFrom("[email protected]"); msg.setText("Some text here ..."); msg.setRecipient(RecipientType.TO, new InternetAddress("[email protected]")); mf.add(msg); // 11 mf.add(msg); // 12 mf.add(msg); // 13 mb.getRoot().getOrAddSubFolder("test").create().add(msg); final Store store = session.getStore("mock_pop3"); store.connect("[email protected]", null); final Folder defaultFolder = store.getDefaultFolder(); final Folder inbox = defaultFolder.getFolder("INBOX"); inbox.open(Folder.READ_WRITE); Assert.assertEquals("[INBOX]", Arrays.toString(defaultFolder.list())); Assert.assertEquals(3, inbox.getMessageCount()); Assert.assertNotNull(inbox.getMessage(1)); inbox.close(true); Assert.assertEquals(3, inbox.getMessageCount()); inbox.open(Folder.READ_ONLY); inbox.getMessage(1).setFlag(Flag.DELETED, true); inbox.close(true); inbox.open(Folder.READ_WRITE); Assert.assertEquals(2, inbox.getMessageCount()); Assert.assertTrue(inbox instanceof POP3Folder); Assert.assertEquals("12", ((POP3Folder) inbox).getUID(inbox.getMessage(1))); inbox.close(true); }
Example #7
Source File: ElasticsearchMailDestination.java From elasticsearch-imap with Apache License 2.0 | 3 votes |
@SuppressWarnings("rawtypes") @Override public void onMessageDeletes(final Set msgs, final Folder folder) throws IOException, MessagingException { if (msgs.size() == 0) { return; } createIndexIfNotExists(); client.admin().indices().refresh(new RefreshRequest()).actionGet(); logger.info("Will delete " + msgs.size() + " messages locally for folder " + folder.getURLName().toString()); final BoolQueryBuilder query = new BoolQueryBuilder(); if (folder instanceof POP3Folder) { query.must(QueryBuilders.termsQuery("popId", msgs)); } else { query.must(QueryBuilders.termsQuery("uid", msgs)); } query.must(QueryBuilders.termQuery("folderUri", folder.getURLName().toString())); DeleteByQuery.deleteByQuery(client, index, new String[]{type}, query); }