📄 quickviewer.java
字号:
attachPane_.validate(); attachScroller_.revalidate(); } }//............................................................ /** * Distribute events from other sources to action listeners and distributors. * * @param event the event to distribute */ public void distribute( ActionEvent event ) { actionListener_.actionPerformed( event ); }//............................................................ // UNDONE Currently only showing certificates of first signer... // Need a better, more versatile dialog... public void showSigners() { ICEMail.getSMIMELibrary().showSigners( message_ ); } public void showEnvelope() { ICEMail.getSMIMELibrary().showEnvelope( message_ ); }//............................................................ public void loadLayoutProperties() { hdrSplit_.setDividerLocation( Configuration.getDividerLocation( Configuration.P_MSG_VIEWER_HDR_DIVIDER, 75 ) ); bodyDivLoc_ = Configuration.getDividerLocation( Configuration.P_MSG_VIEWER_BODY_DIVIDER, 75 ); } public void saveLayoutProperties() { Configuration.saveDividerLocation( Configuration.P_MSG_VIEWER_HDR_DIVIDER, hdrSplit_.getDividerLocation() ); Configuration.saveDividerLocation( Configuration.P_MSG_VIEWER_BODY_DIVIDER, bodyDivLoc_ ); }//............................................................ /** * Set the header text area from the contents of the current message. * Either the standard headers or all headers are decoded from the current message * into a string, which is then used to reset the contents of the header text area. */ private void getHeaderComponent() { if ( Package.DEBUG && Package.isTraceable( "QuickViewer" ) ) { System.out.println( "QuickViewer.getHeaderComponent()" ); } // clear previous headers if current message is null if ( outerMessage_ == null ) { hdrTextArea_.setText( null ); // removes all contents return; } // pull off the basic headers if present, i.e. date, addresses, subject, etc StringBuffer xtext = new StringBuffer(); Address[] xaddresses = null; try { xaddresses = outerMessage_.getFrom(); if ( xaddresses != null && xaddresses.length > 0 ) { xtext.append( ICEMail.getBundle().getString( "QuickViewer.From" ) ); xtext.append( MessageUtilities.decodeAddresses( xaddresses ) ); xtext.append( '\n' ); } } catch ( MessagingException xex ) { } try { xtext.append( ICEMail.getBundle().getString( "QuickViewer.Subject" ) ); xtext.append( outerMessage_.getSubject() ); xtext.append( '\n' ); } catch ( MessagingException xex ) { } try { Date xdate = outerMessage_.getSentDate(); if ( xdate != null ) { xtext.append( ICEMail.getBundle().getString( "QuickViewer.Date" ) ); xtext.append( ICEMail.getDateFormat().format( xdate ) ); xtext.append( '\n' ); } } catch ( MessagingException xex ) { } try { xaddresses = outerMessage_.getRecipients( Message.RecipientType.TO ); if ( xaddresses != null && xaddresses.length > 0 ) { xtext.append( ICEMail.getBundle().getString( "QuickViewer.To" ) ); xtext.append( MessageUtilities.decodeAddresses( xaddresses ) ); xtext.append( '\n' ); } } catch ( MessagingException xex ) { } try { xaddresses = outerMessage_.getRecipients( Message.RecipientType.CC ); if ( xaddresses != null && xaddresses.length > 0 ) { xtext.append( ICEMail.getBundle().getString( "QuickViewer.Cc" ) ); xtext.append( MessageUtilities.decodeAddresses( xaddresses ) ); xtext.append( '\n' ); } } catch ( MessagingException xex ) { } try { xaddresses = outerMessage_.getRecipients( Message.RecipientType.BCC ); if ( xaddresses != null && xaddresses.length > 0 ) { xtext.append( ICEMail.getBundle().getString( "QuickViewer.Bcc" ) ); xtext.append( MessageUtilities.decodeAddresses( xaddresses ) ); xtext.append( '\n' ); } } catch ( MessagingException xex ) { } try { xaddresses = outerMessage_.getReplyTo(); if ( xaddresses != null && xaddresses.length > 0 ) { xtext.append( ICEMail.getBundle().getString( "QuickViewer.Reply" ) ); xtext.append( MessageUtilities.decodeAddresses( xaddresses ) ); xtext.append( '\n' ); } } catch ( MessagingException xex ) { } // now the extra headers if desired if ( showFullHeaders_ ) { // We use getHeadersWithFrom() to pick up the 'From ' header // line if there is one. try { InternetHeaders xheaders = MessageUtilities.getHeadersWithFrom( outerMessage_ ); xheaders.removeHeader( "date" ); xheaders.removeHeader( "from" ); xheaders.removeHeader( "to" ); xheaders.removeHeader( "cc" ); xheaders.removeHeader( "bcc" ); xheaders.removeHeader( "reply-to" ); xheaders.removeHeader( "subject" ); Enumeration xenum = xheaders.getAllHeaderLines(); while ( xenum.hasMoreElements() ) { xtext.append( xenum.nextElement() ); xtext.append( '\n' ); } } catch ( MessagingException xex ) { } } if ( xtext.charAt( xtext.length() - 1 ) == '\n' ) { xtext.setLength( xtext.length() - 1 ); } hdrTextArea_.setText( xtext.toString() ); hdrTextArea_.setCaretPosition( 0 ); } private void establishEditorPane( Part bodyPart ) { if ( Package.DEBUG && Package.isTraceable( "QuickViewer" ) ) { System.out.println( "QuickViewer.establishEditorPane(p)" ); } if ( editorPane_ != null ) { addAttachment( bodyPart ); } else { // UNDONE - if content type we can't edit, attach... JEditorPane pane = null; EditorKit editor = null; Document doc = null; try { ContentType xct = MessageUtilities.getContentType( bodyPart ); if ( xct.match( "text/html" ) ) { pane = new JEditorPane(); pane.setContentType( "text/html" ); pane.setEditable( false ); editor = pane.getEditorKit(); doc = editor.createDefaultDocument(); pane.addHyperlinkListener( new IHyperlinkListener() ); } else if ( xct.match( "text/rtf" ) ) { pane = new JEditorPane(); pane.setContentType( "text/rtf" ); editor = pane.getEditorKit(); doc = editor.createDefaultDocument(); } else if ( xct.match( "text/*" ) ) { doc = new DefaultStyledDocument(); pane = new JTextPane( (StyledDocument)doc ); editor = pane.getEditorKit(); } if ( pane != null && doc != null ) { BufferedReader xreader = MessageUtilities.getTextReader( bodyPart ); editor.read( xreader, doc, 0 ); xreader.close(); /* ** NOTE This code is great, IF the html pane is adequate. ** The current version (JDK 1.1.6), is quite lame, and ** if the html is bad, it hangs the program. Thus, we ** may turn this on in a later more robust release. ** // Check to see if this looks like some valid HTML. // If so, we will compensate for the poor mailer. // UNDONE This should be controllable via a property. // if ( pane instanceof JTextPane ) { StringWriter contWrt = new StringWriter(); int len = doc.getLength(); if ( len > 6 ) len = 6; editor.write( contWrt, doc, 0, len ); if ( contWrt.toString(). equalsIgnoreCase( "<html>" ) ) { len = doc.getLength(); contWrt = new StringWriter(); editor.write( contWrt, doc, 0, len ); String contStr = pane = new JEditorPane(); pane.setContentType( "text/html" ); editor = pane.getEditorKit(); doc = editor.createDefaultDocument(); StringReader contRdr = new StringReader( contWrt.toString() ); editor.read( contRdr, doc, 0 ); } } ** */ pane.setDocument( doc ); } //undo_ = new UndoManager(); doc.addUndoableEditListener( undo_ ); editorPane_ = pane; } catch ( IOException ex ) { ex.printStackTrace( System.err ); editorPane_ = null; } catch ( BadLocationException ex ) { ex.printStackTrace( System.err ); editorPane_ = null; } catch ( MessagingException ex ) { ex.printStackTrace( System.err ); editorPane_ = null; } } } private void parseMessagePart( Part bodyPart ) { if ( Package.DEBUG && Package.isTraceable( "QuickViewer" ) ) { System.out.println( "QuickViewer.parseMessagePart(p)" ); } if ( bodyPart == null ) { return; } //------------ // now get a content viewer for the main type... //------------ try { int xpartSize = bodyPart.getSize(); ContentType xpartType = MessageUtilities.getContentType( bodyPart ); if ( Package.DEBUG && Debug_ > 5 ) { System.out.println("----------------------------------------"); System.out.println( "Content-Type: " + xpartType.toString() ); System.out.println( "Size: " + xpartSize ); System.out.println( "Class: " + bodyPart.getClass().toString() ); } if ( xpartType.match( "multipart/*" ) ) { // ----------------------------------------------------- // ---------- M U L T I P A R T // ----------------------------------------------------- Multipart mPart = (Multipart)MessageUtilities.getPartContent( bodyPart ); int partCount = mPart.getCount(); for ( int i = 0, row = 0 ; i < partCount ; i++ ) { parseMessagePart( mPart.getBodyPart(i) ); } } else if ( xpartType.match( "message/*" ) ) { // ----------------------------------------------------- // ---------- M E S S A G E // ----------------------------------------------------- try { Part part = (Message)MessageUtilities.getPartContent( bodyPart ); parseMessagePart( part ); } catch ( java.lang.SecurityException ex ) { try { MimeMessage msg = new MimeMessage( ICEMail.getDefaultSession(), bodyPart.getInputStream() ); parseMessagePart( msg ); } catch ( IOException ex1 ) { ex1.printStackTrace(); } catch ( MessagingException ex1 ) { ex1.printStackTrace(); } } } else if ( xpartSize > maxBodyPartSize_ ) { // ----------------------------------------------------- // ---------- T O O L A R G E // ----------------------------------------------------- // UNDONE - if text, grab first 16K and display... addAttachment( bodyPart ); } else if ( xpartType.match( "text/*" ) ) { // ----------------------------------------------------- // ---------- T E X T / * // ----------------------------------------------------- establishEditorPane( bodyPart ); } else { // ----------------------------------------------------- // ---------- O T H E R // ----------------------------------------------------- addAttachment( bodyPart ); } } catch ( Exception ex ) { if ( editorPane_ != null ) { // UNDONE Figure out how to implement this... // addAttachment( ex ); ex.printStackTrace( System.err ); } else { JEditorPane pane = new JTextPane( new DefaultStyledDocument() ); ByteArrayOutputStream xbaos = new ByteArrayOutputStream(); ex.printStackTrace( new PrintWriter( xbaos ) ); pane.setText( "INTERNAL ERROR processing message part.\n\n" + xbaos ); editorPane_ = pane; } } } private void addAttachment( Part bodyPart ) { if ( Package.DEBUG && Package.isTraceable( "QuickViewer" ) ) { System.out.println( "QuickViewer.addAttachment(p)" ); } boolean isHTML = false; boolean isWord = false; ImageIcon icon = QuickViewer.AttUnknownIcon; int partSize = -1; String name = "Untitled"; ContentType xct = new ContentType(); try { partSize = bodyPart.getSize(); name = MessageUtilities.getFileName( bodyPart ); xct = MessageUtilities.getContentType( bodyPart ); if ( name == null || name.length() < 1 ) { name = bodyPart.getDescription(); if ( name == null ) { name = "Untitled"; } else if ( name.length() < 1 ) { name = "Untitled"; } else if ( name.length() > 48 ) { name = name.substring( 0, 48 ); } } icon = getMailcapIcon( bodyPart.getDataHandler() ); } catch ( ParseException ex ) { ex.printStackTrace( System.err ); } catch ( MessagingException ex ) { ex.printStackTrace( System.err ); } String btnName = name + " " + partSize + " bytes"; if ( attachPane_ == null ) { attachPane_ = theAttachPane_; theAttachPane_.removeAll(); } if ( Package.DEBUG && Debug_ > 0 ) { System.out.println( "QuickViewer.addAttachment(p): n-" + name ); } JButton btn = new JButton( btnName, icon ); Insets mgn = btn.getMargin(); mgn.left = 2; mgn.right = 6; btn.setMargin(mgn); String tip = xct.getBaseType(); if ( xct.getParameter( "charset" ) != null ) { tip = tip + "; " + xct.getParameter( "charset" ); } btn.setToolTipText( tip ); btn.addActionListener( new ViewAttachementAction( bodyPart ) ); btn.addMouseListener( new IMouseAdapter( btn, popupMenu_, bodyPart ) ); attachPane_.add( btn ); } private void viewPartProperties( Part part ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -