KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > jmail > base > MessageSourceFrame


1 package org.lucane.applications.jmail.base;
2
3 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
4  * This file is part of JMail *
5  * Copyright (C) 2002-2003 Yvan Norsa <norsay@wanadoo.fr> *
6  * *
7  * JMail is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * any later version. *
11  * *
12  * JMail is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License along *
18  * with JMail; if not, write to the Free Software Foundation, Inc., *
19  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20  * *
21  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

22
23 import java.io.*;
24 import javax.mail.*;
25 import javax.mail.internet.*;
26 import javax.swing.*;
27
28 /** Simple frame allowing to view a message's source */
29 final class MessageSourceFrame extends JFrame
30 {
31     private Message msg;
32     
33     private JPanel panel;
34     private JTextArea area;
35     private JScrollPane scrollPane;
36
37     /** Constructor
38      * @param subject subject of the mail
39      * @param msg message
40      */

41     protected MessageSourceFrame(String JavaDoc subject, Message msg)
42     {
43     super(subject);
44
45     this.msg = msg;
46
47     panel = new JPanel();
48
49     area = new JTextArea();
50     area.setEditable(false);
51     fillArea();
52     area.setCaretPosition(0);
53
54     area.setRows(30);
55     area.setColumns(40);
56     
57     scrollPane = new JScrollPane(area, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
58     panel.add(scrollPane);
59
60     setContentPane(panel);
61
62     setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
63
64     pack();
65     setResizable(false);
66     setVisible(true);
67     }
68
69     /** Copies the mail in a temporary files and display its content */
70     private void fillArea()
71     {
72     try
73     {
74         String JavaDoc fileName = ((MimeMessage)msg).getMessageID();
75         fileName = fileName.substring(1, 10);
76
77         File file = File.createTempFile(fileName, null);
78
79         FileOutputStream out = new FileOutputStream(file);
80         msg.writeTo(out);
81         out.close();
82
83         BufferedReader in = new BufferedReader(new FileReader(file));
84         
85         String JavaDoc line = new String JavaDoc();
86
87         while((line = in.readLine()) != null)
88         area.append(line + "\n");
89
90         in.close();
91
92         file.delete();
93     }
94
95     catch(Exception JavaDoc e)
96     {
97         e.printStackTrace();
98     }
99     }
100 }
101
Popular Tags