當前位置: 首頁>>代碼示例>>Java>>正文


Java Store.getDefaultFolder方法代碼示例

本文整理匯總了Java中javax.mail.Store.getDefaultFolder方法的典型用法代碼示例。如果您正苦於以下問題:Java Store.getDefaultFolder方法的具體用法?Java Store.getDefaultFolder怎麽用?Java Store.getDefaultFolder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.mail.Store的用法示例。


在下文中一共展示了Store.getDefaultFolder方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getEmail

import javax.mail.Store; //導入方法依賴的package包/類
public void getEmail() throws MessagingException, IOException {
    Session session = Session.getDefaultInstance(System.getProperties(),null);
    Store store = null;
    store = session.getStore("imaps");

    // store.connect(this.host, this.userName, this.password);

    // Get default folder
    Folder folder = store.getDefaultFolder();
    folder.getMessages();
    folder.getNewMessageCount();
    Message m = folder.getMessage(0);
    m.getMessageNumber();
    m.getAllRecipients();
    m.getReceivedDate();
    m.getFrom();
    m.getSubject();
    m.getReplyTo();
    m.getContent();
    m.getSize();

    // Get any folder by name
    Folder[] folderList = folder.list();
}
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:25,代碼來源:PNetwork.java

示例2: createTestMessages

import javax.mail.Store; //導入方法依賴的package包/類
public void createTestMessages() {
    try {
        GreenMailUser user = greenMail.setUser(TEST_RECIP, "password");

        final String subject = GreenMailUtil.random();
        final String body = GreenMailUtil.random();
        user.deliver(createMimeMessage("[email protected]", subject, body, null));
        user.deliver(createMimeMessage("[email protected]", "Great stuff cheap!", "body", null));
        user.deliver(createMimeMessage("[email protected]", "Happening this month", "stuff", null));
        user.deliver(createMimeMessage("[email protected]", "Get certified today!", "Cheap!", null));
        user.deliver(createMimeMessage("[email protected]", "It's been a long time!", "Let's talk", null));
        user.deliver(createMimeMessage("[email protected]", "The Sound of Drums", "boom boom boom", 
                 Date.from(LocalDate.now().minusYears(2).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())));

        Session imapSession = greenMail.getImap().createSession();
        Store store = imapSession.getStore("imap");
        store.connect(TEST_RECIP, "password");
        
        Folder defaultFolder = store.getDefaultFolder();  
        Folder inbox = store.getFolder("INBOX");
        inbox.open(Folder.READ_WRITE);
        
        Folder ads = defaultFolder.getFolder("Ads");
        ads.create(Folder.HOLDS_MESSAGES);   
        
        Folder spam = defaultFolder.getFolder("Spam");
        spam.create(Folder.HOLDS_MESSAGES); 
    } catch (MessagingException ex) {
        Logger.getLogger(TestMailUtil.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
開發者ID:PacktPublishing,項目名稱:Java-9-Programming-Blueprints,代碼行數:32,代碼來源:TestMailUtil.java

示例3: checkInbox

import javax.mail.Store; //導入方法依賴的package包/類
public void checkInbox(int mode) throws MessagingException, IOException {
	if (mode == 0) {
		return;
	}
	boolean show = (mode & MailClient.SHOW_MESSAGES) > 0;
	boolean clear = (mode & MailClient.CLEAR_MESSAGES) > 0;
	String action = (show ? "Show" : "") + (show && clear ? " and " : "") + (clear ? "Clear" : "");
	System.out.println(action + " INBOX for " + from);
	Store store = session.getStore();
	store.connect();
	Folder root = store.getDefaultFolder();
	Folder inbox = root.getFolder("inbox");
	inbox.open(Folder.READ_WRITE);
	Message[] msgs = inbox.getMessages();
	if (msgs.length == 0 && show) {
		System.out.println("No messages in inbox");
	}
	for (Message msg2 : msgs) {
		MimeMessage msg = (MimeMessage) msg2;
		if (show) {
			System.out.println("    From: " + msg.getFrom()[0]);
			System.out.println(" Subject: " + msg.getSubject());
			System.out.println(" Content: " + msg.getContent());
		}
		if (clear) {
			msg.setFlag(Flags.Flag.DELETED, true);
		}
	}
	inbox.close(true);
	store.close();
	System.out.println();
}
 
開發者ID:darciopacifico,項目名稱:omr,代碼行數:33,代碼來源:MailClient.java

示例4: checkInboxSave

import javax.mail.Store; //導入方法依賴的package包/類
public void checkInboxSave(int mode) throws MessagingException, IOException {
	
	Store store = session.getStore();
	store.connect();
	Folder root = store.getDefaultFolder();
	Folder inbox = root.getFolder("inbox");
	inbox.open(Folder.READ_WRITE);
	Message[] msgs = inbox.getMessages();
	
	for (Message msg2 : msgs) {
		
		POP3Message msg = (POP3Message) msg2;
		
		Object object = msg.getContent();
		if (object instanceof Multipart) {
			Multipart multipart = (Multipart) object;
			
			for (int i = 0, n = multipart.getCount(); i < n; i++) {
				MailClient.handlePart(multipart.getBodyPart(i));
			}
			
		}
		
		System.out.println("    From: " + msg.getFrom()[0]);
		System.out.println(" Subject: " + msg.getSubject());
		System.out.println(" Content: " + object);
	}
	inbox.close(true);
	store.close();
}
 
開發者ID:darciopacifico,項目名稱:omr,代碼行數:31,代碼來源:MailClient.java

示例5: main

import javax.mail.Store; //導入方法依賴的package包/類
public static void main(String[] args) throws MessagingException {

    String url = "https://outlook.office365.com/ews/exchange.asmx";
    Properties properties = new Properties();
    properties.setProperty("org.sourceforge.net.javamail4ews.util.Util.EnableServiceTrace", "true");
    Session session = Session.getInstance(properties);

    System.out.println("retrieving the store");
    //Get the EWS store implementation
    Store store = session.getStore("ewsstore");

    System.out.println("done");

    //Connect to the Exchange server - No port required.
    //Also connect() might be used if the session is initalized with the known mail.* properties
    System.out.println(String.format("connecting to %s", url));
    store.connect(url,
      "[email protected]",
      "p4ssw0rd");

    System.out.println(String.format("connected to %s", url));
    System.out.println(String.format("get default folder", url));
    Folder folder = store.getDefaultFolder();
    System.out.println(String.format("open default folder as read-only"));
    folder.open(Folder.READ_ONLY);
    System.out.println(String.format("done"));
    Message[] messages = folder.getMessages();
    System.out.println(String.format("there is %d messages", messages.length));

    System.out.println(messages[0].getFrom());
  }
 
開發者ID:gartcimore,項目名稱:javamail4ews,代碼行數:32,代碼來源:MailSample.java

示例6: openFolder

import javax.mail.Store; //導入方法依賴的package包/類
private Folder openFolder( cfSession _Session, Store popStore )  throws cfmRunTimeException	{
	try{
		Folder folder = popStore.getDefaultFolder();
		Folder popFolder = folder.getFolder("INBOX");
		popFolder.open( Folder.READ_WRITE );
		return popFolder;
	}catch(Exception E){
		throw newRunTimeException( E.getMessage() );
	}
}
 
開發者ID:OpenBD,項目名稱:openbd-core,代碼行數:11,代碼來源:cfPOP3.java

示例7: main

import javax.mail.Store; //導入方法依賴的package包/類
public static void main(String[] argv) throws Exception {
    String fileName = MailConstants.PROPS_FILE_NAME;
    String protocol = null;
    String host = null;
    String user = null;
    String password = null;
    String root = null;

    // If argc == 1, assume it's a Properties file.
    if (argv.length == 1) {
        fileName = argv[0];
        FileProperties fp = new FileProperties(fileName);
        fp.load();
        protocol = fp.getProperty(MailConstants.RECV_PROTO);
        host = fp.getProperty(MailConstants.RECV_HOST);
        user = fp.getProperty(MailConstants.RECV_USER);
        password = fp.getProperty(MailConstants.RECV_PASS);
        root = fp.getProperty(MailConstants.RECV_ROOT);
    }
    // If not, assume listing all args in long form.
    else if (argv.length == 5) {
        protocol = argv[0];
        host = argv[1];
        user = argv[2];
        password = argv[3];
        root = argv[4];
    }
    // Otherwise give up.
    else {
        System.err.println(
            "Usage: MailLister protocol host user pw root");
        System.exit(0);
    }

    boolean recursive = false;

    // Start with a JavaMail Session object
    Session session = Session.getDefaultInstance(
        System.getProperties(), null);
    session.setDebug(false);

    // Get a Store object for the given protocol
    Store store = session.getStore(protocol);
    if (password.equals("*")) {
        final char[] passBytes = 
            System.console().readPassword("Password:", (Object[])null);
        password = new String(passBytes);
    }
    store.connect(host, user, password);

    // Get Folder object for root, and list it
    // If root name = "", getDefaultFolder(), else getFolder(root)
    Folder rf;
    if (root.length() != 0) {
        System.out.println("Getting folder " + root + ".");
        rf = store.getFolder(root);
    } else {
        System.out.println("Getting default folder.");
        rf = store.getDefaultFolder();
    }
    rf.open(Folder.READ_WRITE);

    if (rf.getType() == Folder.HOLDS_FOLDERS) {
        Folder[] fs = rf.list();
        for (Folder f : fs) {
            listFolder(f, "", recursive);
        }
    } else {
        listFolder(rf, "", false);
    }
}
 
開發者ID:shashanksingh28,項目名稱:code-similarity,代碼行數:72,代碼來源:MailLister.java

示例8: get

import javax.mail.Store; //導入方法依賴的package包/類
public JavaxMailStorage get() throws MessagingException {
  Properties properties = new Properties();
  properties.setProperty("mail.store.protocol", "mstor");
  properties.setProperty("mstor.mbox.metadataStrategy", "none");
  properties.setProperty("mstor.mbox.cacheBuffers", "disabled");
  properties.setProperty("mstor.mbox.bufferStrategy", "mapped");
  properties.setProperty("mstor.metadata", "disabled");
  properties.setProperty("mstor.mozillaCompatibility", "enabled");

  Session session = Session.getDefaultInstance(properties);

  // /Users/flan/Desktop/Copy of Marie's Mail/Mail/Mail/mail.lean.to
  File mailbox = new File(commandLineArguments.mailboxFileName);
  if (!mailbox.exists()) {
    throw new MessagingException("No such mailbox:" + mailbox);
  }

  Store store = session.getStore(
      new URLName("mstor:" + mailbox.getAbsolutePath()));
  store.connect();

  return new ThunderbirdMailStorage(
      logger,
      new JavaxMailFolder(store.getDefaultFolder()),
      statusParser);
}
 
開發者ID:google,項目名稱:mail-importer,代碼行數:27,代碼來源:ThunderbirdMailbox.java

示例9: before

import javax.mail.Store; //導入方法依賴的package包/類
@Before
public void before() throws Exception {
    session = Session.getInstance(new Properties());

    Store localStore = session.getStore("imap");
    localStore.connect("localhost", "camel", "dummy");

    Store riderStore = session.getStore("imap");
    riderStore.connect("camel", "rider", "dummy");

    inbox = localStore.getDefaultFolder();
    inbox.open(Folder.READ_ONLY);
    read = localStore.getFolder("after-processing");
    read.open(Folder.READ_ONLY);

    riderInbox = riderStore.getDefaultFolder();
    riderInbox.open(Folder.READ_ONLY);
}
 
開發者ID:jboss-switchyard,項目名稱:switchyard,代碼行數:19,代碼來源:CamelMailBindingTest.java

示例10: checkMessages

import javax.mail.Store; //導入方法依賴的package包/類
protected void checkMessages(Store store, Session session) throws MessagingException {
    if (!store.isConnected()) {
        store.connect();
    }

    // open the default folder
    Folder folder = store.getDefaultFolder();
    if (!folder.exists()) {
        throw new MessagingException("No default (root) folder available");
    }

    // open the inbox
    folder = folder.getFolder(INBOX);
    if (!folder.exists()) {
        throw new MessagingException("No INBOX folder available");
    }

    // get the message count; stop if nothing to do
    folder.open(Folder.READ_WRITE);
    int totalMessages = folder.getMessageCount();
    if (totalMessages == 0) {
        folder.close(false);
        return;
    }

    // get all messages
    Message[] messages = folder.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
    FetchProfile profile = new FetchProfile();
    profile.add(FetchProfile.Item.ENVELOPE);
    profile.add(FetchProfile.Item.FLAGS);
    profile.add("X-Mailer");
    folder.fetch(messages, profile);

    // process each message
    for (Message message: messages) {
        // process each un-read message
        if (!message.isSet(Flags.Flag.SEEN)) {
            long messageSize = message.getSize();
            if (message instanceof MimeMessage && messageSize >= maxSize) {
                Debug.logWarning("Message from: " + message.getFrom()[0] + "not received, too big, size:" + messageSize + " cannot be more than " + maxSize + " bytes", module);

                // set the message as read so it doesn't continue to try to process; but don't delete it
                message.setFlag(Flags.Flag.SEEN, true);
            } else {
                this.processMessage(message, session);
                if (Debug.verboseOn()) Debug.logVerbose("Message from " + UtilMisc.toListArray(message.getFrom()) + " with subject [" + message.getSubject() + "]  has been processed." , module);
                message.setFlag(Flags.Flag.SEEN, true);
                if (Debug.verboseOn()) Debug.logVerbose("Message [" + message.getSubject() + "] is marked seen", module);

                // delete the message after processing
                if (deleteMail) {
                    if (Debug.verboseOn()) Debug.logVerbose("Message [" + message.getSubject() + "] is being deleted", module);
                    message.setFlag(Flags.Flag.DELETED, true);
                }
            }
        }
    }

    // expunge and close the folder
    folder.close(true);
}
 
開發者ID:gildaslemoal,項目名稱:elpi,代碼行數:62,代碼來源:JavaMailContainer.java

示例11: testOnlyInbox

import javax.mail.Store; //導入方法依賴的package包/類
@Test(expected = MockTestException.class)
public void testOnlyInbox() 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(Providers.getPOP3Provider("makes_no_differernce", false, true));
    store.connect("[email protected]", null);
    final Folder defaultFolder = store.getDefaultFolder();

    try {
        defaultFolder.getFolder("test");
    } catch (final MessagingException e) {
        throw new MockTestException(e);
    }

}
 
開發者ID:salyh,項目名稱:javamail-mock2,代碼行數:28,代碼來源:POP3TestCase.java

示例12: main

import javax.mail.Store; //導入方法依賴的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

示例13: testACLUnsupported

import javax.mail.Store; //導入方法依賴的package包/類
@Test(expected = MockTestException.class)
public void testACLUnsupported() 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 IMAPFolder testImap = (IMAPFolder) test;

    try {
        testImap.getACL();
    } catch (final MessagingException e) {
        throw new MockTestException(e);
    }

}
 
開發者ID:salyh,項目名稱:javamail-mock2,代碼行數:31,代碼來源:IMAPTestCase.java

示例14: testAppendFailMessage

import javax.mail.Store; //導入方法依賴的package包/類
@Test
// (expected = MockTestException.class)
public void testAppendFailMessage() 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();
    store.connect("[email protected]", null);
    final Folder defaultFolder = store.getDefaultFolder();
    final Folder inbox = defaultFolder.getFolder("INBOX");

    inbox.open(Folder.READ_ONLY);

    try {
        inbox.appendMessages(new MimeMessage[] { msg });
    } catch (final IllegalStateException e) {
        // throw new MockTestException(e);
    }

    // Assert.fail("Exception expected before this point");

    Assert.assertEquals(4, inbox.getMessageCount());

    inbox.close(false);

}
 
開發者ID:salyh,項目名稱:javamail-mock2,代碼行數:37,代碼來源:IMAPTestCase.java

示例15: testAppendMessage

import javax.mail.Store; //導入方法依賴的package包/類
@Test
public void testAppendMessage() 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(Providers.getIMAPProvider("makes_no_difference_here", true, true));
    store.connect("[email protected]", null);
    final Folder defaultFolder = store.getDefaultFolder();
    final Folder inbox = defaultFolder.getFolder("INBOX");

    inbox.open(Folder.READ_WRITE);

    inbox.appendMessages(new MimeMessage[] { msg });

    Assert.assertEquals(4, inbox.getMessageCount());

    inbox.close(true);

}
 
開發者ID:salyh,項目名稱:javamail-mock2,代碼行數:30,代碼來源:IMAPTestCase.java


注:本文中的javax.mail.Store.getDefaultFolder方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。