1. Miki Tebeka
  2. ensalvage

Commits

Miki Tebeka  committed 76ebfa5

Semi working

  • Participants
  • Parent commits 0ea4953
  • Branches default

Comments (0)

Files changed (1)

File ensalvage

View file
 import re
 from email import message_from_string
 from mmap import mmap
-from os.path import isdir
+from os.path import isdir, isfile
 from os import makedirs
 from itertools import count
 import Tkinter as tk
 from tkFileDialog import askopenfilename, askdirectory
+from tkMessageBox import showerror
+from threading import Thread
 
 def subfn(match):
     return match.group(1).decode("base64")
         log("%d: %s" % (i, subject))
         fname = "%s/emails/%d.txt" % (outdir, i)
         cls = ["even", "odd"][i % 2]
-        print >> html, tr % (cls, msg["Date"], msg["From"], fname, subject)
+        print >> html, TR % (cls, msg["Date"], msg["From"], fname, subject)
         with open(fname, "wb") as outfo:
             outfo.write(text)
 
     data.close()
     fo.close()
 
+    log("* DONE (%d emails)" % i)
+
 def _get(entry, func):
     def get():
         name = func()
     root = tk.Tk()
     root.title("EnSalvage")
     tk.Label(root, text="Database:").grid(row=0, sticky=tk.W)
-    e = tk.Entry(root)
-    e.grid(row=0, column=1)
-    tk.Button(root, text="...", command=askfile(e)).grid(row=0, column=2)
+    db = tk.Entry(root, width=40)
+    db.grid(row=0, column=1, sticky=tk.W+tk.E)
+    tk.Button(root, text="...", command=askfile(db)).grid(row=0, column=2)
 
     tk.Label(root, text="Output Directory:").grid(row=1, sticky=tk.W)
-    e = tk.Entry(root)
-    e.grid(row=1, column=1)
-    tk.Button(root, text="...", command=askdir(e)).grid(row=1, column=2)
+    out = tk.Entry(root, width=40)
+    out.grid(row=1, column=1, sticky=tk.W+tk.E)
+    tk.Button(root, text="...", command=askdir(out)).grid(row=1, column=2)
+    tk.Label(root, text="Progress:").grid(row=2, sticky=tk.W)
+    progress = tk.Label(root, text="", width=40)
+    progress.grid(row=2, column=1, columnspan=2, sticky=tk.W+tk.E)
 
+    def log(message):
+        try:
+            progress["text"] = message
+        except RuntimeError:
+            pass
+
+    def go():
+        dbfile = db.get().strip()
+        if not isfile(dbfile):
+            showerror("File Not Found", "Can't find database - %s" % dbfile)
+            return
+        
+        outdir = out.get().strip()
+        if not isdir(outdir):
+            showerror("Directory Not Found",
+                      "Can't find output directory - %s" % outdir)
+            return
+
+        t = Thread(target=salvage, args=(dbfile, outdir, log))
+        t.deamon = 1
+        t.start()
+
+    tk.Button(root, text="Salvage", command=go).grid(row=3)
+    tk.Button(root, text="Quit", command=root.quit).grid(row=3, column=1)
+
+    root.columnconfigure(1, weight=1)
     root.mainloop()