📄 sendmessagethread.java
字号:
/*** $Id: SendMessageThread.java,v 1.7 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 java.util.Date;import java.awt.Container;import java.awt.Dimension;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Point;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JProgressBar;import javax.mail.Address;import javax.mail.Folder;import javax.mail.Message;import javax.mail.MessagingException;import javax.mail.Store;import javax.mail.Transport;import org.icemail.util.AWTUtilities; import org.icemail.util.ComponentFactory; import org.icemail.util.UserProperties;/** * SendMessageThread presents a dialog which displays the progress of sending * a specific message. * <p> * The message is checked and completed before sending. It may also be saved * into the configured 'sent' folder. * <p> * After the message is sent, this thread also disposes of the parent frame, i.e. composer. * * @see ComposeFrame */public class SendMessageThread extends Thread{ private ComposeFrame frame_; private Message message_; private JDialog dialog_; private JProgressBar progress_; /** * Create a thread of execution for sending the given message, and saving * the message to the configured 'sent' folder if necessary. * * @param frame frame of the message composer * @param message message to send */ public SendMessageThread( ComposeFrame frame, Message message ) throws MessagingException { super(); frame_ = frame; message_ = message; // verify the message contents now, before sending Address[] xaddresses = message_.getAllRecipients(); if ( xaddresses == null || xaddresses.length < 1 ) { String xstring = ICEMail.getBundle().getString( "Exception.noRecipients" ); throw new MessagingException( xstring ); } } /** * <p> * Implementation of Thread.run() */ public void run() { dialog_ = new JDialog( frame_, false ); dialog_.setTitle( ICEMail.getBundle().getString( "SendMessage.Title" ) ); Container content = dialog_.getContentPane(); content.setLayout( new GridBagLayout() ); JLabel lbl; lbl = ComponentFactory.getLabel( ICEMail.getBundle(), "SendMessage.Sending" ); lbl.setHorizontalAlignment( JLabel.CENTER ); AWTUtilities.constrain( content, lbl, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, 0, 0, 0, 1, 1.0, 0.0 ); progress_ = new JProgressBar(); progress_.setValue( 0 ); progress_.setMinimum( 0 ); progress_.setMaximum( 100 ); AWTUtilities.constrain( content, progress_, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, 0, 1, 0, 1, 1.0, 0.0 ); dialog_.pack(); Dimension sz = dialog_.getSize(); if ( sz.width < 350 ) { sz.width = 350; dialog_.setSize( sz ); } Point loc = AWTUtilities.computeDialogLocation( dialog_ ); dialog_.setLocation( loc.x, loc.y ); dialog_.show(); String xstate = "building"; try { // set required headers, if necessary Date xsentdate = message_.getSentDate(); if ( xsentdate == null ) { message_.setSentDate( new Date() ); } progress_.setValue( 10 ); Address[] xaddresses = message_.getFrom(); if ( xaddresses == null || xaddresses.length < 1 ) { message_.setFrom( MessageUtilities.getDefaultFromAddress() ); xaddresses = message_.getFrom(); } progress_.setValue( 20 ); // FIXME; how to set Sender?? progress_.setValue( 30 ); xaddresses = message_.getReplyTo(); if ( xaddresses == null || xaddresses.length < 1 ) { xaddresses = new Address[1]; xaddresses[0] = MessageUtilities.getDefaultReplyTo(); message_.setReplyTo( xaddresses ); } progress_.setValue( 40 ); xstate = "sending"; Transport.send( message_ ); progress_.setValue( 90 ); xstate = "saving to sent"; String xpath = UserProperties.getProperty( "sentFolderPath", null ); if ( xpath != null && xpath.length() > 0 ) { MailUtilities.saveMessage( message_, xpath ); } progress_.setValue( 100 ); dialog_.dispose(); frame_.dispose( true ); } catch ( MessagingException ex ) { dialog_.dispose(); Object[] xargs = new Object[2]; xargs[0] = xstate; xargs[1] = ex.getMessage(); ComponentFactory.showDialog( ICEMail.getBundle(), "SendMessage.SendError", 0, JOptionPane.ERROR_MESSAGE, xargs ); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -