src/strip.vala
[app.mailtrimmer] / src / strip.vala
index 5424e96..ca947c0 100644 (file)
@@ -370,11 +370,11 @@ public class Strip : GLib.Object {
        
        // initialize it with known data..
        // that should wipe out dupes.
-       var matches = this.execute("SELECT id   FROM Attachment WHERE id = %d".printf(
+       var matches = this.query("SELECT count(id)   FROM Attachment WHERE id = %d".printf(
                        int.parse(sid)));  
 
                 
-               if (matches == "") {     
+               if (matches == "0") {    
                        // 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);
@@ -385,7 +385,7 @@ public class Strip : GLib.Object {
        
        // initialize it with known data..
        // that should wipe out dupes.
-       var filesize = this.execute("SELECT filesize FROM Attachment WHERE id = %d".printf(
+       var filesize = this.query("SELECT filesize FROM Attachment WHERE id = %d".printf(
                        int.parse(sid)));  
 
                if (filesize=="") {      
@@ -444,6 +444,13 @@ public class Strip : GLib.Object {
         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;
+        
+
+               if (!FileUtils.test (fn, FileTest.EXISTS)) {
+                       GLib.debug("SKIP -- file does not exist");
+                       return;
+       }
+        
         var chksum = this.md5_file(fn);
                var mime_type = attachment.get_header("X-strip-content-type");
 
@@ -452,9 +459,6 @@ public class Strip : GLib.Object {
                                                ,GLib.FileQueryInfoFlags.NONE,null);
        var file_size = (int) fileinfo.get_size();
 
-               if (!FileUtils.test (fn, FileTest.EXISTS)) {
-                       GLib.debug("SKIP -- file does not exist");
-               }
       
                this.real_query(-1, """
                       
@@ -627,7 +631,7 @@ public class Strip : GLib.Object {
                        target_fn = StripApplication.opt_target_path + "/" + this.created_dir +"/"+ file_id  + "-" + GLib.Uri.escape_string(filename,"", false);
                } 
                    
-           var stored =  "/" + this.created_dir +"/"+ file_id  + "-" + filename;
+           var stored =  "/" + this.created_dir +"/"+ file_id  + "-" + GLib.Uri.escape_string(filename,"", false);
                 this.query("""
                
                        SELECT attachment_update_store(
@@ -646,15 +650,15 @@ public class Strip : GLib.Object {
         rep.set_filename(filename);
         string txt = "<html><body>"+
             "<a href=\"" + StripApplication.opt_replace_link + "/" +
-                       file_id + "/" + this.created_dir + "/"+chksum+"/"+ GLib.Uri.escape_string( filename) +"\">" + 
-            GLib.Uri.escape_string( filename) + // fixme needs html escaping...
+                       file_id + "/" + this.created_dir + "/"+chksum+"/"+ GLib.Uri.escape_string( filename, "", false) +"\">" + 
+            GLib.Uri.escape_string( filename, "", false) + // fixme needs html escaping...
             "</a>" +
             "</body></html>";
 
         rep.get_content_type().set_parameter("charset", "utf-8");
                rep.set_header("X-strip-id", file_id);
                rep.set_header("X-strip-content-name",  filename);                              
-               rep.set_header("X-strip-path", this.created_dir + "/" + file_id + "-" + filename);              
+               rep.set_header("X-strip-path", this.created_dir + "/" + file_id + "-" +  GLib.Uri.escape_string(filename,"", false));           
                rep.set_header("X-strip-content-type", mime_type);              
         var stream =  new GMime.StreamMem.with_buffer(txt.data);
         var con = new GMime.DataWrapper.with_stream(stream,GMime.ContentEncoding.DEFAULT);