import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileReader; import java.net.URI; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** * web mail reader * * @author matecsaba */ public class mailer { /** * this is needed for cli startup * * @param args command line parameters */ public static void main(String[] args) { mailer app = new mailer(); String a; try { ByteArrayOutputStream buf = new ByteArrayOutputStream(); a = "" + app.getClass().getName() + "."; a = mailer.httpRequest("http://localhost/" + a, "./" + a, "cli", "clibrowser", "user", args, buf); a = "type=" + a + "\r\ndata:\r\n" + buf.toString(); } catch (Exception e) { a = "exception " + e.getMessage(); } System.out.println(a); } /** * where i'm located in ram */ protected static mailer staticMailer = null; /** * do one request * * @param url url of app * @param path path of app * @param peer client address * @param agent user agent * @param user auth data * @param par parameters * @param buf result buffer, if empty, pathname must present * @return [pathname"][file name.]extension * @throws Exception if something went wrong */ public static String httpRequest(String url, String path, String peer, String agent, String user, String[] par, ByteArrayOutputStream buf) throws Exception { if (staticMailer == null) { staticMailer = new mailer(); staticMailer.path = path.substring(0, path.lastIndexOf(".")); staticMailer.url = new URI(url).toURL().getPath(); staticMailer.doInit(); } staticMailer.doRequest(par, buf, user); return "html"; } /** * where i'm located on host */ protected String path; /** * where i'm located on net */ protected String url; /** * where mail located on host */ protected String mail = ""; /** * initialize */ public void doInit() { readConfig(); } private void readConfig() { try { BufferedReader f = new BufferedReader(new FileReader(path + ".cfg")); mail = f.readLine(); f.close(); } catch (Exception e) { } } /** * do one request * * @param par parameters * @param buf buffer to use * @param user username * @throws Exception if something went wrong */ public void doRequest(String[] par, ByteArrayOutputStream buf, String user) throws Exception { String id = ""; for (int i = 0; i < par.length; i++) { String a = par[i]; int o = a.indexOf("="); if (o < 1) { continue; } String b = a.substring(0, o); a = a.substring(o + 1, a.length()); if (b.equals("id")) { id = a; } } if (id.length() > 0) { buf.write("
from | subject | date |
" + from + " | " + subj + " | " + date + " |