src/strip.vala
[app.mailtrimmer] / src / strip.vala
index 88cf364..02a0b27 100644 (file)
@@ -370,13 +370,16 @@ public class Strip : GLib.Object {
        
        // initialize it with known data..
        // that should wipe out dupes.
-       var matches = this.execute("SELECT count(id) FROM Attachment WHERE id = %d".printf(
+       var matches = this.execute("SELECT count(id) as nid FROM Attachment WHERE id = %d".printf(
                        int.parse(sid)));  
-                GLib.error("Got Matches :%s", matches);
+
                 
-               if (matches=="0") {      
-                  GLib.error("Failed to find id  :%s", sid);
-                  return;
+               if (matches == "") {     
+                       // our old mailfort code deleted the crap out of old records...
+                       // if this occurs we will need to create the record again..
+                       this.fix_deleted_attachment_db(int.parse(sid),attachment);
+                       return;
                }
        
        
@@ -386,7 +389,7 @@ public class Strip : GLib.Object {
                        int.parse(sid)));  
 
                if (filesize=="") {      
-                  GLib.debug("Ignoring record id (missing in database) :%s", sid);
+                  GLib.error("Ignoring record id (missing in database) :%s", sid);
                   return;
                }
                if (int.parse(filesize) < 1) {
@@ -435,6 +438,43 @@ public class Strip : GLib.Object {
     }
     
     
+    public void fix_deleted_attachment_db(int id, GMime.Part attachment)
+    {
+               
+        var filename = attachment.get_header("X-strip-content-name");
+        var file_path  = attachment.get_header("X-strip-path");
+        var fn =  StripApplication.opt_target_path + "/" + file_path;
+        var chksum = this.md5_file(fn);
+               var mime_filename = attachment.get_header("X-strip-content-type");
+
+               var fileinfo = File.new_for_path(fn)
+                                       .query_info(GLib.FileAttribute.STANDARD_SIZE+","+GLib.FileAttribute.TIME_MODIFIED
+                                               ,GLib.FileQueryInfoFlags.NONE,null);
+       var file_size = (int) fileinfo.get_size();
+
+               
+               GLib.error("GOT FN: %s  | PATH: %s | CT: %s", filename, file_path, mime_filename);
+     
+               /*
+               this.query("""
+                        INSERT INTO Attachments
+                               (id, exim_msg?, chksum, filesize)
+                               values
+                               ( 
+                            %d,   '%s', '%s',  '%s', %d
+                            ) 
+                            
+                     """.printf(
+                               id,
+                                     this.mysql_escape(this.active_message_exim_id),
+                                     this.mysql_escape(chksum),
+                                 this.mysql_escape(mime_filename),                       
+                                     int.parse(filesize)
+                       ));
+               */
+    }
+    
+    
     public void replace_attachment(GMime.Multipart parent, GMime.Part attachment)
     {
         var sid = attachment.get_header("X-strip-id");
@@ -616,6 +656,8 @@ public class Strip : GLib.Object {
 
         var rs = mysql.use_result();
         
+        //GLib.debug("got %d rows", (int) rs.num_rows());
+        
         var got_row = false;
                string[] row;
                string ret = "";
@@ -625,15 +667,20 @@ public class Strip : GLib.Object {
                
                }
                if (!need_return) {
-                       GLib.debug("got %s", got_row ? "=Nothing=" : ret);
+               if (StripApplication.opt_debug_sql) {
+                               GLib.debug("got %s", got_row ? "=Nothing=" : ret);
+                       }
                        return got_row ? "" : ret;
                }
                if (!got_row) {
+
                         GLib.debug("ERROR : no rows returned");
                        Posix.exit(1);
                        return "";
                }
-               GLib.debug("got %s", ret);
+       if (StripApplication.opt_debug_sql) {
+                       GLib.debug("got %s", ret);
+               }
                return ret;