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


Java Folder.exists方法代码示例

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


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

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

示例2: assertConnection

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

示例3: clear

import javax.mail.Folder; //导入方法依赖的package包/类
private static void clear(Folder folder) throws MessagingException {
	if(folder.exists() && (folder.getType() & Folder.HOLDS_MESSAGES) == Folder.HOLDS_MESSAGES) {
		int totMessages = folder.getMessageCount();
		System.out.println(totMessages + " messages from folder: " + folder.getFullName());
		folder.open(Folder.READ_WRITE);
		Message[] messages = folder.getMessages();
		for (int i = 0; i < messages.length; i++) {
			System.out.println("Deleting message: " + (i+1) + " of " + totMessages);
			messages[i].setFlag(Flags.Flag.DELETED, true);
		}
		folder.close(true);
	}
	Folder[] childs = folder.list();
	for (int i = 0; i < childs.length; i++) {
		clear(childs[i]);
	}
}
 
开发者ID:Ardulink,项目名称:Ardulink-1,代码行数:18,代码来源:MailListener.java

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

示例5: createFolder

import javax.mail.Folder; //导入方法依赖的package包/类
public void createFolder( String newFolder ){
	if ( newFolder.length() == 0 )
		return;
	
   try{
   
     Folder folderToUse = mailStore.getFolder( newFolder );
		
		if ( !folderToUse.exists() ){
			folderToUse.create( Folder.HOLDS_FOLDERS | Folder.HOLDS_MESSAGES );
		}
		
     setData( "succeeded", 	cfBooleanData.TRUE );
   
   } catch (Exception E ){
     setData( "errortext", 	new cfStringData( E.getMessage() ) );
     setData( "succeeded", 	cfBooleanData.FALSE );
   }
	
	setTotalMessages( 0 );
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:22,代码来源:cfImapConnection.java

示例6: deleteFolder

import javax.mail.Folder; //导入方法依赖的package包/类
public void deleteFolder( String folderToDelete ){
	if ( folderToDelete.length() == 0 )
		return;

   try{
   
     Folder folderToUse = mailStore.getFolder( folderToDelete );
		
		if ( folderToUse.exists() ){
			folderToUse.delete( true );
		}
		
     setData( "succeeded", 	cfBooleanData.TRUE );
     
   } catch (Exception E ){
     setData( "errortext", 	new cfStringData( E.getMessage() ) );
     setData( "succeeded", 	cfBooleanData.FALSE );
   }
	
	setTotalMessages( 0 );
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:22,代码来源:cfImapConnection.java

示例7: renameFolder

import javax.mail.Folder; //导入方法依赖的package包/类
public void renameFolder( String oldFolder, String newFolder ){
	
	if ( oldFolder.length() == 0 || newFolder.length() == 0 )
		return;
	
   try{
   
     Folder folderToUse 		= mailStore.getFolder( oldFolder );
		Folder newfolderToUse = mailStore.getFolder( newFolder );
		
		if ( folderToUse.exists() && !newfolderToUse.exists() ){
			folderToUse.renameTo( newfolderToUse );
		}
		
     setData( "succeeded", 	cfBooleanData.TRUE );
   
   } catch (Exception E ){
     setData( "errortext", 	new cfStringData( E.getMessage() ) );
     setData( "succeeded", 	cfBooleanData.FALSE );
   }
	
	setTotalMessages( 0 );
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:24,代码来源:cfImapConnection.java

示例8: send

import javax.mail.Folder; //导入方法依赖的package包/类
public String send()
{
  Session session = _getSession();
  Message msg = _setupMessage(new MimeMessage(session));
  if (msg == null)
  {
    _LOG.info("Could not create Message object for " + getSubject());
    return null;
  }

  try
  {
    Transport.send(msg);
  }
  catch (MessagingException me)
  {
    _showSendException(me);
    return null;
  }

  _LOG.info("Sent succesfully");

  try
  {
    Store store = _account.getStore();
    // =-=AEW Hardcoding "Sent" as the folder to save "Sent" messages
    Folder folder = store.getFolder("Sent");
    if (folder == null)
    {
      // Can "folder" be null here?
      throw new IllegalStateException("\"Sent\" folder was null");
    }
    else
    {
      if (!folder.exists())
        folder.create(Folder.HOLDS_MESSAGES);

      folder.appendMessages(new Message[]{msg});
    }
  }
  // Need to do something better;  like a "Warning: message sent, but not
  // saved" message for the user?
  catch (Exception e)
  {
    _LOG.log(Level.WARNING, "Couldn't save message in \"Sent\" folder", e);
  }

  return "sentMessage";
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:50,代码来源:NewMessageBackingBean.java

示例9: saveAsDraft

import javax.mail.Folder; //导入方法依赖的package包/类
public String saveAsDraft()
{
  _LOG.info("Beginning send of message " + getSubject());

  Session session = _getSession();
  Message msg = _setupMessage(new MimeMessage(session));
  if (msg == null)
  {
    _LOG.info("Could not create Message object for " + getSubject());
    return null;
  }

  try
  {
    Store store = _account.getStore();
    // =-=AEW Hardcoding "Drafts" as the folder to save drafts
    Folder folder = store.getFolder("Drafts");
    if (folder == null)
    {
      // Can "folder" be null here?
      throw new IllegalStateException("\"Drafts\" folder was null");
    }
    else
    {
      if (!folder.exists())
        folder.create(Folder.HOLDS_MESSAGES);
      
      folder.appendMessages(new Message[]{msg});
    }
  }
  // Need to do something better...
  catch (Exception e)
  {
    _showSendException(e);
    return null;
  }
  
  // And go back to the current message folder
  // =-=aew Should be a "popView" thing
  return "messages";
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:42,代码来源:NewMessageBackingBean.java


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