KickJava   Java API By Example, From Geeks To Geeks.

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


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.
18

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

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