当前位置: 首页>>代码示例>>Java>>正文


Java IMAPFolder.getMessageByUID方法代码示例

本文整理汇总了Java中com.sun.mail.imap.IMAPFolder.getMessageByUID方法的典型用法代码示例。如果您正苦于以下问题:Java IMAPFolder.getMessageByUID方法的具体用法?Java IMAPFolder.getMessageByUID怎么用?Java IMAPFolder.getMessageByUID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.mail.imap.IMAPFolder的用法示例。


在下文中一共展示了IMAPFolder.getMessageByUID方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testGetMessageByUnknownUidInEmptyINBOX

import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
@Test
public void testGetMessageByUnknownUidInEmptyINBOX() throws MessagingException, FolderException {
    greenMail.getManagers()
            .getImapHostManager()
            .getInbox(user)
            .deleteAllMessages();
    store.connect("[email protected]", "pwd");
    try {
        IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
        folder.open(Folder.READ_ONLY);
        Message message = folder.getMessageByUID(666);
        assertEquals(null, message);
    } finally {
        store.close();
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:17,代码来源:ImapProtocolTest.java

示例2: deleteEmail

import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
private void deleteEmail(final IMAPStore store, long uid) throws Exception {
	IMAPFolder inbox = (IMAPFolder) store.getFolder("INBOX");
	inbox.open(Folder.READ_WRITE);
	javax.mail.Message message = inbox.getMessageByUID(uid);
	if (message != null) {
		Folder trash = store.getFolder(getTrashFolderLocalisedName(inbox));
		trash.open(Folder.READ_WRITE);
		inbox.copyMessages(new javax.mail.Message[] { message }, trash);
		trash.close(true);
	}
	inbox.close(true);
}
 
开发者ID:danielebufarini,项目名称:Reminders,代码行数:13,代码来源:DeleteEmailViaImap.java

示例3: testUIDExpunge

import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
@Test
public void testUIDExpunge() throws MessagingException {
    greenMail.setUser("[email protected]", "pwd");

    // Create some test emails
    int numberOfEmails = 10;
    long[] uids = new long[numberOfEmails];
    for (int i = 0; i < numberOfEmails; i++) {
        GreenMailUtil.sendTextEmail("[email protected]", "[email protected]", "Test UID expunge #" + i,
                "Test message", greenMail.getSmtp().getServerSetup());
    }

    final IMAPStore store = greenMail.getImap().createStore();
    store.connect("[email protected]", "pwd");
    try {
        IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
        folder.open(Folder.READ_WRITE);

        Message[] messages = folder.getMessages();
        assertEquals(numberOfEmails, messages.length);

        // Mark even as deleted ...
        Message[] msgsForDeletion = new Message[uids.length / 2];
        for (int i = 0; i < messages.length; i++) {
            assertFalse(messages[i].getFlags().contains(Flags.Flag.DELETED));
            uids[i] = folder.getUID(messages[i]);
            if (i % 2 == 0) { // Deleted
                messages[i].setFlag(Flags.Flag.DELETED, true);
                msgsForDeletion[i / 2] = messages[i];
            }
        }

        // ... and expunge (with UID)
        folder.expunge(msgsForDeletion);

        // Check
        for (int i = 0; i < uids.length; i++) {
            final Message message = folder.getMessageByUID(uids[i]);
            if (i % 2 == 0) { // Deleted
                assertNull(message);
            } else {
                assertTrue("" + i, !message.isExpunged());
                assertTrue("" + i, !message.getFlags().contains(Flags.Flag.DELETED));
            }
        }
    } finally {
        store.close();
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:50,代码来源:ImapServerTest.java

示例4: testAppend

import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
@Test
public void testAppend() throws MessagingException {
    greenMail.setUser("[email protected]", "pwd");

    GreenMailUtil.sendTextEmail("[email protected]", "[email protected]", "Test Append",
            "Test message", greenMail.getSmtp().getServerSetup());

    final IMAPStore store = greenMail.getImap().createStore();
    store.connect("[email protected]", "pwd");
    try {
        IMAPFolder inboxFolder = (IMAPFolder) store.getFolder("INBOX");
        inboxFolder.open(Folder.READ_WRITE);

        Message[] messages = inboxFolder.getMessages();
        assertEquals(1, messages.length);
        Message message = messages[0];

        Message[] toBeAppended = new Message[]{
                new MimeMessage((MimeMessage) message) // Copy
        };
        toBeAppended[0].setSubject("testAppend#1");

        inboxFolder.appendMessages(toBeAppended);
        messages = inboxFolder.getMessages();
        assertEquals(2, messages.length);

        // UIDPLUS
        toBeAppended[0] = new MimeMessage((MimeMessage) message);
        toBeAppended[0].setSubject("testAppend#2");

        final AppendUID[] appendUIDs = inboxFolder.appendUIDMessages(toBeAppended); // Copy again
        long uid = appendUIDs[0].uid;
        Message newMsg = inboxFolder.getMessageByUID(uid);
        assertEquals(toBeAppended[0].getSubject(), newMsg.getSubject());
        assertTrue(appendUIDs[0].uidvalidity == inboxFolder.getUIDValidity());
        messages = inboxFolder.getMessages();
        assertEquals(3, messages.length);
    } finally {
        store.close();
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:42,代码来源:ImapServerTest.java


注:本文中的com.sun.mail.imap.IMAPFolder.getMessageByUID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。