📄 mailutilities.java
字号:
/*** $Id: MailUtilities.java,v 1.5 2001/05/07 12:37:22 kunugi Exp $**** Copyright (c) 2000-2001 Jeff Gay** on behalf of ICEMail.org <http://www.icemail.org>** Copyright (c) 1998-2000 by Timothy Gerard Endres** ** This program is free software.** ** You may redistribute it and/or modify it under the terms of the GNU** General Public License as published by the Free Software Foundation.** Version 2 of the license should be included with this distribution in** the file LICENSE, as well as License.html. If the license is not** included with this distribution, you may find a copy at the FSF web** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.**** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR** REDISTRIBUTION OF THIS SOFTWARE. */package org.icemail.mail;import javax.mail.AuthenticationFailedException;import javax.mail.Folder;import javax.mail.Message;import javax.mail.MessagingException;import javax.mail.Store;import javax.swing.JOptionPane;import org.icemail.util.ComponentFactory;/** * General mail store and folder utilities. */public class MailUtilities{ private MailUtilities() { }// used by SendMessageThread.java// used by StoreTreeNode.java// used by MailEventThread.java// used by FolderTreePanel.java// used by FolderTreeNode.java static public void setStoreConnected( Store store ) throws MessagingException { synchronized ( store ) { if ( ! store.isConnected() ) { for ( ; ; ) { try { store.connect(); MailEventThread.getInstance().addStore( store ); break; } catch ( AuthenticationFailedException ex ) { // UNDONE // I think what I need to do here is to somehow remove and // reinstall this node. This should cause the tree to decide // to call loadChildren() again when we are opened again. // if ( store.isConnected() ) store.close(); Object[] xargs = new Object[1]; xargs[0] = ex.toString(); int option = ComponentFactory.showDialog( ICEMail.getBundle(), "MailUtilities.Authenticate", 0, JOptionPane.ERROR_MESSAGE, xargs ); if ( option != JOptionPane.YES_OPTION ) { throw ex; } } } } } }// used by FolderTableModel.java// used by FolderTreePanel.java// used by MailEventThread.java// MessagePanel.java// QuickViewer.java static public void setFolderOpenAndReady( Folder f, int perm ) throws MessagingException { MailUtilities.setStoreConnected( f.getStore() ); synchronized ( f ) { if ( ! f.isOpen() ) { System.err.println( "OPEN FOLDER '" + f.getFullName() + "'" ); f.open( perm ); } } } /** * Save the given message to the given folder. */ static public void saveMessage( Message message, String path ) throws MessagingException { int xindex = path.indexOf( "/" ); if ( xindex > 0 ) { String xstoreName = path.substring( 0, xindex ); String xfolderPath = path.substring( xindex + 1 ); Store xstore = FolderTreePanel.getInstance().getStore( xstoreName ); if ( xstore != null ) { MailUtilities.setStoreConnected( xstore ); Folder xfolder = xstore.getFolder( xfolderPath ); if ( xfolder != null && xfolder.exists() ) { MailUtilities.setFolderOpenAndReady( xfolder, Folder.READ_WRITE ); Message[] xmessages = { message }; xfolder.appendMessages( xmessages ); xfolder.close( false ); } else { Object[] xargs = new Object[1]; xargs[0] = xfolderPath; String xstring = ICEMail.getBundle().getFormatString( "Exception.missingFolder", xargs ); throw new MessagingException( xstring ); } } else { Object[] xargs = new Object[1]; xargs[0] = xstoreName; String xstring = ICEMail.getBundle().getFormatString( "Exception.missingStore", xargs ); throw new MessagingException( xstring ); } } else { Object[] xargs = new Object[1]; xargs[0] = path; String xstring = ICEMail.getBundle().getFormatString( "Exception.invalidFolderPath", xargs ); throw new MessagingException( xstring ); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -