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


Java IMAPFolder.open方法代码示例

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


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

示例1: markMessagesAsRead

import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
public void markMessagesAsRead(String[] ids, boolean seen) throws NoSuchProviderException, MessagingException, IOException {
  IMAPFolder folder = (IMAPFolder)getStore().getFolder("Inbox");
  folder.open(Folder.READ_WRITE);
  UIDFolder uidFolder = folder;
  
  Message[] msgs;
  

  long[] uids = new long[ids.length];
  int i = 0;
  for (String s : ids) {
    try {
      uids[i++] = Long.parseLong(s);
    } catch (Exception ex) {
      Log.d("rgai", "", ex);
    }
  }
  // TODO: if instance not support UID, then use simple id
  msgs = uidFolder.getMessagesByUID(uids);

  folder.setFlags(msgs, new Flags(Flags.Flag.SEEN), seen);

  folder.close(false);
}
 
开发者ID:k-kojak,项目名称:yako,代码行数:25,代码来源:SimpleEmailMessageProvider.java

示例2: testSearchNotFlags

import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
@Test
public void testSearchNotFlags() throws MessagingException {
    store.connect("[email protected]", "pwd");
    try {
        IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
        folder.open(Folder.READ_WRITE);
        folder.setFlags(new int[]{2,3}, new Flags(Flags.Flag.ANSWERED), true);
        Response[] ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() {
            @Override
            public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
                return protocol.command("SEARCH NOT (ANSWERED) NOT (DELETED) NOT (SEEN) NOT (FLAGGED) ALL", null);
            }
        });
        IMAPResponse response = (IMAPResponse) ret[0];
        assertFalse(response.isBAD());
        assertEquals("1 4 5 6 7 8 9 10" /* 2 and 3 set to answered */, response.getRest());
    } finally {
        store.close();
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:21,代码来源:ImapProtocolTest.java

示例3: 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

示例4: openPop3InboxReadWrite

import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
/**
 * opens inbox folder in read write modus returns inbox folder
 */
public static Folder openPop3InboxReadWrite(final Session session) throws MessagingException {
	final Store store = session.getStore("imaps");
	store.connect("imap.googlemail.com", EmailUtils.user, EmailUtils.pass);

	final IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
	if (!folder.isOpen()) {
		folder.open(Folder.READ_WRITE);
	}
	return folder;
}
 
开发者ID:bptlab,项目名称:Unicorn,代码行数:14,代码来源:EmailUtils.java

示例5: openPop3TrashReadWrite

import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
/**
 * return trash folder in read write modus
 */
public static Folder openPop3TrashReadWrite(final Session session) throws MessagingException {
	final Store store = session.getStore("imaps");
	store.connect("imap.googlemail.com", EmailUtils.user, EmailUtils.pass);

	final IMAPFolder folder = (IMAPFolder) store.getFolder("[Gmail]/Papierkorb");
	if (!folder.isOpen()) {
		folder.open(Folder.READ_WRITE);
	}
	return folder;
}
 
开发者ID:bptlab,项目名称:Unicorn,代码行数:14,代码来源:EmailUtils.java

示例6: 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

示例7: testEightBitMessage

import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
public void testEightBitMessage() throws Exception
{

    Store lstore = session.getStore(PROTOCOL);
    lstore.connect(imapServer.getHost(), imapServer.getPort(), ADMIN_USER_NAME, ADMIN_USER_PASSWORD);

    String folderName = "Alfresco IMAP/" + IMAP_FOLDER_NAME;
    
    IMAPFolder lfolder = (IMAPFolder) lstore.getFolder(folderName);
    lfolder.open(Folder.READ_WRITE);

    InputStream messageFileInputStream1 = null;
    InputStream messageFileInputStream2 = null;
    try
    {
        ClassPathResource fileResource = new ClassPathResource("imap/test-8bit-message.eml");
        messageFileInputStream1 = new FileInputStream(fileResource.getFile());
        Message message = new MimeMessage(Session.getDefaultInstance(new Properties()), messageFileInputStream1);
        String subject = message.getSubject();
        
        // get original bytes for further comparation
        messageFileInputStream2 = new FileInputStream(fileResource.getFile());
        byte[] original = ASCIIUtility.getBytes(messageFileInputStream2);
        
        Message[] messages = {message};
        
        lfolder.appendMessages(messages);
        
        
        
        // The search is not implemented. 
        // SearchTerm term = new HeaderTerm("X-Alfresco-Unique", "test8bit");
        // messages = folder.search(term);
        
        // So wee need to get our test message's UID from the repo
        
        String messageXPath = companyHomePathInStore + "/" + NamespaceService.CONTENT_MODEL_PREFIX + ":" + IMAP_FOLDER_NAME + "/*[like(@cm:title, $cm:title, true)]";
        
        QueryParameterDefinition[] params = new QueryParameterDefinition[1];
        params[0] = new QueryParameterDefImpl(
              ContentModel.PROP_TITLE,
              serviceRegistry.getDictionaryService().getDataType(DataTypeDefinition.TEXT),
              true,
              subject);

        List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, messageXPath, params, namespaceService, true);
        
        
        // does the message exist
        assertEquals(1, nodeRefs.size());
        
        NodeRef messageNodeRef = nodeRefs.get(0);
        
        // get message UID
        Long dbid = (Long) nodeService.getProperty(messageNodeRef, ContentModel.PROP_NODE_DBID);
        
        // fetch the massage
        RFC822DATA data = getRFC822Message(lfolder, dbid);
        
        assertNotNull("Can't fetch a message from the repositiry", data);
        
        byte[] processed = ASCIIUtility.getBytes(data.getByteArrayInputStream());
        
        assertTrue("Original message doesn't coincide to the message processed by the repository", Arrays.equals(original, processed));
    }
    finally
    {
        if (messageFileInputStream1 != null) messageFileInputStream1.close();
        if (messageFileInputStream2 != null) messageFileInputStream2.close();
    }
        
    // close connection
    lfolder.close(true);
    lstore.close();
    
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:77,代码来源:ImapMessageTest.java

示例8: main

import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {

        final Session session = Session.getInstance(getProperties());

        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_imap");
        store.connect("[email protected]", null);
        final Folder defaultFolder = store.getDefaultFolder();
        final IMAPFolder test = (IMAPFolder) defaultFolder.getFolder("test");

        final IdleMessageCountListener mcl = new IdleMessageCountListener();
        test.addMessageCountListener(mcl);

        test.open(Folder.READ_WRITE);

        final IdleThread it = new IdleThread(test);
        it.start();

        final IdleThread it2 = new IdleThread(test);
        it2.start();

        test.addMessages(new Message[] { msg });
        test.addMessages(new Message[] { msg });
        test.addMessages(new Message[] { msg });

        // test.close(true);

        System.out.println(it.getException());
        System.out.println(mcl.getAddedCount());
        System.out.println(mcl.getRemovedCount());
        System.out.println(test.getMessageCount());
        System.out.println(it.getIdleCount());

        // System.exit(1);

    }
 
开发者ID:salyh,项目名称:javamail-mock2,代码行数:49,代码来源:Main.java

示例9: testIDLESupported

import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
@Test
public void testIDLESupported() 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_imap");
    store.connect("[email protected]", null);
    final Folder defaultFolder = store.getDefaultFolder();
    final IMAPFolder test = (IMAPFolder) defaultFolder.getFolder("test");

    final IdleMessageCountListener mcl = new IdleMessageCountListener();
    test.addMessageCountListener(mcl);

    test.open(Folder.READ_WRITE);

    final IdleThread it = new IdleThread(test);
    it.start();

    test.addMessages(new Message[] { msg });
    test.addMessages(new Message[] { msg });
    test.addMessages(new Message[] { msg });

    Thread.sleep(500);

    it.interrupt();
    it.join();

    test.close(true);

    Assert.assertNull(it.getException());
    Assert.assertEquals(3, mcl.getAddedCount());
    Assert.assertEquals(0, mcl.getRemovedCount());
    Assert.assertEquals(4, test.getMessageCount());

}
 
开发者ID:salyh,项目名称:javamail-mock2,代码行数:47,代码来源:IMAPTestCase.java

示例10: getFlagChangesOfMessages

import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
private MessageListResult getFlagChangesOfMessages(TreeSet<MessageListElement> loadedMessages) throws MessagingException {
  
  List<MessageListElement> emails = new LinkedList<MessageListElement>();
  Store store = getStore(account);
  
  if (store == null || !store.isConnected()) {
    return new MessageListResult(emails, MessageListResult.ResultType.ERROR);
  }
  IMAPFolder imapFolder = (IMAPFolder)store.getFolder(accountFolder.folder);
  imapFolder.open(Folder.READ_ONLY);
  UIDFolder uidFolder = imapFolder;
  
  long smallestUID = getSmallestUID(loadedMessages);

  Message messages[] = imapFolder.getMessagesByUID(smallestUID, UIDFolder.LASTUID);

  FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
  Message unseenMsgs[] = imapFolder.search(ft, messages);

  addMessagesToListAs(uidFolder, emails, unseenMsgs, loadedMessages, false);

  // searching for seen messages
  List<Message> seenMessages = new ArrayList<Message>(Arrays.asList(messages));
  for (int k = 0; k < unseenMsgs.length; k++) {
    String unseenUid = Long.toString(uidFolder.getUID(unseenMsgs[k]));
    for (int l = 0; l < seenMessages.size(); ) {
      String seenUid = Long.toString(uidFolder.getUID(seenMessages.get(l)));
      if (seenUid.equals(unseenUid)) {
        seenMessages.remove(l);
      } else {
        l++;
      }
    }
  }

  addMessagesToListAs(uidFolder, emails, seenMessages.toArray(new Message[seenMessages.size()]), loadedMessages, true);

  imapFolder.close(false);

  return new MessageListResult(emails, MessageListResult.ResultType.FLAG_CHANGE);
}
 
开发者ID:k-kojak,项目名称:yako,代码行数:42,代码来源:SimpleEmailMessageProvider.java

示例11: markMessageAsRead

import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
@Override
public void markMessageAsRead(String id, boolean seen) throws NoSuchProviderException, MessagingException, IOException {
  
  IMAPFolder folder = (IMAPFolder)getStore().getFolder("Inbox");
  folder.open(Folder.READ_WRITE);
  UIDFolder uidFolder = (UIDFolder)folder;
  
  Message ms = uidFolder.getMessageByUID(Long.parseLong(id));

  if (ms != null) {
    ms.setFlag(Flags.Flag.SEEN, seen);
  }
  folder.close(false);
}
 
开发者ID:k-kojak,项目名称:yako,代码行数:15,代码来源:SimpleEmailMessageProvider.java

示例12: deleteMessage

import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
public void deleteMessage(String id) throws NoSuchProviderException, MessagingException, IOException {
  IMAPFolder folder = (IMAPFolder)getStore().getFolder("Inbox");
  folder.open(Folder.READ_WRITE);
  UIDFolder uidFolder = (UIDFolder)folder;
  
  Message ms = uidFolder.getMessageByUID(Long.parseLong(id));

  if (ms != null) {
    ms.setFlag(Flags.Flag.DELETED, true);
  }
  folder.close(true);
}
 
开发者ID:k-kojak,项目名称:yako,代码行数:13,代码来源:SimpleEmailMessageProvider.java

示例13: testFetchUidsAndSize

import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
@Test
public void testFetchUidsAndSize() throws MessagingException {
    store.connect("[email protected]", "pwd");
    try {
        IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
        folder.open(Folder.READ_ONLY);
        Response[] ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() {
            @Override
            public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
                return protocol.command("UID FETCH 1:* RFC822.SIZE", null);
            }
        });

        FetchResponse fetchResponse = (FetchResponse) ret[0];
        assertFalse(fetchResponse.isBAD());
        assertEquals(2, fetchResponse.getItemCount()); // UID and SIZE

        RFC822SIZE size = fetchResponse.getItem(RFC822SIZE.class);
        assertNotNull(size);
        assertTrue(size.size > 0);

        UID uid = fetchResponse.getItem(UID.class);
        assertEquals(folder.getUID(folder.getMessage(1)), uid.uid);
    } finally {
        store.close();
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:28,代码来源:ImapProtocolTest.java

示例14: testRenameFolder

import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
@Test
public void testRenameFolder() throws MessagingException {
    store.connect("[email protected]", "pwd");
    try {
        IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
        folder.open(Folder.READ_WRITE);
        Response[] ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() {
            @Override
            public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
                return protocol.command("CREATE foo", null);
            }
        });

        IMAPResponse response = (IMAPResponse) ret[0];
        assertFalse(response.isBAD());

        ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() {
            @Override
            public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
                return protocol.command("RENAME foo bar", null);
            }
        });

        Response response2 = ret[0];
        assertTrue(response2.isOK());

        final Folder bar = store.getFolder("bar");
        bar.open(Folder.READ_ONLY);
        assertTrue(bar.exists());
    } finally {
        store.close();
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:34,代码来源:ImapProtocolTest.java

示例15: testSendAndReceiveWithQuotedAddress

import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
@Test
public void testSendAndReceiveWithQuotedAddress() throws MessagingException, IOException {
    // See https://en.wikipedia.org/wiki/Email_address#Local-part
    String[] toList = {"\"John..Doe\"@localhost",
            "abc.\"defghi\"[email protected]",
            "\"abcdefghixyz\"@localhost",
            "\"Foo Bar\"[email protected]"
    };
    for(String to: toList) {
        greenMail.setUser(to, "pwd");
        InternetAddress[] toAddress = InternetAddress.parse(to);
        String from = to; // Same from and to address for testing correct escaping of both

        final String subject = "testSendAndReceiveWithQuotedAddress";
        final String content = "some body";
        GreenMailUtil.sendTextEmailTest(to, from,
                subject, content);

        assertTrue(greenMail.waitForIncomingEmail(5000, 1));

        final IMAPStore store = greenMail.getImap().createStore();
        store.connect(to, "pwd");
        try {
            IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
            folder.open(Folder.READ_ONLY);
            Message[] msgs = folder.getMessages();
            assertTrue(null != msgs && msgs.length == 1);
            final Message msg = msgs[0];
            assertEquals(to, ((InternetAddress)msg.getRecipients(Message.RecipientType.TO)[0]).getAddress());
            assertEquals(from, ((InternetAddress)msg.getFrom()[0]).getAddress());
            assertEquals(subject, msg.getSubject());
            assertEquals(content, msg.getContent().toString());
            assertArrayEquals(toAddress, msg.getRecipients(Message.RecipientType.TO));
        } finally {
            store.close();
        }
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:39,代码来源:SenderRecipientTest.java


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