From: adam Date: Thu, 9 Mar 2006 08:31:56 +0000 (+0000) Subject: confirmation X-Git-Url: http://git.megacz.com/?p=org.ibex.mail.git;a=commitdiff_plain;h=e78a29d33bcfa1bc071cf6df0a59d1a170514a6b confirmation darcs-hash:20060309083156-5007d-f3e6a682795e4abc4f8b3df836152e1d05ee7415.gz --- diff --git a/src/org/ibex/mail/Confirmation.java b/src/org/ibex/mail/Confirmation.java index ba15fb8..ccb8793 100644 --- a/src/org/ibex/mail/Confirmation.java +++ b/src/org/ibex/mail/Confirmation.java @@ -23,13 +23,27 @@ import java.io.*; public abstract class Confirmation implements Externalizable { public static final long serialVersionUID = 0x981879f18a11ffeeL; - public static final Address FROM = Address.parse("adam@megacz.com"); // FIXME + + public static int master_serial = 0; public transient Address who = null; public long expiration; public abstract String getDescription(); + public abstract String getURL(String tail); + public int serial; + + private static HashMap all = new HashMap(); - protected Confirmation(Address who, long expiration) { this.who = who; this.expiration = expiration; } + public static Confirmation get(int serial) { + return all.get(serial); + } + + protected Confirmation(Address who, long expiration) { + this.who = who; + this.expiration = expiration; + this.serial = master_serial++; + all.put(serial, this); + } public void readExternal(ObjectInput s) throws IOException { try { @@ -87,13 +101,17 @@ public abstract class Confirmation implements Externalizable { } } - public void signAndSend(long secret, Date now) throws IOException, Message.Malformed { - SMTP.Outgoing.accept(Message.newMessage(new Fountain.StringFountain("From: " + FROM + "\r\n" + - "To: " + who.toString(true) + "\r\n" + - "Subject: confirm " + getDescription() + "\r\n" + - "\r\n" + - "Please click the link below to " + getDescription() + "\r\n" + - sign(secret))) + public void signAndSend(Address sender, long secret, Date now) throws IOException, Message.Malformed { + SMTP.Outgoing.accept(Message.newMessage(new Fountain.StringFountain("From: " + sender + "\r\n" + + "To: " + who.toString(true) + "\r\n" + + "Subject: confirm " + getDescription() + "\r\n" + + "Message-Id: "+Message.generateFreshMessageId()+"\r\n" + + "\r\n" + + "Please click the link below to " + getDescription() + "\r\n" + + getURL(sign(secret))), + sender, + who + ) ); } @@ -104,7 +122,9 @@ public abstract class Confirmation implements Externalizable { oos.flush(); oos.close(); byte[] b = os.toByteArray(); - StringBuffer sb = new StringBuffer(new String(Encode.toBase64(b))); + StringBuffer sb = new StringBuffer(); + sb.append(serial); + //sb.append(new String(Encode.toBase64(b))); sb.append('.'); SHA1 sha1 = new SHA1(); sha1.update(b, 0, b.length); @@ -116,15 +136,11 @@ public abstract class Confirmation implements Externalizable { public static Confirmation decode(String encoded, long secret, Date now) { try { - String payload = encoded.substring(0, encoded.indexOf('.')); - ObjectInputStream ois = new ObjectInputStream(new InflaterInputStream(new Encode.Base64InputStream(payload))); - Confirmation cve = (Confirmation)ois.readObject(); + String serial = encoded.substring(0, encoded.indexOf('.')); + Confirmation cve = get(Integer.parseInt(serial)); if (!cve.sign(secret).equals(encoded)) throw new InvalidSignature(); if (now.getTime() > cve.expiration) throw new Expired(); return cve; - } catch (ClassNotFoundException e) { - Log.error(Confirmation.class, e); - throw new InvalidSignature(); } catch (IOException e) { Log.error(Confirmation.class, e); throw new InvalidSignature();