當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。