PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : thebat2mbox - Automatisierter Export



sPUNK
04.09.03, 23:57
Hi!

Aus lauter Langeweile habe ich ein kleines Java Programm geschrieben, um meine The Bat! Konten mühelos ins mbox Format konvertieren zu können und zwar samt der ganzen Ordnerstruktur. Ich poste mal hier den Quellcode, falls einige Interesse daran haben und es brauchen können.

Ausserdem habe ich hier die .class Dateien abgelegt, damit Ihr nicht mehr selber kompilieren müsst:

http://people.freenet.de/derspunk/code/cccb_thebat2mbox_0.1a.rar

Alles was Ihr braucht ist eigentlich ein funktionierendes Java Runtime Environment (JRE) und ein richtig gesetzter CLASSPATH (Kurzanleitung unten)


/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.

* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

/**
* @author sPUNK <sPUNK@myrealbox.com>
* @license http://www.gnu.org/licenses/gpl.txt
* @version 0.1a
* @created: Sep 09, 2003
* @last update: Sep 09, 2003
* @updated by: sPUNK
*/

import java.io.*;
import java.util.*;

class Parser {

private String thebat = "\"C:\\Programme\\The Bat!\\thebat.exe\"";

private File input,
output;

private Vector accounts;


public Parser(File input, File output) {

this.input = input;
this.output = output;

accounts = new Vector();

scanForAccounts();

start();

} // public Parser(File input, File output)


private void parse(File idir) {

File[] list = idir.listFiles();

for (int i=0; i < list.length; i++) {

if (list[i].isDirectory()) {

String part0 = list[i].getPath().substring(input.getPath().length(), list[i].getPath().length());
String part1 = thebat +" /EXPORTF=\"\\"+ part0 +"\\;UNIX;O=\"";
String part2 = "\""+ output + part0 +"\\"+ list[i].getName() +".mbox\"";

String command = part1 + part2;

try {
Runtime.getRuntime().exec(command);
} catch (Exception e) {
System.out.println("Error : "+ e.toString());

}

parse(list[i]);
}

}

} // private void parse(File idir)


private void start() {

for (int i=0; i < accounts.size(); i++) {

System.out.println("Info : Parsing account "+ ((File)accounts.get(i)).getName());
parse((File) accounts.get(i));
}
}


private void scanForAccounts() {

File[] list = input.listFiles();

for (int i=0; i < list.length; i++) {

if (list[i] .isDirectory()) {
accounts.add(list[i]);
System.out.println("Info : Found account "+ list[i].getName());
}
}

if (accounts.size() == 0) {
System.out.println("Error : No mailaccounts found");
System.exit(1);
}

System.out.println();

} // private void scanForAccounts()

} // class Parser


public class thebat2mbox {

public static void main(String[] args) {

if (args.length != 2) {

System.out.println("Usage : java thebat2mbox [The Bat! Maildirectory] [Outputdirectory]");
System.out.println("Example : java thebat2mbox \"C:\\Programme\\The Bat!\\MAIL\\\" C:\\Temp");
System.exit(1);

} else if (args.length == 2) {

File input = new File(args[0]);
File output = new File(args[1]);

if (input.isDirectory() && input.getName().equals("MAIL") && output.isDirectory()) {

new Parser(input, output);

} else {

System.out.println("Usage : java thebat2mbox [The Bat! Maildirectory] [Outputdirectory]");
System.out.println("Example : java thebat2mbox \"C:\\Programme\\The Bat!\\MAIL\\\" C:\\Temp");
System.exit(1);

}
}

} // public static void main(String[] args)

} // public class thebat2mbox

MfG

sPUNK

P.S.: Wie gesagt, habe ich das ganze aus Langeweile gemacht und weil ich nichts anderes gefunden habe. Das Programm ist weder optimiert, ausgereift, etc. Bei mir hat es funktioniert und seinen Dienst erledigt

Kurzanleitung

CLASSPATH=.;C:\Programme\Java\j2re1.4.2\lib;
PATH=C:\Programme\Java\j2re1.4.2\bin;

- Obiges .rar mit den Klassen entpacken nach z.B. C:\Temp
- Eingabeaufforderung öffnen und nach C:\Temp wechseln
- TheBat! starten !!!
- java thebat2mbox C:\Programme\The Bat!\MAIL C:\Temp

Die Pfade natürlich an Eure Umgebung anpassen!