[geary] Don't create Archive folders for GMail accounts. Bug 767259.



commit 67018ecdaca2e8f156e2c365d7831d5be5b0bca4
Author: Michael James Gratton <mike vee net>
Date:   Sun Jun 5 18:36:16 2016 +1000

    Don't create Archive folders for GMail accounts. Bug 767259.
    
    * src/engine/imap-engine/imap-engine-generic-account.vala
      (GenericAccount): Add a protected virtual 'supported_special_folders'
      property and use that to determine what special folders should be
      created and can be required. Use that in
      ::get_required_special_folder_async and ::ensure_special_folders_async.
    
    * src/engine/imap-engine/gmail/imap-engine-gmail-account.vala
      (GmailAccount): Override supported_special_folders, don't include the
      Archive special folder.

 .../gmail/imap-engine-gmail-account.vala           |   17 ++++++-
 .../imap-engine/imap-engine-generic-account.vala   |   48 +++++++++-----------
 2 files changed, 37 insertions(+), 28 deletions(-)
---
diff --git a/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala 
b/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala
index 050913b..8607637 100644
--- a/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala
+++ b/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala
@@ -5,6 +5,15 @@
  */
 
 private class Geary.ImapEngine.GmailAccount : Geary.ImapEngine.GenericAccount {
+
+    // Archive is handled specially, so don't require it
+    private const Geary.SpecialFolderType[] SUPPORTED_SPECIAL_FOLDERS = {
+        Geary.SpecialFolderType.DRAFTS,
+        Geary.SpecialFolderType.SENT,
+        Geary.SpecialFolderType.SPAM,
+        Geary.SpecialFolderType.TRASH,
+    };
+
     public static Geary.Endpoint generate_imap_endpoint() {
         return new Geary.Endpoint(
             "imap.gmail.com",
@@ -20,7 +29,11 @@ private class Geary.ImapEngine.GmailAccount : Geary.ImapEngine.GenericAccount {
             Geary.Endpoint.Flags.SSL,
             Smtp.ClientConnection.DEFAULT_TIMEOUT_SEC);
     }
-    
+
+    protected override Geary.SpecialFolderType[] supported_special_folders {
+        get { return SUPPORTED_SPECIAL_FOLDERS; }
+    }
+
     public GmailAccount(string name, Geary.AccountInformation account_information,
         Imap.Account remote, ImapDB.Account local) {
         base (name, account_information, true, remote, local);
@@ -52,7 +65,7 @@ private class Geary.ImapEngine.GmailAccount : Geary.ImapEngine.GenericAccount {
                 return new GmailFolder(this, remote_account, local_account, local_folder, 
special_folder_type);
         }
     }
-    
+
     protected override SearchFolder new_search_folder() {
         return new GmailSearchFolder(this);
     }
diff --git a/src/engine/imap-engine/imap-engine-generic-account.vala 
b/src/engine/imap-engine/imap-engine-generic-account.vala
index 69f4fc1..1e99263 100644
--- a/src/engine/imap-engine/imap-engine-generic-account.vala
+++ b/src/engine/imap-engine/imap-engine-generic-account.vala
@@ -5,12 +5,24 @@
  */
 
 private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
+
     private const int REFRESH_FOLDER_LIST_SEC = 2 * 60;
     private const int REFRESH_UNSEEN_SEC = 1;
-    
+    private const Geary.SpecialFolderType[] SUPPORTED_SPECIAL_FOLDERS = {
+        Geary.SpecialFolderType.DRAFTS,
+        Geary.SpecialFolderType.SENT,
+        Geary.SpecialFolderType.SPAM,
+        Geary.SpecialFolderType.TRASH,
+        Geary.SpecialFolderType.ARCHIVE,
+    };
+
     private static Geary.FolderPath? outbox_path = null;
     private static Geary.FolderPath? search_path = null;
-    
+
+    protected virtual Geary.SpecialFolderType[] supported_special_folders {
+        get { return SUPPORTED_SPECIAL_FOLDERS; }
+    }
+
     private Imap.Account remote;
     private ImapDB.Account local;
     private bool open = false;
@@ -671,37 +683,21 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
     
     public override async Geary.Folder get_required_special_folder_async(Geary.SpecialFolderType special,
         Cancellable? cancellable) throws Error {
-        switch (special) {
-            case Geary.SpecialFolderType.DRAFTS:
-            case Geary.SpecialFolderType.SENT:
-            case Geary.SpecialFolderType.SPAM:
-            case Geary.SpecialFolderType.TRASH:
-            case Geary.SpecialFolderType.ARCHIVE:
-            break;
-            
-            default:
-                throw new EngineError.BAD_PARAMETERS(
-                    "Invalid special folder type %s passed to get_required_special_folder_async",
-                    special.to_string());
+        if (!(special in this.supported_special_folders)) {
+            throw new EngineError.BAD_PARAMETERS(
+                "Invalid special folder type %s passed to get_required_special_folder_async",
+                special.to_string());
         }
-        
         check_open();
-        
+
         return yield ensure_special_folder_async(special, cancellable);
     }
-    
+
     private async void ensure_special_folders_async(Cancellable? cancellable) throws Error {
-        Geary.SpecialFolderType[] required = {
-            Geary.SpecialFolderType.DRAFTS,
-            Geary.SpecialFolderType.SENT,
-            Geary.SpecialFolderType.SPAM,
-            Geary.SpecialFolderType.TRASH,
-            Geary.SpecialFolderType.ARCHIVE,
-        };
-        foreach (Geary.SpecialFolderType special in required)
+        foreach (Geary.SpecialFolderType special in this.supported_special_folders)
             yield ensure_special_folder_async(special, cancellable);
     }
-    
+
     private async void update_folders_async(Gee.Map<FolderPath, Geary.Folder> existing_folders,
         Gee.Map<FolderPath, Imap.Folder> remote_folders, bool remote_folders_suspect, Cancellable? 
cancellable) {
         // update all remote folders properties in the local store and active in the system


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