src/strip.vala
[app.mailtrimmer] / src / strip.vala
index 1b22486..a30e35e 100644 (file)
@@ -87,7 +87,9 @@ public class StripApplication : GLib.Application {
        public static string? opt_db_name = null;       
        public static string? opt_db_user = null;               
        public static string? opt_db_pass = null;               
-
+       public static string? opt_scan_mailfort_only = "";              
+       
+       
        public static int    opt_limit = -1;
 
        public static int    opt_age_newest = 1;
@@ -100,6 +102,7 @@ public class StripApplication : GLib.Application {
        public static bool      opt_scan_mailfort  = false;     
        public static bool              opt_dump = false;       
        public static bool              opt_debug = false; 
+       public static bool              opt_stamp = false; 
        
        public static bool opt_debug_sql = false;       
        public static string? opt_replace_link = null;
@@ -131,8 +134,9 @@ public class StripApplication : GLib.Application {
                { "oldest", 0, 0, OptionArg.INT, ref opt_age_oldest, "do not replace messages older than X (default is 6 months)", null },
 
                { "scan-maildir", 0, 0, OptionArg.NONE, ref opt_scan_maildir, "scan an maildir tree", null },
+               { "stamp", 0, 0, OptionArg.NONE, ref opt_stamp, "create and honour directory stamps - flag that a folder has been scanned already", null },
                { "scan-mailfort", 0, 0, OptionArg.NONE, ref opt_scan_mailfort, "scan a mailfort tree", null }, 
-               { "scan-mailfort-only", 0, 0, OptionArg.NONE, ref opt_scan_mailfort, "scan a mailfort Year/month eg. 2010/08", null }, 
+               { "scan-mailfort-only", 0, 0, OptionArg.STRING, ref opt_scan_mailfort_only, "scan a mailfort Year/month eg. /2010/08", null }, 
                { null }       
        };         
     public StripApplication( string[] args ) 
@@ -239,7 +243,7 @@ public class StripApplication : GLib.Application {
                return 0;
         }
 
-               strip.scan_dir(opt_path, "");
+               strip.scan_dir(opt_path, opt_scan_mailfort_only);
         
 
         
@@ -552,6 +556,9 @@ public class Strip : GLib.Object {
                        "/"+ this.active_name + "."+   GLib.Uri.escape_string(filename,"", false);
 
            var outfile = new GMime.StreamFile.for_path(fn, "w");
+           if (outfile == null) {
+               return; // something has gone wrong??
+       }
            outfile.set_owner(true);
            var file_size = (int) c.write_to_stream(outfile);
            var chksum = this.md5_file(fn);
@@ -1064,6 +1071,10 @@ public class Strip : GLib.Object {
                
         }
         
+       if (StripApplication.opt_stamp && GLib.FileUtils.test( basepath + subpath + ".strip-done-stamp", GLib.FileTest.EXISTS )) {
+               return;
+               }
+        
         
         var f = File.new_for_path(basepath + subpath);
                FileEnumerator file_enum;
@@ -1145,6 +1156,13 @@ public class Strip : GLib.Object {
             this.scan_dir(basepath,sp);
             
         }
+        
+        // completed this folder
+        
+        if (StripApplication.opt_stamp) {
+               GLib.FileUtils.set_contents (basepath + subpath + ".strip-done-stamp", "Stripper done");
+        }
+        
     
     
     }