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


Java IMAPStore类代码示例

本文整理汇总了Java中com.sun.mail.imap.IMAPStore的典型用法代码示例。如果您正苦于以下问题:Java IMAPStore类的具体用法?Java IMAPStore怎么用?Java IMAPStore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: supportsIdle

import com.sun.mail.imap.IMAPStore; //导入依赖的package包/类
protected boolean supportsIdle(Folder folder) throws MessagingException {
	Store store = folder.getStore();

	if (store instanceof IMAPStore) {
		IMAPStore imapStore = (IMAPStore) store;
		return imapStore.hasCapability("IDLE") && folder instanceof IMAPFolder;
	} else {
		return false;
	}
}
 
开发者ID:camunda,项目名称:camunda-bpm-mail,代码行数:11,代码来源:MailNotificationService.java

示例2: deleteEmail

import com.sun.mail.imap.IMAPStore; //导入依赖的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: connectToImap

import com.sun.mail.imap.IMAPStore; //导入依赖的package包/类
/**
  * Connects and authenticates to an IMAP server with OAuth2. You must have
  * called {@code initialize}.
  *
  * @param host Hostname of the imap server, for example {@code
  *     imap.googlemail.com}.
  * @param port Port of the imap server, for example 993.
  * @param userEmail Email address of the user to authenticate, for example
  *     {@code [email protected]}.
  * @param oauthToken The user's OAuth token.
  * @param debug Whether to enable debug logging on the IMAP connection.
  *
  * @return An authenticated IMAPStore that can be used for IMAP operations.
  */
public static IMAPStore connectToImap(String host, int port, String userEmail,
		String oauthToken, boolean debug) throws Exception
{
	Properties props = new Properties();
	props.put("mail.imaps.sasl.enable", "true");
	props.put("mail.imaps.sasl.mechanisms", "XOAUTH2");
	props.put(OAuth2SaslClientFactory.OAUTH_TOKEN_PROP, oauthToken);
	Session session = Session.getInstance(props);
	session.setDebug(debug);

	final URLName unusedUrlName = null;
	IMAPSSLStore store = new IMAPSSLStore(session, unusedUrlName);
	store.connect(host, port, userEmail, EMPTY_PASSWORD);
	
	return store;
}
 
开发者ID:danielebufarini,项目名称:Reminders,代码行数:31,代码来源:OAuth2Authenticator.java

示例4: connectToImap

import com.sun.mail.imap.IMAPStore; //导入依赖的package包/类
/**
 * Connects and authenticates to an IMAP server with OAuth2. You must have
 * called {@code initialize}.
 *
 * @param host Hostname of the imap server, for example {@code
 *     imap.googlemail.com}.
 * @param port Port of the imap server, for example 993.
 * @param userEmail Email address of the user to authenticate, for example
 *     {@code [email protected]}.
 * @param oauthToken The user's OAuth token.
 * @param debug Whether to enable debug logging on the IMAP connection.
 *
 * @return An authenticated IMAPStore that can be used for IMAP operations.
 */
public static IMAPStore connectToImap(String host,
                                      int port,
                                      String userEmail,
                                      String oauthToken,
                                      boolean debug) throws Exception {
  Properties props = new Properties();
  props.put("mail.imaps.sasl.enable", "true");
  props.put("mail.imaps.sasl.mechanisms", "XOAUTH2");
  props.put(OAuth2SaslClientFactory.OAUTH_TOKEN_PROP, oauthToken);
  Session session = Session.getInstance(props);
  session.setDebug(debug);

  final URLName unusedUrlName = null;
  IMAPSSLStore store = new IMAPSSLStore(session, unusedUrlName);
  final String emptyPassword = "";
  store.connect(host, port, userEmail, emptyPassword);
  return store;
}
 
开发者ID:google,项目名称:gmail-oauth2-tools,代码行数:33,代码来源:OAuth2Authenticator.java

示例5: main

import com.sun.mail.imap.IMAPStore; //导入依赖的package包/类
/**
 * Authenticates to IMAP with parameters passed in on the commandline.
 */
public static void main(String args[]) throws Exception {
  if (args.length != 2) {
    System.err.println(
        "Usage: OAuth2Authenticator <email> <oauthToken>");
    return;
  }
  String email = args[0];
  String oauthToken = args[1];

  initialize();

  IMAPStore imapStore = connectToImap("imap.gmail.com",
                                      993,
                                      email,
                                      oauthToken,
                                      true);
  System.out.println("Successfully authenticated to IMAP.\n");
  SMTPTransport smtpTransport = connectToSmtp("smtp.gmail.com",
                                              587,
                                              email,
                                              oauthToken,
                                              true);
  System.out.println("Successfully authenticated to SMTP.");
}
 
开发者ID:google,项目名称:gmail-oauth2-tools,代码行数:28,代码来源:OAuth2Authenticator.java

示例6: testQUOTAUnsupported

import com.sun.mail.imap.IMAPStore; //导入依赖的package包/类
@Test(expected = MockTestException.class)
public void testQUOTAUnsupported() 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 Folder test = defaultFolder.getFolder("test");

    final IMAPStore imapStore = (IMAPStore) store;

    try {
        imapStore.getQuota("");
    } catch (final MessagingException e) {
        throw new MockTestException(e);
    }

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

示例7: testSendAndReceiveWithQuotedAddress

import com.sun.mail.imap.IMAPStore; //导入依赖的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

示例8: testQuotaCapability

import com.sun.mail.imap.IMAPStore; //导入依赖的package包/类
@Test
public void testQuotaCapability() throws MessagingException {
    greenMail.setUser("[email protected]", "pwd");
    greenMail.setQuotaSupported(false);
    final IMAPStore store = greenMail.getImap().createStore();
    try {
        store.connect("[email protected]", "pwd");

        Quota testQuota = new Quota("INBOX");
        testQuota.setResourceLimit("STORAGE", 1024L * 42L);
        testQuota.setResourceLimit("MESSAGES", 5L);
        store.setQuota(testQuota);
        fail("Excepted MessageException since quota capability is turned off");
    } catch (MessagingException ex) {
        assertEquals(ex.getMessage(), "QUOTA not supported");
    } finally {
        store.close();
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:20,代码来源:ImapServerTest.java

示例9: populateFromStore

import com.sun.mail.imap.IMAPStore; //导入依赖的package包/类
/**
 * Static method to populate a {@link StoreIndex} with the messages in an {@link IMAPStore}
 *
 * @param index
 * @param store
 * @param threads
 * @return
 * @throws MessagingException
 * @throws InterruptedException
 */
public static final StoreIndex populateFromStore(final StoreIndex index, IMAPStore store,
        int threads) throws MessagingException, InterruptedException {
    MessagingException messagingException = null;
    //Crawl
    synchronized (index.getFolders()) {
        final ExecutorService service = Executors.newFixedThreadPool(threads);
        try {
            crawlFolders(store, index, store.getDefaultFolder(), service);
        } catch (MessagingException ex) {
            messagingException = ex;
        }
        service.shutdown();
        service.awaitTermination(1, TimeUnit.HOURS);
        if (index.hasCrawlException()) {
            messagingException = index.getCrawlExceptions().get(0);
        }
    }
    if (messagingException != null) {
        throw messagingException;
    }
    return index;
}
 
开发者ID:manusa,项目名称:mnIMAPSync,代码行数:33,代码来源:StoreIndex.java

示例10: hasSortCapability

import com.sun.mail.imap.IMAPStore; //导入依赖的package包/类
/**
 * Check whether the email store has the sort capability or not.
 *
 * @param store Email store
 * @return true if the store is an IMAP store and it has the store capability
 * @throws MessagingException In case capability check fails
 */
private static boolean hasSortCapability(Store store) throws MessagingException {
    if (store instanceof IMAPStore) {
        IMAPStore imapStore = (IMAPStore) store;
        if (imapStore.hasCapability("SORT*")) {
            return true;
        }
    }
    return false;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:MailConsumer.java

示例11: getInbox

import com.sun.mail.imap.IMAPStore; //导入依赖的package包/类
private IMAPFolder getInbox(IMAPStore store) throws MessagingException {
	IMAPFolder inbox = (IMAPFolder) store.getFolder("INBOX");
	inbox.open(Folder.READ_WRITE);
	return inbox;
}
 
开发者ID:danielebufarini,项目名称:Reminders,代码行数:6,代码来源:GMailImapReader.java

示例12: connect

import com.sun.mail.imap.IMAPStore; //导入依赖的package包/类
private boolean connect(String protocol, String host, String port, String userName, String password) {
	Properties properties = getServerProperties(protocol, host, port);
	Session session = Session.getDefaultInstance(properties);
	try {
		store = (IMAPStore)session.getStore(protocol);
		store.connect(userName, password);
		return true;
	} catch (Exception e) {
		e.printStackTrace();
		return false;
	}
}
 
开发者ID:mathieulegoc,项目名称:SmartTokens,代码行数:13,代码来源:GmailReader.java

示例13: connect

import com.sun.mail.imap.IMAPStore; //导入依赖的package包/类
public boolean connect(String protocol, String host, String port, String userName, String password) {
	Properties properties = getServerProperties(protocol, host, port);
	Session session = Session.getDefaultInstance(properties);

	try {
		store = (IMAPStore)session.getStore(protocol);
		store.connect(userName, password);
		return true;
	} catch (Exception e) {
		e.printStackTrace();
		return false;
	}
}
 
开发者ID:mathieulegoc,项目名称:SmartTokens,代码行数:14,代码来源:MailBean.java

示例14: testSendAndReceive

import com.sun.mail.imap.IMAPStore; //导入依赖的package包/类
@Test
public void testSendAndReceive() throws UnsupportedEncodingException, MessagingException, UserException {
    Session smtpSession = greenMail.getSmtp().createSession();

    Message msg = new MimeMessage(smtpSession);
    msg.setFrom(new InternetAddress("[email protected]"));
    msg.addRecipient(Message.RecipientType.TO,
            new InternetAddress("[email protected]"));
    msg.setSubject("Email sent to GreenMail via plain JavaMail");
    msg.setText("Fetch me via IMAP");
    Transport.send(msg);

    // Create user, as connect verifies pwd
    greenMail.setUser("[email protected]", "[email protected]", "secret-pwd");

    // Alternative 1: Create session and store or ...
    Session imapSession = greenMail.getImap().createSession();
    Store store = imapSession.getStore("imap");
    store.connect("[email protected]", "secret-pwd");
    Folder inbox = store.getFolder("INBOX");
    inbox.open(Folder.READ_ONLY);
    Message msgReceived = inbox.getMessage(1);
    assertEquals(msg.getSubject(), msgReceived.getSubject());

    // Alternative 2: ... let GreenMail create and configure a store:
    IMAPStore imapStore = greenMail.getImap().createStore();
    imapStore.connect("[email protected]", "secret-pwd");
    inbox = imapStore.getFolder("INBOX");
    inbox.open(Folder.READ_ONLY);
    msgReceived = inbox.getMessage(1);
    assertEquals(msg.getSubject(), msgReceived.getSubject());

    // Alternative 3: ... directly fetch sent message using GreenMail API
    assertEquals(1, greenMail.getReceivedMessagesForDomain("[email protected]").length);
    msgReceived = greenMail.getReceivedMessagesForDomain("[email protected]")[0];
    assertEquals(msg.getSubject(), msgReceived.getSubject());

    store.close();
    imapStore.close();
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:41,代码来源:ExampleJavaMailTest.java

示例15: testRenameINBOXFolder

import com.sun.mail.imap.IMAPStore; //导入依赖的package包/类
/**
 * 
 * https://tools.ietf.org/html/rfc3501#page-37 :
 * <q>
 *     Renaming INBOX is permitted, and has special behavior.  It moves
 *     all messages in INBOX to a new mailbox with the given name,
 *     leaving INBOX empty.  If the server implementation supports
 *     inferior hierarchical names of INBOX, these are unaffected by a
 *     rename of INBOX.
 *  </q>
 *
 * @throws MessagingException
 * @throws InterruptedException
 */
@Test
public void testRenameINBOXFolder() throws MessagingException, InterruptedException {
    greenMail.setUser("[email protected]", "pwd");
    GreenMailUtil.sendTextEmail("[email protected]", "[email protected]", "Test subject",
            "Test message", greenMail.getSmtp().getServerSetup());

    final IMAPStore store = greenMail.getImap().createStore();
    store.connect("[email protected]", "pwd");
    try {

        // Create some folders
        Folder inboxFolder = store.getFolder("INBOX");
        assertTrue(inboxFolder.exists());
        inboxFolder.open(Folder.READ_ONLY);
        assertEquals(1, inboxFolder.getMessages().length);

        Folder inboxRenamedFolder = store.getFolder("INBOX-renamed");
        assertFalse(inboxRenamedFolder.exists());

        inboxFolder.close(true);
        inboxFolder.renameTo(inboxRenamedFolder);
        assertTrue(inboxRenamedFolder.exists());
        inboxRenamedFolder.open(Folder.READ_ONLY);
        assertEquals(1, inboxRenamedFolder.getMessages().length);

        inboxFolder = store.getFolder("INBOX");
        assertTrue(inboxFolder.exists());
        inboxFolder.open(Folder.READ_ONLY);
        assertEquals(0, inboxFolder.getMessages().length);
    } finally {
        store.close();
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:48,代码来源:ImapServerTest.java


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