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


Java Store.close方法代碼示例

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


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

示例1: closeStoreConnection

import javax.mail.Store; //導入方法依賴的package包/類
/**
 * Close connection
 * <b>Note</b>Internal method
 * @throws MessagingException
 */
public void closeStoreConnection(
                                  boolean storeConnected ) throws MessagingException {

    if (storeConnected) {
        // the folder is empty when the message is not loaded from IMAP server, but from a file
        Folder imapFolder = message.getFolder();
        if (imapFolder == null) {
            imapFolder = partOfImapFolder; // in case of nested package but still originating from IMAP server
        }
        if (imapFolder != null) {
            Store store = imapFolder.getStore();
            if (store != null && store.isConnected()) {
                // closing store closes and its folders
                log.debug("Closing store (" + store.toString() + ") and associated folders");
                store.close();
            }
        }
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:25,代碼來源:MimePackage.java

示例2: isMailReceivedBySubject

import javax.mail.Store; //導入方法依賴的package包/類
/**
 * Check mail folder for an email using subject.
 *
 * @param emailSubject Email subject
 * @param folder       mail folder to check for an email
 * @param protocol     protocol used to connect to the server
 * @return whether mail received or not
 * @throws MessagingException if we're unable to connect to the store
 */
private static boolean isMailReceivedBySubject(String emailSubject, String folder, String protocol,
        GreenMailUser user) throws MessagingException {
    boolean emailReceived = false;
    Folder mailFolder;
    Store store = getConnection(user, protocol);
    try {
        mailFolder = store.getFolder(folder);
        mailFolder.open(Folder.READ_WRITE);
        SearchTerm searchTerm = new AndTerm(new SubjectTerm(emailSubject), new BodyTerm(emailSubject));
        Message[] messages = mailFolder.search(searchTerm);
        for (Message message : messages) {
            if (message.getSubject().contains(emailSubject)) {
                log.info("Found the Email with Subject : " + emailSubject);
                emailReceived = true;
                break;
            }
        }
    } finally {
        if (store != null) {
            store.close();
        }
    }
    return emailReceived;
}
 
開發者ID:wso2,項目名稱:product-ei,代碼行數:34,代碼來源:GreenMailServer.java

示例3: deleteAllEmails

import javax.mail.Store; //導入方法依賴的package包/類
/**
 * Delete all emails in the inbox.
 *
 * @param protocol protocol used to connect to the server
 * @throws MessagingException if we're unable to connect to the store
 */
public static void deleteAllEmails(String protocol, GreenMailUser user) throws MessagingException {
    Folder inbox = null;
    Store store = getConnection(user, protocol);
    try {
        inbox = store.getFolder(EMAIL_INBOX);
        inbox.open(Folder.READ_WRITE);
        Message[] messages = inbox.getMessages();

        for (Message message : messages) {
            message.setFlag(Flags.Flag.DELETED, true);
            log.info("Deleted email Subject : " + message.getSubject());
        }
    } finally {
        if (inbox != null) {
            inbox.close(true);
        }
        if (store != null) {
            store.close();
        }
    }
}
 
開發者ID:wso2,項目名稱:product-ei,代碼行數:28,代碼來源:GreenMailServer.java

示例4: assertConnection

import javax.mail.Store; //導入方法依賴的package包/類
/**
 * Asserts that a connection to the given mailbox is possible.
 *
 * @param protocol
 *            The protocol.
 * @param isStartTls
 *            True, if StartTLS ist possible.
 * @param host
 *            The host.
 * @param port
 *            The port.
 * @param login
 *            The login.
 * @param password
 *            The password.
 * @param mailbox
 *            The mailbox.
 * @throws ConnectionException
 *             Exception.
 * @throws MessagingException
 *             Exception.
 */
private void assertConnection(String protocol, boolean isStartTls, String host, String port,
        String login, String password, String mailbox) throws ConnectionException,
        MessagingException {
    String propertiesProtocolPrefix = "mail." + protocol + ".";
    Properties properties = new Properties();
    properties.putAll(System.getProperties());
    properties.put(propertiesProtocolPrefix + "starttls.enable", isStartTls);
    Session session = Session.getInstance(properties);
    Store store = session.getStore(protocol);
    try {
        store.connect(host, NumberUtils.toInt(port, -1), login, password);
        Folder folder = store.getFolder(mailbox);
        if (!folder.exists()) {
            throw new FolderNotFoundException();
        }
    } finally {
        store.close();
    }
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:42,代碼來源:MailInController.java

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

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

示例7: testAllServices

import javax.mail.Store; //導入方法依賴的package包/類
@Test
public void testAllServices() throws MessagingException {
    // Send messages via SMTP and secure SMTPS
    GreenMailUtil.sendTextEmail("[email protected]", "[email protected]",
            "test1", "Test GreenMail Docker service",
            ServerSetupTest.SMTP.createCopy(bindAddress));
    GreenMailUtil.sendTextEmail("[email protected]", "[email protected]",
            "test2", "Test GreenMail Docker service",
            ServerSetupTest.SMTPS.createCopy(bindAddress));

    // IMAP
    for (ServerSetup setup : Arrays.asList(
            ServerSetupTest.IMAP.createCopy(bindAddress),
            ServerSetupTest.IMAPS.createCopy(bindAddress),
            ServerSetupTest.POP3.createCopy(bindAddress),
            ServerSetupTest.POP3S.createCopy(bindAddress))) {
        final Store store = Session.getInstance(setup.configureJavaMailSessionProperties(null, false)).getStore();
        store.connect("[email protected]", "[email protected]");
        try {
            Folder folder = store.getFolder("INBOX");
            folder.open(Folder.READ_ONLY);
            assertEquals("Can not check mails using "+store.getURLName(), 2, folder.getMessageCount());
        } finally {
            store.close();
        }
    }
}
 
開發者ID:greenmail-mail-test,項目名稱:greenmail,代碼行數:28,代碼來源:DockerServiceIT.java

示例8: closeStore

import javax.mail.Store; //導入方法依賴的package包/類
/**
 * Handy method to do the try catch try of closing a mail store and folder.
 * @param mailStore
 * @param mailFolder
 */
private void closeStore(final Store mailStore, final Folder mailFolder)  {
    try {
        if (mailFolder != null && mailFolder.isOpen()) {
            mailFolder.close(true);
        }
    } catch (final MessagingException e) {
    	LogUtils.debugf(this, e, "Unable to close mail folder.");
    } finally {
        try {
            if (mailStore != null && mailStore.isConnected()) {
                mailStore.close();
            }
        } catch (final MessagingException e1) {
        	LogUtils.debugf(this, e1, "Unable to close message store.");
        }
    }
}
 
開發者ID:qoswork,項目名稱:opennmszh,代碼行數:23,代碼來源:MailTransportMonitor.java

示例9: deleteMailsFromUserMailbox

import javax.mail.Store; //導入方法依賴的package包/類
protected void deleteMailsFromUserMailbox(final Properties props, final String folderName, final int start, final int deleteCount,
        final String user, final String password) throws MessagingException {
    final Store store = Session.getInstance(props).getStore();

    store.connect(user, password);
    checkStoreForTestConnection(store);
    final Folder f = store.getFolder(folderName);
    f.open(Folder.READ_WRITE);

    final int msgCount = f.getMessageCount();

    final Message[] m = deleteCount == -1 ? f.getMessages() : f.getMessages(start, Math.min(msgCount, deleteCount + start - 1));
    int d = 0;

    for (final Message message : m) {
        message.setFlag(Flag.DELETED, true);
        logger.info("Delete msgnum: {} with sid {}", message.getMessageNumber(), message.getSubject());
        d++;
    }

    f.close(true);
    logger.info("Deleted " + d + " messages");
    store.close();

}
 
開發者ID:salyh,項目名稱:elasticsearch-imap,代碼行數:26,代碼來源:AbstractIMAPRiverUnitTest.java

示例10: getEmail

import javax.mail.Store; //導入方法依賴的package包/類
public Mail getEmail(int mailId, MailCredentials credentials, String salt) throws MessagingException, IOException {
	Properties properties = getServerProperties(credentials.getProtocol(), credentials.getHost(),
			"" + credentials.getPort());
	Session session = Session.getDefaultInstance(properties);

	// connects to the message store
	Store store = session.getStore(credentials.getProtocol());
	store.connect(credentials.getUsername(), credentials.getPassword());

	// opens the inbox folder
	Folder folderInbox = store.getFolder("INBOX");
	folderInbox.open(Folder.READ_ONLY);

	// fetches new messages from server
	int msgnum[] = new int[] { mailId };
	Message[] messages = folderInbox.getMessages(msgnum);

	Mail mail = getMails(messages).get(0);

	// disconnect
	folderInbox.close(false);
	store.close();
	return mail;
}
 
開發者ID:HTWK-App,項目名稱:Server-Application,代碼行數:25,代碼來源:EmailReceiver.java

示例11: changeMailStatus

import javax.mail.Store; //導入方法依賴的package包/類
public void changeMailStatus(int mailId, Flag flag, MailCredentials credentials) throws MessagingException {
	Properties properties = getServerProperties(credentials.getProtocol(), credentials.getHost(),
			"" + credentials.getPort());
	Session session = Session.getDefaultInstance(properties);

	// connects to the message store
	Store store = session.getStore(credentials.getProtocol());
	store.connect(credentials.getUsername(), credentials.getPassword());

	// opens the inbox folder
	Folder folderInbox = store.getFolder("INBOX");
	folderInbox.open(Folder.READ_WRITE);

	logger.debug("unread:" + folderInbox.getUnreadMessageCount() + ", new:" + folderInbox.getNewMessageCount());

	// fetches new messages from server
	int msgnum[] = new int[] { mailId };
	Message[] messages = folderInbox.getMessages(msgnum);

	if (messages.length == 1 && messages[0] != null) {
		messages[0].setFlag(flag, true);
	}

	folderInbox.close(false);
	store.close();
}
 
開發者ID:HTWK-App,項目名稱:Server-Application,代碼行數:27,代碼來源:EmailReceiver.java

示例12: _getEmail

import javax.mail.Store; //導入方法依賴的package包/類
public MessageWrapper _getEmail( String hostName, MessageFilter[] messageFilters, Map<String, String> propertyMap )
{
    Properties mailProps = new Properties();
    mailProps.putAll( propertyMap );

    List<Message> messageList = new ArrayList<Message>( 10 );
    MessageWrapper messageWrapper = null;

    try
    {
        Session emailSession = Session.getDefaultInstance( mailProps );
        Store store = emailSession.getStore( propertyMap.get( PROTOCOL ) );
        store.connect( hostName, propertyMap.get( USER_NAME ), propertyMap.get( PASSWORD ) );

        Folder emailFolder = store.getFolder( propertyMap.get( FOLDER_NAME ) != null ? propertyMap.get( FOLDER_NAME ) : DEFAULT_FOLDER_NAME );
        emailFolder.open( Folder.READ_WRITE );

        Message[] messages = emailFolder.getMessages();

        int messageCount = emailFolder.getMessageCount();
        if ( messageCount > MAX_MESSAGES )
            messageCount = MAX_MESSAGES;

        if ( log.isInfoEnabled() )
            log.info( "Processing " + messageCount + " messages" );

        for ( int i = 0; i < messageCount; i++ )
        {
            if ( applyFilters( messages[i], messageFilters ) )
            {
                messageList.add( messages[i] );
            }
        }

        if ( messageList.size() == 0 )
            throw new ScriptException( "Failed to find any email messages that met the criteria" );
            
        Collections.sort( messageList, new DateComparator() );

        String messageContent = null;
        String contentType = messageList.get( 0 ).getContentType();

        if ( contentType.startsWith( "text/" ) )
            messageContent = messageList.get( 0 ).getContent().toString();
        else if ( messageList.get( 0 ).isMimeType( "multipart/*" ) )
            messageContent = getTextFromMimeMultipart( (MimeMultipart) messageList.get( 0 ).getContent() );
        else
            messageContent = messageList.get( 0 ).getContent().getClass().getName();

        messageWrapper = new MessageWrapper( messageList.size(), messageList.get( 0 ).getFrom()[0].toString(), messageList.get( 0 ).getSubject(), messageContent, contentType );

        emailFolder.close( false );
        store.close();
    }
    catch ( Exception e )
    {
        e.printStackTrace();
        throw new ScriptException( "Failed to find email" );
    }

    return messageWrapper;
}
 
開發者ID:xframium,項目名稱:xframium-java,代碼行數:63,代碼來源:DefaultReceiveEmailProvider.java

示例13: receive

import javax.mail.Store; //導入方法依賴的package包/類
/**
 * �����ʼ�
 */ 
public static void receive() throws Exception { 
    // ׼�����ӷ������ĻỰ��Ϣ 
    Properties props = new Properties(); 
    props.setProperty("mail.store.protocol", "pop3");       // �� 
    props.setProperty("mail.pop3.port", "110");             // �˿� 
    props.setProperty("mail.pop3.host", "pop3.sina.com");    // pop3������ 
     
    // ����Sessionʵ������ 
    Session session = Session.getInstance(props); 
    Store store = session.getStore("pop3"); 
    store.connect("[email protected]", "mh899821671104"); 
     
    // ����ռ��� 
    Folder folder = store.getFolder("INBOX"); 
    /* Folder.READ_ONLY��ֻ��Ȩ��
     * Folder.READ_WRITE���ɶ���д�������޸��ʼ���״̬��
     */ 
    folder.open(Folder.READ_WRITE); //���ռ��� 
     
    // ����POP3Э���޷���֪�ʼ���״̬,����getUnreadMessageCount�õ������ռ�����ʼ����� 
    System.out.println("δ���ʼ���: " + folder.getUnreadMessageCount()); 
     
    // ����POP3Э���޷���֪�ʼ���״̬,��������õ��Ľ��ʼ�ն���Ϊ0 
    System.out.println("ɾ���ʼ���: " + folder.getDeletedMessageCount()); 
    System.out.println("���ʼ�: " + folder.getNewMessageCount()); 
     
    // ����ռ����е��ʼ����� 
    System.out.println("�ʼ�����: " + folder.getMessageCount()); 
     
    // �õ��ռ����е������ʼ�,������ 
    Message[] messages = folder.getMessages(); 
    parseMessage(messages); 
     
    //�ͷ���Դ 
    folder.close(true); 
    store.close(); 
}
 
開發者ID:bjut-2014,項目名稱:scada,代碼行數:41,代碼來源:MailUtils.java

示例14: main

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

		Properties props = new Properties();

		String host = "pop.mailinator.com";
		String username = "x-test-m";
		String password = "mypwdxxx";
		String provider = "pop3";

		Session session = Session.getDefaultInstance(props, null);
		Store store = session.getStore(provider);
		store.connect(host, username, password);

		Folder inbox = store.getFolder("INBOX");
		if (inbox == null) {
			System.out.println("No INBOX");
			System.exit(1);
		}
		inbox.open(Folder.READ_ONLY);

		Message[] messages = inbox.getMessages();
		for (int i = 0; i < messages.length; i++) {
			System.out.println("Message " + (i + 1));
			messages[i].writeTo(System.out);
		}
		inbox.close(false);
		store.close();

	}
 
開發者ID:qmetry,項目名稱:qaf,代碼行數:30,代碼來源:MalinatorUtil.java

示例15: receive

import javax.mail.Store; //導入方法依賴的package包/類
/**
 * 接收郵件
 */
public static void receive() throws Exception {
	// 準備連接服務器的會話信息
	Properties props = new Properties();
	props.setProperty("mail.store.protocol", "pop3");		// 協議
	props.setProperty("mail.pop3.port", "995");				// 端口
	props.setProperty("mail.pop3.host", "pop3.live.com");	// pop3服務器
	
	// 創建Session實例對象
	Session session = Session.getInstance(props);
	Store store = session.getStore("pop3");
	store.connect("[email protected]", "Mo8yOU8u");
	
	// 獲得收件箱
	Folder folder = store.getFolder("INBOX");
	/* Folder.READ_ONLY:隻讀權限
	 * Folder.READ_WRITE:可讀可寫(可以修改郵件的狀態)
	 */
	folder.open(Folder.READ_WRITE);	//打開收件箱
	
	// 由於POP3協議無法獲知郵件的狀態,所以getUnreadMessageCount得到的是收件箱的郵件總數
	System.out.println("未讀郵件數: " + folder.getUnreadMessageCount());
	
	// 由於POP3協議無法獲知郵件的狀態,所以下麵得到的結果始終都是為0
	System.out.println("刪除郵件數: " + folder.getDeletedMessageCount());
	System.out.println("新郵件: " + folder.getNewMessageCount());
	
	// 獲得收件箱中的郵件總數
	System.out.println("郵件總數: " + folder.getMessageCount());
	
	// 得到收件箱中的所有郵件,並解析
	Message[] messages = folder.getMessages();
	parseMessage(messages);
	
	//釋放資源
	folder.close(true);
	store.close();
}
 
開發者ID:xiaomin0322,項目名稱:alimama,代碼行數:41,代碼來源:POP3ReceiveMailTest.java


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