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 EvolutionImporter extends AbstractMailboxImporter {
034: public EvolutionImporter() {
035: super ();
036: }
037:
038: public EvolutionImporter(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() == true) {
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 ") == false)
068: || (str.length() == 0)) {
069: strbuf.append(str + "\n");
070: } else {
071: // line contains "@" (evolution mbox style) or
072: // -> import message in Columba
073: if (str.indexOf("@") != -1) {
074: if (strbuf.length() != 0) {
075: // found new message
076: saveMessage(strbuf.toString(), worker,
077: getDestinationFolder());
078:
079: count++;
080:
081: sucess = true;
082: }
083:
084: strbuf = new StringBuffer();
085: } else {
086: strbuf.append(str + "\n");
087: }
088: }
089: }
090:
091: // save last message, because while loop aborted before being able to
092: // save message
093: if ((sucess == true) && (strbuf.length() > 0)) {
094: saveMessage(strbuf.toString(), worker,
095: getDestinationFolder());
096: }
097:
098: in.close();
099: }
100:
101: public String getDescription() {
102: return MailResourceLoader.getString("dialog", "mailboximport",
103: "Evolution_description");
104: }
105: }
|