package org.fidonet;

import org.fidonet.config.Config;
import org.fidonet.protocol.binkp.*;
import org.fidonet.misc.Logger;
import org.fidonet.types.FTNAddr;

import java.io.*;

public class JFtn {

    static void Help() {
        System.out.println("java ftn usage:");
        System.out.println("jftn <action>:");
        System.out.println("    help - show this help");
        System.out.println("    toss - toss incoming echomail");
    }

    public static void main(String[] args) throws IOException {

        final long starttime = System.currentTimeMillis();
        Config.ReadConfig("jftn.conf");
        if (!Config.isValid()) {
            return;
        }

        if (args.length == 0) {
            System.out.println("Error: No action in commandline.");
            Help();
        } else {
            if (args[0].equalsIgnoreCase("toss")) {
                Tosser.RunFast(Config.getInbound());
            } else if (args[0].equalsIgnoreCase("help")) {
                Help();
            } else if (args[0].equalsIgnoreCase("poll")) {
                FTNAddr boss = new FTNAddr("2:5030/1111.0");
                BinkP bink = new BinkP();
                SessionResult res = bink.Poll(Config.getLink(boss));
                SessFile[] files = res.getFiles();
                for (int i = 0; i < res.getStatus(); i++) {
                    RandomAccessFile of = null;
                    try {
                        of = new RandomAccessFile(Config.getInbound() + "/" + files[i].filename, "rw");
                        if (files[i].body != null) {
                                    of.write(files[i].body);
                        }
                        of.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    } finally {
                        if (of != null) {
                            of.close();
                        }
                    }
                }

                System.out.println("Session " + res.getStatus());
            } else {
                System.out.println("Error: Unknown commandline argument.");
                Help();
            }
        }

        Logger.Log("Work time: " + (System.currentTimeMillis() - starttime) / 1000.0 + " sec");
    }
}

@@ -49,16 +49,48 @@
 Config;%0A
+import org.fidonet.misc.Logger;%0A
 import o
@@ -115,17 +115,21 @@
 l.binkp.
-*
+BinkP
 ;%0Aimport
@@ -137,35 +137,96 @@
 org.fidonet.
-misc.Logger
+protocol.binkp.SessFile;%0Aimport org.fidonet.protocol.binkp.SessionResult
 ;%0Aimport org
@@ -269,9 +269,52 @@
 .io.
-*
+IOException;%0Aimport java.io.RandomAccessFile
 ;%0A%0Ap
@@ -337,16 +337,24 @@
  %7B%0A%0A    
+private 
 static v

Optimize imports. Help() is private now.