zoukankan      html  css  js  c++  java
  • 网易邮件采集器(4)

    邮件查看:用switch语句,根据不同的case,执行相应的查看方式

    if (args.length > 0) {
                String s = args[0];
    
                switch (s) {
                case "account":
    
                    try {
                        File f = new File(Constants.strFilePath, Constants.strFileName);
    
                        if (f.exists()) {
                            FileReader fr = new FileReader(f);
    
                            char[] ch = new char[1024];
    
                            int i = 0;
    
                            String str = "";
                            while ((i = fr.read(ch)) > 0) {
                                str += new String(ch, 0, i);
                            }
    
                            JSONObject jo = new JSONObject(str);
                            fr.close();
                            String userName = (String) jo.getJSONObject("account").get("username");
                            String password = (String) jo.getJSONObject("account").get("password");
                            System.out.println("account的username = " + userName);
                            System.out.println("account的password = " + password);
                        } else {
                            System.out.println("文件不存在");
                        }
    
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
    
                    break;
    
                case "status":
                    int count = 0;
                    int post = 0;
    
                    File mf = new File("d:/mail/date");
    
                    File[] ms = mf.listFiles();
                    for (File y : ms) {
                        if (y.isFile())
                            count++;
                        else if (y.isDirectory()) {
                            // 判断是否包含附件
                            if (y.getName().contains("_attachment")) {
                                post++;
                            }
                        }
    
                    }
                    System.out.println("邮件数量:" + count + "封; 包含附件的邮件:" + post + "封");
    
                    break;
                case "search":
                    if (args.length > 1) {
                        int mail = 0;
                        String keyword = args[1];
                        if (new File("d:/mail/date").exists()) {
                            try {
                                File[] ms_ = new File("d:/mail/date").listFiles();
                                for (File y : ms_) {
                                    if (y.exists()) {
                                        FileReader fr = new FileReader(y);
                                        JSONReader jr = new JSONReader(fr);
                                        MailGet mg = jr.readObject(MailGet.class);
    
                                        if (mg.getSubject().contains(keyword)) {
                                            mail++;
                                            System.out.println("符合搜索条件的第" + mail 
                                                    + "封邮件:  标题:" 
                                                    + mg.getSubject() + ",  文件名:"
                                                    + y.getName());
                                        }
    
                                        fr.close();
                                        jr.close();
                                    } else {
                                        System.out.println("文件不存在");
                                    }
    
                                }
    
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
    
                        }
                    }
                }
            } else {
    
                System.out.println("请输入"account","status"或"search <keyword>"");
            }
        }
  • 相关阅读:
    ZZ: kvm qemu kqemu qemu-kvm libvirt
    ZZ:爬虫
    Mac下安装及配置Appium环境
    badboy使用手册
    如何正确做 Web端压力测试?
    关于web页面性能测量指标与建议
    Pycharm的使用一
    如何下载安装Python
    apache jmeter下载与安装
    但行其事,不问前程
  • 原文地址:https://www.cnblogs.com/wenwen123/p/5797109.html
Copyright © 2011-2022 走看看