[geary/wip/save-sent-713263] Add outbox "sent" column



commit 490e11837501f19cb61758e5f52193cb086932a2
Author: Charles Lindsay <chaz yorba org>
Date:   Thu Jan 23 13:07:52 2014 -0800

    Add outbox "sent" column

 sql/version-017.sql                               |    7 +++
 src/engine/api/geary-email-flags.vala             |   11 +++++
 src/engine/imap-db/outbox/smtp-outbox-folder.vala |   51 +++++++++++++++------
 3 files changed, 54 insertions(+), 15 deletions(-)
---
diff --git a/sql/version-017.sql b/sql/version-017.sql
new file mode 100644
index 0000000..f1cb4d3
--- /dev/null
+++ b/sql/version-017.sql
@@ -0,0 +1,7 @@
+--
+-- We're now keeping sent mail around after sending, so we can also push it up
+-- to the Sent Mail folder.  This column lets us keep track of the state of
+-- messages in the outbox.
+--
+
+ALTER TABLE SmtpOutboxTable ADD COLUMN sent INTEGER DEFAULT 0;
diff --git a/src/engine/api/geary-email-flags.vala b/src/engine/api/geary-email-flags.vala
index 2f019d3..b7ff54b 100644
--- a/src/engine/api/geary-email-flags.vala
+++ b/src/engine/api/geary-email-flags.vala
@@ -31,6 +31,13 @@ public class Geary.EmailFlags : Geary.NamedFlags {
         return new NamedFlag("DRAFT");
     } }
     
+    /// Signifies a message in our outbox that has been sent but we're still
+    /// keeping around for other purposes, i.e. pushing up to Sent Mail.
+    public static NamedFlag OUTBOX_SENT { owned get {
+        // This shouldn't ever touch the wire, so make it invalid IMAP.
+        return new NamedFlag(" OUTBOX SENT ");
+    } }
+    
     public EmailFlags() {
     }
     
@@ -50,5 +57,9 @@ public class Geary.EmailFlags : Geary.NamedFlags {
     public inline bool is_draft() {
         return contains(DRAFT);
     }
+    
+    public inline bool is_outbox_sent() {
+        return contains(OUTBOX_SENT);
+    }
 }
 
diff --git a/src/engine/imap-db/outbox/smtp-outbox-folder.vala 
b/src/engine/imap-db/outbox/smtp-outbox-folder.vala
index e048632..e92c8ae 100644
--- a/src/engine/imap-db/outbox/smtp-outbox-folder.vala
+++ b/src/engine/imap-db/outbox/smtp-outbox-folder.vala
@@ -17,10 +17,11 @@ private class Geary.SmtpOutboxFolder : Geary.AbstractLocalFolder, Geary.FolderSu
         public int64 id;
         public int position;
         public int64 ordering;
+        public bool sent;
         public Memory.Buffer? message;
         public SmtpOutboxEmailIdentifier outbox_id;
         
-        public OutboxRow(int64 id, int position, int64 ordering, Memory.Buffer? message,
+        public OutboxRow(int64 id, int position, int64 ordering, bool sent, Memory.Buffer? message,
             SmtpOutboxFolderRoot root) {
             assert(position >= 1);
             
@@ -28,6 +29,7 @@ private class Geary.SmtpOutboxFolder : Geary.AbstractLocalFolder, Geary.FolderSu
             this.position = position;
             this.ordering = ordering;
             this.message = message;
+            this.sent = sent;
             
             outbox_id = new SmtpOutboxEmailIdentifier(id, ordering);
         }
@@ -139,14 +141,18 @@ private class Geary.SmtpOutboxFolder : Geary.AbstractLocalFolder, Geary.FolderSu
         try {
             Gee.ArrayList<OutboxRow> list = new Gee.ArrayList<OutboxRow>();
             yield db.exec_transaction_async(Db.TransactionType.RO, (cx, cancellable) => {
-                Db.Statement stmt = cx.prepare(
-                    "SELECT id, ordering, message FROM SmtpOutboxTable ORDER BY ordering");
+                Db.Statement stmt = cx.prepare("""
+                    SELECT id, ordering, message
+                    FROM SmtpOutboxTable
+                    WHERE sent = 0
+                    ORDER BY ordering
+                """);
                 
                 Db.Result results = stmt.exec(cancellable);
                 int position = 1;
                 while (!results.finished) {
                     list.add(new OutboxRow(results.rowid_at(0), position++, results.int64_at(1),
-                        results.string_buffer_at(2), _path));
+                        false, results.string_buffer_at(2), _path));
                     results.next(cancellable);
                 }
                 
@@ -314,7 +320,7 @@ private class Geary.SmtpOutboxFolder : Geary.AbstractLocalFolder, Geary.FolderSu
             
             int position = do_get_position_by_ordering(cx, ordering, cancellable);
             
-            row = new OutboxRow(id, position, ordering, message, _path);
+            row = new OutboxRow(id, position, ordering, false, message, _path);
             email_count = do_get_email_count(cx, cancellable);
             
             return Db.TransactionOutcome.COMMIT;
@@ -366,15 +372,23 @@ private class Geary.SmtpOutboxFolder : Geary.AbstractLocalFolder, Geary.FolderSu
             
             Db.Statement stmt;
             if (initial_id != null) {
-                stmt = cx.prepare(
-                    "SELECT id, ordering, message FROM SmtpOutboxTable WHERE ordering >= ? "
-                    + "ORDER BY ordering %s LIMIT ?".printf(dir));
+                stmt = cx.prepare("""
+                    SELECT id, ordering, message, sent
+                    FROM SmtpOutboxTable
+                    WHERE ordering >= ?
+                    ORDER BY ordering %s
+                    LIMIT ?
+                """.printf(dir));
                 stmt.bind_int64(0,
                     flags.is_including_id() ? initial_id.ordering : initial_id.ordering + 1);
                 stmt.bind_int(1, count);
             } else {
-                stmt = cx.prepare(
-                    "SELECT id, ordering, message FROM SmtpOutboxTable ORDER BY ordering %s LIMIT 
?".printf(dir));
+                stmt = cx.prepare("""
+                    SELECT id, ordering, message, sent
+                    FROM SmtpOutboxTable
+                    ORDER BY ordering %s
+                    LIMIT ?
+                """.printf(dir));
                 stmt.bind_int(0, count);
             }
             
@@ -392,7 +406,7 @@ private class Geary.SmtpOutboxFolder : Geary.AbstractLocalFolder, Geary.FolderSu
                 }
                 
                 list.add(row_to_email(new OutboxRow(results.rowid_at(0), position, ordering,
-                    results.string_buffer_at(2), _path)));
+                    results.bool_at(3), results.string_buffer_at(2), _path)));
                 position += flags.is_newest_to_oldest() ? -1 : 1;
                 assert(position >= 1);
             } while (results.next());
@@ -538,7 +552,10 @@ private class Geary.SmtpOutboxFolder : Geary.AbstractLocalFolder, Geary.FolderSu
         Geary.Email email = message.get_email(row.outbox_id);
         // TODO: Determine message's total size (header + body) to store in Properties.
         email.set_email_properties(new SmtpOutboxEmailProperties(new DateTime.now_local(), -1));
-        email.set_flags(new Geary.EmailFlags());
+        Geary.EmailFlags flags = new Geary.EmailFlags();
+        if (row.sent)
+            flags.add(Geary.EmailFlags.OUTBOX_SENT);
+        email.set_flags(flags);
         
         return email;
     }
@@ -682,8 +699,11 @@ private class Geary.SmtpOutboxFolder : Geary.AbstractLocalFolder, Geary.FolderSu
     
     private OutboxRow? do_fetch_row_by_ordering(Db.Connection cx, int64 ordering, Cancellable? cancellable)
         throws Error {
-        Db.Statement stmt = cx.prepare(
-            "SELECT id, message FROM SmtpOutboxTable WHERE ordering=?");
+        Db.Statement stmt = cx.prepare("""
+            SELECT id, message, sent
+            FROM SmtpOutboxTable
+            WHERE ordering=?
+        """);
         stmt.bind_int64(0, ordering);
         
         Db.Result results = stmt.exec(cancellable);
@@ -694,7 +714,8 @@ private class Geary.SmtpOutboxFolder : Geary.AbstractLocalFolder, Geary.FolderSu
         if (position < 1)
             return null;
         
-        return new OutboxRow(results.rowid_at(0), position, ordering, results.string_buffer_at(1), _path);
+        return new OutboxRow(results.rowid_at(0), position, ordering, results.bool_at(2),
+            results.string_buffer_at(1), _path);
     }
     
     private bool do_remove_email(Db.Connection cx, SmtpOutboxEmailIdentifier id, Cancellable? cancellable)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]