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.dation, Inc., 59 Temple Place - Suite 330, Boston, MA
018: // 02111-1307, USA.
019:
020: package org.columba.mail.folder.mailboximport;
021:
022: import java.io.BufferedReader;
023: import java.io.File;
024: import java.io.FileReader;
025:
026: import org.columba.api.command.IWorkerStatusController;
027: import org.columba.mail.folder.IMailbox;
028: import org.columba.mail.util.MailResourceLoader;
029:
030: /**
031: * @version 1.0
032: * @author
033: */
034: public class PegasusMailImporter extends AbstractMailboxImporter {
035: public PegasusMailImporter() {
036: super ();
037: }
038:
039: public PegasusMailImporter(IMailbox destinationFolder,
040: File[] sourceFiles) {
041: super (destinationFolder, sourceFiles);
042: }
043:
044: public int getType() {
045: return TYPE_FILE;
046: }
047:
048: public void importMailboxFile(File file,
049: IWorkerStatusController worker, IMailbox destFolder)
050: throws Exception {
051: int count = 0;
052: boolean sucess = false;
053:
054: StringBuffer strbuf = new StringBuffer();
055:
056: BufferedReader in = new BufferedReader(new FileReader(file));
057: String str;
058:
059: // parse line by line
060: while ((str = in.readLine()) != null) {
061: // if user cancelled task exit immediately
062: if (worker.cancelled() == true) {
063: return;
064: }
065:
066: // if line doesn't start with "From ???@???" or line length is 0
067: // -> save everything in StringBuffer
068: if ((str.startsWith("From ???@???") == false)
069: || (str.length() == 0)) {
070: strbuf.append(str + "\n");
071: } else {
072: if (strbuf.length() != 0) {
073: // found new message
074: saveMessage(strbuf.toString(), worker,
075: getDestinationFolder());
076:
077: count++;
078:
079: sucess = true;
080: }
081:
082: strbuf = new StringBuffer();
083: }
084: }
085:
086: // save last message, because while loop aborted before being able to
087: // save message
088: if ((sucess == true) && (strbuf.length() > 0)) {
089: saveMessage(strbuf.toString(), worker,
090: getDestinationFolder());
091: }
092:
093: in.close();
094: }
095:
096: public String getDescription() {
097: return MailResourceLoader.getString("dialog", "mailboximport",
098: "PegasusMail_description");
099: }
100: }
|