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


Java Folder.getFolder方法代码示例

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


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

示例1: createTestMessages

import javax.mail.Folder; //导入方法依赖的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

示例2: checkInbox

import javax.mail.Folder; //导入方法依赖的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

示例3: checkInboxSave

import javax.mail.Folder; //导入方法依赖的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

示例4: openFolder

import javax.mail.Folder; //导入方法依赖的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

示例5: checkMessages

import javax.mail.Folder; //导入方法依赖的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


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