当前位置: 首页>>代码示例>>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;未经允许,请勿转载。