01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
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;
20: import java.io.File;
21: import java.io.FileReader;
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[] 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 directory,
54: IWorkerStatusController worker, IMailbox destFolder)
55: throws Exception {
56: File[] list = directory.listFiles(MHMessageFileFilter
57: .getInstance());
58:
59: for (int i = 0; i < list.length; i++) {
60: File file = list[i];
61:
62: String name = file.getName();
63:
64: if (name.equals(".") || name.equals("..")) {
65: continue;
66: }
67:
68: if (name.startsWith(".")) {
69: continue;
70: }
71:
72: if ((file.exists()) && (file.length() > 0)) {
73: importMessage(file, worker);
74: }
75: }
76: }
77:
78: protected void importMessage(File file,
79: IWorkerStatusController worker) throws Exception {
80: StringBuffer strbuf = new StringBuffer();
81:
82: BufferedReader in = new BufferedReader(new FileReader(file));
83: String str;
84: strbuf = new StringBuffer();
85:
86: while ((str = in.readLine()) != null) {
87: strbuf.append(str + "\n");
88: }
89:
90: in.close();
91:
92: saveMessage(strbuf.toString(), worker, getDestinationFolder());
93: }
94:
95: public String getDescription() {
96: //TODO (@author fdietz): Add proper description here
97: return "";
98: }
99: }
|