001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018:
019: package org.columba.mail.folder.mailboximport;
020:
021: import java.io.BufferedReader;
022: import java.io.File;
023: import java.io.FileReader;
024:
025: import org.columba.api.command.IWorkerStatusController;
026: import org.columba.mail.folder.IMailbox;
027: import org.columba.mail.util.MailResourceLoader;
028:
029: /**
030: * @version 1.0
031: * @author
032: */
033: public class MozillaImporter extends AbstractMailboxImporter {
034: public MozillaImporter() {
035: super ();
036: }
037:
038: public MozillaImporter(IMailbox destinationFolder,
039: File[] sourceFiles) {
040: super (destinationFolder, sourceFiles);
041: }
042:
043: public int getType() {
044: return TYPE_FILE;
045: }
046:
047: public void importMailboxFile(File file,
048: IWorkerStatusController worker, IMailbox destFolder)
049: throws Exception {
050: int count = 0;
051: boolean sucess = false;
052:
053: StringBuffer strbuf = new StringBuffer();
054:
055: BufferedReader in = new BufferedReader(new FileReader(file));
056: String str;
057:
058: // parse line by line
059: while ((str = in.readLine()) != null) {
060: // if user cancelled task exit immediately
061: if (worker.cancelled()) {
062: return;
063: }
064:
065: // if line doesn't start with "From" or line length is 0
066: // -> save everything in StringBuffer
067: if (!str.startsWith("From ") || str.length() == 0) {
068: strbuf.append(str + "\n");
069: } else {
070: // line contains "-" (mozilla mbox style)
071: // -> import message in Columba
072: if (str.indexOf("-") != -1) {
073: if (strbuf.length() != 0) {
074: // found new message
075: saveMessage(strbuf.toString(), worker,
076: getDestinationFolder());
077:
078: count++;
079:
080: sucess = true;
081: }
082:
083: strbuf = new StringBuffer();
084: } else {
085: strbuf.append(str + "\n");
086: }
087: }
088: }
089:
090: // save last message, because while loop aborted before being able to
091: // save message
092: if (sucess && strbuf.length() > 0) {
093: saveMessage(strbuf.toString(), worker,
094: getDestinationFolder());
095: }
096:
097: in.close();
098: }
099:
100: public String getDescription() {
101: return MailResourceLoader.getString("dialog", "mailboximport",
102: "Mozilla_description");
103: }
104: }
|