it compiles
[org.ibex.mail.git] / src / org / ibex / mail / target / Transcript.java
1 package org.ibex.mail.target;
2 import org.ibex.mail.*;
3 import org.ibex.util.*;
4 import org.ibex.mail.*;
5 import java.io.*;
6 import java.net.*;
7 import java.util.*;
8 import java.text.*;
9
10 /** a fast-write, slow-read place to stash all messages we touch -- in case of a major f*ckup */
11 public class Transcript extends Mailbox {
12     private String path;
13     public Transcript(String path) throws MailException { new File(this.path = path).mkdirs(); }
14     private static String lastTime = null;
15     private static int lastCounter = 0;
16
17     // FIXME
18     public String getName() { return "Transcript"; }
19
20     public Mailbox.Iterator iterator() { return null; }
21     public int uidValidity() { return 0; }
22     public int uidNext() { return 0; }
23     
24     /** returns a message identifier */
25     public synchronized int add(Message message) throws MailException {
26         try {
27             File today = new File(path + File.separatorChar + (new SimpleDateFormat("yy-MMM-dd").format(new Date())));
28             today.mkdirs();
29                 
30             String time = new SimpleDateFormat("HH:mm:ss").format(new Date());
31             synchronized (Transcript.class) {
32                 if (lastTime != null && lastTime.equals(time)) {
33                     time += "." + (++lastCounter);
34                 } else {
35                     lastTime = time;
36                 }
37             }
38                 
39             File target = new File(today.getPath() + File.separatorChar + time + ".txt");
40             OutputStream os = new FileOutputStream(target);
41             message.dump(os);
42             os.close();
43             return -1;
44         } catch (IOException e) { throw new MailException.IOException(e); }
45     }
46 }
47