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


Java Store.isConnected方法代碼示例

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


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

示例1: closeStoreConnection

import javax.mail.Store; //導入方法依賴的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

示例2: reconnectStoreIfClosed

import javax.mail.Store; //導入方法依賴的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

示例3: getStore

import javax.mail.Store; //導入方法依賴的package包/類
private Store getStore(EmailAccount account) throws MessagingException {
    Store store = null;
    if (storeConnections == null) {
//      Log.d("rgai", "CREATING STORE CONTAINER");
      storeConnections = new HashMap<EmailAccount, Store>();
    } else {
      if (storeConnections.containsKey(account)) {
        store = storeConnections.get(account);
//        Log.d("rgai", "STORE EXISTS");
      }
    }
    
    if (store == null || !store.isConnected()) {
//      Log.d("rgai", "CREATING STORE || reconnection store");
      store = getStore();
      storeConnections.put(account, store);
    }
    
    return store;
  }
 
開發者ID:k-kojak,項目名稱:yako,代碼行數:21,代碼來源:SimpleEmailMessageProvider.java

示例4: closeStore

import javax.mail.Store; //導入方法依賴的package包/類
/**
 * Handy method to do the try catch try of closing a mail store and folder.
 * @param mailStore
 * @param mailFolder
 */
private void closeStore(final Store mailStore, final Folder mailFolder)  {
    try {
        if (mailFolder != null && mailFolder.isOpen()) {
            mailFolder.close(true);
        }
    } catch (final MessagingException e) {
    	LogUtils.debugf(this, e, "Unable to close mail folder.");
    } finally {
        try {
            if (mailStore != null && mailStore.isConnected()) {
                mailStore.close();
            }
        } catch (final MessagingException e1) {
        	LogUtils.debugf(this, e1, "Unable to close message store.");
        }
    }
}
 
開發者ID:qoswork,項目名稱:opennmszh,代碼行數:23,代碼來源:MailTransportMonitor.java

示例5: ensureConnectedStore

import javax.mail.Store; //導入方法依賴的package包/類
private void ensureConnectedStore(Store store) throws MessagingException {
  if (!store.isConnected()) {
    LOGGER.debug("connect to sore");

    store.connect(configuration.getUserName(), configuration.getPassword());
  }
}
 
開發者ID:camunda,項目名稱:camunda-bpm-mail,代碼行數:8,代碼來源:MailService.java

示例6: getEmails

import javax.mail.Store; //導入方法依賴的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

示例7: testEmailConfiguration

import javax.mail.Store; //導入方法依賴的package包/類
/**
 * API to test the email configuration.
 * 
 * @param emailConfigData {@link EmailConfigurationData}
 * @return true or false based on the connection made successfully with the email setting passed
 * @throws MessagingException {@link MessagingException}
 * @throws AuthenticationFailedException {@link AuthenticationFailedException}
 */
public static boolean testEmailConfiguration(final EmailConfigurationData emailConfigData) throws MessagingException,
		AuthenticationFailedException {
	LOGGER.info("Enter method testEmailConfiguration.");
	boolean isBValidConfig = true;
	Store store = null;
	if (emailConfigData != null) {
		String serverType = emailConfigData.getServerType();
		LOGGER.debug("Server type :: " + serverType);
		if (emailConfigData.getIsSSL()) {
			if (IUtilCommonConstants.POP3_CONFIG.equalsIgnoreCase(serverType)) {
				store = connectWithPOP3SSL(emailConfigData);
			} else if (IUtilCommonConstants.IMAP_CONFIG.equalsIgnoreCase(serverType)) {
				store = connectWithIMAPSSL(emailConfigData);
			} else {
				LOGGER.error("Error in Server Type Configuration, only imap/pop3 is allowed.");
				throw new MessagingException("Error in Server Type Configuration, only imap/pop3 is allowed.");
			}
		} else {
			store = connectWithNonSSL(emailConfigData);
		}
	}
	if (store == null || !store.isConnected()) {
		LOGGER.error("Not able to establish connection. Please check settings.");
		isBValidConfig = false;
	}
	LOGGER.info("Exiting method testEmailConfiguration.");
	return isBValidConfig;
}
 
開發者ID:kuzavas,項目名稱:ephesoft,代碼行數:37,代碼來源:EmailUtil.java

示例8: connect

import javax.mail.Store; //導入方法依賴的package包/類
public synchronized static boolean connect (Store _store,
                                         String _protocol,
                                         String _host,
                                         int _port,
                                         String _user, String _password) {
    ConnectionPoint cp = getConnPoint(_store,
                                      _protocol,
                                      _host,
                                      _port,
                                      _user, _password);
    boolean connected = false;
    try {
        Store store = cp.getStore();
        if (!store.isConnected()) {
            cp.getStore().connect(_host, _port, _user, _password );
         }
        ++cp.connectionCount;
        LOGGER.debug("Connecting store: connectionCount = " + cp.connectionCount);
        connected = true;
    }
    catch (Exception e) {
    	connected = false;
    	if (LogThrottle.isReady("Syncstore1",240)) {
        LOGGER.warn("Could not connect..." + e.getMessage());
    	}
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    return connected;
}
 
開發者ID:trackplus,項目名稱:Genji,代碼行數:30,代碼來源:SyncStore.java

示例9: checkMessages

import javax.mail.Store; //導入方法依賴的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

示例10: getFlagChangesOfMessages

import javax.mail.Store; //導入方法依賴的package包/類
private MessageListResult getFlagChangesOfMessages(TreeSet<MessageListElement> loadedMessages) throws MessagingException {
  
  List<MessageListElement> emails = new LinkedList<MessageListElement>();
  Store store = getStore(account);
  
  if (store == null || !store.isConnected()) {
    return new MessageListResult(emails, MessageListResult.ResultType.ERROR);
  }
  IMAPFolder imapFolder = (IMAPFolder)store.getFolder(accountFolder.folder);
  imapFolder.open(Folder.READ_ONLY);
  UIDFolder uidFolder = imapFolder;
  
  long smallestUID = getSmallestUID(loadedMessages);

  Message messages[] = imapFolder.getMessagesByUID(smallestUID, UIDFolder.LASTUID);

  FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
  Message unseenMsgs[] = imapFolder.search(ft, messages);

  addMessagesToListAs(uidFolder, emails, unseenMsgs, loadedMessages, false);

  // searching for seen messages
  List<Message> seenMessages = new ArrayList<Message>(Arrays.asList(messages));
  for (int k = 0; k < unseenMsgs.length; k++) {
    String unseenUid = Long.toString(uidFolder.getUID(unseenMsgs[k]));
    for (int l = 0; l < seenMessages.size(); ) {
      String seenUid = Long.toString(uidFolder.getUID(seenMessages.get(l)));
      if (seenUid.equals(unseenUid)) {
        seenMessages.remove(l);
      } else {
        l++;
      }
    }
  }

  addMessagesToListAs(uidFolder, emails, seenMessages.toArray(new Message[seenMessages.size()]), loadedMessages, true);

  imapFolder.close(false);

  return new MessageListResult(emails, MessageListResult.ResultType.FLAG_CHANGE);
}
 
開發者ID:k-kojak,項目名稱:yako,代碼行數:42,代碼來源:SimpleEmailMessageProvider.java

示例11: close

import javax.mail.Store; //導入方法依賴的package包/類
public static void close(final Store store) {
    try {
        if (store != null && store.isConnected()) {
            store.close();
        }
    } catch (final Exception e) {
        // ignore
    }

}
 
開發者ID:salyh,項目名稱:elasticsearch-imap,代碼行數:11,代碼來源:IMAPUtils.java

示例12: checkStoreForTestConnection

import javax.mail.Store; //導入方法依賴的package包/類
protected void checkStoreForTestConnection(final Store store) {
    if (!store.isConnected()) {
        IMAPUtils.close(store);
        throw new RuntimeException("Store not connected");
    }

    if (!store.getURLName().getUsername().toLowerCase().startsWith("es_imapriver_unittest")) {
        IMAPUtils.close(store);
        throw new RuntimeException("User " + store.getURLName().getUsername() + " belongs not to a valid test mail connection");
    }
}
 
開發者ID:salyh,項目名稱:elasticsearch-imap,代碼行數:12,代碼來源:AbstractIMAPRiverUnitTest.java

示例13: getMessagesFromGreenMailFolder

import javax.mail.Store; //導入方法依賴的package包/類
/**
 * Method implementing to get the messages in the given folder.
 *
 * @param folderName Name of the folder to get mails.
 * @return Array of messages which contains inside the given folder.
 * @throws MessagingException MessagingException when fail to read the message from given folder.
 */
private Message[] getMessagesFromGreenMailFolder(String folderName) throws MessagingException {
    Properties properties = new Properties();
    properties.put(EmailTestConstant.MAIL_IMAP_PORT, EmailTestConstant.MAIL_IMAP_PORT_VALUE);
    Session session = Session.getInstance(properties);
    Store store = session.getStore(STORE_TYPE);
    store.connect(LOCALHOST, USER_NAME, PASSWORD);
    Folder folder = store.getFolder(folderName);
    folder.open(Folder.READ_ONLY);
    Message[] messages = folder.getMessages();
    if (store.isConnected()) {
        store.close();
    }
    return messages;
}
 
開發者ID:wso2,項目名稱:carbon-transports,代碼行數:22,代碼來源:EmailServerConnectorViaImapTestCase.java

示例14: getTestMessages

import javax.mail.Store; //導入方法依賴的package包/類
private List<Message> getTestMessages(final String account, final String password) throws Exception {
        final Properties props = new Properties();
//        if (protocol.endsWith("s")) {
//            props.put("mail.pop3.starttls.enable", Boolean.TRUE);
//            props.put("mail.imap.starttls.enable", Boolean.TRUE);
//        }
        props.setProperty("mail.imaps.socketFactory.class", DummySSLSocketFactory.class.getName());
        props.setProperty("mail.pop3s.socketFactory.class", DummySSLSocketFactory.class.getName());
        props.setProperty("mail.imap.socketFactory.fallback", "false");
        props.setProperty("mail.imaps.socketFactory.fallback", "false");
        props.setProperty("mail.pop3s.socketFactory.fallback", "false");

        final String timeout = "15000";
        props.setProperty("mail.imap.connectiontimeout", timeout);
        props.setProperty("mail.imaps.connectiontimeout", timeout);
        props.setProperty("mail.pop3.connectiontimeout", timeout);
        props.setProperty("mail.pop3s.connectiontimeout", timeout);
        props.setProperty("mail.imap.timeout", timeout);
        props.setProperty("mail.imaps.timeout", timeout);
        props.setProperty("mail.pop3.timeout", timeout);
        props.setProperty("mail.pop3s.timeout", timeout);

        Store store = null;
        try {
	        final Session session = Session.getInstance(props, null);
	        session.setDebug(verbose);
	        store = session.getStore(ServerSetup.PROTOCOL_IMAP);
	        store.connect(imapSetup.getBindAddress(), imapSetup.getPort(), account, password);
	        final Folder rootFolder = store.getFolder("INBOX");        
	        final List<Message> t = getMessages(rootFolder);
	        
	        final List<Message> clonedMsgs = new ArrayList<Message>();
	        for (Message msg : t) {
	        	MimeMessage clonedMsg = copy(session, msg);
	        	clonedMsgs.add(clonedMsg);	        
	        }
	        return clonedMsgs;
        } finally {
        	if (store != null && store.isConnected()) {
        		store.close();
        	}
        }
    }
 
開發者ID:rbattenfeld,項目名稱:arquillian-extension-mail-master,代碼行數:44,代碼來源:DefaultMailTestUtil.java


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