src/strip.vala
authorAlan Knowles <alan@roojs.com>
Fri, 4 May 2018 05:14:44 +0000 (13:14 +0800)
committerAlan Knowles <alan@roojs.com>
Fri, 4 May 2018 05:14:44 +0000 (13:14 +0800)
src/strip.vala

index b41cda0..df3d702 100644 (file)
@@ -26,11 +26,21 @@ More notes on our Mailfort DB sync:
 * some of these attachments are already in the database...
  - so we need to update the DB..
  - probably worth putting the code in a stored procedure..
+ -- key scenarios
+   * first scan (and extract)
+   * rescan (as I messed up the first time - fix the DB...)
+   * email scan - attachments might not have related messages.
  - {id} attachment_init(
                {exim_msg_id}
                {chksum}
                {filename),
        )
+       // creates or returns id (can look for existing messages?
+       // can do a merge?? - copy 'old' record data into 'new'....  "prefer checksummed"
+       
        attachment_update(
                {id}
                {exim_msg_id}
@@ -343,36 +353,22 @@ public class Strip : GLib.Object {
                return;
        }
        this.query("""
-                       UPDATE  
-                               Attachment
-                       SET  
-                                queue_id = COALESCE((SELECT id from MailQueue where msgid = '%s' AND message_sig = '%s' AND  msgid != '' AND message_sig != '' LIMIT 1),0),
-                                mime_cdisp = 'attachment',
-                                mime_size = filesize,
-                                
-                                mime_is_cover = 0,
-                                mime_is_multi = 0,
-                                mime_is_mail = 0,
-                                
-                                msgid = '%s',
-                                maillog_id = COALESCE((SELECT id from email_log where msgid = '%s' AND message_sig = '%s' AND  msgid != '' AND message_sig != '' LIMIT 1),0),
-                                delivered = created
-                       WHERE
-                               id = %d
-                               AND 
-                               id != 0
-                               AND
-                               (queue_id IS NULL OR queue_id  = 0)
-                               AND
-                               delivered is NULL
-                       LIMIT  1
+               SELECT attachment_update(
+                               %d, -- in_id INT(11),
+                               '%s', -- in_mime_type varchar(255),
+                               %d, -- in_mime_size int(11),
+                               '%s', -- in_created DATETIME,
+                               '%s' -- in_mailfort_sig varchar(64)
+                               
+                   )""
+       
                                 
              """.printf(
-                       this.mysql_escape(this.active_message_exim_id), this.mysql_escape(this.active_message_x_mailfort_sig),
-                       
-                       this.mysql_escape(this.active_message_exim_id),
-                       this.mysql_escape(this.active_message_exim_id), this.mysql_escape(this.active_message_x_mailfort_sig),
-                       int.parse(sid)
+                       int.parse(sid),
+                       "", // this will be ignored..
+                       0, // this will be ingored..
+                               this.created_date,
+                               this.mysql_escape(this.active_message_x_mailfort_sig)
              
              )
                );