KickJava   Java API By Example, From Geeks To Geeks.

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


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

17 package org.columba.mail.folder.mailboximport;
18
19 import java.io.BufferedReader JavaDoc;
20 import java.io.File JavaDoc;
21 import java.io.FileReader JavaDoc;
22
23 import org.columba.api.command.IWorkerStatusController;
24 import org.columba.mail.folder.IMailbox;
25 import org.columba.mail.folder.mh.MHMessageFileFilter;
26
27 /**
28  * @author frd
29  *
30  * To change this generated comment go to
31  * Window>Preferences>Java>Code Generation>Code and Comments
32  */

33 public class MHImporter extends AbstractMailboxImporter {
34     public MHImporter() {
35         super();
36     }
37
38     /**
39  * @param destinationFolder
40  * @param sourceFile
41  */

42     public MHImporter(IMailbox destinationFolder, File JavaDoc[] sourceFiles) {
43         super(destinationFolder, sourceFiles);
44     }
45
46     public int getType() {
47         return TYPE_DIRECTORY;
48     }
49
50     /* (non-Javadoc)
51  * @see org.columba.mail.folder.mailboximport.AbstractMailboxImporter#importMailbox(java.io.File, org.columba.api.command.IWorkerStatusController)
52  */

53     public void importMailboxFile(File JavaDoc directory,
54         IWorkerStatusController worker, IMailbox destFolder)
55         throws Exception JavaDoc {
56         File JavaDoc[] list = directory.listFiles(MHMessageFileFilter.getInstance());
57
58         for (int i = 0; i < list.length; i++) {
59             File JavaDoc file = list[i];
60
61             String JavaDoc name = file.getName();
62
63             if (name.equals(".") || name.equals("..")) {
64                 continue;
65             }
66
67             if (name.startsWith(".")) {
68                 continue;
69             }
70
71             if ((file.exists()) && (file.length() > 0)) {
72                 importMessage(file, worker);
73             }
74         }
75     }
76
77     protected void importMessage(File JavaDoc file, IWorkerStatusController worker)
78         throws Exception JavaDoc {
79         StringBuffer JavaDoc strbuf = new StringBuffer JavaDoc();
80
81         BufferedReader JavaDoc in = new BufferedReader JavaDoc(new FileReader JavaDoc(file));
82         String JavaDoc str;
83         strbuf = new StringBuffer JavaDoc();
84
85         while ((str = in.readLine()) != null) {
86             strbuf.append(str + "\n");
87         }
88
89         in.close();
90
91         saveMessage(strbuf.toString(), worker, getDestinationFolder());
92     }
93     
94     public String JavaDoc getDescription() {
95         //TODO (@author fdietz): Add proper description here
96
return "";
97     }
98 }
99
Popular Tags