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


Java Folder.isOpen方法代碼示例

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


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

示例1: reconnectStoreIfClosed

import javax.mail.Folder; //導入方法依賴的package包/類
/**
 * Reconnects if connection is closed.
 * <b>Note</b>Internal method
 * @return true if store re-connection is performed and this means that close should be closed after the work is done
 * @throws MessagingException
 */
public boolean reconnectStoreIfClosed() throws MessagingException {

    boolean storeReconnected = false;

    // 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 = this.partOfImapFolder;
    } else {
        partOfImapFolder = imapFolder; // keep reference
    }
    if (imapFolder != null) {
        Store store = imapFolder.getStore();
        if (store != null) {
            if (!store.isConnected()) {
                log.debug("Reconnecting store... ");
                store.connect();
                storeReconnected = true;
            }

            // Open folder in read-only mode
            if (!imapFolder.isOpen()) {
                log.debug("Reopening folder " + imapFolder.getFullName()
                          + " in order to get contents of mail message");
                imapFolder.open(Folder.READ_ONLY);
            }
        }
    }
    return storeReconnected;
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:37,代碼來源:MimePackage.java

示例2: receiveByFolder

import javax.mail.Folder; //導入方法依賴的package包/類
public void receiveByFolder(Folder folder, JavamailConfig javamailConfig)
        throws MessagingException, IOException {
    logger.info("receive : {}", folder);

    if ((Folder.HOLDS_MESSAGES & folder.getType()) != 0) {
        this.receiveMessageByFolder(folder, javamailConfig);
    }

    if ((Folder.HOLDS_FOLDERS & folder.getType()) != 0) {
        for (Folder childFolder : folder.list()) {
            this.receiveByFolder(childFolder, javamailConfig);
        }
    }

    if (folder.isOpen()) {
        // 關閉資源
        folder.close(false);
    }
}
 
開發者ID:zhaojunfei,項目名稱:lemon,代碼行數:20,代碼來源:JavamailService.java

示例3: getFolder

import javax.mail.Folder; //導入方法依賴的package包/類
private Folder getFolder(String folderName, int mode) {
    Folder source = null;
    try {
        if (folders.containsKey(folderName)) {
            source = folders.get(folderName);
        } else {
            source = store.getFolder(folderName);
            if (source == null || !source.exists()) {
                throw new IllegalArgumentException("Invalid folder: " + folderName);
            }
            folders.put(folderName, source);
        }
        if (!source.isOpen()) {
            source.open(mode);
        }
    } catch (MessagingException ex) {
        Logger.getLogger(AccountProcessor.class.getName()).log(Level.SEVERE, null, ex);
    }
    return source;
}
 
開發者ID:PacktPublishing,項目名稱:Java-9-Programming-Blueprints,代碼行數:21,代碼來源:AccountProcessor.java

示例4: ensureOpenFolder

import javax.mail.Folder; //導入方法依賴的package包/類
public Folder ensureOpenFolder(Folder folder) throws MessagingException {
  ensureConnectedStore(folder.getStore());

  if (!folder.isOpen()) {
    openFolder(folder);
  }

  return folder;
}
 
開發者ID:camunda,項目名稱:camunda-bpm-mail,代碼行數:10,代碼來源:MailService.java

示例5: getEmails

import javax.mail.Folder; //導入方法依賴的package包/類
@Override
public List<SimpleMailMessage> getEmails()
    throws MessagingException, IOException, NamingException {
  Session emailSession = null;
  Store store = null;
  Folder emailFolder = null;
  List<SimpleMailMessage> receivedEmails = new ArrayList<SimpleMailMessage>();
  try {
    if (!StringUtils.isEmpty(mailSettings.getJndiName())) {
      InitialContext ic = new InitialContext();
      emailSession = (Session) ic.lookup(mailSettings.getJndiName());
      store = emailSession.getStore();
      store.connect();
    }
    else {

      // Set connection properties
      Properties properties = new Properties();
      String prefix = "mail.".concat(mailSettings.getProtocol());
      properties.put(String.format("%s.host", prefix), mailSettings.getHost());
      properties.put(String.format("%s.port", prefix), mailSettings.getPort());
      properties.put("mail.store.protocol", mailSettings.getProtocol());
      properties.put(String.format("%s.starttls.enable", prefix), mailSettings.getStarttlsEnabled());

      // Create the session and the object Store to get the emails
      emailSession = Session.getDefaultInstance(properties);
      store = emailSession.getStore();
      store.connect(mailSettings.getUsername(), mailSettings.getPassword());
    }

    // Get the folder that contains the emails and open it
    emailFolder = store.getFolder("INBOX");
    emailFolder.open(Folder.READ_ONLY);

    // Get emails that haven't been read
    Message[] messagesReceived = emailFolder.getMessages();
    for (Message message : messagesReceived) {
      Object content = message.getContent();
      String body = null;
      if (content instanceof Multipart) {
        Multipart multipart = (Multipart) content;
        BodyPart bodyPart = multipart.getBodyPart(0);
        if (bodyPart != null) {
          body = bodyPart.getContent().toString();
        }
      }
      else if (content instanceof String) {
        body = (String) content;
      }
      SimpleMailMessage email = new SimpleMailMessage();
      email.setSubject(message.getSubject());
      email.setText(body);
      email.setFrom(message.getFrom()[0].toString());
      email.setSentDate(message.getSentDate());
      receivedEmails.add(email);
    }
  }
  finally {
    // Close objects Folder and Store
    if (emailFolder != null && emailFolder.isOpen()) {
      emailFolder.close(false);
    }
    if (store != null && store.isConnected()) {
      store.close();
    }

  }
  return receivedEmails;

}
 
開發者ID:DISID,項目名稱:springlets,代碼行數:71,代碼來源:MailReceiverServiceImpl.java

示例6: closeFolder

import javax.mail.Folder; //導入方法依賴的package包/類
/**
 * Close the folder if it is open.
 *
 * @param folder Instance of the folder which is used to fetch emails
 * @throws EmailConnectorException EmailConnectorException
 *                                        due to a email layer error.
 */
protected void closeFolder(Folder folder) throws EmailConnectorException {
    if (folder.isOpen()) {
        try {
            folder.close(true);
        } catch (MessagingException e) {
            log.warn("Couldn't close the folder '" + folderName + "' by the email server connector"
                    + " with service id: " + serviceId + "." + e.getMessage(), e);
        }
    }
}
 
開發者ID:wso2,項目名稱:carbon-transports,代碼行數:18,代碼來源:EmailConsumer.java

示例7: getMessage

import javax.mail.Folder; //導入方法依賴的package包/類
public void getMessage( cfImapConnection imapConnection, String rootFolder, long messageID, String _attachURI, String _attachDIR ) throws cfmRunTimeException {
	try{
		Folder	folderToList;

		if ( rootFolder == null || rootFolder.length() == 0 )
			folderToList = imapConnection.mailStore.getDefaultFolder();
		else
			folderToList = imapConnection.mailStore.getFolder(rootFolder);
			
		if ( (folderToList.getType() & Folder.HOLDS_MESSAGES) != 0){
		
			if ( !folderToList.isOpen() )
				folderToList.open( Folder.READ_ONLY );

			boolean bResult = false;
			if ( folderToList instanceof UIDFolder )	
				bResult = extractMessage( ((UIDFolder)folderToList).getMessageByUID( messageID ), messageID, _attachURI, _attachDIR );
			else
				bResult = extractMessage( folderToList.getMessage( (int)messageID ), messageID, _attachURI, _attachDIR );
			
			if ( !bResult )	imapConnection.setStatus( false, "Message does not exist" );
			else imapConnection.setStatus( true, "" );
			
			folderToList.close(false);
		}

	}catch(Exception E){
		imapConnection.setStatus( false, E.getMessage() );
	}
}
 
開發者ID:OpenBD,項目名稱:openbd-core,代碼行數:31,代碼來源:cfMailMessageData.java

示例8: listFolderMessages

import javax.mail.Folder; //導入方法依賴的package包/類
public cfQueryResultData listFolderMessages( cfImapConnection imapConnection, String rootFolder, int startRow, int totalMessages, boolean reverseOrder ) {
	cfQueryResultData query = new cfQueryResultData( new String[]{"subject","id","rxddate","sentdate","from","to","cc","bcc","size","lines","answered","deleted","draft","flagged","recent","seen"}, "CFIMAP" );

	try{
		Folder	folderToList;
		if ( rootFolder == null || rootFolder.length() == 0 )
			folderToList = imapConnection.mailStore.getDefaultFolder();
		else
			folderToList = imapConnection.mailStore.getFolder(rootFolder);
		
		if ( (folderToList.getType() & Folder.HOLDS_MESSAGES) != 0){
		
			if ( !folderToList.isOpen() )
				folderToList.open( Folder.READ_ONLY );
			
			Message[] messageArray;
			if ( startRow != -1 ){
				
				int folderCount = folderToList.getMessageCount();
				int start, end;
				if ( !reverseOrder ){
					start = startRow;
					if ( folderCount < (startRow+totalMessages-1) ){
						start = startRow;
						end = folderCount; 
					}else{
						end = startRow + totalMessages - 1;
					}
				}else{
					end = folderCount - startRow + 1;
					if ( folderCount < (startRow+totalMessages-1) ){ 
						start = 1;
					}else{
						start = folderCount - startRow - totalMessages + 2;
					}
					
				}
				
				messageArray = folderToList.getMessages( start, end );
				imapConnection.setTotalMessages( folderCount );
				
				
			}else{
				messageArray = folderToList.getMessages();
				imapConnection.setTotalMessages( messageArray.length );
			}

			// To improve performance, pre-fetch all of the message items
			// used by the CFIMAP list action. This will retrieve all of the
			// items for all of the messages with one single FETCH command.
			FetchProfile fp = new FetchProfile();
			fp.add(FetchProfile.Item.ENVELOPE);
			fp.add(FetchProfile.Item.FLAGS);
			fp.add(FetchProfile.Item.CONTENT_INFO);
			folderToList.fetch(messageArray, fp);
			List<Map<String, cfData>>	vectorMessages = new ArrayList<Map<String, cfData>>(messageArray.length);
			
			if ( reverseOrder ){
				int msgIndex = messageArray.length-1;
				for (int i = 0; i < messageArray.length; i++)
					vectorMessages.add( extractMessage( messageArray[msgIndex--] ) );
				
			}else{
				for (int i = 0; i < messageArray.length; i++)
					vectorMessages.add( extractMessage( messageArray[i] ) );
			}
			
			folderToList.close(false);
			query.populateQuery( vectorMessages );
		}

	}catch(Exception E){
		cfEngine.log( E.getMessage() );
		imapConnection.setStatus( false, E.getMessage() );
	}
	
	return query;
}
 
開發者ID:OpenBD,項目名稱:openbd-core,代碼行數:79,代碼來源:cfMailFolderMessagesData.java

示例9: openFolder

import javax.mail.Folder; //導入方法依賴的package包/類
private void openFolder(Folder folder) throws MessagingException {

    LOGGER.debug("open folder '{}'", folder.getName());

    folder.open(Folder.READ_WRITE);

    if (!folder.isOpen()) {
      throw new IllegalStateException("folder is not open");
    }
  }
 
開發者ID:camunda,項目名稱:camunda-bpm-mail,代碼行數:11,代碼來源:MailService.java


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