[Xfce4-commits] <postler:master> Fetch folders after creating new account

Christian Dywan noreply at xfce.org
Sun Dec 19 03:06:03 CET 2010


Updating branch refs/heads/master
         to 1e371a673d0d0125d068318c3f1eb63898063099 (commit)
       from b7597419dfbab55057b99e6376866aa6021eab1d (commit)

commit 1e371a673d0d0125d068318c3f1eb63898063099
Author: Bernd Prünster <bernd.pruenster at gmail.com>
Date:   Sun Dec 19 01:59:56 2010 +0100

    Fetch folders after creating new account

 postler/postler-accounts.vala     |   20 ++++++++++++++
 postler/postler-accountsetup.vala |    1 +
 postler/postler-bureau.vala       |    2 +
 postler/postler-client.vala       |    9 ++++++
 postler/postler-service.vala      |   51 +++++++++++++++++++++++++++++++++++++
 5 files changed, 83 insertions(+), 0 deletions(-)

diff --git a/postler/postler-accounts.vala b/postler/postler-accounts.vala
index e6b9711..0c16ee8 100644
--- a/postler/postler-accounts.vala
+++ b/postler/postler-accounts.vala
@@ -520,6 +520,26 @@ public class Postler.Accounts : GLib.Object {
         return command;
     }
 
+    public string get_fetch_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 --list -c %s  mirror".printf (
+                mbsync, filename);
+        }
+        else
+            throw new GLib.FileError.FAILED (
+                _("Account \"%s\" can't receive mail."), info.name);
+
+        if (DirUtils.create_with_parents (info.path, 0700) != 0)
+            throw new GLib.FileError.FAILED (_("Mail folder couldn't be created."));
+        return command;
+    }
+
     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 (
diff --git a/postler/postler-accountsetup.vala b/postler/postler-accountsetup.vala
index 281a45c..d936823 100644
--- a/postler/postler-accountsetup.vala
+++ b/postler/postler-accountsetup.vala
@@ -117,6 +117,7 @@ public class Postler.AccountSetup : Gtk.Dialog {
     private AccountSetup (AccountInfo? info=null) {
         widget = new AccountWidget (info);
         widget.done.connect ((info) => {
+            hide ();
             done (info);
             destroy ();
         });
diff --git a/postler/postler-bureau.vala b/postler/postler-bureau.vala
index 7c178f5..af1df51 100644
--- a/postler/postler-bureau.vala
+++ b/postler/postler-bureau.vala
@@ -333,6 +333,7 @@ public class Postler.Bureau : Gtk.Window {
     void action_account_new () {
         AccountSetup.new_account ().done.connect ((setup, info) => {
             accounts.add_info (info);
+            client.fetch ();
             folders.populate ();
         } );
     }
@@ -655,6 +656,7 @@ public class Postler.Bureau : Gtk.Window {
                 messages.parent.set_no_show_all (false);
                 messages.parent.show_all ();
                 accounts.add_info (info);
+                client.fetch ();
                 folders.populate ();
             });
         }
diff --git a/postler/postler-client.vala b/postler/postler-client.vala
index ddcdcc2..17b36d7 100644
--- a/postler/postler-client.vala
+++ b/postler/postler-client.vala
@@ -15,6 +15,7 @@ namespace Postler {
     interface PostlerClient : Object {
         public signal void progress (string text, double fraction);
         public abstract bool receive (string account) throws IOError;
+        public abstract bool fetch (string account) throws IOError;
         public abstract bool send (string account, string filename) throws IOError;
     }
 
@@ -47,6 +48,14 @@ namespace Postler {
             }
         }
 
+        public bool fetch (string account="") {
+            try {
+                return client.fetch (account);
+            } catch (GLib.Error error) {
+                return false;
+            }
+        }
+
         public bool send (string account, string filename) {
             try {
                 return client.send (account, filename);
diff --git a/postler/postler-service.vala b/postler/postler-service.vala
index 2139813..a94c02d 100644
--- a/postler/postler-service.vala
+++ b/postler/postler-service.vala
@@ -135,6 +135,57 @@ namespace Postler {
             return true;
         }
 
+        public bool fetch (string account) {
+            var infos = new GLib.List<AccountInfo> ();
+            var accounts = new Accounts ();
+            if (account == "") {
+                foreach (var info in accounts.get_infos ()) {
+                    if (info.type == AccountType.IMAP)
+                        infos.prepend (info);
+                }
+            }
+            else {
+                foreach (var info in accounts.get_infos ()) {
+                    if (info.name == account)
+                        infos.prepend (info);
+                }
+            }
+
+            if (infos.length () == 0)
+                return false;
+
+            unread = 0;
+            foreach (var info in infos) {
+                try {
+                    string command = accounts.get_fetch_command (info);
+                    string output;
+                    Process.spawn_sync (null, command.split (" "), null, SpawnFlags.SEARCH_PATH, null, out output);
+                    GLib.debug ("%s -> %s", info.path, output);
+                    string[] folders = ((output.split ("INBOX\n"
+                                        + "Channel local-remote\n"
+                                        + "Opening slave local...\n"
+                                        + "local-remote:"))[1]).split ("\n");
+                    /* INBOX is always needed */
+                    DirUtils.create (info.path + "/INBOX", 0700);
+                    DirUtils.create (info.path + "/INBOX/new", 0700);
+                    DirUtils.create (info.path + "/INBOX/cur", 0700);
+                    DirUtils.create (info.path + "/INBOX/tmp", 0700);
+                    foreach (string current_folder in folders) {
+                        if (current_folder == "")
+                            continue;
+                        DirUtils.create (info.path + "/" + current_folder.replace ("/", "~-"), 0700);
+                        DirUtils.create (info.path + "/" + current_folder.replace ("/", "~-") + "/new", 0700);
+                        DirUtils.create (info.path + "/" + current_folder.replace ("/", "~-") + "/cur", 0700);
+                        DirUtils.create (info.path + "/" + current_folder.replace ("/", "~-") + "/tmp", 0700);
+                    }
+                } catch (Error error) {
+                    return false;
+                }
+            }
+
+            return true;
+        }
+
         bool msmtp_input (IOChannel channel, IOCondition condition) {
             if ((condition & IOCondition.HUP) == IOCondition.HUP) {
                 /* FIXME: Move file */



More information about the Xfce4-commits mailing list