예제 #1
0
  public static final void main(String[] args) throws Exception {
    if (args.length == 1 && "--help".equals(args[0])) {
      System.out.println(
          "Usage: java [-Dparam=value] " + EmailClient.class.getName() + " [EmailClientType args]");
      System.out.println("\tEmailClientType: mailto or " + Arrays.asList(EmailClientType.values()));
      System.out.println("\tparam: to, subject, body, files (seprated by ',' double it to escape)");
      return;
    }

    final EmailClient client = createFromString(args);
    final String to =
        System.getProperty("to", "Pierre Dupond <*****@*****.**>, [email protected]");
    // ',to=' to test escaping of Thunderbird (passing subject='foo'bar' works)
    final String subject =
        System.getProperty("subject", "Sujé € du courrier ',to='&;\\<> \"autre'\n2nd line");
    final String body =
        System.getProperty("body", "Bonjour,\n\tsingle ' double \" backslash(arrière) \\ slash /");
    final String filesPath = System.getProperty("files");
    final String[] paths =
        filesPath == null || filesPath.length() == 0
            ? new String[0]
            : filesPath.split("(?<!,),(?!,)");
    final File[] f = new File[paths.length];
    for (int i = 0; i < f.length; i++) {
      f[i] = new File(paths[i].replace(",,", ","));
    }
    client.compose(to, subject, body, f);
  }