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


Java Folder类代码示例

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


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

示例1: getEmail

import javax.mail.Folder; //导入依赖的package包/类
public void getEmail() throws MessagingException, IOException {
    Session session = Session.getDefaultInstance(System.getProperties(),null);
    Store store = null;
    store = session.getStore("imaps");

    // store.connect(this.host, this.userName, this.password);

    // Get default folder
    Folder folder = store.getDefaultFolder();
    folder.getMessages();
    folder.getNewMessageCount();
    Message m = folder.getMessage(0);
    m.getMessageNumber();
    m.getAllRecipients();
    m.getReceivedDate();
    m.getFrom();
    m.getSubject();
    m.getReplyTo();
    m.getContent();
    m.getSize();

    // Get any folder by name
    Folder[] folderList = folder.list();
}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:25,代码来源:PNetwork.java

示例2: deleteMails

import javax.mail.Folder; //导入依赖的package包/类
/**
 * Connect to the mail server and delete all mails.
 */
public void deleteMails() throws MessagingException {
    Folder folder = getStore().getFolder(MAIL_INBOX);
    folder.open(Folder.READ_WRITE);

    // Get folder's list of messages.
    Message[] messages = folder.getMessages();

    // Retrieve message headers for each message in folder.
    FetchProfile profile = new FetchProfile();
    profile.add(FetchProfile.Item.ENVELOPE);
    folder.fetch(messages, profile);

    for (Message message : messages) {
        message.setFlag(Flags.Flag.DELETED, true);
    }
    folder.close(true);

}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:22,代码来源:MailReader.java

示例3: changeStatus

import javax.mail.Folder; //导入依赖的package包/类
public void changeStatus( String folderName, long mailIDs[], Flags.Flag newFlag, boolean value ){
  try{
  
    Folder folderToUse = mailStore.getFolder(folderName);
    folderToUse.open( Folder.READ_WRITE );
    
    Flags f = new Flags();
    f.add( newFlag );
	
	Message mlist[];
	if ( folderToUse instanceof UIDFolder )
		mlist = ((UIDFolder)folderToUse).getMessagesByUID( mailIDs );
	else
		mlist = folderToUse.getMessages( returnToInts(mailIDs) );
	
	for ( int x=0; x < mlist.length; x++ )
		mlist[x].setFlags( f, value );
    
    folderToUse.close( true );
	setData( "succeeded", 	cfBooleanData.TRUE );
  
  } catch (Exception E ){
	setData( "errortext", 	new cfStringData( E.getMessage() ) );
	setData( "succeeded", 	cfBooleanData.FALSE );
  }
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:27,代码来源:cfImapConnection.java

示例4: closeStoreConnection

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

示例5: isMailReceivedBySubject

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

示例6: prepareMailbox

import javax.mail.Folder; //导入依赖的package包/类
private void prepareMailbox() throws Exception {
    // connect to mailbox
    Mailbox.clearAll();
    JavaMailSender sender = new DefaultJavaMailSender();
    Store store = sender.getSession().getStore("pop3");
    store.connect("localhost", 25, "jones", "secret");
    Folder folder = store.getFolder("INBOX");
    folder.open(Folder.READ_WRITE);
    folder.expunge();

    // inserts 5 new messages
    Message[] messages = new Message[5];
    for (int i = 0; i < 5; i++) {
        messages[i] = new MimeMessage(sender.getSession());
        messages[i].setHeader("Message-ID", "" + i);
        messages[i].setText("Message " + i);
    }
    folder.appendMessages(messages);
    folder.close(true);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:MailFetchSizeTest.java

示例7: initInbox

import javax.mail.Folder; //导入依赖的package包/类
private static void initInbox() {
	try {
		System.out.println("Inbox initiating...");

        Properties props = new Properties();
        props.setProperty(MAIL_STORE_PROTOCOL_KEY, mailConfig.getProperty(MAIL_STORE_PROTOCOL_KEY));

        // Used gmail with lesser secure authentication (https://www.google.com/settings/security/lesssecureapps)
        // For a full access I should implement OAuth2 for ArdulinkMail (https://java.net/projects/javamail/pages/OAuth2)
        
        Session session = Session.getInstance(props, null);
		Store store = session.getStore();
		System.out.println(mailConfig.getProperty(MAIL_HOST_KEY) + " " + mailConfig.getProperty(MAIL_USER_KEY) + " " + mailConfig.getProperty(MAIL_PASSWORD_KEY));
        store.connect(mailConfig.getProperty(MAIL_HOST_KEY), mailConfig.getProperty(MAIL_USER_KEY), mailConfig.getProperty(MAIL_PASSWORD_KEY));
        
        // clearDefault(store.getDefaultFolder()); // With GMAIL it doesn't work since "all messages" cannot be cleared.
        clearMainFolder(store.getFolder("INBOX"));
        
        inbox = store.getFolder("INBOX");
        inbox.open(Folder.READ_WRITE);
		System.out.println("Inbox initiated");
	} catch (Exception e) {
		throw new IllegalStateException("Error initiating inbox. Exiting...");
	}
}
 
开发者ID:Ardulink,项目名称:Ardulink-1,代码行数:26,代码来源:MailListener.java

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

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

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

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

示例12: connect

import javax.mail.Folder; //导入依赖的package包/类
@Override
public void connect() {
  Properties properties = new Properties();
  try {
    int port = configuration.getPort();
    String portS = String.valueOf(port);
    properties.setProperty("mail.store.protocol", "pop3");
    properties.setProperty("mail.pop3.port", portS);
    properties.setProperty("mail.pop3.socketFactory.class",
        "javax.net.ssl.SSLSocketFactory");
    properties.setProperty("mail.pop3.socketFactory.fallback", "true");
    properties.setProperty("mail.pop3.port", portS);
    properties.setProperty("mail.pop3.socketFactory.port", portS);
    URLName url = new URLName("pop3s", configuration.getServer(), port, "",
        configuration.getUsername(), configuration.getPassword());

    Session session = Session.getInstance(properties, null);
    store = session.getStore(url);
    store.connect();
    folder = store.getFolder(configuration.getFolderName());
    folder.open(Folder.READ_WRITE);
  } catch (MessagingException e) {
    LOGGER.error("error - cannot connect to mail server", e);
    throw new ConnectorException(e);
  }
}
 
开发者ID:Cognifide,项目名称:bobcat,代码行数:27,代码来源:Pop3SecureConnector.java

示例13: getMessages

import javax.mail.Folder; //导入依赖的package包/类
protected Message[] getMessages(Folder folder, DeleteMailRequest request) throws MessagingException {

    if (request.getMails() != null) {
      LOGGER.debug("delete mails: {}", request.getMails());

      List<String> messageIds = collectMessageIds(request.getMails());
      return getMessagesByIds(folder, messageIds);

    } else if (request.getMessageIds() != null) {
      LOGGER.debug("delete mails with message ids: {}", request.getMessageIds());

      return getMessagesByIds(folder, request.getMessageIds());

    } else {
      LOGGER.debug("delete mails with message numbers: {}", request.getMessageNumbers());

      int[] numbers = request.getMessageNumbers().stream().mapToInt(i -> i).toArray();
      return folder.getMessages(numbers);
    }
  }
 
开发者ID:camunda,项目名称:camunda-bpm-mail,代码行数:21,代码来源:DeleteMailConnector.java

示例14: deleteAllEmails

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

示例15: isMailReceived

import javax.mail.Folder; //导入依赖的package包/类
/**
 * Check whether email received by reading the emails.
 *
 * @param protocol to connect to the store
 * @param user whose mail store should be connected
 * @param subject the subject of the mail to search
 * @return
 * @throws MessagingException when unable to connect to the store
 */
public static boolean isMailReceived(String protocol, GreenMailUser user, String subject)
        throws MessagingException {
    Store store = getConnection(user, protocol);
    Folder folder = store.getFolder(EMAIL_INBOX);
    folder.open(Folder.READ_ONLY);
    boolean isReceived = false;
    Message[] messages = folder.getMessages();
    for (Message message : messages) {
        if (message.getSubject().contains(subject)) {
            log.info("Found the Email with Subject : " + subject);
            isReceived = true;
            break;
        }
    }
    return isReceived;
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:26,代码来源:GreenMailServer.java


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