⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mlist2jgossip.java

📁 jGossip是一个简单而功能强大的Java论坛软件(消息板)
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                                            + "] BP [" + bpi + "] isa "
                                            + bp.getClass().getName());
                                }
                            }
                        } else {
                            System.err.println("MSG [" + msgId + "] isa "
                                    + bodyObj.getClass().getName());
                        }

                        if (bodyStr != null) {
                            System.out
                                    .println("INSERT INTO jrf_message "
                                            + "( id, sender, centents, intime, heading, threadid, ip )");

                            System.out.println("   VALUES " + "( "
                                    + this.fMsgId++ + ", " + "'" + this.fSender
                                    + "', " + "'" + bodyStr + "', " + "'"
                                    + dateStr + "', " + "'" + subject + "', "
                                    + this.fThreadId + ", " + "'"
                                    + this.fIpAddress + "'" + " ); ");
                        }
                    }
                } catch (Exception ex) {
                    System.err.println(ex.getClass().getName() + ": "
                            + ex.getMessage());
                    System.err.println("        " + msgId);
                    ex.printStackTrace(System.err);
                }
            }
        }
    }

    private void addBySubject(String subject, String msgId) {
        String sub = subject;
        if (sub.length() > 50) sub = sub.substring(0, 50);

        ArrayList ma = (ArrayList) this.bySubject.get(sub);

        if (ma == null) {
            // This is a NEW THREAD
            //
            ma = new ArrayList();
            this.bySubject.put(sub, ma);
        }

        if (!ma.contains(msgId)) ma.add(msgId);

        this.byMsgId.put(msgId, ma);
    }

    private void loadArchive(String archivePath) throws IOException,
            NumberFormatException, ParseException {
        int numMsgs = 0;
        long begMillis = System.currentTimeMillis();

        File archDirF = new File(archivePath);

        if (this.verbose)
                System.err.println("LOAD MESSAGES FROM: " + archDirF.getPath());

        if (!archDirF.exists()) {
            System.err.println("Directory '" + archivePath
                    + "' does not exist.");
            return;
        }

        if (!archDirF.isDirectory()) {
            System.err
                    .println("Path '" + archivePath + "' is not a directory.");
            return;
        }

        String[] dirList = archDirF.list();

        for (int idx = 0; idx < dirList.length; ++idx) {
            File f = new File(archDirF, dirList[idx]);

            if (f.exists() && f.isFile()) {
                FileInputStream fis = null;

                try {
                    fis = new FileInputStream(f);
                    MimeMessage msg = new MimeMessage(this.session, fis);

                    String msgId = msg.getMessageID();
                    if (this.debug) System.err.println("MSGID: " + msgId);

                    if (this.allMsgs.containsKey(msgId)) {
                        ++this.errDupes;
                        System.err.println("ERROR: duplicate msgID '" + msgId
                                + "'");
                    } else {
                        this.allMsgs.put(msgId, msg);
                    }

                    Date msgDate = msg.getSentDate();
                    if (this.debug) System.err.println("   DATE: " + msgDate);

                    String subject = msg.getSubject();
                    this.subjects.put(msgId, subject);
                    if (this.debug) System.err.println("   SUBJ: " + subject);

                    String sub = (subject == null ? "" : subject);
                    while (sub.toUpperCase().startsWith("RE: ")) {
                        sub = sub.substring(4);
                    }

                    this.addBySubject(sub, msgId);

                    ++numMsgs;
                } catch (Exception ex) {
                    System.err.println("Error loading '" + f.getPath() + "', "
                            + ex.getMessage());
                    ex.printStackTrace(System.err);
                } finally {
                    if (fis != null) fis.close();
                }
            }
        }

        long endMillis = System.currentTimeMillis();

        if (this.verbose)
                System.err.println("Processed " + numMsgs + " messages "
                        + " in " + ((endMillis - begMillis) / 1000)
                        + " seconds.");

        if (this.verbose)
                System.err.println("Processed " + numMsgs + " messages "
                        + " producing " + this.bySubject.size() + " threads.");

        if (this.verbose)
                System.err.println("ERRORS: Duplicate MsgIDs = "
                        + this.errDupes);
    }

    private void processArguments(String[] argv) {
        int i = 0;

        for (; i < argv.length; ++i) {
            if (!argv[i].startsWith("-") || argv[i].equals("--")) {
                break;
            } else if (argv[i].equals("-?") || argv[i].equals("--help")) {
                this.printUsageAndExit();
            } else if (argv[i].equals("--debug")) {
                this.debug = true;
            } else if (argv[i].equals("--verbose")) {
                this.verbose = true;
            } else if (argv[i].equals("--sender")) {
                this.fSender = argv[++i];
            } else if (argv[i].equals("--ipaddr")) {
                this.fIpAddress = argv[++i];
            } else if (argv[i].equals("--forum")) {
                ++i;
                try {
                    this.fForumId = Integer.parseInt(argv[i]);
                } catch (Exception ex) {
                    ex.printStackTrace(System.err);
                    this.printUsageAndExit();
                }
            } else if (argv[i].equals("--threadid")) {
                ++i;
                try {
                    this.fThreadId = Integer.parseInt(argv[i]);
                } catch (Exception ex) {
                    ex.printStackTrace(System.err);
                    this.printUsageAndExit();
                }
            } else if (argv[i].equals("--msgid")) {
                ++i;
                try {
                    this.fMsgId = Integer.parseInt(argv[i]);
                } catch (Exception ex) {
                    ex.printStackTrace(System.err);
                    this.printUsageAndExit();
                }
            } else if (argv[i].equals("--archive")) {
                try {
                    this.loadArchive(argv[++i]);
                } catch (Exception ex) {
                    ex.printStackTrace(System.err);
                }
            } else {
                System.err.println("UNKNOWN OPTION: " + argv[i]);
                this.printUsageAndExit();
            }
        }
    }

    public void printUsageAndExit() {
        System.err.println("usage: " + this.getClass().getName()
                + " [options] --archive path [--archive path]...");
        System.err.println("version: " + VERSION_STR);
        System.err.println("options:");
        System.err
                .println("  --archive path         Mailing list archive path.");
        System.err
                .println("  --debug                Turn on debugging output.");
        System.err
                .println("  --verbose              Turn on operational verbosity.");
        System.err
                .println("  --forum id             Forum ID assigned to each message.");
        System.err.println("  --msgid id             Beginning message id.");
        System.err.println("  --threadid id          Beginning thread id.");
        System.err
                .println("  --sender name          Sender name assigned to each message.");
        System.err
                .println("  --ipaddr addr          IP Address assigned to each message.");
        System.exit(1);
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -