[Xfce4-commits] <postler:master> Move receive and send execution into the service

Christian Dywan noreply at xfce.org
Mon Dec 13 04:28:03 CET 2010


Updating branch refs/heads/master
         to 7cd1a90be8b788d5063243b78114c1b6e788497a (commit)
       from 50df203efe3985eb17b6acadbb6b8793a453c852 (commit)

commit 7cd1a90be8b788d5063243b78114c1b6e788497a
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sun Dec 12 23:01:55 2010 +0100

    Move receive and send execution into the service

 postler/postler-accounts.vala |   72 ++++++++++++++++-------------------------
 postler/postler-service.vala  |   45 ++++++++++++++++++-------
 2 files changed, 60 insertions(+), 57 deletions(-)

diff --git a/postler/postler-accounts.vala b/postler/postler-accounts.vala
index 7ec9b47..065a4da 100644
--- a/postler/postler-accounts.vala
+++ b/postler/postler-accounts.vala
@@ -361,7 +361,7 @@ public class Postler.Accounts : GLib.Object {
         delete_account (info);
     }
 
-    string? get_tool_configuration_filename (string? send, AccountInfo info) throws GLib.FileError {
+    string? get_tool_configfile (string? send, AccountInfo info) throws GLib.FileError {
         unowned string cache_dir = Environment.get_user_cache_dir ();
         string cache_path = cache_dir + "/postler/mail";
         if (DirUtils.create_with_parents (cache_path, 0700) != 0)
@@ -380,8 +380,8 @@ public class Postler.Accounts : GLib.Object {
         return null;
     }
 
-    void generate_tool_configuration (string? send, AccountInfo info) throws GLib.FileError {
-        string filename = get_tool_configuration_filename (send, info);
+    string get_tool_configuration (string? send, AccountInfo info) throws GLib.FileError {
+        string filename = get_tool_configfile (send, info);
         /* FIXME: Bail out if the file exists and is younger than accountrc */
 
         if (certificate_file == null)
@@ -438,7 +438,7 @@ public class Postler.Accounts : GLib.Object {
                     );
             FileUtils.set_contents (filename, msmtprc, -1);
             FileUtils.chmod (filename, 0600);
-            return;
+            return filename;
         }
 
         switch (info.type) {
@@ -486,53 +486,37 @@ public class Postler.Accounts : GLib.Object {
             break;
         case AccountType.MAILDIR:
         case AccountType.SEARCH:
-            throw new GLib.FileError.FAILED (_("This type can't receive mail."));
+            throw new GLib.FileError.FAILED (
+                _("Account \"%s\" can't receive mail."), info.name);
         }
+        return filename;
     }
 
-    public void send_or_receive (string? send, AccountInfo? info=null) {
-        var infos = new GLib.List<AccountInfo> ();
-        if (info != null)
-            infos.prepend (info);
-        else {
-            foreach (var info in this.infos) {
-                if (info.type == AccountType.IMAP)
-                    infos.prepend (info);
-            }
+    public string get_receive_command (AccountInfo info) throws FileError {
+        string command;
+        
+        if (info.type == AccountType.IMAP) {
+            unowned string? mbsync = Environment.get_variable ("POSTLER_MBSYNC");
+            if (mbsync == null || mbsync == "")
+                mbsync = "postler-mbsync";
+            string filename = get_tool_configuration (null, info);
+            command = "%s -c %s --pull%s mirror".printf (
+                mbsync, filename, info.sync == "full" ? " --push --expunge" : "");
         }
+        else
+            throw new GLib.FileError.FAILED (
+                _("Account \"%s\" can't receive mail."), info.name);
 
-        foreach (var info in infos) {
-            try {
-            string filename = get_tool_configuration_filename (send, info);
-            string command;
-            if (send != null)
-                command = "%s -c 'cat \"%s\" | msmtp -C %s -t'".printf (
-                    Environment.get_variable ("SHELL"), send, filename);
-            else if (info.type == AccountType.IMAP) {
-                unowned string? mbsync = Environment.get_variable ("POSTLER_MBSYNC");
-                if (mbsync == null || mbsync == "")
-                    mbsync = "postler-mbsync";
-                command = "%s -c %s --pull%s mirror".printf (
-                    mbsync, filename, info.sync == "full" ? " --push --expunge" : "");
-            } else
-                continue;
-                generate_tool_configuration (send, info);
-                if (DirUtils.create_with_parents (info.path, 0700) != 0)
-                    throw new GLib.FileError.FAILED (_("Mail folder couldn't be created."));
-                Postler.App.execute_command (command);
-            } catch (GLib.Error error) {
-                GLib.warning (_("Failed to generate configuration for type \"%s\"."),
-                    info.type.to_string ());
-            }
-        }
-    }
-
-    public void receive (AccountInfo? info=null) {
-        send_or_receive (null, info);
+        if (DirUtils.create_with_parents (info.path, 0700) != 0)
+            throw new GLib.FileError.FAILED (_("Mail folder couldn't be created."));
+        return command;
     }
 
-    public void send (AccountInfo? info=null, string filename) {
-        send_or_receive (filename, info);
+    public string get_send_command (AccountInfo info, string send) throws FileError {
+        string filename = get_tool_configuration (send, info);
+        string command = "%s -c 'cat \"%s\" | msmtp -C %s -t'".printf (
+            Environment.get_variable ("SHELL"), send, filename);
+        return command;
     }
 }
 
diff --git a/postler/postler-service.vala b/postler/postler-service.vala
index 28054e9..55cad78 100644
--- a/postler/postler-service.vala
+++ b/postler/postler-service.vala
@@ -14,28 +14,47 @@ namespace Postler {
     [DBus (name = "org.elementary.Postler")]
     class PostlerService : Object {
         public bool receive (string account) {
+            var infos = new GLib.List<AccountInfo> ();
             var accounts = new Accounts ();
             if (account == "") {
-                accounts.receive (null);
-                return true;
+                foreach (var info in accounts.get_infos ()) {
+                    if (info.type == AccountType.IMAP)
+                        infos.prepend (info);
+                }
             }
-
-            foreach (var info in accounts.get_infos ())
-                if (info.name == account) {
-                    accounts.receive (info);
-                    return true;
+            else {
+                foreach (var info in accounts.get_infos ()) {
+                    if (info.name == account)
+                        infos.prepend (info);
                 }
+            }
 
-            return false;
+            if (infos.length () == 0)
+                return false;
+
+            foreach (var info in infos) {
+                try {
+                    string command = accounts.get_receive_command (info);
+                    Postler.App.execute_command (command);
+                } catch (Error error) {
+                    return false;
+                }
+            }
+            return true;
         }
 
         public bool send (string account, string filename) {
             var accounts = new Accounts ();
-            foreach (var info in accounts.get_infos ())
-                if (info.name == account) {
-                    accounts.send (info, filename);
-                    return true;
-                }
+            try {
+                foreach (var info in accounts.get_infos ())
+                    if (info.name == account) {
+                        string command = accounts.get_send_command (info, filename);
+                        Postler.App.execute_command (command);
+                        return true;
+                    }
+            } catch (Error error) {
+                return false;
+            }
             return false;
         }
     }



More information about the Xfce4-commits mailing list