KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > folder > mailboximport > PegasusMailImporter


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.dation, Inc., 59 Temple Place - Suite 330, Boston, MA
18
// 02111-1307, USA.
19

20 package org.columba.mail.folder.mailboximport;
21
22 import java.io.BufferedReader JavaDoc;
23 import java.io.File JavaDoc;
24 import java.io.FileReader JavaDoc;
25
26 import org.columba.api.command.IWorkerStatusController;
27 import org.columba.mail.folder.IMailbox;
28 import org.columba.mail.util.MailResourceLoader;
29
30 /**
31  * @version 1.0
32  * @author
33  */

34 public class PegasusMailImporter extends AbstractMailboxImporter {
35     public PegasusMailImporter() {
36         super();
37     }
38
39     public PegasusMailImporter(IMailbox destinationFolder, File JavaDoc[] sourceFiles) {
40         super(destinationFolder, sourceFiles);
41     }
42
43     public int getType() {
44         return TYPE_FILE;
45     }
46
47     public void importMailboxFile(File JavaDoc file, IWorkerStatusController worker,
48             IMailbox destFolder) throws Exception JavaDoc {
49         int count = 0;
50         boolean sucess = false;
51
52         StringBuffer JavaDoc strbuf = new StringBuffer JavaDoc();
53
54         BufferedReader JavaDoc in = new BufferedReader JavaDoc(new FileReader JavaDoc(file));
55         String JavaDoc str;
56
57         // parse line by line
58
while ((str = in.readLine()) != null) {
59             // if user cancelled task exit immediately
60
if (worker.cancelled() == true) {
61                 return;
62             }
63
64             // if line doesn't start with "From ???@???" or line length is 0
65
// -> save everything in StringBuffer
66
if ((str.startsWith("From ???@???") == false) ||
67                     (str.length() == 0)) {
68                 strbuf.append(str + "\n");
69             } else {
70                 if (strbuf.length() != 0) {
71                     // found new message
72
saveMessage(strbuf.toString(), worker,
73                         getDestinationFolder());
74
75                     count++;
76
77                     sucess = true;
78                 }
79
80                 strbuf = new StringBuffer JavaDoc();
81             }
82         }
83
84         // save last message, because while loop aborted before being able to
85
// save message
86
if ((sucess == true) && (strbuf.length() > 0)) {
87             saveMessage(strbuf.toString(), worker, getDestinationFolder());
88         }
89
90         in.close();
91     }
92
93     public String JavaDoc getDescription() {
94         return MailResourceLoader.getString("dialog", "mailboximport",
95             "PegasusMail_description");
96     }
97 }
98
Popular Tags