made newMessage a static method and Message() private
[org.ibex.mail.git] / src / org / ibex / mail / Confirmation.java
index dc1cf3e..f741890 100644 (file)
@@ -1,6 +1,6 @@
 package org.ibex.mail;
 import java.lang.reflect.*;
-import org.prevayler.*;
+//import org.prevayler.*;
 import org.ibex.crypto.*;
 import org.ibex.util.*;
 import org.ibex.mail.protocol.*;
@@ -83,15 +83,14 @@ public abstract class Confirmation implements Externalizable {
         }
     }
 
-    public void signAndSend(long secret) throws IOException, Message.Malformed {
-        SMTP.Outgoing.accept(new Message(new Stream("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)),
-                                         new Message.Envelope(FROM, who, new Date())
-                                         )
+    public void signAndSend(long secret, Date now) throws IOException, Message.Malformed {
+        SMTP.Outgoing.accept(Message.newMessage(new Stream("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)),
+                                                FROM, who)
                              );
     }
 
@@ -112,14 +111,13 @@ public abstract class Confirmation implements Externalizable {
         return sb.toString();
     }
 
-    public static Confirmation decode(String encoded, long secret) {
+    public static Confirmation decode(String encoded, long secret, Date now) {
         try {
-            // FIXME: not prevayler-safe!
             String payload = encoded.substring(0, encoded.indexOf('.'));
             ObjectInputStream ois = new ObjectInputStream(new InflaterInputStream(new Base64.InputStream(payload)));
             Confirmation cve = (Confirmation)ois.readObject();
             if (!cve.sign(secret).equals(encoded)) throw new InvalidSignature();
-            if (System.currentTimeMillis() > cve.expiration) throw new Expired();
+            if (now.getTime() > cve.expiration) throw new Expired();
             return cve;
         } catch (ClassNotFoundException e) {
            Log.error(Confirmation.class, e);