[balsa/wip/gtk4: 255/351] Uncrustify mailbox_*.[ch]



commit a4998f1723adddd773cffeb52871eed964276ae6
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Mon Mar 26 13:28:15 2018 -0400

    Uncrustify mailbox_*.[ch]

 libbalsa/mailbox_imap.c    | 3189 +++++++++++++++++++++++++-------------------
 libbalsa/mailbox_imap.h    |   78 +-
 libbalsa/mailbox_local.c   | 1512 ++++++++++++---------
 libbalsa/mailbox_local.h   |   76 +-
 libbalsa/mailbox_maildir.c |  702 ++++++-----
 libbalsa/mailbox_maildir.h |   15 +-
 libbalsa/mailbox_mbox.c    | 1358 +++++++++++--------
 libbalsa/mailbox_mbox.h    |   14 +-
 libbalsa/mailbox_mh.c      |  988 ++++++++------
 libbalsa/mailbox_mh.h      |   15 +-
 libbalsa/mailbox_pop3.c    | 1131 +++++++++-------
 libbalsa/mailbox_pop3.h    |   40 +-
 libbalsa/mailbox_remote.c  |   47 +-
 libbalsa/mailbox_remote.h  |   19 +-
 14 files changed, 5155 insertions(+), 4029 deletions(-)
---
diff --git a/libbalsa/mailbox_imap.c b/libbalsa/mailbox_imap.c
index e8cdf56..613d276 100644
--- a/libbalsa/mailbox_imap.c
+++ b/libbalsa/mailbox_imap.c
@@ -5,29 +5,29 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option) 
+ * the Free Software Foundation; either version 2, or (at your option)
  * any later version.
- *  
+ *
  * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of 
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *  
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 /* NOTES:
 
-   CACHING: persistent cache is implemented using a directory. 
+   CACHING: persistent cache is implemented using a directory.
 
    CONNECTIONS: there is always one connection per opened mailbox to
    keep track of untagged responses. Understand idea of untagged
    responses particularly for shared mailboxes before you try messing
    with this.
-*/
+ */
 #if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H
-# include "config.h"
+#   include "config.h"
 #endif                          /* HAVE_CONFIG_H */
 
 
@@ -63,19 +63,19 @@
 struct _LibBalsaMailboxImap {
     LibBalsaMailboxRemote mailbox;
     ImapMboxHandle *handle;     /* stream that has this mailbox selected */
-    guint handle_refs;         /* reference counter */
-    gint search_stamp;         /* search result validator */
+    guint handle_refs;          /* reference counter */
+    gint search_stamp;          /* search result validator */
 
-    gchar *path;               /* Imap local path (third part of URL) */
-    ImapUID      uid_validity;
+    gchar *path;                /* Imap local path (third part of URL) */
+    ImapUID uid_validity;
 
-    GArray* messages_info;
+    GArray *messages_info;
     GPtrArray *msgids; /* message-ids */
 
     GArray *sort_ranks;
     guint unread_update_id;
     LibBalsaMailboxSortFields sort_field;
-    unsigned opened:1;
+    unsigned opened : 1;
 
     ImapAclType rights;     /* RFC 4314 'myrights' */
     GList *acls;            /* RFC 4314 acl's */
@@ -92,43 +92,42 @@ struct message_info {
     LibBalsaMessageFlag user_flags;
 };
 
-static off_t ImapCacheSize = 30*1024*1024; /* 30MB */
-
- /* issue message if downloaded part has more than this size */
-static unsigned SizeMsgThreshold = 50*1024;
-static void libbalsa_mailbox_imap_dispose(GObject * object);
-static void libbalsa_mailbox_imap_finalize(GObject * object);
-static void libbalsa_mailbox_imap_class_init(LibBalsaMailboxImapClass *
-                                            klass);
-static void libbalsa_mailbox_imap_init(LibBalsaMailboxImap * mailbox);
-static gboolean libbalsa_mailbox_imap_open(LibBalsaMailbox * mailbox,
-                                          GError **err);
-static void libbalsa_mailbox_imap_close(LibBalsaMailbox * mailbox,
-                                        gboolean expunge);
+static off_t ImapCacheSize = 30 * 1024 * 1024; /* 30MB */
+
+/* issue message if downloaded part has more than this size */
+static unsigned SizeMsgThreshold = 50 * 1024;
+static void         libbalsa_mailbox_imap_dispose(GObject *object);
+static void         libbalsa_mailbox_imap_finalize(GObject *object);
+static void         libbalsa_mailbox_imap_class_init(LibBalsaMailboxImapClass *
+                                                     klass);
+static void         libbalsa_mailbox_imap_init(LibBalsaMailboxImap *mailbox);
+static gboolean     libbalsa_mailbox_imap_open(LibBalsaMailbox *mailbox,
+                                               GError         **err);
+static void         libbalsa_mailbox_imap_close(LibBalsaMailbox *mailbox,
+                                                gboolean         expunge);
 static GMimeStream *libbalsa_mailbox_imap_get_message_stream(LibBalsaMailbox *
-                                                            mailbox,
-                                                            guint msgno,
-                                                            gboolean peek);
-static void libbalsa_mailbox_imap_check(LibBalsaMailbox * mailbox);
-
-static void
-libbalsa_mailbox_imap_search_iter_free(LibBalsaMailboxSearchIter * iter);
-static gboolean libbalsa_mailbox_imap_message_match(LibBalsaMailbox* mailbox,
-                                                   guint msgno,
-                                                   LibBalsaMailboxSearchIter
-                                                   * search_iter);
-static gboolean libbalsa_mailbox_imap_can_match(LibBalsaMailbox  *mbox,
-                                               LibBalsaCondition *condition);
-static void libbalsa_mailbox_imap_save_config(LibBalsaMailbox * mailbox,
-                                             const gchar * prefix);
-static void libbalsa_mailbox_imap_load_config(LibBalsaMailbox * mailbox,
-                                             const gchar * prefix);
-
-static gboolean libbalsa_mailbox_imap_sync(LibBalsaMailbox * mailbox,
-                                           gboolean expunge);
-static LibBalsaMessage* libbalsa_mailbox_imap_get_message(LibBalsaMailbox*
-                                                         mailbox,
-                                                         guint msgno);
+                                                             mailbox,
+                                                             guint    msgno,
+                                                             gboolean peek);
+static void     libbalsa_mailbox_imap_check(LibBalsaMailbox *mailbox);
+
+static void     libbalsa_mailbox_imap_search_iter_free(LibBalsaMailboxSearchIter *iter);
+static gboolean libbalsa_mailbox_imap_message_match(LibBalsaMailbox *mailbox,
+                                                    guint            msgno,
+                                                    LibBalsaMailboxSearchIter
+                                                                    *search_iter);
+static gboolean libbalsa_mailbox_imap_can_match(LibBalsaMailbox   *mbox,
+                                                LibBalsaCondition *condition);
+static void     libbalsa_mailbox_imap_save_config(LibBalsaMailbox *mailbox,
+                                                  const gchar     *prefix);
+static void     libbalsa_mailbox_imap_load_config(LibBalsaMailbox *mailbox,
+                                                  const gchar     *prefix);
+
+static gboolean         libbalsa_mailbox_imap_sync(LibBalsaMailbox *mailbox,
+                                                   gboolean         expunge);
+static LibBalsaMessage *libbalsa_mailbox_imap_get_message(LibBalsaMailbox *
+                                                          mailbox,
+                                                          guint msgno);
 static gboolean libbalsa_mailbox_imap_prepare_threading(LibBalsaMailbox *
                                                         mailbox,
                                                         guint start);
@@ -138,54 +137,56 @@ static gboolean libbalsa_mailbox_imap_fetch_structure(LibBalsaMailbox *
                                                       message,
                                                       LibBalsaFetchFlag
                                                       flags);
-static void libbalsa_mailbox_imap_fetch_headers(LibBalsaMailbox *mailbox,
-                                                LibBalsaMessage *message);
+static void     libbalsa_mailbox_imap_fetch_headers(LibBalsaMailbox *mailbox,
+                                                    LibBalsaMessage *message);
 static gboolean libbalsa_mailbox_imap_get_msg_part(LibBalsaMessage *msg,
-                                                  LibBalsaMessageBody *,
-                                                   GError **err);
+                                                   LibBalsaMessageBody *,
+                                                   GError         **err);
 static GArray *libbalsa_mailbox_imap_duplicate_msgnos(LibBalsaMailbox *
-                                                     mailbox);
+                                                      mailbox);
 
-static guint libbalsa_mailbox_imap_add_messages(LibBalsaMailbox *mailbox,
-                                               LibBalsaAddMessageIterator mi,
-                                               void *mi_arg,
-                                               GError ** err);
+static guint libbalsa_mailbox_imap_add_messages(LibBalsaMailbox           *mailbox,
+                                                LibBalsaAddMessageIterator mi,
+                                                void                      *mi_arg,
+                                                GError                   **err);
 
-static gboolean lbm_imap_messages_change_flags(LibBalsaMailbox * mailbox,
-                                               GArray * seqno,
-                                              LibBalsaMessageFlag set,
-                                              LibBalsaMessageFlag clear);
+static gboolean lbm_imap_messages_change_flags(LibBalsaMailbox    *mailbox,
+                                               GArray             *seqno,
+                                               LibBalsaMessageFlag set,
+                                               LibBalsaMessageFlag clear);
 static gboolean libbalsa_mailbox_imap_msgno_has_flags(LibBalsaMailbox *
-                                                      mailbox, guint seqno,
+                                                      mailbox,
+                                                      guint seqno,
                                                       LibBalsaMessageFlag
                                                       set,
                                                       LibBalsaMessageFlag
                                                       unset);
-static gboolean libbalsa_mailbox_imap_can_do(LibBalsaMailbox* mbox,
+static gboolean libbalsa_mailbox_imap_can_do(LibBalsaMailbox               *mbox,
                                              enum LibBalsaMailboxCapability c);
 
 static void libbalsa_mailbox_imap_set_threading(LibBalsaMailbox *mailbox,
-                                               LibBalsaMailboxThreadingType
-                                               thread_type);
-static void lbm_imap_update_view_filter(LibBalsaMailbox   *mailbox,
-                                        LibBalsaCondition *view_filter);
-static void libbalsa_mailbox_imap_sort(LibBalsaMailbox *mailbox,
-                                       GArray *array);
-static guint libbalsa_mailbox_imap_total_messages(LibBalsaMailbox *
-                                                 mailbox);
+                                                LibBalsaMailboxThreadingType
+                                                thread_type);
+static void     lbm_imap_update_view_filter(LibBalsaMailbox   *mailbox,
+                                            LibBalsaCondition *view_filter);
+static void     libbalsa_mailbox_imap_sort(LibBalsaMailbox *mailbox,
+                                           GArray          *array);
+static guint    libbalsa_mailbox_imap_total_messages(LibBalsaMailbox *
+                                                     mailbox);
 static gboolean libbalsa_mailbox_imap_messages_copy(LibBalsaMailbox *
-                                                   mailbox,
-                                                   GArray * msgnos,
-                                                   LibBalsaMailbox *
-                                                   dest,
+                                                    mailbox,
+                                                    GArray *msgnos,
+                                                    LibBalsaMailbox *
+                                                    dest,
                                                     GError **err);
 
-static void server_host_settings_changed_cb(LibBalsaServer * server,
-                                           LibBalsaMailbox * mailbox);
+static void server_host_settings_changed_cb(LibBalsaServer  *server,
+                                            LibBalsaMailbox *mailbox);
 
-static struct message_info *message_info_from_msgno(
-                                                 LibBalsaMailboxImap * mimap,
-                                                 guint msgno)
+static struct message_info *
+message_info_from_msgno(
+    LibBalsaMailboxImap *mimap,
+    guint                msgno)
 {
     struct message_info *msg_info;
 
@@ -194,14 +195,16 @@ static struct message_info *message_info_from_msgno(
                libbalsa_mailbox_get_name(LIBBALSA_MAILBOX(mimap)), msgno,
                mimap->messages_info->len);
         msg_info = NULL;
-    } else
+    } else {
         msg_info =
             &g_array_index(mimap->messages_info, struct message_info,
                            msgno - 1);
+    }
 
     return msg_info;
 }
 
+
 #define IMAP_MAILBOX_UID_VALIDITY(mailbox) (LIBBALSA_MAILBOX_IMAP(mailbox)->uid_validity)
 
 G_DEFINE_TYPE(LibBalsaMailboxImap,
@@ -209,78 +212,80 @@ G_DEFINE_TYPE(LibBalsaMailboxImap,
               LIBBALSA_TYPE_MAILBOX_REMOTE)
 
 static void
-libbalsa_mailbox_imap_class_init(LibBalsaMailboxImapClass * klass)
+libbalsa_mailbox_imap_class_init(LibBalsaMailboxImapClass *klass)
 {
     GObjectClass *object_class;
     LibBalsaMailboxClass *libbalsa_mailbox_class;
 
-    object_class = G_OBJECT_CLASS(klass);
+    object_class           = G_OBJECT_CLASS(klass);
     libbalsa_mailbox_class = LIBBALSA_MAILBOX_CLASS(klass);
 
     object_class->dispose  = libbalsa_mailbox_imap_dispose;
     object_class->finalize = libbalsa_mailbox_imap_finalize;
 
-    libbalsa_mailbox_class->open_mailbox = libbalsa_mailbox_imap_open;
+    libbalsa_mailbox_class->open_mailbox  = libbalsa_mailbox_imap_open;
     libbalsa_mailbox_class->close_mailbox = libbalsa_mailbox_imap_close;
 
     libbalsa_mailbox_class->check = libbalsa_mailbox_imap_check;
-    
+
     libbalsa_mailbox_class->search_iter_free =
-       libbalsa_mailbox_imap_search_iter_free;
+        libbalsa_mailbox_imap_search_iter_free;
     libbalsa_mailbox_class->message_match =
-       libbalsa_mailbox_imap_message_match;
+        libbalsa_mailbox_imap_message_match;
     libbalsa_mailbox_class->can_match =
-       libbalsa_mailbox_imap_can_match;
+        libbalsa_mailbox_imap_can_match;
 
     libbalsa_mailbox_class->save_config =
-       libbalsa_mailbox_imap_save_config;
+        libbalsa_mailbox_imap_save_config;
     libbalsa_mailbox_class->load_config =
-       libbalsa_mailbox_imap_load_config;
-    libbalsa_mailbox_class->sync = libbalsa_mailbox_imap_sync;
-    libbalsa_mailbox_class->get_message = libbalsa_mailbox_imap_get_message;
+        libbalsa_mailbox_imap_load_config;
+    libbalsa_mailbox_class->sync              = libbalsa_mailbox_imap_sync;
+    libbalsa_mailbox_class->get_message       = libbalsa_mailbox_imap_get_message;
     libbalsa_mailbox_class->prepare_threading =
         libbalsa_mailbox_imap_prepare_threading;
-    libbalsa_mailbox_class->fetch_message_structure = 
+    libbalsa_mailbox_class->fetch_message_structure =
         libbalsa_mailbox_imap_fetch_structure;
-    libbalsa_mailbox_class->fetch_headers = 
+    libbalsa_mailbox_class->fetch_headers =
         libbalsa_mailbox_imap_fetch_headers;
-    libbalsa_mailbox_class->get_message_part = 
+    libbalsa_mailbox_class->get_message_part =
         libbalsa_mailbox_imap_get_msg_part;
     libbalsa_mailbox_class->get_message_stream =
-       libbalsa_mailbox_imap_get_message_stream;
+        libbalsa_mailbox_imap_get_message_stream;
     libbalsa_mailbox_class->duplicate_msgnos =
         libbalsa_mailbox_imap_duplicate_msgnos;
-    libbalsa_mailbox_class->add_messages = libbalsa_mailbox_imap_add_messages;
+    libbalsa_mailbox_class->add_messages          = libbalsa_mailbox_imap_add_messages;
     libbalsa_mailbox_class->messages_change_flags =
-       lbm_imap_messages_change_flags;
+        lbm_imap_messages_change_flags;
     libbalsa_mailbox_class->msgno_has_flags =
-       libbalsa_mailbox_imap_msgno_has_flags;
+        libbalsa_mailbox_imap_msgno_has_flags;
     libbalsa_mailbox_class->can_do =
-       libbalsa_mailbox_imap_can_do;
+        libbalsa_mailbox_imap_can_do;
     libbalsa_mailbox_class->set_threading =
-       libbalsa_mailbox_imap_set_threading;
+        libbalsa_mailbox_imap_set_threading;
     libbalsa_mailbox_class->update_view_filter =
         lbm_imap_update_view_filter;
-    libbalsa_mailbox_class->sort = libbalsa_mailbox_imap_sort;
+    libbalsa_mailbox_class->sort           = libbalsa_mailbox_imap_sort;
     libbalsa_mailbox_class->total_messages =
-       libbalsa_mailbox_imap_total_messages;
+        libbalsa_mailbox_imap_total_messages;
     libbalsa_mailbox_class->messages_copy =
-       libbalsa_mailbox_imap_messages_copy;
+        libbalsa_mailbox_imap_messages_copy;
 }
 
+
 static void
-libbalsa_mailbox_imap_init(LibBalsaMailboxImap * mailbox)
+libbalsa_mailbox_imap_init(LibBalsaMailboxImap *mailbox)
 {
-    mailbox->path = NULL;
-    mailbox->handle = NULL;
-    mailbox->handle_refs = 0;
-    mailbox->sort_ranks = g_array_new(FALSE, FALSE, sizeof(guint));
-    mailbox->sort_field = -1;  /* Initially invalid. */
+    mailbox->path         = NULL;
+    mailbox->handle       = NULL;
+    mailbox->handle_refs  = 0;
+    mailbox->sort_ranks   = g_array_new(FALSE, FALSE, sizeof(guint));
+    mailbox->sort_field   = -1; /* Initially invalid. */
     mailbox->disconnected = FALSE;
 }
 
+
 static void
-libbalsa_mailbox_imap_dispose(GObject * object)
+libbalsa_mailbox_imap_dispose(GObject *object)
 {
     LibBalsaMailboxRemote *remote;
     LibBalsaServer *server;
@@ -301,13 +306,14 @@ libbalsa_mailbox_imap_dispose(GObject * object)
     G_OBJECT_CLASS(libbalsa_mailbox_imap_parent_class)->dispose(object);
 }
 
+
 /* libbalsa_mailbox_imap_finalize:
    NOTE: we have to close mailbox ourselves without waiting for
    LibBalsaMailbox::finalize because we want to destroy server as well,
-   and close requires server for proper operation.  
-*/
+   and close requires server for proper operation.
+ */
 static void
-libbalsa_mailbox_imap_finalize(GObject * object)
+libbalsa_mailbox_imap_finalize(GObject *object)
 {
     LibBalsaMailboxImap *mailbox;
 
@@ -324,7 +330,8 @@ libbalsa_mailbox_imap_finalize(GObject * object)
     G_OBJECT_CLASS(libbalsa_mailbox_imap_parent_class)->finalize(object);
 }
 
-LibBalsaMailbox*
+
+LibBalsaMailbox *
 libbalsa_mailbox_imap_new(void)
 {
     LibBalsaMailbox *mailbox;
@@ -333,12 +340,13 @@ libbalsa_mailbox_imap_new(void)
     return mailbox;
 }
 
+
 /* libbalsa_mailbox_imap_update_url:
    this is to be used only by mailboxImap functions, with exception
    for the folder scanner, which has to go around libmutt limitations.
-*/
+ */
 void
-libbalsa_mailbox_imap_update_url(LibBalsaMailboxImap* mailbox)
+libbalsa_mailbox_imap_update_url(LibBalsaMailboxImap *mailbox)
 {
     LibBalsaServer *s = LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mailbox);
     gchar *url;
@@ -348,8 +356,10 @@ libbalsa_mailbox_imap_update_url(LibBalsaMailboxImap* mailbox)
     g_free(url);
 }
 
+
 void
-libbalsa_mailbox_imap_set_path(LibBalsaMailboxImap* mailbox, const gchar* path)
+libbalsa_mailbox_imap_set_path(LibBalsaMailboxImap *mailbox,
+                               const gchar         *path)
 {
     g_return_if_fail(mailbox);
     g_free(mailbox->path);
@@ -357,9 +367,11 @@ libbalsa_mailbox_imap_set_path(LibBalsaMailboxImap* mailbox, const gchar* path)
     libbalsa_mailbox_imap_update_url(mailbox);
 }
 
+
 gboolean
-libbalsa_imap_get_quota(LibBalsaMailboxImap * mailbox,
-                        gulong *max_kbyte, gulong *used_kbyte)
+libbalsa_imap_get_quota(LibBalsaMailboxImap *mailbox,
+                        gulong              *max_kbyte,
+                        gulong              *used_kbyte)
 {
     g_return_val_if_fail(LIBBALSA_MAILBOX_IMAP(mailbox), FALSE);
 
@@ -367,91 +379,104 @@ libbalsa_imap_get_quota(LibBalsaMailboxImap * mailbox,
                                max_kbyte, used_kbyte) == IMR_OK;
 }
 
+
 /* converts ACL's to a standard RFC 4314 acl string */
 static char *
 imap_acl_to_str(ImapAclType acl)
 {
     GString *rights;
     /* include "cd" for RFC 2086 support: */
-    static const char * flags = "lrswipkxteacd";
+    static const char *flags = "lrswipkxteacd";
     unsigned n;
 
     rights = g_string_new("");
-    for (n = 0; n < strlen(flags); n++)
-        if (acl & (1 << n))
+    for (n = 0; n < strlen(flags); n++) {
+        if (acl & (1 << n)) {
             rights = g_string_append_c(rights, flags[n]);
+        }
+    }
     return g_string_free(rights, FALSE);
 }
 
+
 gchar *
-libbalsa_imap_get_rights(LibBalsaMailboxImap * mailbox)
+libbalsa_imap_get_rights(LibBalsaMailboxImap *mailbox)
 {
     g_return_val_if_fail(LIBBALSA_MAILBOX_IMAP(mailbox), NULL);
 
-    if (mailbox->rights == IMAP_ACL_NONE)
+    if (mailbox->rights == IMAP_ACL_NONE) {
         return NULL;
-    else
+    } else {
         return imap_acl_to_str(mailbox->rights);
+    }
 }
 
+
 gchar **
-libbalsa_imap_get_acls(LibBalsaMailboxImap * mailbox)
+libbalsa_imap_get_acls(LibBalsaMailboxImap *mailbox)
 {
-    gchar ** acls;
+    gchar **acls;
     guint n;
     GList *p;
 
     g_return_val_if_fail(LIBBALSA_MAILBOX_IMAP(mailbox), NULL);
 
-    if (!mailbox->acls)
+    if (!mailbox->acls) {
         return NULL;
+    }
     acls = g_new0(char *, 2 * g_list_length(mailbox->acls) + 1);
-    n = 0;
+    n    = 0;
     for (p = mailbox->acls; p != NULL; p = p->next, n += 2) {
-        acls[n] = g_strdup(((ImapUserAclType *)p->data)->uid);
+        acls[n]     = g_strdup(((ImapUserAclType *)p->data)->uid);
         acls[n + 1] = imap_acl_to_str(((ImapUserAclType *)p->data)->acl);
     }
     return acls;
 }
 
-const gchar*
-libbalsa_mailbox_imap_get_path(LibBalsaMailboxImap * mailbox)
+
+const gchar *
+libbalsa_mailbox_imap_get_path(LibBalsaMailboxImap *mailbox)
 {
     return mailbox->path;
 }
 
+
 static void
-server_host_settings_changed_cb(LibBalsaServer * server,
-                               LibBalsaMailbox * mailbox)
+server_host_settings_changed_cb(LibBalsaServer  *server,
+                                LibBalsaMailbox *mailbox)
 {
     libbalsa_mailbox_imap_update_url(LIBBALSA_MAILBOX_IMAP(mailbox));
 }
 
-static gchar*
+
+static gchar *
 get_cache_dir(gboolean is_persistent)
 {
     gchar *fname;
-    if(is_persistent) {
+    if (is_persistent) {
         const gchar *home = g_get_home_dir();
         fname = g_strconcat(home, G_DIR_SEPARATOR_S ".balsa"
                             G_DIR_SEPARATOR_S "imap-cache", NULL);
-    } else
+    } else {
         fname = g_strconcat(g_get_tmp_dir(),
                             G_DIR_SEPARATOR_S "/balsa-",
                             g_get_user_name(), NULL);
+    }
 
     return fname;
 }
 
-static gchar*
+
+static gchar *
 get_header_cache_path(LibBalsaMailboxImap *mimap)
 {
-    LibBalsaServer *s = LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mimap);
-    gchar *cache_dir = get_cache_dir(TRUE); /* FIXME */
+    LibBalsaServer *s  = LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mimap);
+    gchar *cache_dir   = get_cache_dir(TRUE); /* FIXME */
     gchar *header_file = g_strdup_printf("%s@%s-%s-%u-headers2",
-                                        libbalsa_server_get_username(s), libbalsa_server_get_host(s),
-                                        (mimap->path ? mimap->path : "INBOX"),
-                                        mimap->uid_validity);
+                                         libbalsa_server_get_username(s),
+                                         libbalsa_server_get_host(s),
+                                         (mimap->path ? mimap->path : "INBOX"),
+                                         mimap->uid_validity);
     gchar *encoded_path = libbalsa_urlencode(header_file);
     g_free(header_file);
     header_file = g_build_filename(cache_dir, encoded_path, NULL);
@@ -461,22 +486,24 @@ get_header_cache_path(LibBalsaMailboxImap *mimap)
     return header_file;
 }
 
-static gchar**
-get_cache_name_pair(LibBalsaMailboxImap* mailbox, const gchar *type,
-                    ImapUID uid)
+
+static gchar **
+get_cache_name_pair(LibBalsaMailboxImap *mailbox,
+                    const gchar         *type,
+                    ImapUID              uid)
 {
     LibBalsaServer *s      = LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mailbox);
     LibBalsaImapServer *is = LIBBALSA_IMAP_SERVER(s);
     gboolean is_persistent = libbalsa_imap_server_has_persistent_cache(is);
-    gchar **res = g_malloc(3*sizeof(gchar*));
-    ImapUID uid_validity = LIBBALSA_MAILBOX_IMAP(mailbox)->uid_validity;
+    gchar **res            = g_malloc(3 * sizeof(gchar *));
+    ImapUID uid_validity   = LIBBALSA_MAILBOX_IMAP(mailbox)->uid_validity;
     gchar *fname;
 
     res[0] = get_cache_dir(is_persistent);
-    fname = g_strdup_printf("%s@%s-%s-%u-%u-%s",
-                            libbalsa_server_get_username(s), libbalsa_server_get_host(s),
-                            (mailbox->path ? mailbox->path : "INBOX"),
-                            uid_validity, uid, type);
+    fname  = g_strdup_printf("%s@%s-%s-%u-%u-%s",
+                             libbalsa_server_get_username(s), libbalsa_server_get_host(s),
+                             (mailbox->path ? mailbox->path : "INBOX"),
+                             uid_validity, uid, type);
     res[1] = libbalsa_urlencode(fname);
     g_free(fname);
     res[2] = NULL;
@@ -484,55 +511,60 @@ get_cache_name_pair(LibBalsaMailboxImap* mailbox, const gchar *type,
     return res;
 }
 
+
 /* clean_cache:
    removes unused entries from the cache file.
-*/
+ */
 struct file_info {
-    char  *name;
-    off_t  size;
+    char *name;
+    off_t size;
     time_t time;
 };
 static gint
-cmp_by_time (gconstpointer  a, gconstpointer  b)
+cmp_by_time(gconstpointer a,
+            gconstpointer b)
 {
-    return ((const struct file_info*)b)->time
-        -((const struct file_info*)a)->time;
+    return ((const struct file_info *)b)->time
+           - ((const struct file_info *)a)->time;
 }
 
+
 static void
-clean_dir(const char *dir_name, off_t cache_size)
+clean_dir(const char *dir_name,
+          off_t       cache_size)
 {
-    DIR* dir;
-    struct dirent* key;
+    DIR *dir;
+    struct dirent *key;
     GList *list, *lst;
     off_t sz;
     dir = opendir(dir_name);
-    if(!dir)
+    if (!dir) {
         return;
+    }
 
     list = NULL;
-    while ( (key=readdir(dir)) != NULL) {
+    while ((key = readdir(dir)) != NULL) {
         struct stat st;
         struct file_info *fi;
         gchar *fname = g_build_filename(dir_name, key->d_name, NULL);
-        if(stat(fname, &st) == -1 || !S_ISREG(st.st_mode)) {
-           g_free(fname);
+        if ((stat(fname, &st) == -1) || !S_ISREG(st.st_mode)) {
+            g_free(fname);
             continue;
-       }
-        fi = g_new(struct file_info,1);
+        }
+        fi       = g_new(struct file_info, 1);
         fi->name = fname;
         fi->size = st.st_size;
         fi->time = st.st_atime;
-        list = g_list_prepend(list, fi);
+        list     = g_list_prepend(list, fi);
     }
     closedir(dir);
 
     list = g_list_sort(list, cmp_by_time);
-    sz = 0;
-    for(lst = list; lst; lst = lst->next) {
-        struct file_info *fi = (struct file_info*)(lst->data);
+    sz   = 0;
+    for (lst = list; lst; lst = lst->next) {
+        struct file_info *fi = (struct file_info *)(lst->data);
         sz += fi->size;
-        if(sz>cache_size) {
+        if (sz > cache_size) {
             /* printf("removing %s\n", fi->name); */
             unlink(fi->name);
         }
@@ -542,123 +574,145 @@ clean_dir(const char *dir_name, off_t cache_size)
     g_list_free(list);
 }
 
+
 static gboolean
-clean_cache(LibBalsaMailbox* mailbox)
+clean_cache(LibBalsaMailbox *mailbox)
 {
-    LibBalsaServer *s= LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mailbox);
+    LibBalsaServer *s      = LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mailbox);
     gboolean is_persistent =
         libbalsa_imap_server_has_persistent_cache(LIBBALSA_IMAP_SERVER(s));
-    gchar* dir;
+    gchar *dir;
 
     dir = get_cache_dir(is_persistent);
     clean_dir(dir, ImapCacheSize);
     g_free(dir);
- 
+
     return TRUE;
 }
+
+
 struct ImapCacheManager;
-static struct ImapCacheManager*imap_cache_manager_new_from_file(const char *header_cache_path);
-static void imap_cache_manager_free(struct ImapCacheManager *icm);
+static struct ImapCacheManager *imap_cache_manager_new_from_file(const char *header_cache_path);
+static void                     imap_cache_manager_free(struct ImapCacheManager *icm);
 static struct ImapCacheManager *icm_store_cached_data(ImapMboxHandle *h);
-static void icm_restore_from_cache(ImapMboxHandle *h,
-                                   struct ImapCacheManager *icm);
-static gboolean icm_save_to_file(struct ImapCacheManager *icm,
-                                const gchar *path);
+static void                     icm_restore_from_cache(ImapMboxHandle          *h,
+                                                       struct ImapCacheManager *icm);
+static gboolean                 icm_save_to_file(struct ImapCacheManager *icm,
+                                                 const gchar             *path);
 
 static ImapResult
 mi_reconnect(ImapMboxHandle *h)
 {
     struct ImapCacheManager *icm = icm_store_cached_data(h);
     ImapResult r;
-    unsigned old_cnt = imap_mbox_handle_get_exists(h);
+    unsigned old_cnt  = imap_mbox_handle_get_exists(h);
     unsigned old_next = imap_mbox_handle_get_uidnext(h);
 
     r = imap_mbox_handle_reconnect(h, NULL);
-    if(r==IMAP_SUCCESS) icm_restore_from_cache(h, icm);
+    if (r == IMAP_SUCCESS) {
+        icm_restore_from_cache(h, icm);
+    }
     imap_cache_manager_free(icm);
-    if(imap_mbox_handle_get_exists(h) != old_cnt ||
-       imap_mbox_handle_get_uidnext(h) != old_next)
-       g_signal_emit_by_name(h, "exists-notify", 0);
+    if ((imap_mbox_handle_get_exists(h) != old_cnt) ||
+        (imap_mbox_handle_get_uidnext(h) != old_next)) {
+        g_signal_emit_by_name(h, "exists-notify", 0);
+    }
     return r;
 }
+
+
 /* ImapIssue macro handles reconnecting. We might issue a
    LIBBALSA_INFORMATION_MESSAGE here but it would be overwritten by
    login information... */
-#define II(rc,h,line) \
-   {int trials=2;do{\
-    if(imap_mbox_is_disconnected(h) &&mi_reconnect(h)!=IMAP_SUCCESS)\
-        {rc=IMR_NO;break;};\
-    rc=line; \
-    if(imap_handle_op_cancelled(h))\
-        break;\
-    else if(rc==IMR_SEVERED)                             \
-    libbalsa_information(LIBBALSA_INFORMATION_WARNING, \
-    _("IMAP connection has been severed. Reconnecting…")); \
-    else if(rc==IMR_PROTOCOL)                               \
-    libbalsa_information(LIBBALSA_INFORMATION_WARNING, \
-    _("IMAP protocol error. Try enabling bug workarounds.")); \
-    else if(rc==IMR_BYE) {char *text = imap_mbox_handle_get_last_msg(h); \
-    libbalsa_information(LIBBALSA_INFORMATION_WARNING, \
-    _("IMAP server has shut the connection: %s Reconnecting…"), text); \
-    g_free(text);}\
-    else break;}while(trials-->0);}
-#define IIA(rc,h,line,cmd)                         \
-   {int trials=2;do{\
-    if(imap_mbox_is_disconnected(h) &&mi_reconnect(h)!=IMAP_SUCCESS)\
-        {rc=0;break;};\
-    rc=line; \
-    if(imap_mbox_op_cancelled(h))\
-        break;\
-    else if(rc != IMR_OK) \
-    libbalsa_information(LIBBALSA_INFORMATION_WARNING, \
-     _("Async IMAP cmd %s could not be executed. Reconnecting…"),cmd); \
-    else break;}while(trials-->0);}
+#define II(rc, h, line) \
+    {int trials = 2; do { \
+         if (imap_mbox_is_disconnected(h) && mi_reconnect(h) != IMAP_SUCCESS) \
+         {rc = IMR_NO; break;}; \
+         rc = line; \
+         if (imap_handle_op_cancelled(h)) { \
+             break;} \
+         else if (rc == IMR_SEVERED) {                             \
+             libbalsa_information(LIBBALSA_INFORMATION_WARNING, \
+                                  _("IMAP connection has been severed. Reconnecting…"));} \
+         else if (rc == IMR_PROTOCOL) {                               \
+             libbalsa_information(LIBBALSA_INFORMATION_WARNING, \
+                                  _("IMAP protocol error. Try enabling bug workarounds."));} \
+         else if (rc == IMR_BYE) {char *text = imap_mbox_handle_get_last_msg(h); \
+                                  libbalsa_information(LIBBALSA_INFORMATION_WARNING, \
+                                                       _( \
+                                                           "IMAP server has shut the connection: %s 
Reconnecting…"), \
+                                                       text); \
+                                  g_free(text);} \
+         else { break;} } while (trials -- > 0);}
+#define IIA(rc, h, line, cmd)                         \
+    {int trials = 2; do { \
+         if (imap_mbox_is_disconnected(h) && mi_reconnect(h) != IMAP_SUCCESS) \
+         {rc = 0; break;}; \
+         rc = line; \
+         if (imap_mbox_op_cancelled(h)) { \
+             break;} \
+         else if (rc != IMR_OK) { \
+             libbalsa_information(LIBBALSA_INFORMATION_WARNING, \
+                                  _("Async IMAP cmd %s could not be executed. Reconnecting…"), \
+                                  cmd);} \
+         else { break;} } while (trials -- > 0);}
 
 static ImapMboxHandle *
-libbalsa_mailbox_imap_get_handle(LibBalsaMailboxImap *mimap, GError **err)
+libbalsa_mailbox_imap_get_handle(LibBalsaMailboxImap *mimap,
+                                 GError             **err)
 {
 
     g_return_val_if_fail(LIBBALSA_MAILBOX_IMAP(mimap), NULL);
 
-    if(!mimap->handle) {
+    if (!mimap->handle) {
         LibBalsaServer *server = LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mimap);
         LibBalsaImapServer *imap_server;
-        if (!LIBBALSA_IS_IMAP_SERVER(server))
+        if (!LIBBALSA_IS_IMAP_SERVER(server)) {
             return NULL;
-        imap_server = LIBBALSA_IMAP_SERVER(server);
-        mimap->handle = libbalsa_imap_server_get_handle(imap_server, err);
-       mimap->handle_refs = 1;
-    } else
-       ++mimap->handle_refs;
+        }
+        imap_server        = LIBBALSA_IMAP_SERVER(server);
+        mimap->handle      = libbalsa_imap_server_get_handle(imap_server, err);
+        mimap->handle_refs = 1;
+    } else {
+        ++mimap->handle_refs;
+    }
 
     return mimap->handle;
 }
 
-#define RELEASE_HANDLE(mailbox,handle) \
+
+#define RELEASE_HANDLE(mailbox, handle) \
     libbalsa_imap_server_release_handle( \
-               LIBBALSA_IMAP_SERVER(LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mailbox)),\
-               handle)
+        LIBBALSA_IMAP_SERVER(LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mailbox)), \
+        handle)
 
 static void
-lbimap_update_flags(LibBalsaMessage *message, ImapMessage *imsg)
+lbimap_update_flags(LibBalsaMessage *message,
+                    ImapMessage     *imsg)
 {
     message->flags = 0;
-    if (!IMSG_FLAG_SEEN(imsg->flags))
+    if (!IMSG_FLAG_SEEN(imsg->flags)) {
         message->flags |= LIBBALSA_MESSAGE_FLAG_NEW;
-    if (IMSG_FLAG_DELETED(imsg->flags))
+    }
+    if (IMSG_FLAG_DELETED(imsg->flags)) {
         message->flags |= LIBBALSA_MESSAGE_FLAG_DELETED;
-    if (IMSG_FLAG_FLAGGED(imsg->flags))
+    }
+    if (IMSG_FLAG_FLAGGED(imsg->flags)) {
         message->flags |= LIBBALSA_MESSAGE_FLAG_FLAGGED;
-    if (IMSG_FLAG_ANSWERED(imsg->flags))
+    }
+    if (IMSG_FLAG_ANSWERED(imsg->flags)) {
         message->flags |= LIBBALSA_MESSAGE_FLAG_REPLIED;
-    if (IMSG_FLAG_RECENT(imsg->flags))
-       message->flags |= LIBBALSA_MESSAGE_FLAG_RECENT;
+    }
+    if (IMSG_FLAG_RECENT(imsg->flags)) {
+        message->flags |= LIBBALSA_MESSAGE_FLAG_RECENT;
+    }
 }
 
+
 /* mi_get_imsg is a thin wrapper around imap_mbox_handle_get_msg().
    We wrap around imap_mbox_handle_get_msg() in case the libimap data
    was invalidated by eg. disconnect.
-*/
+ */
 struct collect_seq_data {
     unsigned *msgno_arr;
     unsigned cnt;
@@ -666,35 +720,44 @@ struct collect_seq_data {
     unsigned has_it;
 };
 
-static const unsigned MAX_CHUNK_LENGTH = 20; 
+static const unsigned MAX_CHUNK_LENGTH = 20;
 static gboolean
-collect_seq_cb(GNode *node, gpointer data)
+collect_seq_cb(GNode   *node,
+               gpointer data)
 {
     /* We prefetch envelopes in chunks to save on RTTs.
      * Try to get the messages both before and after the message. */
-    struct collect_seq_data *csd = (struct collect_seq_data*)data;
-    unsigned msgno = GPOINTER_TO_UINT(node->data);
-    if(msgno==0) /* root node */
+    struct collect_seq_data *csd = (struct collect_seq_data *)data;
+    unsigned msgno               = GPOINTER_TO_UINT(node->data);
+    if (msgno == 0) { /* root node */
         return FALSE;
+    }
     csd->msgno_arr[(csd->cnt++) % MAX_CHUNK_LENGTH] = msgno;
-    if(csd->has_it>0) csd->has_it++;
-    if(csd->needed_msgno == msgno)
+    if (csd->has_it > 0) {
+        csd->has_it++;
+    }
+    if (csd->needed_msgno == msgno) {
         csd->has_it = 1;
+    }
     /* quit if we have enough messages and at least half of them are
      * after message in question. */
-    return csd->cnt >= MAX_CHUNK_LENGTH && csd->has_it*2>MAX_CHUNK_LENGTH;
+    return csd->cnt >= MAX_CHUNK_LENGTH && csd->has_it * 2 > MAX_CHUNK_LENGTH;
 }
 
+
 static int
-cmp_msgno(const void* a, const void *b)
+cmp_msgno(const void *a,
+          const void *b)
 {
-    return (*(unsigned*)a) - (*(unsigned*)b);
+    return (*(unsigned *)a) - (*(unsigned *)b);
 }
 
-static ImapMessage*
-mi_get_imsg(LibBalsaMailboxImap *mimap, unsigned msgno)
+
+static ImapMessage *
+mi_get_imsg(LibBalsaMailboxImap *mimap,
+            unsigned             msgno)
 {
-    ImapMessage* imsg;
+    ImapMessage *imsg;
     struct collect_seq_data csd;
     ImapResponse rc;
     GNode *msg_tree;
@@ -702,10 +765,12 @@ mi_get_imsg(LibBalsaMailboxImap *mimap, unsigned msgno)
     /* This test too weak: I can imagine unsolicited ENVELOPE
      * responses sent from server that wil create the ImapMessage
      * structure but message size or UID etc will not be available. */
-    if( (imsg = imap_mbox_handle_get_msg(mimap->handle, msgno)) 
-        != NULL && imsg->envelope) return imsg;
+    if (((imsg = imap_mbox_handle_get_msg(mimap->handle, msgno))
+         != NULL) && imsg->envelope) {
+        return imsg;
+    }
     csd.needed_msgno = msgno;
-    csd.msgno_arr    = g_malloc(MAX_CHUNK_LENGTH*sizeof(csd.msgno_arr[0]));
+    csd.msgno_arr    = g_malloc(MAX_CHUNK_LENGTH * sizeof(csd.msgno_arr[0]));
     csd.cnt          = 0;
     csd.has_it       = 0;
 
@@ -714,7 +779,9 @@ mi_get_imsg(LibBalsaMailboxImap *mimap, unsigned msgno)
         g_node_traverse(msg_tree,
                         G_PRE_ORDER, G_TRAVERSE_ALL, -1, collect_seq_cb,
                         &csd);
-        if(csd.cnt>MAX_CHUNK_LENGTH) csd.cnt = MAX_CHUNK_LENGTH;
+        if (csd.cnt > MAX_CHUNK_LENGTH) {
+            csd.cnt = MAX_CHUNK_LENGTH;
+        }
         qsort(csd.msgno_arr, csd.cnt, sizeof(csd.msgno_arr[0]), cmp_msgno);
     } else {
         /* It may happen that we want to perform an automatic
@@ -724,11 +791,13 @@ mi_get_imsg(LibBalsaMailboxImap *mimap, unsigned msgno)
            LibBalsaMessage object are present, and these require that
            some basic information is fetched from the server.  */
         unsigned i, total_msgs = mimap->messages_info->len;
-        csd.cnt = msgno+MAX_CHUNK_LENGTH>total_msgs
-            ? total_msgs-msgno+1 : MAX_CHUNK_LENGTH;
-        for(i=0; i<csd.cnt; i++) csd.msgno_arr[i] = msgno+i;
+        csd.cnt = msgno + MAX_CHUNK_LENGTH > total_msgs
+            ? total_msgs - msgno + 1 : MAX_CHUNK_LENGTH;
+        for (i = 0; i < csd.cnt; i++) {
+            csd.msgno_arr[i] = msgno + i;
+        }
     }
-    II(rc,mimap->handle,
+    II(rc, mimap->handle,
        imap_mbox_handle_fetch_set(mimap->handle, csd.msgno_arr,
                                   csd.cnt,
                                   IMFETCH_FLAGS |
@@ -737,19 +806,21 @@ mi_get_imsg(LibBalsaMailboxImap *mimap, unsigned msgno)
                                   IMFETCH_RFC822SIZE |
                                   IMFETCH_CONTENT_TYPE));
     g_free(csd.msgno_arr);
-    if (rc != IMR_OK)
+    if (rc != IMR_OK) {
         return FALSE;
+    }
     return imap_mbox_handle_get_msg(mimap->handle, msgno);
 }
 
+
 /* Forward reference. */
-static void lbm_imap_get_unseen(LibBalsaMailboxImap * mimap);
+static void lbm_imap_get_unseen(LibBalsaMailboxImap *mimap);
 
 /** imap_flags_cb() is called by the imap backend when flags are
    fetched. Note that we may not have yet the preprocessed data in
    LibBalsaMessage.  We ignore the info in this case.
    OBSERVE: it must not trigger any IMAP activity under NO circumstances!
-*/
+ */
 static gboolean
 idle_unread_update_cb(LibBalsaMailbox *mailbox)
 {
@@ -757,72 +828,84 @@ idle_unread_update_cb(LibBalsaMailbox *mailbox)
 
     libbalsa_lock_mailbox(mailbox);
     unread = libbalsa_mailbox_get_unread_messages(mailbox);
-    
+
     lbm_imap_get_unseen(LIBBALSA_MAILBOX_IMAP(mailbox));
-    if(unread != libbalsa_mailbox_get_unread_messages(mailbox))
+    if (unread != libbalsa_mailbox_get_unread_messages(mailbox)) {
         libbalsa_mailbox_set_unread_messages_flag(mailbox,
-                                                  libbalsa_mailbox_get_unread_messages(mailbox)>0);
+                                                  libbalsa_mailbox_get_unread_messages(
+                                                      mailbox) > 0);
+    }
     LIBBALSA_MAILBOX_IMAP(mailbox)->unread_update_id = 0;
     libbalsa_unlock_mailbox(mailbox);
     return FALSE;
 }
 
+
 static void
-imap_flags_cb(unsigned cnt, const unsigned seqno[], LibBalsaMailboxImap *mimap)
+imap_flags_cb(unsigned             cnt,
+              const unsigned       seqno[],
+              LibBalsaMailboxImap *mimap)
 {
     LibBalsaMailbox *mailbox = LIBBALSA_MAILBOX(mimap);
     unsigned i;
 
     libbalsa_lock_mailbox(mailbox);
-    for(i=0; i<cnt; i++) {
-        struct message_info *msg_info = 
+    for (i = 0; i < cnt; i++) {
+        struct message_info *msg_info =
             message_info_from_msgno(mimap, seqno[i]);
-        if(msg_info && msg_info->message) {
+        if (msg_info && msg_info->message) {
             LibBalsaMessageFlag flags;
             /* since we are talking here about updating just received,
                usually unsolicited flags from the server, we do not
                need to go to great lengths to assure that the
                connection is up. */
-            ImapMessage *imsg = 
+            ImapMessage *imsg =
                 imap_mbox_handle_get_msg(mimap->handle, seqno[i]);
-            if(!imsg) continue;
+            if (!imsg) {
+                continue;
+            }
 
             flags = msg_info->message->flags;
             lbimap_update_flags(msg_info->message, imsg);
-            if (flags == msg_info->message->flags)
+            if (flags == msg_info->message->flags) {
                 continue;
+            }
 
-           libbalsa_mailbox_index_set_flags(mailbox, seqno[i],
-                                            msg_info->message->flags);
-           ++mimap->search_stamp;
+            libbalsa_mailbox_index_set_flags(mailbox, seqno[i],
+                                             msg_info->message->flags);
+            ++mimap->search_stamp;
         }
     }
-    if(!mimap->unread_update_id)
+    if (!mimap->unread_update_id) {
         mimap->unread_update_id =
             g_idle_add((GSourceFunc)idle_unread_update_cb, mailbox);
+    }
     libbalsa_unlock_mailbox(mailbox);
 }
 
+
 static gboolean
 imap_exists_idle(gpointer data)
 {
-    LibBalsaMailboxImap *mimap = (LibBalsaMailboxImap*)data;
-    LibBalsaMailbox *mailbox = LIBBALSA_MAILBOX(mimap);
+    LibBalsaMailboxImap *mimap = (LibBalsaMailboxImap *)data;
+    LibBalsaMailbox *mailbox   = LIBBALSA_MAILBOX(mimap);
     unsigned cnt;
     GNode *msg_tree;
 
     libbalsa_lock_mailbox(mailbox);
 
-    mimap->sort_field = -1;    /* Invalidate. */
+    mimap->sort_field = -1;     /* Invalidate. */
 
-    if(mimap->handle && /* was it closed in meantime? */
-       (cnt = imap_mbox_handle_get_exists(mimap->handle))
-       != mimap->messages_info->len) {
+    if (mimap->handle && /* was it closed in meantime? */
+        ((cnt = imap_mbox_handle_get_exists(mimap->handle))
+         != mimap->messages_info->len)) {
         unsigned i;
-        struct message_info a = {0};
+        struct message_info a = {
+            0
+        };
         GNode *sibling = NULL;
 
-        if(cnt<mimap->messages_info->len) {
+        if (cnt < mimap->messages_info->len) {
             /* remove messages; we probably missed some EXPUNGE responses
                - the only sensible scenario is that the connection was
                severed. Still, we need to recover from this somehow... -
@@ -830,40 +913,42 @@ imap_exists_idle(gpointer data)
             printf("%s: expunge ignored? Had %u messages and now only %u. "
                    "Bug in the program or broken connection\n",
                    __func__, mimap->messages_info->len, cnt);
-            for(i=0; i<mimap->messages_info->len; i++) {
+            for (i = 0; i < mimap->messages_info->len; i++) {
                 gchar *msgid;
                 struct message_info *msg_info =
-                    message_info_from_msgno(mimap, i+1);
-                if(!msg_info)
+                    message_info_from_msgno(mimap, i + 1);
+                if (!msg_info) {
                     continue;
+                }
                 g_clear_object(&msg_info->message);
                 msgid = g_ptr_array_index(mimap->msgids, i);
-                if(msgid) { 
+                if (msgid) {
                     g_free(msgid);
                     g_ptr_array_index(mimap->msgids, i) = NULL;
                 }
                 libbalsa_mailbox_index_entry_clear(mailbox, i + 1);
             }
-            for(i=mimap->messages_info->len; i>cnt; i--) {
-                g_array_remove_index(mimap->messages_info, i-1);
-                g_ptr_array_remove_index(mimap->msgids, i-1);
+            for (i = mimap->messages_info->len; i > cnt; i--) {
+                g_array_remove_index(mimap->messages_info, i - 1);
+                g_ptr_array_remove_index(mimap->msgids, i - 1);
                 libbalsa_mailbox_msgno_removed(mailbox, i);
             }
-        } 
+        }
 
         msg_tree = libbalsa_mailbox_get_msg_tree(LIBBALSA_MAILBOX(mimap));
-        if (msg_tree != NULL)
+        if (msg_tree != NULL) {
             sibling = g_node_last_child(msg_tree);
-        for(i=mimap->messages_info->len+1; i <= cnt; i++) {
+        }
+        for (i = mimap->messages_info->len + 1; i <= cnt; i++) {
             g_array_append_val(mimap->messages_info, a);
             g_ptr_array_add(mimap->msgids, NULL);
             libbalsa_mailbox_msgno_inserted(mailbox, i, msg_tree,
                                             &sibling);
         }
         ++mimap->search_stamp;
-        
-       libbalsa_mailbox_run_filters_on_reception(mailbox);
-       lbm_imap_get_unseen(LIBBALSA_MAILBOX_IMAP(mailbox));    
+
+        libbalsa_mailbox_run_filters_on_reception(mailbox);
+        lbm_imap_get_unseen(LIBBALSA_MAILBOX_IMAP(mailbox));
     }
 
     libbalsa_unlock_mailbox(mailbox);
@@ -872,15 +957,19 @@ imap_exists_idle(gpointer data)
     return FALSE;
 }
 
+
 static void
-imap_exists_cb(ImapMboxHandle *handle, LibBalsaMailboxImap *mimap)
+imap_exists_cb(ImapMboxHandle      *handle,
+               LibBalsaMailboxImap *mimap)
 {
     g_object_ref(G_OBJECT(mimap));
     g_idle_add(imap_exists_idle, mimap);
 }
 
+
 static void
-imap_expunge_cb(ImapMboxHandle *handle, unsigned seqno,
+imap_expunge_cb(ImapMboxHandle      *handle,
+                unsigned             seqno,
                 LibBalsaMailboxImap *mimap)
 {
     ImapMessage *imsg;
@@ -893,15 +982,15 @@ imap_expunge_cb(ImapMboxHandle *handle, unsigned seqno,
 
     libbalsa_mailbox_msgno_removed(mailbox, seqno);
     ++mimap->search_stamp;
-    mimap->sort_field = -1;    /* Invalidate. */
+    mimap->sort_field = -1;     /* Invalidate. */
 
     /* Use imap_mbox_handle_get_msg(mimap->handle, seqno)->uid, not
      * IMAP_MESSAGE_UID(msg_info->message), as the latter may try to
      * fetch the message from the server. */
     if ((imsg = imap_mbox_handle_get_msg(mimap->handle, seqno))) {
-       gchar **pair = get_cache_name_pair(mimap, "body", imsg->uid);
-        gchar *fn = g_build_filename(pair[0], pair[1], NULL);
-        unlink(fn); /* ignore error; perhaps the message 
+        gchar **pair = get_cache_name_pair(mimap, "body", imsg->uid);
+        gchar *fn    = g_build_filename(pair[0], pair[1], NULL);
+        unlink(fn); /* ignore error; perhaps the message
                      * was not in the cache.  */
         g_free(fn);
         g_strfreev(pair);
@@ -909,9 +998,10 @@ imap_expunge_cb(ImapMboxHandle *handle, unsigned seqno,
 
     msg_info = message_info_from_msgno(mimap, seqno);
     if (msg_info) {
-        if (msg_info->message)
+        if (msg_info->message) {
             g_object_unref(msg_info->message);
-        g_array_remove_index(mimap->messages_info, seqno-1);
+        }
+        g_array_remove_index(mimap->messages_info, seqno - 1);
     }
 
     if (seqno <= mimap->msgids->len) {
@@ -923,38 +1013,41 @@ imap_expunge_cb(ImapMboxHandle *handle, unsigned seqno,
     }
 
     for (i = seqno - 1; i < mimap->messages_info->len; i++) {
-       struct message_info *info =
-           &g_array_index(mimap->messages_info, struct message_info, i);
+        struct message_info *info =
+            &g_array_index(mimap->messages_info, struct message_info, i);
 
         g_assert(info != NULL);
-       if (info->message)
-           info->message->msgno = i + 1;
+        if (info->message) {
+            info->message->msgno = i + 1;
+        }
     }
 
     libbalsa_unlock_mailbox(mailbox);
 }
 
+
 static void
-libbalsa_mailbox_imap_release_handle(LibBalsaMailboxImap * mimap)
+libbalsa_mailbox_imap_release_handle(LibBalsaMailboxImap *mimap)
 {
     g_assert(mimap->handle != NULL);
     g_assert(mimap->handle_refs > 0);
 
     if (--mimap->handle_refs == 0) {
-       /* Only selected handles have these signal handlers, but we'll
-        * disconnect them anyway. */
-       g_signal_handlers_disconnect_matched(mimap->handle,
-                                            G_SIGNAL_MATCH_DATA,
-                                            0, 0, NULL, NULL, mimap);
+        /* Only selected handles have these signal handlers, but we'll
+         * disconnect them anyway. */
+        g_signal_handlers_disconnect_matched(mimap->handle,
+                                             G_SIGNAL_MATCH_DATA,
+                                             0, 0, NULL, NULL, mimap);
         imap_handle_set_flagscb(mimap->handle, NULL, NULL);
-       RELEASE_HANDLE(mimap, mimap->handle);
-       mimap->handle = NULL;
+        RELEASE_HANDLE(mimap, mimap->handle);
+        mimap->handle = NULL;
     }
 }
 
+
 static ImapMboxHandle *
 libbalsa_mailbox_imap_get_selected_handle(LibBalsaMailboxImap *mimap,
-                                         GError **err)
+                                          GError             **err)
 {
     LibBalsaServer *server;
     LibBalsaImapServer *imap_server;
@@ -965,43 +1058,47 @@ libbalsa_mailbox_imap_get_selected_handle(LibBalsaMailboxImap *mimap,
     g_return_val_if_fail(LIBBALSA_MAILBOX_IMAP(mimap), NULL);
 
     server = LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mimap);
-    if (!LIBBALSA_IS_IMAP_SERVER(server))
-       return NULL;
+    if (!LIBBALSA_IS_IMAP_SERVER(server)) {
+        return NULL;
+    }
     imap_server = LIBBALSA_IMAP_SERVER(server);
-    if(!mimap->handle) {
-        mimap->handle = 
-           libbalsa_imap_server_get_handle_with_user(imap_server,
-                                                     mimap, err);
-        if (!mimap->handle)
+    if (!mimap->handle) {
+        mimap->handle =
+            libbalsa_imap_server_get_handle_with_user(imap_server,
+                                                      mimap, err);
+        if (!mimap->handle) {
             return NULL;
+        }
     }
-    II(rc,mimap->handle,
+    II(rc, mimap->handle,
        imap_mbox_select(mimap->handle, mimap->path, &readonly));
     libbalsa_mailbox_set_readonly(LIBBALSA_MAILBOX(mimap), readonly);
     if (rc != IMR_OK) {
-       gchar *msg = imap_mbox_handle_get_last_msg(mimap->handle);
-       g_set_error(err, LIBBALSA_MAILBOX_ERROR, LIBBALSA_MAILBOX_OPEN_ERROR,
-                   "%s", msg);
-       g_free(msg);
-       RELEASE_HANDLE(mimap, mimap->handle);
+        gchar *msg = imap_mbox_handle_get_last_msg(mimap->handle);
+        g_set_error(err, LIBBALSA_MAILBOX_ERROR, LIBBALSA_MAILBOX_OPEN_ERROR,
+                    "%s", msg);
+        g_free(msg);
+        RELEASE_HANDLE(mimap, mimap->handle);
         mimap->handle = NULL;
-       return NULL;
+        return NULL;
     }
 
     /* check if we have RFC 4314 acl's for the selected mailbox */
     if (imap_mbox_get_my_rights(mimap->handle, &mimap->rights, FALSE) ==
         IMR_OK) {
-        if (!IMAP_RIGHTS_CAN_WRITE(mimap->rights))
+        if (!IMAP_RIGHTS_CAN_WRITE(mimap->rights)) {
             libbalsa_mailbox_set_readonly(LIBBALSA_MAILBOX(mimap), TRUE);
-        if (mimap->rights & IMAP_ACL_ADMIN)
+        }
+        if (mimap->rights & IMAP_ACL_ADMIN) {
             imap_mbox_get_acl(mimap->handle, mimap->path, &mimap->acls);
+        }
     }
 
     /* test validity */
     uidval = imap_mbox_handle_get_validity(mimap->handle);
     if (mimap->uid_validity != uidval) {
-       mimap->uid_validity = uidval;
-       /* FIXME: update/remove msg uids */
+        mimap->uid_validity = uidval;
+        /* FIXME: update/remove msg uids */
     }
 
     imap_handle_set_flagscb(mimap->handle, (ImapFlagsCb)imap_flags_cb, mimap);
@@ -1015,32 +1112,36 @@ libbalsa_mailbox_imap_get_selected_handle(LibBalsaMailboxImap *mimap,
     return mimap->handle;
 }
 
+
 /* Get the list of unseen messages from the server and set
  * the unread-messages count. */
 static void
-lbm_imap_get_unseen(LibBalsaMailboxImap * mimap)
+lbm_imap_get_unseen(LibBalsaMailboxImap *mimap)
 {
     LibBalsaMailbox *mailbox;
     guint i, count, total;
     guint first_unread;
 
-    if (!mimap->handle)
-       return;
+    if (!mimap->handle) {
+        return;
+    }
 
-    mailbox = LIBBALSA_MAILBOX(mimap);
-    total = imap_mbox_handle_get_exists(mimap->handle);
+    mailbox      = LIBBALSA_MAILBOX(mimap);
+    total        = imap_mbox_handle_get_exists(mimap->handle);
     first_unread = total;
-    for(i=count=0; i<total; i++) {
-        if(imap_mbox_handle_msgno_has_flags(mimap->handle,
-                                            i+1,
-                                            0, IMSGF_SEEN|IMSGF_DELETED)) {
+    for (i = count = 0; i < total; i++) {
+        if (imap_mbox_handle_msgno_has_flags(mimap->handle,
+                                             i + 1,
+                                             0, IMSGF_SEEN | IMSGF_DELETED)) {
             count++;
-            if (first_unread > i)
+            if (first_unread > i) {
                 first_unread = i + 1;
+            }
         }
     }
-    if (count == 0)
+    if (count == 0) {
         first_unread = 0;
+    }
 
     libbalsa_mailbox_set_first_unread(mailbox, first_unread);
     libbalsa_mailbox_clear_unread_messages(mailbox);
@@ -1048,11 +1149,13 @@ lbm_imap_get_unseen(LibBalsaMailboxImap * mimap)
     libbalsa_mailbox_set_unread_messages_flag(mailbox, count > 0);
 }
 
+
 /* libbalsa_mailbox_imap_open:
    opens IMAP mailbox. On failure leaves the object in sane state.
-*/
+ */
 static gboolean
-libbalsa_mailbox_imap_open(LibBalsaMailbox * mailbox, GError **err)
+libbalsa_mailbox_imap_open(LibBalsaMailbox *mailbox,
+                           GError         **err)
 {
     LibBalsaMailboxImap *mimap;
     unsigned i;
@@ -1068,71 +1171,79 @@ libbalsa_mailbox_imap_open(LibBalsaMailbox * mailbox, GError **err)
     if (!mimap->handle) {
         mimap->opened       = FALSE;
         mimap->disconnected = TRUE;
-       return FALSE;
+        return FALSE;
     }
 
-    mimap->opened       = TRUE;
-    mimap->disconnected = FALSE;
-    total_messages = imap_mbox_handle_get_exists(mimap->handle);
+    mimap->opened        = TRUE;
+    mimap->disconnected  = FALSE;
+    total_messages       = imap_mbox_handle_get_exists(mimap->handle);
     mimap->messages_info = g_array_sized_new(FALSE, TRUE,
-                                            sizeof(struct message_info),
-                                            total_messages);
+                                             sizeof(struct message_info),
+                                             total_messages);
     mimap->msgids = g_ptr_array_sized_new(total_messages);
-    for(i=0; i < total_messages; i++) {
-       struct message_info a = {0};
-       g_array_append_val(mimap->messages_info, a);
-       g_ptr_array_add(mimap->msgids, NULL);
+    for (i = 0; i < total_messages; i++) {
+        struct message_info a = {
+            0
+        };
+        g_array_append_val(mimap->messages_info, a);
+        g_ptr_array_add(mimap->msgids, NULL);
     }
     icm = g_object_get_data(G_OBJECT(mailbox), "cache-manager");
-    if(!icm) { /* Try restoring from file... */
-       gchar *header_cache_path = get_header_cache_path(mimap);
-       icm = imap_cache_manager_new_from_file(header_cache_path);
-       g_free(header_cache_path);
+    if (!icm) { /* Try restoring from file... */
+        gchar *header_cache_path = get_header_cache_path(mimap);
+        icm = imap_cache_manager_new_from_file(header_cache_path);
+        g_free(header_cache_path);
         from_file = TRUE;
     }
     if (icm) {
         icm_restore_from_cache(mimap->handle, icm);
-        if (from_file)
+        if (from_file) {
             imap_cache_manager_free(icm);
-        else
+        } else {
             g_object_set_data(G_OBJECT(mailbox), "cache-manager", NULL);
+        }
     }
 
     libbalsa_mailbox_set_first_unread(mailbox,
                                       imap_mbox_handle_first_unseen(mimap->handle));
     libbalsa_mailbox_run_filters_on_reception(mailbox);
     lbm_imap_get_unseen(mimap);
-    if (mimap->search_stamp)
-       ++mimap->search_stamp;
-    else
-       mimap->search_stamp = libbalsa_mailbox_get_stamp(mailbox);
+    if (mimap->search_stamp) {
+        ++mimap->search_stamp;
+    } else {
+        mimap->search_stamp = libbalsa_mailbox_get_stamp(mailbox);
+    }
 
 #ifdef DEBUG
     g_print(_("%s: Opening %s Refcount: %d\n"),
-           "LibBalsaMailboxImap", libbalsa_mailbox_get_name(mailbox),
+            "LibBalsaMailboxImap", libbalsa_mailbox_get_name(mailbox),
             libbalsa_mailbox_get_open_ref(mailbox));
 #endif
     return TRUE;
 }
 
+
 static void
-free_messages_info(LibBalsaMailboxImap * mbox)
+free_messages_info(LibBalsaMailboxImap *mbox)
 {
     guint i;
     GArray *messages_info = mbox->messages_info;
 
-    if(messages_info->len != mbox->msgids->len)
-       g_warning("free_messages_info: array sizes do not match.");
+    if (messages_info->len != mbox->msgids->len) {
+        g_warning("free_messages_info: array sizes do not match.");
+    }
     for (i = 0; i < messages_info->len; i++) {
-       gchar *msgid;
-       struct message_info *msg_info =
-           &g_array_index(messages_info, struct message_info, i);
-       if (msg_info->message) {
-           msg_info->message->mailbox = NULL;
-           g_object_unref(msg_info->message);
-       }
-       msgid = g_ptr_array_index(mbox->msgids, i);
-       if(msgid) g_free(msgid);
+        gchar *msgid;
+        struct message_info *msg_info =
+            &g_array_index(messages_info, struct message_info, i);
+        if (msg_info->message) {
+            msg_info->message->mailbox = NULL;
+            g_object_unref(msg_info->message);
+        }
+        msgid = g_ptr_array_index(mbox->msgids, i);
+        if (msgid) {
+            g_free(msgid);
+        }
     }
     g_array_free(mbox->messages_info, TRUE);
     mbox->messages_info = NULL;
@@ -1140,13 +1251,15 @@ free_messages_info(LibBalsaMailboxImap * mbox)
     mbox->msgids = NULL;
 }
 
+
 static void
-libbalsa_mailbox_imap_close(LibBalsaMailbox * mailbox, gboolean expunge)
+libbalsa_mailbox_imap_close(LibBalsaMailbox *mailbox,
+                            gboolean         expunge)
 {
-    LibBalsaServer *s      = LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mailbox);
-    LibBalsaImapServer *is = LIBBALSA_IMAP_SERVER(s);
-    gboolean is_persistent = libbalsa_imap_server_has_persistent_cache(is);
-    LibBalsaMailboxImap *mbox = LIBBALSA_MAILBOX_IMAP(mailbox);
+    LibBalsaServer *s            = LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mailbox);
+    LibBalsaImapServer *is       = LIBBALSA_IMAP_SERVER(s);
+    gboolean is_persistent       = libbalsa_imap_server_has_persistent_cache(is);
+    LibBalsaMailboxImap *mbox    = LIBBALSA_MAILBOX_IMAP(mailbox);
     struct ImapCacheManager *icm = icm_store_cached_data(mbox->handle);
 
     mbox->opened = FALSE;
@@ -1155,78 +1268,86 @@ libbalsa_mailbox_imap_close(LibBalsaMailbox * mailbox, gboolean expunge)
 
     /* we do not attempt to reconnect here */
     if (expunge) {
-       if (is_persistent) { /* We appreciate expunge info to simplify
-                               next resync. */
-           imap_mbox_expunge_a(mbox->handle);
-       }
-       imap_mbox_close(mbox->handle);
-    } else
-       imap_mbox_unselect(mbox->handle);
+        if (is_persistent) {
+            /* We appreciate expunge info to simplify
+               next resync. */
+            imap_mbox_expunge_a(mbox->handle);
+        }
+        imap_mbox_close(mbox->handle);
+    } else {
+        imap_mbox_unselect(mbox->handle);
+    }
 
     /* We have received last notificiations, we can save the cache now. */
-    if(is_persistent) {
-       /* Implement only for persistent. Cache dir is shared for all
-          non-persistent caches. */
-       gchar *header_file = get_header_cache_path(mbox);
-       icm_save_to_file(icm, header_file);
-       g_free(header_file);
+    if (is_persistent) {
+        /* Implement only for persistent. Cache dir is shared for all
+           non-persistent caches. */
+        gchar *header_file = get_header_cache_path(mbox);
+        icm_save_to_file(icm, header_file);
+        g_free(header_file);
     }
     clean_cache(mailbox);
 
 
     free_messages_info(mbox);
     libbalsa_mailbox_imap_release_handle(mbox);
-    mbox->sort_field = -1;     /* Invalidate. */
+    mbox->sort_field = -1;      /* Invalidate. */
 }
 
-static FILE*
-get_cache_stream(LibBalsaMailboxImap *mimap, guint uid, gboolean peek)
+
+static FILE *
+get_cache_stream(LibBalsaMailboxImap *mimap,
+                 guint                uid,
+                 gboolean             peek)
 {
     FILE *stream;
     gchar **pair, *path;
 
-    pair = get_cache_name_pair(mimap, "body", uid);
-    path = g_build_filename(pair[0], pair[1], NULL);
+    pair   = get_cache_name_pair(mimap, "body", uid);
+    path   = g_build_filename(pair[0], pair[1], NULL);
     stream = fopen(path, "rb");
-    if(!stream) {
+    if (!stream) {
         FILE *cache;
-       ImapResponse rc;
+        ImapResponse rc;
 
-        g_mkdir_with_parents(pair[0], S_IRUSR|S_IWUSR|S_IXUSR);
+        g_mkdir_with_parents(pair[0], S_IRUSR | S_IWUSR | S_IXUSR);
 #if 0
-        if(msg->length>(signed)SizeMsgThreshold)
-            libbalsa_information(LIBBALSA_INFORMATION_MESSAGE, 
+        if (msg->length > (signed)SizeMsgThreshold) {
+            libbalsa_information(LIBBALSA_INFORMATION_MESSAGE,
                                  _("Downloading %ld kB"),
-                                 msg->length/1024);
+                                 msg->length / 1024);
+        }
 #endif
         cache = fopen(path, "wb");
-        if(cache) {
-           int ferr;
-            II(rc,mimap->handle,
+        if (cache) {
+            int ferr;
+            II(rc, mimap->handle,
                imap_mbox_handle_fetch_rfc822_uid(mimap->handle, uid, peek,
-                                                cache));
-           ferr = ferror(cache);
+                                                 cache));
+            ferr = ferror(cache);
             fclose(cache);
-           if(ferr || rc != IMR_OK) {
-               printf("Error fetching RFC822 message, removing cache.\n");
-               unlink(path);
-           }
+            if (ferr || (rc != IMR_OK)) {
+                printf("Error fetching RFC822 message, removing cache.\n");
+                unlink(path);
+            }
         }
-       stream = fopen(path,"rb");
+        stream = fopen(path, "rb");
     }
-    g_free(path); 
+    g_free(path);
     g_strfreev(pair);
     return stream;
 }
 
-/* libbalsa_mailbox_imap_get_message_stream: 
+
+/* libbalsa_mailbox_imap_get_message_stream:
    Fetch data from cache first, if available.
    When calling imap_fetch_message(), we make use of fact that
    imap_fetch_message doesn't set msg->path field.
-*/
+ */
 static GMimeStream *
-libbalsa_mailbox_imap_get_message_stream(LibBalsaMailbox * mailbox,
-                                        guint msgno, gboolean peek)
+libbalsa_mailbox_imap_get_message_stream(LibBalsaMailbox *mailbox,
+                                         guint            msgno,
+                                         gboolean         peek)
 {
     FILE *stream;
     ImapMessage *imsg;
@@ -1243,7 +1364,7 @@ libbalsa_mailbox_imap_get_message_stream(LibBalsaMailbox * mailbox,
         return NULL;
     }
     imsg = mi_get_imsg(mimap, msgno);
-    
+
     stream = imsg ? get_cache_stream(mimap, imsg->uid, peek) : NULL;
 
     libbalsa_unlock_mailbox(mailbox);
@@ -1251,57 +1372,67 @@ libbalsa_mailbox_imap_get_message_stream(LibBalsaMailbox * mailbox,
     return stream ? g_mime_stream_file_new(stream) : NULL;
 }
 
+
 /* libbalsa_mailbox_imap_check:
    checks imap mailbox for new messages.
    Called with the mailbox locked.
-*/
+ */
 struct mark_info {
     const gchar *path;
     gboolean marked;
 };
 
 static void
-lbm_imap_list_cb(ImapMboxHandle * handle, int delim, ImapMboxFlags flags,
-                 char *folder, gpointer data)
+lbm_imap_list_cb(ImapMboxHandle *handle,
+                 int             delim,
+                 ImapMboxFlags   flags,
+                 char           *folder,
+                 gpointer        data)
 {
     struct mark_info *info = data;
 
-    if (strcmp(folder, info->path) == 0
-        && IMAP_MBOX_HAS_FLAG(flags, IMLIST_MARKED))
+    if ((strcmp(folder, info->path) == 0)
+        && IMAP_MBOX_HAS_FLAG(flags, IMLIST_MARKED)) {
         info->marked = TRUE;
+    }
 }
 
+
 static gboolean
-lbm_imap_check(LibBalsaMailbox * mailbox)
+lbm_imap_check(LibBalsaMailbox *mailbox)
 {
     LibBalsaMailboxImap *mimap = LIBBALSA_MAILBOX_IMAP(mailbox);
-    LibBalsaServer *server = LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mailbox);
+    LibBalsaServer *server     = LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mailbox);
     ImapMboxHandle *handle;
     gulong id;
 
     handle = libbalsa_mailbox_imap_get_handle(mimap, NULL);
-    if (!handle)
-       return FALSE;
+    if (!handle) {
+        return FALSE;
+    }
 
-    if(libbalsa_imap_server_get_use_status(LIBBALSA_IMAP_SERVER(server))) {
+    if (libbalsa_imap_server_get_use_status(LIBBALSA_IMAP_SERVER(server))) {
         static struct ImapStatusResult info[] = {
-            { IMSTAT_UNSEEN, 0 }, { IMSTAT_NONE, 0 } };
+            { IMSTAT_UNSEEN, 0 }, { IMSTAT_NONE, 0 }
+        };
         /* cannot do status on an open mailbox */
         g_return_val_if_fail(!mimap->opened, FALSE);
-        if(imap_mbox_status(handle, mimap->path, info) != IMR_OK)
+        if (imap_mbox_status(handle, mimap->path, info) != IMR_OK) {
             return FALSE;
+        }
         libbalsa_mailbox_imap_release_handle(mimap);
         return info[0].result > 0;
     } else {
         struct mark_info info;
-        info.path = mimap->path;
+        info.path   = mimap->path;
         info.marked = FALSE;
 
         id = g_signal_connect(G_OBJECT(handle), "list-response",
                               G_CALLBACK(lbm_imap_list_cb), &info);
 
-        if (imap_mbox_list(handle, mimap->path) != IMR_OK)
+        if (imap_mbox_list(handle, mimap->path) != IMR_OK) {
             info.marked = FALSE;
+        }
 
         g_signal_handler_disconnect(G_OBJECT(handle), id);
         libbalsa_mailbox_imap_release_handle(mimap);
@@ -1310,48 +1441,55 @@ lbm_imap_check(LibBalsaMailbox * mailbox)
     }
 }
 
+
 static void
-libbalsa_mailbox_imap_check(LibBalsaMailbox * mailbox)
+libbalsa_mailbox_imap_check(LibBalsaMailbox *mailbox)
 {
     g_assert(LIBBALSA_IS_MAILBOX_IMAP(mailbox));
 
     if (!MAILBOX_OPEN(mailbox)) {
         libbalsa_mailbox_set_unread_messages_flag(mailbox,
                                                   lbm_imap_check(mailbox));
-       return;
+        return;
 
     }
 
-    if (LIBBALSA_MAILBOX_IMAP(mailbox)->handle)
-       libbalsa_mailbox_imap_noop(LIBBALSA_MAILBOX_IMAP(mailbox));
-    else
-       g_warning("mailbox has open_ref>0 but no handle!\n");
+    if (LIBBALSA_MAILBOX_IMAP(mailbox)->handle) {
+        libbalsa_mailbox_imap_noop(LIBBALSA_MAILBOX_IMAP(mailbox));
+    } else {
+        g_warning("mailbox has open_ref>0 but no handle!\n");
+    }
 }
 
+
 /* Search iters */
 
-static ImapSearchKey *lbmi_build_imap_query(const LibBalsaCondition * cond,
-                                           ImapSearchKey * last);
+static ImapSearchKey *lbmi_build_imap_query(const LibBalsaCondition *cond,
+                                            ImapSearchKey           *last);
+
 static gboolean
-libbalsa_mailbox_imap_message_match(LibBalsaMailbox* mailbox, guint msgno,
-                                   LibBalsaMailboxSearchIter * search_iter)
+libbalsa_mailbox_imap_message_match(LibBalsaMailbox           *mailbox,
+                                    guint                      msgno,
+                                    LibBalsaMailboxSearchIter *search_iter)
 {
     LibBalsaMailboxImap *mimap;
     struct message_info *msg_info;
     GHashTable *matchings;
 
-    mimap = LIBBALSA_MAILBOX_IMAP(mailbox);
+    mimap    = LIBBALSA_MAILBOX_IMAP(mailbox);
     msg_info = message_info_from_msgno(mimap, msgno);
-    if (!msg_info)
+    if (!msg_info) {
         return FALSE;
+    }
 
-    if (msg_info->message)
+    if (msg_info->message) {
         g_object_ref(msg_info->message);
-    else if (imap_mbox_handle_get_msg(mimap->handle, msgno)
-             && imap_mbox_handle_get_msg(mimap->handle, msgno)->envelope)
+    } else if (imap_mbox_handle_get_msg(mimap->handle, msgno)
+               && imap_mbox_handle_get_msg(mimap->handle, msgno)->envelope) {
         /* The backend has already downloaded the data, we can just
-        * convert it to LibBalsaMessage. */
+         * convert it to LibBalsaMessage. */
         libbalsa_mailbox_imap_get_message(mailbox, msgno);
+    }
     if (msg_info->message) {
         if (libbalsa_condition_can_match(search_iter->condition,
                                          msg_info->message)) {
@@ -1364,166 +1502,200 @@ libbalsa_mailbox_imap_message_match(LibBalsaMailbox* mailbox, guint msgno,
         g_object_unref(msg_info->message);
     }
 
-    if (search_iter->stamp != mimap->search_stamp && search_iter->mailbox
-       && LIBBALSA_MAILBOX_GET_CLASS(search_iter->mailbox)->
-       search_iter_free)
-       LIBBALSA_MAILBOX_GET_CLASS(search_iter->mailbox)->
-           search_iter_free(search_iter);
+    if ((search_iter->stamp != mimap->search_stamp) && search_iter->mailbox
+        && LIBBALSA_MAILBOX_GET_CLASS(search_iter->mailbox)->
+        search_iter_free) {
+        LIBBALSA_MAILBOX_GET_CLASS(search_iter->mailbox)->
+        search_iter_free(search_iter);
+    }
 
     matchings = search_iter->user_data;
     if (!matchings) {
-       ImapSearchKey* query;
-       ImapResponse rc;
+        ImapSearchKey *query;
+        ImapResponse rc;
 
-       matchings = g_hash_table_new(NULL, NULL);
-       query = lbmi_build_imap_query(search_iter->condition, NULL);
-       II(rc,mimap->handle,
+        matchings = g_hash_table_new(NULL, NULL);
+        query     = lbmi_build_imap_query(search_iter->condition, NULL);
+        II(rc, mimap->handle,
            imap_mbox_filter_msgnos(mimap->handle, query, matchings));
-       imap_search_key_free(query);
-       if (rc != IMR_OK) {
-           g_hash_table_destroy(matchings);
-           return FALSE;
-       }
-       search_iter->user_data = matchings;
-       search_iter->mailbox = mailbox;
-       search_iter->stamp = mimap->search_stamp;
+        imap_search_key_free(query);
+        if (rc != IMR_OK) {
+            g_hash_table_destroy(matchings);
+            return FALSE;
+        }
+        search_iter->user_data = matchings;
+        search_iter->mailbox   = mailbox;
+        search_iter->stamp     = mimap->search_stamp;
     }
 
     return g_hash_table_lookup(matchings, GUINT_TO_POINTER(msgno)) != NULL;
 }
 
+
 static void
-libbalsa_mailbox_imap_search_iter_free(LibBalsaMailboxSearchIter * iter)
+libbalsa_mailbox_imap_search_iter_free(LibBalsaMailboxSearchIter *iter)
 {
     GHashTable *matchings = iter->user_data;
 
     if (matchings) {
-       g_hash_table_destroy(matchings);
-       iter->user_data = NULL;
+        g_hash_table_destroy(matchings);
+        iter->user_data = NULL;
     }
     /* iter->condition and iter are freed in the LibBalsaMailbox method. */
 }
 
+
 /* add_or_query() adds a new term to an set of eqs. that can be or-ed.
    There are at least two ways to do it:
    a). transform a and b to NOT (NOT a NOT b)
    b). transform a and b to OR a b
    We keep it simple.
-*/
-static ImapSearchKey*
-add_or_query(ImapSearchKey *or_query, gboolean neg, ImapSearchKey *new_term)
+ */
+static ImapSearchKey *
+add_or_query(ImapSearchKey *or_query,
+             gboolean       neg,
+             ImapSearchKey *new_term)
 {
-    if(!or_query) return new_term;
-    if(neg) {
+    if (!or_query) {
+        return new_term;
+    }
+    if (neg) {
         imap_search_key_set_next(new_term, or_query);
         return new_term;
-    } else return imap_search_key_new_or(FALSE, new_term, or_query);
+    } else {
+        return imap_search_key_new_or(FALSE, new_term, or_query);
+    }
 }
 
-static ImapSearchKey*
-lbmi_build_imap_query(const LibBalsaCondition* cond,
-                      ImapSearchKey *next)
+
+static ImapSearchKey *
+lbmi_build_imap_query(const LibBalsaCondition *cond,
+                      ImapSearchKey           *next)
 {
     gboolean neg;
     ImapSearchKey *query = NULL;
-    int cnt=0;
+    int cnt              = 0;
 
-    if(!cond) return NULL;
+    if (!cond) {
+        return NULL;
+    }
     neg = cond->negate;
     switch (cond->type) {
     case CONDITION_STRING:
-        if (CONDITION_CHKMATCH(cond,CONDITION_MATCH_TO))
-            cnt++,query = add_or_query
-                (query, neg, imap_search_key_new_string
-                 (neg, IMSE_S_TO, cond->match.string.string, NULL));
-        if (CONDITION_CHKMATCH(cond,CONDITION_MATCH_FROM))
-            cnt++,query = add_or_query
-                (query, neg, imap_search_key_new_string
-                 (neg, IMSE_S_FROM, cond->match.string.string, NULL));
-        if (CONDITION_CHKMATCH(cond,CONDITION_MATCH_SUBJECT))
-            cnt++,query = add_or_query
-                (query, neg, imap_search_key_new_string
-                (neg, IMSE_S_SUBJECT,cond->match.string.string, NULL));
-        if (CONDITION_CHKMATCH(cond,CONDITION_MATCH_CC))
-            cnt++,query = add_or_query
-                (query, neg, imap_search_key_new_string
-                 (neg, IMSE_S_CC, cond->match.string.string, NULL));
-        if (CONDITION_CHKMATCH(cond,CONDITION_MATCH_BODY))
-            cnt++,query = add_or_query
-                (query, neg, imap_search_key_new_string
-                 (neg, IMSE_S_BODY, cond->match.string.string, NULL));
-        if (CONDITION_CHKMATCH(cond,CONDITION_MATCH_US_HEAD))
-            cnt++,query = add_or_query
-                (query, neg, imap_search_key_new_string
-                 (neg, IMSE_S_HEADER, cond->match.string.string,
-                  cond->match.string.user_header));
-        if(neg && cnt>1)
+        if (CONDITION_CHKMATCH(cond, CONDITION_MATCH_TO)) {
+            cnt++, query = add_or_query
+                    (query, neg, imap_search_key_new_string
+                        (neg, IMSE_S_TO, cond->match.string.string, NULL));
+        }
+        if (CONDITION_CHKMATCH(cond, CONDITION_MATCH_FROM)) {
+            cnt++, query = add_or_query
+                    (query, neg, imap_search_key_new_string
+                        (neg, IMSE_S_FROM, cond->match.string.string, NULL));
+        }
+        if (CONDITION_CHKMATCH(cond, CONDITION_MATCH_SUBJECT)) {
+            cnt++, query = add_or_query
+                    (query, neg, imap_search_key_new_string
+                        (neg, IMSE_S_SUBJECT, cond->match.string.string, NULL));
+        }
+        if (CONDITION_CHKMATCH(cond, CONDITION_MATCH_CC)) {
+            cnt++, query = add_or_query
+                    (query, neg, imap_search_key_new_string
+                        (neg, IMSE_S_CC, cond->match.string.string, NULL));
+        }
+        if (CONDITION_CHKMATCH(cond, CONDITION_MATCH_BODY)) {
+            cnt++, query = add_or_query
+                    (query, neg, imap_search_key_new_string
+                        (neg, IMSE_S_BODY, cond->match.string.string, NULL));
+        }
+        if (CONDITION_CHKMATCH(cond, CONDITION_MATCH_US_HEAD)) {
+            cnt++, query = add_or_query
+                    (query, neg, imap_search_key_new_string
+                        (neg, IMSE_S_HEADER, cond->match.string.string,
+                        cond->match.string.user_header));
+        }
+        if (neg && (cnt > 1)) {
             query = imap_search_key_new_not(FALSE, query);
+        }
         imap_search_key_set_next(query, next);
         break;
+
     case CONDITION_DATE: {
         ImapSearchKey *slo = NULL;
-        if (cond->match.date.date_low)
-            query  = slo = imap_search_key_new_date
-                (IMSE_D_SINCE, FALSE, cond->match.date.date_low);
+        if (cond->match.date.date_low) {
+            query = slo = imap_search_key_new_date
+                        (IMSE_D_SINCE, FALSE, cond->match.date.date_low);
+        }
         if (cond->match.date.date_high) {
             query = imap_search_key_new_date
-                (IMSE_D_BEFORE, FALSE, cond->match.date.date_high);
-            if(slo)
+                    (IMSE_D_BEFORE, FALSE, cond->match.date.date_high);
+            if (slo) {
                 imap_search_key_set_next(query, slo);
+            }
         }
         /* this might be redundant if only one limit was specified. */
-        if(query)
+        if (query) {
             query = imap_search_key_new_not(neg, query);
+        }
         break;
     }
+
     case CONDITION_FLAG:
-        if (cond->match.flags & LIBBALSA_MESSAGE_FLAG_REPLIED)
-            cnt++,query = add_or_query
-                (query, neg, imap_search_key_new_flag
-                 (neg, IMSGF_ANSWERED));
-        if (cond->match.flags & LIBBALSA_MESSAGE_FLAG_NEW)
-            cnt++,query = add_or_query
-                (query, neg, imap_search_key_new_flag
-                 (!neg, IMSGF_SEEN));
-        if (cond->match.flags & LIBBALSA_MESSAGE_FLAG_DELETED)
-            cnt++,query = add_or_query
-                (query, neg, imap_search_key_new_flag
-                 (neg, IMSGF_DELETED));
-        if (cond->match.flags & LIBBALSA_MESSAGE_FLAG_FLAGGED)
-            cnt++,query = add_or_query
-                (query, neg, imap_search_key_new_flag
-                 (neg, IMSGF_FLAGGED));
-       if (cond->match.flags & LIBBALSA_MESSAGE_FLAG_RECENT)
-           cnt++, query = add_or_query
-               (query, neg, imap_search_key_new_flag
-                (neg, IMSGF_RECENT));
-        if(neg && cnt>1)
+        if (cond->match.flags & LIBBALSA_MESSAGE_FLAG_REPLIED) {
+            cnt++, query = add_or_query
+                    (query, neg, imap_search_key_new_flag
+                        (neg, IMSGF_ANSWERED));
+        }
+        if (cond->match.flags & LIBBALSA_MESSAGE_FLAG_NEW) {
+            cnt++, query = add_or_query
+                    (query, neg, imap_search_key_new_flag
+                        (!neg, IMSGF_SEEN));
+        }
+        if (cond->match.flags & LIBBALSA_MESSAGE_FLAG_DELETED) {
+            cnt++, query = add_or_query
+                    (query, neg, imap_search_key_new_flag
+                        (neg, IMSGF_DELETED));
+        }
+        if (cond->match.flags & LIBBALSA_MESSAGE_FLAG_FLAGGED) {
+            cnt++, query = add_or_query
+                    (query, neg, imap_search_key_new_flag
+                        (neg, IMSGF_FLAGGED));
+        }
+        if (cond->match.flags & LIBBALSA_MESSAGE_FLAG_RECENT) {
+            cnt++, query = add_or_query
+                    (query, neg, imap_search_key_new_flag
+                        (neg, IMSGF_RECENT));
+        }
+        if (neg && (cnt > 1)) {
             query = imap_search_key_new_not(FALSE, query);
+        }
         imap_search_key_set_next(query, next);
         break;
+
     case CONDITION_AND:
-        if(neg) {
+        if (neg) {
             query = imap_search_key_new_not
-                (TRUE, lbmi_build_imap_query
-                 (cond->match.andor.left,
-                  lbmi_build_imap_query
-                  (cond->match.andor.right, NULL)));
+                    (TRUE, lbmi_build_imap_query
+                        (cond->match.andor.left,
+                        lbmi_build_imap_query
+                            (cond->match.andor.right, NULL)));
             imap_search_key_set_next(query, next);
-        } else
+        } else {
             query = lbmi_build_imap_query
-                (cond->match.andor.left,
-                 lbmi_build_imap_query
-                 (cond->match.andor.right, next));
+                    (cond->match.andor.left,
+                    lbmi_build_imap_query
+                        (cond->match.andor.right, next));
+        }
         break;
-    case CONDITION_OR: 
-        query = 
+
+    case CONDITION_OR:
+        query =
             imap_search_key_new_or
-            (neg,
-             lbmi_build_imap_query(cond->match.andor.left, NULL),
-             lbmi_build_imap_query(cond->match.andor.right, NULL));
-            imap_search_key_set_next(query, next);
+                (neg,
+                lbmi_build_imap_query(cond->match.andor.left, NULL),
+                lbmi_build_imap_query(cond->match.andor.right, NULL));
+        imap_search_key_set_next(query, next);
         break;
+
     case CONDITION_NONE:
     case CONDITION_REGEX:
     default:
@@ -1532,101 +1704,112 @@ lbmi_build_imap_query(const LibBalsaCondition* cond,
     return query;
 }
 
+
 typedef struct {
-    GHashTable * uids;
-    GHashTable * res;
+    GHashTable *uids;
+    GHashTable *res;
 } ImapSearchData;
 
 static void
-imap_matched(unsigned uid, ImapSearchData* data)
+imap_matched(unsigned        uid,
+             ImapSearchData *data)
 {
-    LibBalsaMessage* m = 
-        g_hash_table_lookup(data->uids,GUINT_TO_POINTER(uid)); 
-    if(m) 
+    LibBalsaMessage *m =
+        g_hash_table_lookup(data->uids, GUINT_TO_POINTER(uid));
+    if (m) {
         g_hash_table_insert(data->res, m, m);
-    else
+    } else {
         printf("Could not find UID: %u in message list\n", uid);
+    }
 }
 
+
 /* Gets the messages matching the conditions via the IMAP search command
    error is put to TRUE if an error occurred
-*/
+ */
 
-GHashTable * libbalsa_mailbox_imap_get_matchings(LibBalsaMailboxImap* mbox,
-                                                LibBalsaCondition *ct,
-                                                gboolean only_recent,
-                                                gboolean * err)
+GHashTable *
+libbalsa_mailbox_imap_get_matchings(LibBalsaMailboxImap *mbox,
+                                    LibBalsaCondition   *ct,
+                                    gboolean             only_recent,
+                                    gboolean            *err)
 {
-    ImapSearchKey* query;
+    ImapSearchKey *query;
     ImapResponse rc = IMR_NO;
-    ImapSearchData * cbdata;
-    GHashTable * res;
+    ImapSearchData *cbdata;
+    GHashTable *res;
 
     *err = FALSE;
-    
-    cbdata = g_new( ImapSearchData, 1 );
-    cbdata->uids = g_hash_table_new(NULL, NULL); 
+
+    cbdata       = g_new( ImapSearchData, 1 );
+    cbdata->uids = g_hash_table_new(NULL, NULL);
     cbdata->res  = g_hash_table_new(NULL, NULL);
-    query = lbmi_build_imap_query(ct /* FIXME: ONLY RECENT! */, NULL);
+    query        = lbmi_build_imap_query(ct /* FIXME: ONLY RECENT! */, NULL);
     if (query) {
 #ifdef UID_SEARCH_IMPLEMENTED
-       for(msgs= LIBBALSA_MAILBOX(mbox)->message_list; msgs;
-           msgs = msgs->next){
-           LibBalsaMessage *m = LIBBALSA_MESSAGE(msgs->data);
-           ImapMessage *imsg = mi_get_imsg(mbox, m->msgno);
+        for (msgs = LIBBALSA_MAILBOX(mbox)->message_list; msgs;
+             msgs = msgs->next) {
+            LibBalsaMessage *m = LIBBALSA_MESSAGE(msgs->data);
+            ImapMessage *imsg  = mi_get_imsg(mbox, m->msgno);
             if (imsg) {
                 g_hash_table_insert(cbdata->uids,
-                                   GUINT_TO_POINTER(imsg->uid), m);
-            } else
+                                    GUINT_TO_POINTER(imsg->uid), m);
+            } else {
                 g_warning("Msg %d out of range\n", m->msgno);
-       }
-#else  
+            }
+        }
+#else
         g_warning("Search results ignored. Fixme!");
 #endif
-        II(rc,mbox->handle,
+        II(rc, mbox->handle,
            imap_mbox_uid_search(mbox->handle, query,
-                                (void(*)(unsigned,void*))imap_matched,
+                                (void (*)(unsigned, void *))imap_matched,
                                 cbdata));
         imap_search_key_free(query);
     }
     g_hash_table_destroy(cbdata->uids);
     /* Clean up on error */
     if (rc != IMR_OK) {
-       g_hash_table_destroy(cbdata->res);
-       cbdata->res = NULL;
-       *err = TRUE;
-       libbalsa_information(LIBBALSA_INFORMATION_DEBUG,
-                            _("IMAP SEARCH command failed for mailbox %s\n"
-                              "falling back to default searching method"),
-                            libbalsa_mailbox_get_url(LIBBALSA_MAILBOX(mbox)));
-    };
+        g_hash_table_destroy(cbdata->res);
+        cbdata->res = NULL;
+        *err        = TRUE;
+        libbalsa_information(LIBBALSA_INFORMATION_DEBUG,
+                             _("IMAP SEARCH command failed for mailbox %s\n"
+                               "falling back to default searching method"),
+                             libbalsa_mailbox_get_url(LIBBALSA_MAILBOX(mbox)));
+    }
     res = cbdata->res;
     g_free(cbdata);
     return res;
 }
 
+
 /* Returns false if the conditions contain regex matches
    User must be informed that regex match on IMAP will
    be done by default filters functions hence leading to
    SLOW match
-*/
-gboolean libbalsa_mailbox_imap_can_match(LibBalsaMailbox  *mailbox,
-                                        LibBalsaCondition *condition)
+ */
+gboolean
+libbalsa_mailbox_imap_can_match(LibBalsaMailbox   *mailbox,
+                                LibBalsaCondition *condition)
 {
 #if 0
     GSList *cnds;
-    for (cnds =  conditions->cond_list; cnds; cnds = g_slist_next(cnds)) {
-       LibBalsaCondition * cnd = cnds->data;
-       
-       if (cnd->type==CONDITION_REGEX) return FALSE;
+    for (cnds = conditions->cond_list; cnds; cnds = g_slist_next(cnds)) {
+        LibBalsaCondition *cnd = cnds->data;
+
+        if (cnd->type == CONDITION_REGEX) {
+            return FALSE;
+        }
     }
 #endif
     return TRUE;
 }
 
+
 static void
-libbalsa_mailbox_imap_save_config(LibBalsaMailbox * mailbox,
-                                 const gchar * prefix)
+libbalsa_mailbox_imap_save_config(LibBalsaMailbox *mailbox,
+                                  const gchar     *prefix)
 {
     LibBalsaMailboxImap *mimap;
 
@@ -1638,14 +1821,16 @@ libbalsa_mailbox_imap_save_config(LibBalsaMailbox * mailbox,
 
     libbalsa_server_save_config(LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mailbox));
 
-    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_imap_parent_class)->save_config)
-       LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_imap_parent_class)->
-            save_config(mailbox, prefix);
+    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_imap_parent_class)->save_config) {
+        LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_imap_parent_class)->
+        save_config(mailbox, prefix);
+    }
 }
 
+
 static void
-libbalsa_mailbox_imap_load_config(LibBalsaMailbox * mailbox,
-                                 const gchar * prefix)
+libbalsa_mailbox_imap_load_config(LibBalsaMailbox *mailbox,
+                                  const gchar     *prefix)
 {
     LibBalsaMailboxImap *mimap;
     LibBalsaMailboxRemote *remote;
@@ -1658,45 +1843,48 @@ libbalsa_mailbox_imap_load_config(LibBalsaMailbox * mailbox,
     g_free(mimap->path);
     mimap->path = libbalsa_conf_get_string("Path");
     if (!mimap->path) {
-       mimap->path = g_strdup("INBOX");
-       libbalsa_information(LIBBALSA_INFORMATION_WARNING,
+        mimap->path = g_strdup("INBOX");
+        libbalsa_information(LIBBALSA_INFORMATION_WARNING,
                              _("No path found for mailbox “%s”, "
-                              "using “%s”"),
-                            libbalsa_mailbox_get_name(mailbox), mimap->path);
+                               "using “%s”"),
+                             libbalsa_mailbox_get_name(mailbox), mimap->path);
     }
 
     remote = LIBBALSA_MAILBOX_REMOTE(mailbox);
     server = LIBBALSA_SERVER(libbalsa_imap_server_new_from_config());
 
     g_signal_connect(G_OBJECT(server), "config-changed",
-                    G_CALLBACK(server_host_settings_changed_cb),
-                    (gpointer) mailbox);
+                     G_CALLBACK(server_host_settings_changed_cb),
+                     (gpointer) mailbox);
 
     libbalsa_mailbox_remote_set_server(remote, server);
 
-    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_imap_parent_class)->load_config)
-       LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_imap_parent_class)->
-            load_config(mailbox, prefix);
+    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_imap_parent_class)->load_config) {
+        LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_imap_parent_class)->
+        load_config(mailbox, prefix);
+    }
 
     libbalsa_mailbox_imap_update_url(mimap);
 }
 
+
 /* libbalsa_mailbox_imap_subscribe:
    change subscribed status for a mailbox.
    Can be called for a closed mailbox.
  */
 gboolean
-libbalsa_mailbox_imap_subscribe(LibBalsaMailboxImap * mailbox, 
-                                    gboolean subscribe)
+libbalsa_mailbox_imap_subscribe(LibBalsaMailboxImap *mailbox,
+                                gboolean             subscribe)
 {
     ImapResponse rc;
-    ImapMboxHandle* handle;
+    ImapMboxHandle *handle;
 
     g_return_val_if_fail(LIBBALSA_IS_MAILBOX_IMAP(mailbox), FALSE);
 
     handle = libbalsa_mailbox_imap_get_handle(mailbox, NULL);
-    if (!handle)
-       return FALSE;
+    if (!handle) {
+        return FALSE;
+    }
 
     II(rc, handle, imap_mbox_subscribe(handle, mailbox->path, subscribe));
 
@@ -1704,6 +1892,7 @@ libbalsa_mailbox_imap_subscribe(LibBalsaMailboxImap * mailbox,
     return rc == IMR_OK;
 }
 
+
 /* libbalsa_mailbox_imap_noop:
  * pings the connection with NOOP for an open IMAP mailbox.
  * this keeps the connections alive.
@@ -1714,18 +1903,20 @@ libbalsa_mailbox_imap_subscribe(LibBalsaMailboxImap * mailbox,
  */
 
 void
-libbalsa_mailbox_imap_noop(LibBalsaMailboxImap* mimap)
+libbalsa_mailbox_imap_noop(LibBalsaMailboxImap *mimap)
 {
     g_return_if_fail(mimap != NULL);
 
-    if (mimap->handle) /* we do not attempt to reconnect here */
-       if (imap_mbox_handle_noop(mimap->handle) != IMR_OK) {
-           /* FIXME: report error... */
-       }
+    if (mimap->handle) { /* we do not attempt to reconnect here */
+        if (imap_mbox_handle_noop(mimap->handle) != IMR_OK) {
+            /* FIXME: report error... */
+        }
+    }
 }
 
+
 void
-libbalsa_mailbox_imap_force_disconnect(LibBalsaMailboxImap* mimap)
+libbalsa_mailbox_imap_force_disconnect(LibBalsaMailboxImap *mimap)
 {
     g_return_if_fail(mimap != NULL);
 
@@ -1737,8 +1928,9 @@ libbalsa_mailbox_imap_force_disconnect(LibBalsaMailboxImap* mimap)
     }
 }
 
+
 void
-libbalsa_mailbox_imap_reconnect(LibBalsaMailboxImap* mimap)
+libbalsa_mailbox_imap_reconnect(LibBalsaMailboxImap *mimap)
 {
     g_return_if_fail(mimap != NULL);
 
@@ -1750,39 +1942,44 @@ libbalsa_mailbox_imap_reconnect(LibBalsaMailboxImap* mimap)
 
         printf("Reconnecting %s (%u)\n", host, (unsigned)time(NULL));
         if (imap_mbox_handle_reconnect(mimap->handle, &readonly)
-            == IMAP_SUCCESS)
+            == IMAP_SUCCESS) {
             printf("Reconnected %s (%u)\n", host, (unsigned)time(NULL));
+        }
         libbalsa_mailbox_set_readonly(LIBBALSA_MAILBOX(mimap), readonly);
     }
 }
 
+
 gboolean
-libbalsa_mailbox_imap_is_connected(LibBalsaMailboxImap* mimap)
+libbalsa_mailbox_imap_is_connected(LibBalsaMailboxImap *mimap)
 {
     return mimap->handle && !imap_mbox_is_disconnected(mimap->handle);
 }
 
+
 /* imap_close_all_connections:
    close all connections to leave the place cleanly.
-*/
+ */
 void
 libbalsa_imap_close_all_connections(void)
 {
     libbalsa_imap_server_close_all_connections();
 }
 
+
 /* libbalsa_imap_rename_subfolder:
-   dir+parent determine current name. 
+   dir+parent determine current name.
    folder - new name. Can be called for a closed mailbox.
  */
 gboolean
-libbalsa_imap_rename_subfolder(LibBalsaMailboxImap* imap,
-                               const gchar *new_parent, const gchar *folder, 
-                               gboolean subscribe,
-                               GError **err)
+libbalsa_imap_rename_subfolder(LibBalsaMailboxImap *imap,
+                               const gchar         *new_parent,
+                               const gchar         *folder,
+                               gboolean             subscribe,
+                               GError             **err)
 {
     ImapResponse rc;
-    ImapMboxHandle* handle;
+    ImapMboxHandle *handle;
     gchar *new_path;
     char delim[2];
 
@@ -1791,19 +1988,20 @@ libbalsa_imap_rename_subfolder(LibBalsaMailboxImap* imap,
         g_set_error(err, LIBBALSA_MAILBOX_ERROR,
                     LIBBALSA_MAILBOX_RENAME_ERROR,
                     _("Cannot get IMAP handle"));
-       return FALSE;
+        return FALSE;
     }
 
-    II(rc,handle,
+    II(rc, handle,
        imap_mbox_subscribe(handle, imap->path, FALSE));
     delim[0] = imap_mbox_handle_get_delim(handle, new_parent);
     delim[1] = '\0';
     new_path = g_build_path(delim, new_parent, folder, NULL);
-    rc = imap_mbox_rename(handle, imap->path, new_path);
-    if (subscribe && rc == IMR_OK)
-       rc = imap_mbox_subscribe(handle, new_path, TRUE);
+    rc       = imap_mbox_rename(handle, imap->path, new_path);
+    if (subscribe && (rc == IMR_OK)) {
+        rc = imap_mbox_subscribe(handle, new_path, TRUE);
+    }
     g_free(new_path);
-    if(rc != IMR_OK) {
+    if (rc != IMR_OK) {
         gchar *msg = imap_mbox_handle_get_last_msg(handle);
         g_set_error(err, LIBBALSA_MAILBOX_ERROR,
                     LIBBALSA_MAILBOX_RENAME_ERROR,
@@ -1815,38 +2013,44 @@ libbalsa_imap_rename_subfolder(LibBalsaMailboxImap* imap,
     return rc == IMR_OK;
 }
 
+
 gboolean
-libbalsa_imap_new_subfolder(const gchar *parent, const gchar *folder,
-                           gboolean subscribe, LibBalsaServer *server,
-                            GError **err)
+libbalsa_imap_new_subfolder(const gchar    *parent,
+                            const gchar    *folder,
+                            gboolean        subscribe,
+                            LibBalsaServer *server,
+                            GError        **err)
 {
     ImapResponse rc;
-    ImapMboxHandle* handle;
+    ImapMboxHandle *handle;
     gchar *new_path;
 
-    if (!LIBBALSA_IS_IMAP_SERVER(server))
-       return FALSE;
+    if (!LIBBALSA_IS_IMAP_SERVER(server)) {
+        return FALSE;
+    }
     handle = libbalsa_imap_server_get_handle(LIBBALSA_IMAP_SERVER(server),
-                                            NULL);
+                                             NULL);
     if (!handle) {
         g_set_error(err, LIBBALSA_MAILBOX_ERROR,
                     LIBBALSA_MAILBOX_RENAME_ERROR,
                     _("Cannot get IMAP handle"));
-       return FALSE;
+        return FALSE;
     }
     if (parent) {
         char delim[2];
         delim[0] = imap_mbox_handle_get_delim(handle, parent);
         delim[1] = '\0';
         new_path = g_build_path(delim, parent, folder, NULL);
-    } else
+    } else {
         new_path = g_strdup(folder);
-    II(rc,handle,
+    }
+    II(rc, handle,
        imap_mbox_create(handle, new_path));
-    if (subscribe && rc == IMR_OK)
-       rc = imap_mbox_subscribe(handle, new_path, TRUE);
+    if (subscribe && (rc == IMR_OK)) {
+        rc = imap_mbox_subscribe(handle, new_path, TRUE);
+    }
     g_free(new_path);
-    if(rc != IMR_OK) {
+    if (rc != IMR_OK) {
         gchar *msg = imap_mbox_handle_get_last_msg(handle);
         g_set_error(err, LIBBALSA_MAILBOX_ERROR,
                     LIBBALSA_MAILBOX_RENAME_ERROR,
@@ -1858,24 +2062,27 @@ libbalsa_imap_new_subfolder(const gchar *parent, const gchar *folder,
     return rc == IMR_OK;
 }
 
+
 gboolean
-libbalsa_imap_delete_folder(LibBalsaMailboxImap *mailbox, GError **err)
+libbalsa_imap_delete_folder(LibBalsaMailboxImap *mailbox,
+                            GError             **err)
 {
     ImapResponse rc;
-    ImapMboxHandle* handle;
+    ImapMboxHandle *handle;
 
     handle = libbalsa_mailbox_imap_get_handle(mailbox, NULL);
-    if (!handle)
-       return FALSE;
+    if (!handle) {
+        return FALSE;
+    }
 
     /* Some IMAP servers (UW2000) do not like removing subscribed mailboxes:
-     * they do not remove the mailbox from the subscription list since 
+     * they do not remove the mailbox from the subscription list since
      * the subscription list should be treated as a list of bookmarks,
      * not a list of physically existing mailboxes. */
     imap_mbox_subscribe(handle, mailbox->path, FALSE);
-    II(rc,handle,
+    II(rc, handle,
        imap_mbox_delete(handle, mailbox->path));
-    if(rc != IMR_OK) {
+    if (rc != IMR_OK) {
         gchar *msg = imap_mbox_handle_get_last_msg(handle);
         g_set_error(err, LIBBALSA_MAILBOX_ERROR,
                     LIBBALSA_MAILBOX_DELETE_ERROR,
@@ -1887,8 +2094,10 @@ libbalsa_imap_delete_folder(LibBalsaMailboxImap *mailbox, GError **err)
     return rc == IMR_OK;
 }
 
+
 gchar *
-libbalsa_imap_url(LibBalsaServer * server, const gchar * path)
+libbalsa_imap_url(LibBalsaServer *server,
+                  const gchar    *path)
 {
     gchar *enc = libbalsa_urlencode(libbalsa_server_get_username(server));
     gchar *url = g_strdup_printf("imap%s://%s@%s/%s",
@@ -1904,27 +2113,30 @@ libbalsa_imap_url(LibBalsaServer * server, const gchar * path)
     return url;
 }
 
+
 gboolean
-libbalsa_mailbox_imap_sync(LibBalsaMailbox * mailbox, gboolean expunge)
+libbalsa_mailbox_imap_sync(LibBalsaMailbox *mailbox,
+                           gboolean         expunge)
 {
     LibBalsaMailboxImap *mimap = LIBBALSA_MAILBOX_IMAP(mailbox);
-    gboolean res = TRUE;
+    gboolean res               = TRUE;
 
     g_return_val_if_fail(mimap->opened, FALSE);
     /* we are always in sync, we need only to do expunge now and then */
-    if(expunge) {
+    if (expunge) {
         ImapResponse rc;
-        II(rc,mimap->handle,
+        II(rc, mimap->handle,
            imap_mbox_expunge(mimap->handle));
         res = (rc == IMR_OK);
     }
     return res;
 }
 
-static InternetAddress*
+
+static InternetAddress *
 imap_address_to_gmime_mailbox(ImapAddress *addr)
 {
-    gchar *tmp = g_mime_utils_header_decode_text(addr->addr_spec);
+    gchar *tmp               = g_mime_utils_header_decode_text(addr->addr_spec);
     InternetAddress *address = internet_address_mailbox_new(NULL, tmp);
     g_free(tmp);
     if (addr->name) {
@@ -1935,15 +2147,17 @@ imap_address_to_gmime_mailbox(ImapAddress *addr)
     return address;
 }
 
+
 static InternetAddressList *
-internet_address_new_list_from_imap_address(ImapAddress *list,
+internet_address_new_list_from_imap_address(ImapAddress  *list,
                                             ImapAddress **tail)
 {
     InternetAddress *addr;
     InternetAddressList *res;
 
-    if (!list)
+    if (!list) {
         return NULL;
+    }
 
     res = internet_address_list_new();
     do {
@@ -1968,8 +2182,9 @@ internet_address_new_list_from_imap_address(ImapAddress *list,
                 list = imap_addr;
             } else {
                 /* tail */
-                if (tail)
+                if (tail) {
                     *tail = list;
+                }
                 return res;
             }
 
@@ -1977,52 +2192,57 @@ internet_address_new_list_from_imap_address(ImapAddress *list,
         internet_address_list_add(res, addr);
         g_object_unref(addr);
 
-    } while (list &&  (list = list->next) != NULL);
+    } while (list && (list = list->next) != NULL);
     return res;
 }
 
+
 static InternetAddressList *
 internet_address_new_list_from_imap_address_list(ImapAddress *list)
 {
     return internet_address_new_list_from_imap_address(list, NULL);
 }
 
+
 static void
-lb_set_headers(LibBalsaMessageHeaders *headers, ImapEnvelope *  envelope,
-               gboolean is_embedded)
+lb_set_headers(LibBalsaMessageHeaders *headers,
+               ImapEnvelope           *envelope,
+               gboolean                is_embedded)
 {
     headers->date = envelope->date;
     headers->from =
-       internet_address_new_list_from_imap_address_list(envelope->from);
+        internet_address_new_list_from_imap_address_list(envelope->from);
     headers->reply_to =
         internet_address_new_list_from_imap_address_list(envelope->replyto);
     headers->to_list =
-       internet_address_new_list_from_imap_address_list(envelope->to);
+        internet_address_new_list_from_imap_address_list(envelope->to);
     headers->cc_list =
-       internet_address_new_list_from_imap_address_list(envelope->cc);
+        internet_address_new_list_from_imap_address_list(envelope->cc);
     headers->bcc_list =
-       internet_address_new_list_from_imap_address_list(envelope->bcc);
+        internet_address_new_list_from_imap_address_list(envelope->bcc);
 
-    if(is_embedded) {
+    if (is_embedded) {
         headers->subject =
             g_mime_utils_header_decode_text(envelope->subject);
         libbalsa_utf8_sanitize(&headers->subject, TRUE, NULL);
     }
 }
 
+
 static gboolean
 libbalsa_mailbox_imap_load_envelope(LibBalsaMailboxImap *mimap,
-                                   LibBalsaMessage *message)
+                                    LibBalsaMessage     *message)
 {
     ImapEnvelope *envelope;
-    ImapMessage* imsg;
+    ImapMessage *imsg;
     gchar *hdr;
-    
+
     g_return_val_if_fail(mimap->opened, FALSE);
     imsg = mi_get_imsg(mimap, message->msgno);
 
-    if(!imsg || !imsg->envelope) {/* Connection severed and and restore
-                                   *  failed - deal with it! */
+    if (!imsg || !imsg->envelope) {
+        /* Connection severed and and restore
+         *  failed - deal with it! */
         fprintf(stderr, "load_envelope failed!\n");
         return FALSE;
     }
@@ -2030,26 +2250,29 @@ libbalsa_mailbox_imap_load_envelope(LibBalsaMailboxImap *mimap,
     lbimap_update_flags(message, imsg);
 
     lb_set_headers(message->headers, imsg->envelope, FALSE);
-    if ((hdr = imsg->fetched_header_fields) && *hdr && *hdr != '\r')
-       libbalsa_message_set_headers_from_string(message, hdr);
+    if ((hdr = imsg->fetched_header_fields) && *hdr && (*hdr != '\r')) {
+        libbalsa_message_set_headers_from_string(message, hdr);
+    }
     envelope        = imsg->envelope;
     message->length = imsg->rfc822size;
     libbalsa_message_set_subject_from_header(message, envelope->subject);
     message->sender =
-       internet_address_new_list_from_imap_address_list(envelope->sender);
+        internet_address_new_list_from_imap_address_list(envelope->sender);
     libbalsa_message_set_in_reply_to_from_string(message,
-                                                envelope->in_reply_to);
+                                                 envelope->in_reply_to);
     if (envelope->message_id) {
-       message->message_id =
-           g_mime_utils_decode_message_id(envelope->message_id);
+        message->message_id =
+            g_mime_utils_decode_message_id(envelope->message_id);
     }
 
     return TRUE;
 }
 
+
 /* converts the backend data to LibBalsaMessage object */
-static LibBalsaMessage*
-libbalsa_mailbox_imap_get_message(LibBalsaMailbox * mailbox, guint msgno)
+static LibBalsaMessage *
+libbalsa_mailbox_imap_get_message(LibBalsaMailbox *mailbox,
+                                  guint            msgno)
 {
     struct message_info *msg_info;
     LibBalsaMailboxImap *mimap = (LibBalsaMailboxImap *) mailbox;
@@ -2066,93 +2289,120 @@ libbalsa_mailbox_imap_get_message(LibBalsaMailbox * mailbox, guint msgno)
         msg->msgno   = msgno;
         msg->mailbox = mailbox;
         if (libbalsa_mailbox_imap_load_envelope(mimap, msg)) {
-           gchar *id;
-            msg_info->message  = msg;
-           if (libbalsa_message_is_partial(msg, &id)) {
-               libbalsa_mailbox_try_reassemble(mailbox, id);
-               g_free(id);
-           }
-       } else 
+            gchar *id;
+            msg_info->message = msg;
+            if (libbalsa_message_is_partial(msg, &id)) {
+                libbalsa_mailbox_try_reassemble(mailbox, id);
+                g_free(id);
+            }
+        } else {
             g_object_unref(G_OBJECT(msg));
+        }
+    }
+    if (msg_info->message) {
+        g_object_ref(msg_info->message); /* we want to keep one copy */
     }
-    if (msg_info->message)
-       g_object_ref(msg_info->message); /* we want to keep one copy */
     libbalsa_unlock_mailbox(mailbox);
 
     return msg_info->message;
 }
 
+
 static gboolean
-libbalsa_mailbox_imap_prepare_threading(LibBalsaMailbox * mailbox,
-                                        guint start)
+libbalsa_mailbox_imap_prepare_threading(LibBalsaMailbox *mailbox,
+                                        guint            start)
 {
     /* Nothing to do. */
     return TRUE;
 }
 
+
 static void
-lbm_imap_construct_body(LibBalsaMessageBody *lbbody, ImapBody *imap_body)
+lbm_imap_construct_body(LibBalsaMessageBody *lbbody,
+                        ImapBody            *imap_body)
 {
     const char *str;
     g_return_if_fail(lbbody);
     g_return_if_fail(imap_body);
 
-    switch(imap_body->media_basic) {
+    switch (imap_body->media_basic) {
     case IMBMEDIA_MULTIPART:
-        lbbody->body_type = LIBBALSA_MESSAGE_BODY_TYPE_MULTIPART; break;
+        lbbody->body_type = LIBBALSA_MESSAGE_BODY_TYPE_MULTIPART;
+        break;
+
     case IMBMEDIA_APPLICATION:
-        lbbody->body_type = LIBBALSA_MESSAGE_BODY_TYPE_APPLICATION; break;
+        lbbody->body_type = LIBBALSA_MESSAGE_BODY_TYPE_APPLICATION;
+        break;
+
     case IMBMEDIA_AUDIO:
-        lbbody->body_type = LIBBALSA_MESSAGE_BODY_TYPE_AUDIO; break;
+        lbbody->body_type = LIBBALSA_MESSAGE_BODY_TYPE_AUDIO;
+        break;
+
     case IMBMEDIA_IMAGE:
-        lbbody->body_type = LIBBALSA_MESSAGE_BODY_TYPE_IMAGE; break;
+        lbbody->body_type = LIBBALSA_MESSAGE_BODY_TYPE_IMAGE;
+        break;
+
     case IMBMEDIA_MESSAGE_RFC822:
     case IMBMEDIA_MESSAGE_OTHER:
-        lbbody->body_type = LIBBALSA_MESSAGE_BODY_TYPE_MESSAGE; break;
+        lbbody->body_type = LIBBALSA_MESSAGE_BODY_TYPE_MESSAGE;
+        break;
+
     case IMBMEDIA_TEXT:
-        lbbody->body_type = LIBBALSA_MESSAGE_BODY_TYPE_TEXT; break;
+        lbbody->body_type = LIBBALSA_MESSAGE_BODY_TYPE_TEXT;
+        break;
+
     default:
     case IMBMEDIA_OTHER:
-        lbbody->body_type = LIBBALSA_MESSAGE_BODY_TYPE_OTHER; break;
+        lbbody->body_type = LIBBALSA_MESSAGE_BODY_TYPE_OTHER;
+        break;
     }
 
     switch (imap_body->content_dsp) {
     case IMBDISP_INLINE:
-       lbbody->content_dsp = GMIME_DISPOSITION_INLINE; break;
+        lbbody->content_dsp = GMIME_DISPOSITION_INLINE;
+        break;
+
     case IMBDISP_ATTACHMENT:
-       lbbody->content_dsp = GMIME_DISPOSITION_ATTACHMENT; break;
+        lbbody->content_dsp = GMIME_DISPOSITION_ATTACHMENT;
+        break;
+
     case IMBDISP_OTHER:
-       lbbody->content_dsp = imap_body->content_dsp_other; break;
+        lbbody->content_dsp = imap_body->content_dsp_other;
+        break;
     }
-    lbbody->content_id = imap_body->content_id;
+    lbbody->content_id   = imap_body->content_id;
     lbbody->content_type = imap_body_get_content_type(imap_body);
     /* get the name in the same way as g_mime_part_get_filename() does */
     str = imap_body_get_dsp_param(imap_body, "filename");
-    if(!str) str = imap_body_get_param(imap_body, "name");
-    if(str) {
-        lbbody->filename  =
-           g_mime_utils_header_decode_text(str);
+    if (!str) {
+        str = imap_body_get_param(imap_body, "name");
+    }
+    if (str) {
+        lbbody->filename =
+            g_mime_utils_header_decode_text(str);
         libbalsa_utf8_sanitize(&lbbody->filename, TRUE, NULL);
     }
-    lbbody->charset   = g_strdup(imap_body_get_param(imap_body, "charset"));
-    if(imap_body->envelope) {
+    lbbody->charset = g_strdup(imap_body_get_param(imap_body, "charset"));
+    if (imap_body->envelope) {
         lbbody->embhdrs = g_new0(LibBalsaMessageHeaders, 1);
         lb_set_headers(lbbody->embhdrs, imap_body->envelope, TRUE);
     }
-    if(imap_body->next) {
+    if (imap_body->next) {
         LibBalsaMessageBody *body = libbalsa_message_body_new(lbbody->message);
         lbm_imap_construct_body(body, imap_body->next);
         lbbody->next = body;
     }
-    if(imap_body->child) {
+    if (imap_body->child) {
         LibBalsaMessageBody *body = libbalsa_message_body_new(lbbody->message);
         lbm_imap_construct_body(body, imap_body->child);
         lbbody->parts = body;
     }
 }
 
+
 static gboolean
-get_struct_from_cache(LibBalsaMailbox *mailbox, LibBalsaMessage *message,
+get_struct_from_cache(LibBalsaMailbox  *mailbox,
+                      LibBalsaMessage  *message,
                       LibBalsaFetchFlag flags)
 {
     if (!message->mime_msg) {
@@ -2162,10 +2412,11 @@ get_struct_from_cache(LibBalsaMailbox *mailbox, LibBalsaMessage *message,
         GMimeFilter *filter;
         GMimeParser *mime_parser;
         LibBalsaMailboxImap *mimap = LIBBALSA_MAILBOX_IMAP(mailbox);
-       ImapMessage *imsg = mi_get_imsg(mimap, message->msgno);
+        ImapMessage *imsg          = mi_get_imsg(mimap, message->msgno);
 
-       if (!imsg)
-           return FALSE;
+        if (!imsg) {
+            return FALSE;
+        }
 
         pair = get_cache_name_pair(mimap, "body", imsg->uid);
 
@@ -2173,10 +2424,11 @@ get_struct_from_cache(LibBalsaMailbox *mailbox, LibBalsaMessage *message,
         g_strfreev(pair);
         fd = open(filename, O_RDONLY);
         g_free(filename);
-        if (fd == -1)
+        if (fd == -1) {
             return FALSE;
+        }
 
-        stream = g_mime_stream_fs_new(fd);
+        stream  = g_mime_stream_fs_new(fd);
         fstream = g_mime_stream_filter_new(stream);
         g_object_unref(stream);
 
@@ -2191,10 +2443,10 @@ get_struct_from_cache(LibBalsaMailbox *mailbox, LibBalsaMessage *message,
         message->mime_msg = g_mime_parser_construct_message(mime_parser);
         g_object_unref(mime_parser);
     }
-    
+
     /* follow libbalsa_mailbox_local_fetch_structure here;
      * perhaps create common helper */
-    if(flags & LB_FETCH_STRUCTURE) {
+    if (flags & LB_FETCH_STRUCTURE) {
         LibBalsaMessageBody *body = libbalsa_message_body_new(message);
         libbalsa_message_body_set_mime_body(body,
                                             message->mime_msg->mime_part);
@@ -2202,18 +2454,19 @@ get_struct_from_cache(LibBalsaMailbox *mailbox, LibBalsaMessage *message,
         libbalsa_message_headers_from_gmime(message->headers,
                                             message->mime_msg);
     }
-    if(flags & LB_FETCH_RFC822_HEADERS) {
+    if (flags & LB_FETCH_RFC822_HEADERS) {
         g_assert(message->headers != NULL);
-        message->headers->user_hdrs = 
+        message->headers->user_hdrs =
             libbalsa_message_user_hdrs_from_gmime(message->mime_msg);
         message->has_all_headers = 1;
     }
     return TRUE;
 }
 
+
 static gboolean
-libbalsa_mailbox_imap_fetch_structure(LibBalsaMailbox *mailbox,
-                                      LibBalsaMessage *message,
+libbalsa_mailbox_imap_fetch_structure(LibBalsaMailbox  *mailbox,
+                                      LibBalsaMessage  *message,
                                       LibBalsaFetchFlag flags)
 {
     ImapResponse rc;
@@ -2231,45 +2484,51 @@ libbalsa_mailbox_imap_fetch_structure(LibBalsaMailbox *mailbox,
        parts yet. Also, we save some RTTS for very small messages by
        fetching them in their entirety. */
     server = LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mailbox);
-    if(!imap_mbox_handle_can_do(mimap->handle, IMCAP_FETCHBODY) ||
-       libbalsa_imap_server_has_bug(LIBBALSA_IMAP_SERVER(server),
-                                    ISBUG_FETCH) ||
-       LIBBALSA_MESSAGE_GET_LENGTH(message)<8192 ||
-       (message->headers &&
-        (!message->headers->content_type ||
-         g_mime_content_type_is_type(message->headers->content_type, "text", "*"))) ){
+    if (!imap_mbox_handle_can_do(mimap->handle, IMCAP_FETCHBODY) ||
+        libbalsa_imap_server_has_bug(LIBBALSA_IMAP_SERVER(server),
+                                     ISBUG_FETCH) ||
+        (LIBBALSA_MESSAGE_GET_LENGTH(message) < 8192) ||
+        (message->headers &&
+         (!message->headers->content_type ||
+          g_mime_content_type_is_type(message->headers->content_type, "text", "*")))) {
         /* we could optimize this part a little bit: we do not need to
          * keep reopening the stream. */
-        GMimeStream *stream = 
+        GMimeStream *stream =
             libbalsa_mailbox_imap_get_message_stream(mailbox, message->msgno,
-                                                    FALSE);
-        if(!stream) /* oops, connection broken or the message disappeared? */
+                                                     FALSE);
+        if (!stream) { /* oops, connection broken or the message disappeared? */
             return FALSE;
+        }
         g_object_unref(stream);
     }
 
-    if(get_struct_from_cache(mailbox, message, flags))
+    if (get_struct_from_cache(mailbox, message, flags)) {
         return TRUE;
+    }
 
-    if(flags & LB_FETCH_RFC822_HEADERS) ift |= IMFETCH_RFC822HEADERS_SELECTED;
-    if(flags & LB_FETCH_STRUCTURE)      ift |= IMFETCH_BODYSTRUCT;
+    if (flags & LB_FETCH_RFC822_HEADERS) {
+        ift |= IMFETCH_RFC822HEADERS_SELECTED;
+    }
+    if (flags & LB_FETCH_STRUCTURE) {
+        ift |= IMFETCH_BODYSTRUCT;
+    }
 
     II(rc, mimap->handle,
        imap_mbox_handle_fetch_range(mimap->handle, message->msgno,
                                     message->msgno, ift));
-    if(rc == IMR_OK) { /* translate ImapData to LibBalsaMessage */
+    if (rc == IMR_OK) { /* translate ImapData to LibBalsaMessage */
         gchar *hdr;
         ImapMessage *im = imap_mbox_handle_get_msg(mimap->handle,
                                                    message->msgno);
-       /* in case of msg number discrepancies: */
+        /* in case of msg number discrepancies: */
         g_return_val_if_fail(im != NULL, FALSE);
-        if(flags & LB_FETCH_STRUCTURE) {
+        if (flags & LB_FETCH_STRUCTURE) {
             LibBalsaMessageBody *body = libbalsa_message_body_new(message);
             lbm_imap_construct_body(body, im->body);
             libbalsa_message_append_part(message, body);
         }
-        if( (flags & LB_FETCH_RFC822_HEADERS) &&
-            (hdr = im->fetched_header_fields) && *hdr && *hdr != '\r') {
+        if ((flags & LB_FETCH_RFC822_HEADERS) &&
+            (hdr = im->fetched_header_fields) && *hdr && (*hdr != '\r')) {
             libbalsa_message_set_headers_from_string(message, hdr);
             message->has_all_headers = 1;
         }
@@ -2279,6 +2538,7 @@ libbalsa_mailbox_imap_fetch_structure(LibBalsaMailbox *mailbox,
     return FALSE;
 }
 
+
 static void
 libbalsa_mailbox_imap_fetch_headers(LibBalsaMailbox *mailbox,
                                     LibBalsaMessage *message)
@@ -2286,28 +2546,32 @@ libbalsa_mailbox_imap_fetch_headers(LibBalsaMailbox *mailbox,
     LibBalsaMailboxImap *mimap = LIBBALSA_MAILBOX_IMAP(mailbox);
     ImapResponse rc;
 
-    II(rc,mimap->handle,
+    II(rc, mimap->handle,
        imap_mbox_handle_fetch_range(mimap->handle,
                                     message->msgno,
                                     message->msgno,
                                     IMFETCH_RFC822HEADERS_SELECTED));
-    if(rc == IMR_OK) { /* translate ImapData to LibBalsaMessage */
+    if (rc == IMR_OK) { /* translate ImapData to LibBalsaMessage */
         const gchar *hdr;
         ImapMessage *im = imap_mbox_handle_get_msg(mimap->handle,
                                                    message->msgno);
-        if ((hdr = im->fetched_header_fields) && *hdr && *hdr != '\r')
+        if ((hdr = im->fetched_header_fields) && *hdr && (*hdr != '\r')) {
             libbalsa_message_set_headers_from_string(message, hdr);
+        }
     }
 }
 
+
 static gboolean
-is_child_of(LibBalsaMessageBody *body, LibBalsaMessageBody *child,
-            GString *s, gboolean modify)
+is_child_of(LibBalsaMessageBody *body,
+            LibBalsaMessageBody *child,
+            GString             *s,
+            gboolean             modify)
 {
     int i = 1;
     gboolean do_mod;
-    for(i=1; body; body = body->next) {
-        if(body==child) {
+    for (i = 1; body; body = body->next) {
+        if (body == child) {
             g_string_printf(s, "%u", i);
             return TRUE;
         }
@@ -2315,8 +2579,8 @@ is_child_of(LibBalsaMessageBody *body, LibBalsaMessageBody *child,
                    body->parts &&
                    body->parts->body_type ==
                    LIBBALSA_MESSAGE_BODY_TYPE_MULTIPART);
-        if(is_child_of(body->parts, child, s, do_mod)){
-            if(modify) {
+        if (is_child_of(body->parts, child, s, do_mod)) {
+            if (modify) {
                 char buf[12];
                 snprintf(buf, sizeof(buf), "%u.", i);
                 g_string_prepend(s, buf);
@@ -2328,9 +2592,12 @@ is_child_of(LibBalsaMessageBody *body, LibBalsaMessageBody *child,
     return FALSE;
 }
 
+
 #if 0
 static void
-print_structure(LibBalsaMessageBody *part, LibBalsaMessageBody* m, int ind)
+print_structure(LibBalsaMessageBody *part,
+                LibBalsaMessageBody *m,
+                int                  ind)
 {
     static const char *t[] = {
         "LIBBALSA_MESSAGE_BODY_TYPE_OTHER",
@@ -2341,30 +2608,38 @@ print_structure(LibBalsaMessageBody *part, LibBalsaMessageBody* m, int ind)
         "LIBBALSA_MESSAGE_BODY_TYPE_MODEL",
         "LIBBALSA_MESSAGE_BODY_TYPE_MULTIPART",
         "LIBBALSA_MESSAGE_BODY_TYPE_TEXT",
-        "LIBBALSA_MESSAGE_BODY_TYPE_VIDEO" };
+        "LIBBALSA_MESSAGE_BODY_TYPE_VIDEO"
+    };
 
-    int j,i=1;
-    while(part) {
-        for(j=0; j<ind; j++) putchar(' ');
+    int j, i = 1;
+    while (part) {
+        for (j = 0; j < ind; j++) {
+            putchar(' ');
+        }
         printf("%d: %s%s\n", i++, t[part->body_type],
                part == m ? " <--" : "");
-        if(part->parts)
-            print_structure(part->parts, m, ind+2);
+        if (part->parts) {
+            print_structure(part->parts, m, ind + 2);
+        }
         part = part->next;
     }
 }
+
+
 #endif
-static gchar*
-get_section_for(LibBalsaMessage *msg, LibBalsaMessageBody *part)
+static gchar *
+get_section_for(LibBalsaMessage     *msg,
+                LibBalsaMessageBody *part)
 {
     GString *section = g_string_new("");
     LibBalsaMessageBody *parent;
 
     parent = msg->body_list;
-    if (libbalsa_message_body_is_multipart(parent))
-       parent = parent->parts;
+    if (libbalsa_message_body_is_multipart(parent)) {
+        parent = parent->parts;
+    }
 
-    if(!is_child_of(parent, part, section, TRUE)) {
+    if (!is_child_of(parent, part, section, TRUE)) {
         g_warning("Internal error, part %p not found in msg %p.\n",
                   part, msg);
         g_string_free(section, TRUE);
@@ -2376,79 +2651,100 @@ get_section_for(LibBalsaMessage *msg, LibBalsaMessageBody *part)
 #endif
     return g_string_free(section, FALSE);
 }
-struct part_data { char *block; unsigned pos; ImapBody *body; };
+
+
+struct part_data {
+    char *block;
+    unsigned pos;
+    ImapBody *body;
+};
 static void
-append_str(unsigned seqno, const char *buf, size_t buflen, void *arg)
+append_str(unsigned    seqno,
+           const char *buf,
+           size_t      buflen,
+           void       *arg)
 {
-    struct part_data *dt = (struct part_data*)arg;
+    struct part_data *dt = (struct part_data *)arg;
 
-    if(dt->pos + buflen > dt->body->octets) {
-        /* 
-        fprintf(stderr, "IMAP server sends too much data but we just "
+    if (dt->pos + buflen > dt->body->octets) {
+        /*
+           fprintf(stderr, "IMAP server sends too much data but we just "
                 "reallocate the block.\n"); */
-       dt->body->octets = dt->pos + buflen;
-       dt->block = g_realloc(dt->block, dt->body->octets);
+        dt->body->octets = dt->pos + buflen;
+        dt->block        = g_realloc(dt->block, dt->body->octets);
     }
     memcpy(dt->block + dt->pos, buf, buflen);
     dt->pos += buflen;
 }
 
-static const char*
+
+static const char *
 encoding_names(ImapBodyEncoding enc)
 {
-    switch(enc) {
+    switch (enc) {
     case IMBENC_7BIT:   return "7bit";
+
     default:
     case IMBENC_8BIT:   return "8bit";
+
     case IMBENC_BINARY: return "binary";
+
     case IMBENC_BASE64: return "base64";
+
     case IMBENC_QUOTED: return "quoted-printable";
     }
 }
-static LibBalsaMessageBody*
-get_parent(LibBalsaMessageBody *root, LibBalsaMessageBody *part,
+
+
+static LibBalsaMessageBody *
+get_parent(LibBalsaMessageBody *root,
+           LibBalsaMessageBody *part,
            LibBalsaMessageBody *parent)
 {
-    while(root) {
+    while (root) {
         LibBalsaMessageBody *res;
-        if(root == part)
+        if (root == part) {
             return parent;
-        if(root->parts &&
-           (res = get_parent(root->parts, part, root)) != NULL)
+        }
+        if (root->parts &&
+            ((res = get_parent(root->parts, part, root)) != NULL)) {
             return res;
+        }
         root = root->next;
     }
     return NULL;
 }
+
+
 static gboolean
-lbm_imap_get_msg_part_from_cache(LibBalsaMessage * msg,
-                                 LibBalsaMessageBody * part,
-                                 GError **err)
+lbm_imap_get_msg_part_from_cache(LibBalsaMessage     *msg,
+                                 LibBalsaMessageBody *part,
+                                 GError             **err)
 {
     GMimeStream *partstream = NULL;
 
-    gchar **pair,  *part_name;
+    gchar **pair, *part_name;
     LibBalsaMailboxImap *mimap = LIBBALSA_MAILBOX_IMAP(msg->mailbox);
     FILE *fp;
     gchar *section;
     ImapMessage *imsg = mi_get_imsg(mimap, msg->msgno);
 
     if (!imsg) {
-       g_set_error(err,
-                   LIBBALSA_MAILBOX_ERROR, LIBBALSA_MAILBOX_ACCESS_ERROR,
-                   _("Error fetching message from IMAP server: %s"), 
-                   imap_mbox_handle_get_last_msg(mimap->handle));
-       return FALSE;
-    }
-
-   /* look for a part cache */
-    section = get_section_for(msg, part);
-    pair = get_cache_name_pair(mimap, "part", imsg->uid);
-    part_name   = g_strconcat(pair[0], G_DIR_SEPARATOR_S,
-                              pair[1], "-", section, NULL);
-    fp = fopen(part_name,"rb+");
-    
-    if(!fp) { /* no cache element */
+        g_set_error(err,
+                    LIBBALSA_MAILBOX_ERROR, LIBBALSA_MAILBOX_ACCESS_ERROR,
+                    _("Error fetching message from IMAP server: %s"),
+                    imap_mbox_handle_get_last_msg(mimap->handle));
+        return FALSE;
+    }
+
+    /* look for a part cache */
+    section   = get_section_for(msg, part);
+    pair      = get_cache_name_pair(mimap, "part", imsg->uid);
+    part_name = g_strconcat(pair[0], G_DIR_SEPARATOR_S,
+                            pair[1], "-", section, NULL);
+    fp = fopen(part_name, "rb+");
+
+    if (!fp) { /* no cache element */
         struct part_data dt;
         ImapFetchBodyOptions ifbo;
         ImapResponse rc;
@@ -2456,9 +2752,9 @@ lbm_imap_get_msg_part_from_cache(LibBalsaMessage * msg,
 
         libbalsa_lock_mailbox(msg->mailbox);
         mimap = LIBBALSA_MAILBOX_IMAP(msg->mailbox);
-        
-        dt.body  = imap_message_get_body_from_section(imsg, section);
-        if(!dt.body) {
+
+        dt.body = imap_message_get_body_from_section(imsg, section);
+        if (!dt.body) {
             /* This may happen if we reconnect the data dropping the
                body structures but still try refetching the
                message. This can be simulated by randomly
@@ -2466,50 +2762,53 @@ lbm_imap_get_msg_part_from_cache(LibBalsaMessage * msg,
             fprintf(stderr, "Cannot find data for section %s\n", section);
             return FALSE;
         }
-        dt.block = g_malloc(dt.body->octets+1);
+        dt.block = g_malloc(dt.body->octets + 1);
         dt.pos   = 0;
-        if(dt.body->octets>SizeMsgThreshold)
-            libbalsa_information(LIBBALSA_INFORMATION_MESSAGE, 
+        if (dt.body->octets > SizeMsgThreshold) {
+            libbalsa_information(LIBBALSA_INFORMATION_MESSAGE,
                                  _("Downloading %u kB"),
-                                 dt.body->octets/1024);
-       /* Imap_mbox_handle_fetch_body fetches the MIME headers of the
+                                 dt.body->octets / 1024);
+        }
+        /* Imap_mbox_handle_fetch_body fetches the MIME headers of the
          * section, followed by the text. We write this unfiltered to
          * the cache. The probably only exception is the main body
          * which has no headers. In this case, we have to fake them.
-         * We could and probably should dump there first the headers 
+         * We could and probably should dump there first the headers
          * that we have already fetched... */
         parent = get_parent(msg->body_list, part, NULL);
-        if(parent == NULL)
+        if (parent == NULL) {
             ifbo = IMFB_NONE;
-        else {
-            if(parent->body_type == LIBBALSA_MESSAGE_BODY_TYPE_MESSAGE)
+        } else {
+            if (parent->body_type == LIBBALSA_MESSAGE_BODY_TYPE_MESSAGE) {
                 ifbo = IMFB_HEADER;
-            else
+            } else {
                 ifbo = IMFB_MIME;
+            }
         }
         rc = IMR_OK;
-        if (dt.body->octets > 0)
-        II(rc,mimap->handle,
-           imap_mbox_handle_fetch_body(mimap->handle, msg->msgno,
-                                       section, FALSE, ifbo, append_str, &dt));
+        if (dt.body->octets > 0) {
+            II(rc, mimap->handle,
+               imap_mbox_handle_fetch_body(mimap->handle, msg->msgno,
+                                           section, FALSE, ifbo, append_str, &dt));
+        }
         libbalsa_unlock_mailbox(msg->mailbox);
-        if(rc != IMR_OK) {
+        if (rc != IMR_OK) {
             fprintf(stderr, "Error fetching imap message no %lu section %s\n",
                     msg->msgno, section);
             g_free(dt.block);
-            g_free(section); 
+            g_free(section);
             g_strfreev(pair);
             g_free(part_name);
             g_set_error(err,
                         LIBBALSA_MAILBOX_ERROR, LIBBALSA_MAILBOX_ACCESS_ERROR,
-                        _("Error fetching message from IMAP server: %s"), 
+                        _("Error fetching message from IMAP server: %s"),
                         imap_mbox_handle_get_last_msg(mimap->handle));
             return FALSE;
         }
-        g_mkdir_with_parents(pair[0], S_IRUSR|S_IWUSR|S_IXUSR);
+        g_mkdir_with_parents(pair[0], S_IRUSR | S_IWUSR | S_IXUSR);
         fp = fopen(part_name, "wb+");
-        if(!fp) {
-            g_free(section); 
+        if (!fp) {
+            g_free(section);
             g_strfreev(pair);
             g_free(part_name);
             g_set_error(err,
@@ -2517,58 +2816,61 @@ lbm_imap_get_msg_part_from_cache(LibBalsaMessage * msg,
                         _("Cannot create temporary file"));
             return FALSE;
         }
-        if(ifbo == IMFB_NONE || dt.body->octets == 0) {
-            fprintf(fp,"MIME-version: 1.0\r\ncontent-type: %s\r\n"
+        if ((ifbo == IMFB_NONE) || (dt.body->octets == 0)) {
+            fprintf(fp, "MIME-version: 1.0\r\ncontent-type: %s\r\n"
                     "Content-Transfer-Encoding: %s\r\n\r\n",
                     part->content_type ? part->content_type : "text/plain",
                     encoding_names(dt.body->encoding));
         }
         /* Carefully save number of bytes actually read from the file. */
-       if (dt.pos) {
-            if(fwrite(dt.block, 1, dt.pos, fp) != dt.pos
-               || fflush(fp) != 0) {
-            fclose(fp);
-            /* we do not want to have an incomplete part in the cache
-               so that the user still can try again later when the
-               problem with writing (disk space?) is removed */
-            unlink(part_name);
-            g_set_error(err,
-                        LIBBALSA_MAILBOX_ERROR, LIBBALSA_MAILBOX_ACCESS_ERROR,
-                        _("Cannot write to temporary file %s"), part_name);
-            g_free(section); 
-            g_strfreev(pair);
-            g_free(part_name);
-            g_free(dt.block);
-            return FALSE; /* something better ? */
+        if (dt.pos) {
+            if ((fwrite(dt.block, 1, dt.pos, fp) != dt.pos)
+                || (fflush(fp) != 0)) {
+                fclose(fp);
+                /* we do not want to have an incomplete part in the cache
+                   so that the user still can try again later when the
+                   problem with writing (disk space?) is removed */
+                unlink(part_name);
+                g_set_error(err,
+                            LIBBALSA_MAILBOX_ERROR, LIBBALSA_MAILBOX_ACCESS_ERROR,
+                            _("Cannot write to temporary file %s"), part_name);
+                g_free(section);
+                g_strfreev(pair);
+                g_free(part_name);
+                g_free(dt.block);
+                return FALSE; /* something better ? */
             }
         }
         g_free(dt.block);
-       fseek(fp, 0, SEEK_SET);
+        fseek(fp, 0, SEEK_SET);
     }
     partstream = g_mime_stream_file_new (fp);
 
     {
-        GMimeParser *parser =  
+        GMimeParser *parser =
             g_mime_parser_new_with_stream (partstream);
         part->mime_part = g_mime_parser_construct_part (parser);
         g_object_unref (parser);
     }
     g_object_unref (partstream);
-    g_free(section); 
+    g_free(section);
     g_strfreev(pair);
     g_free(part_name);
 
     return TRUE;
 }
 
+
 /* Recursive helper for libbalsa_mailbox_imap_get_msg_part: ensure that
  * we have a mime_part, and if we are in a multipart/signed or
  * multipart/encrypted, ensure that all needed children are also
  * created. */
 static gboolean
-lbm_imap_get_msg_part(LibBalsaMessage * msg, LibBalsaMessageBody * part,
-                      gboolean need_children, GMimeObject * parent_part,
-                      GError **err)
+lbm_imap_get_msg_part(LibBalsaMessage     *msg,
+                      LibBalsaMessageBody *part,
+                      gboolean             need_children,
+                      GMimeObject         *parent_part,
+                      GError             **err)
 {
     g_return_val_if_fail(part, FALSE);
 
@@ -2576,215 +2878,241 @@ lbm_imap_get_msg_part(LibBalsaMessage * msg, LibBalsaMessageBody * part,
         GMimeContentType *type =
             g_mime_content_type_new_from_string(part->content_type);
         if (g_mime_content_type_is_type(type, "multipart", "*")) {
-            if (g_mime_content_type_is_type(type, "multipart", "signed"))
+            if (g_mime_content_type_is_type(type, "multipart", "signed")) {
                 part->mime_part =
                     GMIME_OBJECT(g_mime_multipart_signed_new());
-            else if (g_mime_content_type_is_type(type, "multipart",
-                                                 "encrypted"))
+            } else if (g_mime_content_type_is_type(type, "multipart",
+                                                   "encrypted")) {
                 part->mime_part =
                     GMIME_OBJECT(g_mime_multipart_encrypted_new());
-            else
+            } else {
                 part->mime_part = GMIME_OBJECT(g_mime_multipart_new());
+            }
             g_mime_object_set_content_type(part->mime_part, type);
         } else {
             g_object_unref(type);
-            if (!lbm_imap_get_msg_part_from_cache(msg, part, err))
+            if (!lbm_imap_get_msg_part_from_cache(msg, part, err)) {
                 return FALSE;
+            }
         }
     }
 
     if (parent_part) {
         /* GMime will unref and so will we. */
         g_object_ref(part->mime_part);
-       g_mime_multipart_add(GMIME_MULTIPART(parent_part),
-                            part->mime_part);
+        g_mime_multipart_add(GMIME_MULTIPART(parent_part),
+                             part->mime_part);
     }
 
     if (GMIME_IS_MULTIPART_SIGNED(part->mime_part)
-        || GMIME_IS_MULTIPART_ENCRYPTED(part->mime_part))
+        || GMIME_IS_MULTIPART_ENCRYPTED(part->mime_part)) {
         need_children = TRUE;
+    }
 
     if (need_children) {
-       /* Get the children, if any,... */
+        /* Get the children, if any,... */
         if (GMIME_IS_MULTIPART(part->mime_part)) {
-            if(!lbm_imap_get_msg_part(msg, part->parts, TRUE,
-                                      part->mime_part, err))
+            if (!lbm_imap_get_msg_part(msg, part->parts, TRUE,
+                                       part->mime_part, err)) {
                 return FALSE;
+            }
         }
-       /* ...and siblings. */
-        if(part->next &&
-           !lbm_imap_get_msg_part(msg, part->next, TRUE, parent_part, err))
+        /* ...and siblings. */
+        if (part->next &&
+            !lbm_imap_get_msg_part(msg, part->next, TRUE, parent_part, err)) {
             return FALSE;
-       /* FIXME if GMIME_IS_MESSAGE_PART? */
+        }
+        /* FIXME if GMIME_IS_MESSAGE_PART? */
     }
     return GMIME_IS_PART(part->mime_part)
-        || GMIME_IS_MULTIPART(part->mime_part)
-       || GMIME_IS_MESSAGE_PART(part->mime_part);
+           || GMIME_IS_MULTIPART(part->mime_part)
+           || GMIME_IS_MESSAGE_PART(part->mime_part);
 }
 
+
 static gboolean
-libbalsa_mailbox_imap_get_msg_part(LibBalsaMessage *msg,
+libbalsa_mailbox_imap_get_msg_part(LibBalsaMessage     *msg,
                                    LibBalsaMessageBody *part,
-                                   GError **err)
+                                   GError             **err)
 {
-    if (part->mime_part)
+    if (part->mime_part) {
         return GMIME_IS_PART(part->mime_part)
-            || GMIME_IS_MULTIPART(part->mime_part)
-            || GMIME_IS_MESSAGE_PART(part->mime_part);
+               || GMIME_IS_MULTIPART(part->mime_part)
+               || GMIME_IS_MESSAGE_PART(part->mime_part);
+    }
 
     return lbm_imap_get_msg_part(msg, part, FALSE, NULL, err);
 }
 
+
 /* libbalsa_mailbox_imap_duplicate_msgnos: identify messages with same
    non-empty message-ids. An efficient implementation requires that a
    list of msgids is maintained client side. The algorithm consists of
    four phases:
    a). identify x=largest UID in the message-id hash.
    b). complete the message-id hash from (possibly new) envelopes.
-   c). check for any missing message-ids by fetching the header for 
+   c). check for any missing message-ids by fetching the header for
    UID>x.
-   d). identify duplicates in the message hash. When a duplicate 
+   d). identify duplicates in the message hash. When a duplicate
    is encountered, keep the one with lower MSGNO/UID.
-*/
-static GArray*
+ */
+static GArray *
 libbalsa_mailbox_imap_duplicate_msgnos(LibBalsaMailbox *mailbox)
 {
     LibBalsaMailboxImap *mimap = LIBBALSA_MAILBOX_IMAP(mailbox);
-    unsigned first_to_fetch = 1;
+    unsigned first_to_fetch    = 1;
     GHashTable *dupes;
-    GArray     *res;
+    GArray *res;
     unsigned i;
     /* a+b. */
-    for(i=mimap->msgids->len; i>=1; i--) {
-       ImapMessage *imsg;
-       gchar *msg_id = g_ptr_array_index(mimap->msgids, i-1);
-       if(msg_id) {
-            first_to_fetch = i+1;
+    for (i = mimap->msgids->len; i >= 1; i--) {
+        ImapMessage *imsg;
+        gchar *msg_id = g_ptr_array_index(mimap->msgids, i - 1);
+        if (msg_id) {
+            first_to_fetch = i + 1;
             break;
-       } else {
-           imsg = imap_mbox_handle_get_msg(mimap->handle, i);
-           if(imsg && imsg->envelope)
-               g_ptr_array_index(mimap->msgids, i-1) =
-                   g_strdup(imsg->envelope->message_id);
-       }
+        } else {
+            imsg = imap_mbox_handle_get_msg(mimap->handle, i);
+            if (imsg && imsg->envelope) {
+                g_ptr_array_index(mimap->msgids, i - 1) =
+                    g_strdup(imsg->envelope->message_id);
+            }
+        }
     }
     /* c. */
-    if(imap_mbox_complete_msgids(mimap->handle, mimap->msgids,
-                                first_to_fetch) != IMR_OK)
-       return NULL;
+    if (imap_mbox_complete_msgids(mimap->handle, mimap->msgids,
+                                  first_to_fetch) != IMR_OK) {
+        return NULL;
+    }
     /* d. */
     dupes = g_hash_table_new(g_str_hash, g_str_equal);
     res   = g_array_new(FALSE, FALSE, sizeof(unsigned));
-    for(i=1; i<=mimap->msgids->len; i++) {
-       gchar *msg_id = g_ptr_array_index(mimap->msgids, i-1);
-       if(!msg_id) { /* g_warning("msgid not completed %u", i); */continue; }
-       if(!*msg_id || *msg_id == '\r' || *msg_id == '\n') continue;
-       if(!g_hash_table_lookup(dupes, msg_id))
-           g_hash_table_insert(dupes, msg_id, GINT_TO_POINTER(1));
-       else {
-           g_array_append_val(res, i);
-       }
+    for (i = 1; i <= mimap->msgids->len; i++) {
+        gchar *msg_id = g_ptr_array_index(mimap->msgids, i - 1);
+        if (!msg_id) { /* g_warning("msgid not completed %u", i); */
+            continue;
+        }
+        if (!*msg_id || (*msg_id == '\r') || (*msg_id == '\n')) {
+            continue;
+        }
+        if (!g_hash_table_lookup(dupes, msg_id)) {
+            g_hash_table_insert(dupes, msg_id, GINT_TO_POINTER(1));
+        } else {
+            g_array_append_val(res, i);
+        }
     }
     g_hash_table_destroy(dupes);
     printf("total elements: %d\n", res->len);
-    for(i=0; i<res->len; i++)
-       printf("%u ", GPOINTER_TO_UINT(g_array_index(res, unsigned, i)));
+    for (i = 0; i < res->len; i++) {
+        printf("%u ", GPOINTER_TO_UINT(g_array_index(res, unsigned, i)));
+    }
     puts("");
     return res;
 }
 
-/** Adds given set of messages to given imap mailbox. 
+
+/** Adds given set of messages to given imap mailbox.
     Method can be called on a closed mailbox.
     Called with mailbox locked.
-*/
+ */
 #if 0
 static guint
-libbalsa_mailbox_imap_add_messages(LibBalsaMailbox * mailbox,
-                                  LibBalsaAddMessageIterator msg_iterator,
-                                  void *arg, GError ** err)
+libbalsa_mailbox_imap_add_messages(LibBalsaMailbox           *mailbox,
+                                   LibBalsaAddMessageIterator msg_iterator,
+                                   void                      *arg,
+                                   GError                   **err)
 {
     LibBalsaMailboxImap *mimap = LIBBALSA_MAILBOX_IMAP(mailbox);
     LibBalsaMessageFlag flags;
     GMimeStream *stream;
     unsigned successfully_copied = 0;
 
-    while( msg_iterator(&flags, &stream, arg) ) {
-       ImapMsgFlags imap_flags = IMAP_FLAGS_EMPTY;
-       ImapResponse rc;
-       GMimeStream *tmpstream;
-       GMimeFilter *crlffilter;
-       ImapMboxHandle *handle;
-       gint outfd;
-       gchar *outfile;
-       GMimeStream *outstream;
-       gssize len;
-
-       if (!(flags & LIBBALSA_MESSAGE_FLAG_NEW))
-           IMSG_FLAG_SET(imap_flags, IMSGF_SEEN);
-       if (flags & LIBBALSA_MESSAGE_FLAG_DELETED)
-           IMSG_FLAG_SET(imap_flags, IMSGF_DELETED);
-       if (flags & LIBBALSA_MESSAGE_FLAG_FLAGGED)
-           IMSG_FLAG_SET(imap_flags, IMSGF_FLAGGED);
-       if (flags & LIBBALSA_MESSAGE_FLAG_REPLIED)
-           IMSG_FLAG_SET(imap_flags, IMSGF_ANSWERED);
-
-       tmpstream = g_mime_stream_filter_new(stream);
-
-       crlffilter =
-           g_mime_filter_crlf_new(TRUE,
-                                  FALSE);
-       g_mime_stream_filter_add(GMIME_STREAM_FILTER(tmpstream), crlffilter);
-       g_object_unref(crlffilter);
-
-       outfd = g_file_open_tmp("balsa-tmp-file-XXXXXX", &outfile, err);
-       if (outfd < 0) {
-           g_warning("Could not create temporary file: %s", (*err)->message);
-           g_object_unref(tmpstream);
-           g_object_unref(stream);
-           return successfully_copied;
-       }
-
-       handle = libbalsa_mailbox_imap_get_handle(mimap, err);
-       if (!handle)
-           /* Perhaps the mailbox was closed and the authentication
-              failed or was cancelled? err is set already, we just
-              return. */
-           return successfully_copied;
-
-       outstream = g_mime_stream_fs_new(outfd);
-       libbalsa_mime_stream_shared_lock(stream);
-       g_mime_stream_write_to_stream(tmpstream, outstream);
-       libbalsa_mime_stream_shared_unlock(stream);
-       g_object_unref(tmpstream);
-       g_object_unref(stream);
-
-       len = g_mime_stream_tell(outstream);
-       g_mime_stream_reset(outstream);
-
-       if (len > (signed) SizeMsgThreshold)
-           libbalsa_information(LIBBALSA_INFORMATION_MESSAGE,
-                                _("Uploading %ld kB"), (long) len / 1024);
-       rc = imap_mbox_append_stream(handle, mimap->path,
-                                    imap_flags, outstream, len);
-       if (rc != IMR_OK) {
-           gchar *msg = imap_mbox_handle_get_last_msg(handle);
-           g_set_error(err, LIBBALSA_MAILBOX_ERROR,
-                       LIBBALSA_MAILBOX_APPEND_ERROR, "%s", msg);
-           g_free(msg);
-       }
-       libbalsa_mailbox_imap_release_handle(mimap);
-
-       g_object_unref(outstream);
-       unlink(outfile);
-       g_free(outfile);
-
-       if(rc != IMR_OK)
-           return successfully_copied;
-
-       successfully_copied++;
+    while ( msg_iterator(&flags, &stream, arg)) {
+        ImapMsgFlags imap_flags = IMAP_FLAGS_EMPTY;
+        ImapResponse rc;
+        GMimeStream *tmpstream;
+        GMimeFilter *crlffilter;
+        ImapMboxHandle *handle;
+        gint outfd;
+        gchar *outfile;
+        GMimeStream *outstream;
+        gssize len;
+
+        if (!(flags & LIBBALSA_MESSAGE_FLAG_NEW)) {
+            IMSG_FLAG_SET(imap_flags, IMSGF_SEEN);
+        }
+        if (flags & LIBBALSA_MESSAGE_FLAG_DELETED) {
+            IMSG_FLAG_SET(imap_flags, IMSGF_DELETED);
+        }
+        if (flags & LIBBALSA_MESSAGE_FLAG_FLAGGED) {
+            IMSG_FLAG_SET(imap_flags, IMSGF_FLAGGED);
+        }
+        if (flags & LIBBALSA_MESSAGE_FLAG_REPLIED) {
+            IMSG_FLAG_SET(imap_flags, IMSGF_ANSWERED);
+        }
+
+        tmpstream = g_mime_stream_filter_new(stream);
+
+        crlffilter =
+            g_mime_filter_crlf_new(TRUE,
+                                   FALSE);
+        g_mime_stream_filter_add(GMIME_STREAM_FILTER(tmpstream), crlffilter);
+        g_object_unref(crlffilter);
+
+        outfd = g_file_open_tmp("balsa-tmp-file-XXXXXX", &outfile, err);
+        if (outfd < 0) {
+            g_warning("Could not create temporary file: %s", (*err)->message);
+            g_object_unref(tmpstream);
+            g_object_unref(stream);
+            return successfully_copied;
+        }
+
+        handle = libbalsa_mailbox_imap_get_handle(mimap, err);
+        if (!handle) {
+            /* Perhaps the mailbox was closed and the authentication
+               failed or was cancelled? err is set already, we just
+               return. */
+            return successfully_copied;
+        }
+
+        outstream = g_mime_stream_fs_new(outfd);
+        libbalsa_mime_stream_shared_lock(stream);
+        g_mime_stream_write_to_stream(tmpstream, outstream);
+        libbalsa_mime_stream_shared_unlock(stream);
+        g_object_unref(tmpstream);
+        g_object_unref(stream);
+
+        len = g_mime_stream_tell(outstream);
+        g_mime_stream_reset(outstream);
+
+        if (len > (signed) SizeMsgThreshold) {
+            libbalsa_information(LIBBALSA_INFORMATION_MESSAGE,
+                                 _("Uploading %ld kB"), (long) len / 1024);
+        }
+        rc = imap_mbox_append_stream(handle, mimap->path,
+                                     imap_flags, outstream, len);
+        if (rc != IMR_OK) {
+            gchar *msg = imap_mbox_handle_get_last_msg(handle);
+            g_set_error(err, LIBBALSA_MAILBOX_ERROR,
+                        LIBBALSA_MAILBOX_APPEND_ERROR, "%s", msg);
+            g_free(msg);
+        }
+        libbalsa_mailbox_imap_release_handle(mimap);
+
+        g_object_unref(outstream);
+        unlink(outfile);
+        g_free(outfile);
+
+        if (rc != IMR_OK) {
+            return successfully_copied;
+        }
+
+        successfully_copied++;
     }
     return successfully_copied;
 }
+
+
 #else
 
 struct MultiAppendCbData {
@@ -2799,104 +3127,116 @@ struct MultiAppendCbData {
 static void
 macd_clear(struct MultiAppendCbData *macd)
 {
-    if(macd->outstream) {
-       g_object_unref(macd->outstream);
-       macd->outstream = NULL;
+    if (macd->outstream) {
+        g_object_unref(macd->outstream);
+        macd->outstream = NULL;
     }
 }
 
+
 static void
 macd_destroy(struct MultiAppendCbData *macd)
 {
     GList *outmsgs;
-    for(outmsgs = macd->outfiles; outmsgs; outmsgs = outmsgs->next) {
-       unlink(outmsgs->data);
-       g_free(outmsgs->data);
+    for (outmsgs = macd->outfiles; outmsgs; outmsgs = outmsgs->next) {
+        unlink(outmsgs->data);
+        g_free(outmsgs->data);
     }
     g_list_free(macd->outfiles);
 }
 
+
 static size_t
-multi_append_cb(char * buf, size_t buflen,
-               ImapAppendMultiStage stage,
-               ImapMsgFlags *return_flags, void *arg)
+multi_append_cb(char                *buf,
+                size_t               buflen,
+                ImapAppendMultiStage stage,
+                ImapMsgFlags        *return_flags,
+                void                *arg)
 {
-    struct MultiAppendCbData *macd = (struct MultiAppendCbData*)arg;
+    struct MultiAppendCbData *macd = (struct MultiAppendCbData *)arg;
 
-    switch(stage) {
+    switch (stage) {
     case IMA_STAGE_NEW_MSG: {
-       ImapMsgFlags imap_flags = IMAP_FLAGS_EMPTY;
-       GMimeStream *tmpstream;
-       GMimeFilter *crlffilter;
-       gint outfd;
-       GMimeStream *stream = NULL;
-       gint64 len;
-       LibBalsaMessageFlag flags;
-       GError**err = macd->err;
-       gchar *outf = NULL;
-
-       macd_clear(macd);
-
-       while( macd->msg_iterator(&flags, &stream, macd->iterator_data) &&
-              !stream)
-           ;
-
-       if(!stream) /* No more messages to append! */
-           return 0;
-
-       if (!(flags & LIBBALSA_MESSAGE_FLAG_NEW))
-           IMSG_FLAG_SET(imap_flags, IMSGF_SEEN);
-       if (flags & LIBBALSA_MESSAGE_FLAG_DELETED)
-           IMSG_FLAG_SET(imap_flags, IMSGF_DELETED);
-       if (flags & LIBBALSA_MESSAGE_FLAG_FLAGGED)
-           IMSG_FLAG_SET(imap_flags, IMSGF_FLAGGED);
-       if (flags & LIBBALSA_MESSAGE_FLAG_REPLIED)
-           IMSG_FLAG_SET(imap_flags, IMSGF_ANSWERED);
-
-       tmpstream = g_mime_stream_filter_new(stream);
-
-       crlffilter =
-           g_mime_filter_crlf_new(TRUE,
-                                  FALSE);
-       g_mime_stream_filter_add(GMIME_STREAM_FILTER(tmpstream), crlffilter);
-       g_object_unref(crlffilter);
-
-       outfd = g_file_open_tmp("balsa-tmp-file-XXXXXX", &outf, err);
-       if (outfd < 0) {
-           g_warning("Could not create temporary file: %s", (*err)->message);
-           g_object_unref(tmpstream);
-           g_object_unref(stream);
-           return 0;
-       }
-
-       macd->outstream = g_mime_stream_fs_new(outfd);
-       macd->outfiles = g_list_append(macd->outfiles, outf);
-       libbalsa_mime_stream_shared_lock(stream);
-       g_mime_stream_write_to_stream(tmpstream, macd->outstream);
-       libbalsa_mime_stream_shared_unlock(stream);
-       g_object_unref(tmpstream);
-       g_object_unref(stream);
-
-       len = g_mime_stream_tell(macd->outstream);
-       g_mime_stream_reset(macd->outstream);
-
-       if (len > (signed) SizeMsgThreshold)
-           libbalsa_information(LIBBALSA_INFORMATION_MESSAGE,
+        ImapMsgFlags imap_flags = IMAP_FLAGS_EMPTY;
+        GMimeStream *tmpstream;
+        GMimeFilter *crlffilter;
+        gint outfd;
+        GMimeStream *stream = NULL;
+        gint64 len;
+        LibBalsaMessageFlag flags;
+        GError **err = macd->err;
+        gchar *outf  = NULL;
+
+        macd_clear(macd);
+
+        while ( macd->msg_iterator(&flags, &stream, macd->iterator_data) &&
+                !stream) {
+        }
+
+        if (!stream) { /* No more messages to append! */
+            return 0;
+        }
+
+        if (!(flags & LIBBALSA_MESSAGE_FLAG_NEW)) {
+            IMSG_FLAG_SET(imap_flags, IMSGF_SEEN);
+        }
+        if (flags & LIBBALSA_MESSAGE_FLAG_DELETED) {
+            IMSG_FLAG_SET(imap_flags, IMSGF_DELETED);
+        }
+        if (flags & LIBBALSA_MESSAGE_FLAG_FLAGGED) {
+            IMSG_FLAG_SET(imap_flags, IMSGF_FLAGGED);
+        }
+        if (flags & LIBBALSA_MESSAGE_FLAG_REPLIED) {
+            IMSG_FLAG_SET(imap_flags, IMSGF_ANSWERED);
+        }
+
+        tmpstream = g_mime_stream_filter_new(stream);
+
+        crlffilter =
+            g_mime_filter_crlf_new(TRUE,
+                                   FALSE);
+        g_mime_stream_filter_add(GMIME_STREAM_FILTER(tmpstream), crlffilter);
+        g_object_unref(crlffilter);
+
+        outfd = g_file_open_tmp("balsa-tmp-file-XXXXXX", &outf, err);
+        if (outfd < 0) {
+            g_warning("Could not create temporary file: %s", (*err)->message);
+            g_object_unref(tmpstream);
+            g_object_unref(stream);
+            return 0;
+        }
+
+        macd->outstream = g_mime_stream_fs_new(outfd);
+        macd->outfiles  = g_list_append(macd->outfiles, outf);
+        libbalsa_mime_stream_shared_lock(stream);
+        g_mime_stream_write_to_stream(tmpstream, macd->outstream);
+        libbalsa_mime_stream_shared_unlock(stream);
+        g_object_unref(tmpstream);
+        g_object_unref(stream);
+
+        len = g_mime_stream_tell(macd->outstream);
+        g_mime_stream_reset(macd->outstream);
+
+        if (len > (signed) SizeMsgThreshold) {
+            libbalsa_information(LIBBALSA_INFORMATION_MESSAGE,
                                  _("Uploading %ld kB"),
                                  (long int) ((len + 512) / 1024));
+        }
 
-       *return_flags = imap_flags;
-       macd->copied++;
-       return g_mime_stream_length(macd->outstream);
+        *return_flags = imap_flags;
+        macd->copied++;
+        return g_mime_stream_length(macd->outstream);
     }
-       break;
+    break;
+
     case IMA_STAGE_PASS_DATA:
-       return g_mime_stream_read(macd->outstream, buf, buflen);
+        return g_mime_stream_read(macd->outstream, buf, buflen);
     }
     g_assert_not_reached();
     return 0;
 }
 
+
 struct append_to_cache_data {
     const gchar *user, *host, *path, *cache_dir;
     GList *curr_name;
@@ -2904,44 +3244,51 @@ struct append_to_cache_data {
 };
 
 static void
-create_cache_copy(const gchar *src, const gchar *cache_dir, const gchar *name)
+create_cache_copy(const gchar *src,
+                  const gchar *cache_dir,
+                  const gchar *name)
 {
     gchar *fname = libbalsa_urlencode(name);
-    gchar *dst = g_build_filename(cache_dir, fname, NULL);
-    if(link(src, dst) != 0) {
-       /* Link failed possibly because the two caches reside on
-          different file systems. We attempt to copy the cache instead. */
-       FILE *in  = fopen(src, "r");
-
-       if(in) {
-           FILE *out = fopen(dst, "w");
-           if(out) {
-               size_t sz;
-               char buf[65536];
-               gboolean err;
-               while( (sz=fread(buf, 1, sizeof(buf), in)) > 0)
-                   if(fwrite(buf, 1, sz, out) != sz)
-                       break;
-               err = ferror(in) || ferror(out);
-               fclose(out);
-               if(err)
-                   unlink(dst);
-           }
-           fclose(in);
-       }
+    gchar *dst   = g_build_filename(cache_dir, fname, NULL);
+    if (link(src, dst) != 0) {
+        /* Link failed possibly because the two caches reside on
+           different file systems. We attempt to copy the cache instead. */
+        FILE *in = fopen(src, "r");
+
+        if (in) {
+            FILE *out = fopen(dst, "w");
+            if (out) {
+                size_t sz;
+                char buf[65536];
+                gboolean err;
+                while ((sz = fread(buf, 1, sizeof(buf), in)) > 0) {
+                    if (fwrite(buf, 1, sz, out) != sz) {
+                        break;
+                    }
+                }
+                err = ferror(in) || ferror(out);
+                fclose(out);
+                if (err) {
+                    unlink(dst);
+                }
+            }
+            fclose(in);
+        }
     }
     g_free(fname);
     g_free(dst);
 }
 
+
 static void
-append_to_cache(unsigned uid, void *arg)
+append_to_cache(unsigned uid,
+                void    *arg)
 {
-    struct append_to_cache_data *atcd = (struct append_to_cache_data*)arg;
-    gchar *name = g_strdup_printf("%s@%s-%s-%u-%u-%s",
-                                 atcd->user, atcd->host, atcd->path,
-                                 atcd->uid_validity,
-                                 uid, "body");
+    struct append_to_cache_data *atcd = (struct append_to_cache_data *)arg;
+    gchar *name                       = g_strdup_printf("%s@%s-%s-%u-%u-%s",
+                                                        atcd->user, atcd->host, atcd->path,
+                                                        atcd->uid_validity,
+                                                        uid, "body");
     gchar *msg = atcd->curr_name->data;
 
     atcd->curr_name = atcd->curr_name->next;
@@ -2952,103 +3299,120 @@ append_to_cache(unsigned uid, void *arg)
     g_free(name);
 }
 
+
 static guint
-libbalsa_mailbox_imap_add_messages(LibBalsaMailbox * mailbox,
-                                  LibBalsaAddMessageIterator msg_iterator,
-                                  void *arg, GError ** err)
+libbalsa_mailbox_imap_add_messages(LibBalsaMailbox           *mailbox,
+                                   LibBalsaAddMessageIterator msg_iterator,
+                                   void                      *arg,
+                                   GError                   **err)
 {
     LibBalsaMailboxImap *mimap = LIBBALSA_MAILBOX_IMAP(mailbox);
-    ImapMboxHandle *handle = libbalsa_mailbox_imap_get_handle(mimap, err);
+    ImapMboxHandle *handle     = libbalsa_mailbox_imap_get_handle(mimap, err);
     struct MultiAppendCbData macd;
     ImapResponse rc;
     ImapSequence uid_sequence;
 
     if (!handle) {
-       /* Perhaps the mailbox was closed and the authentication
-          failed or was cancelled? err is set already, we just
-          return. */
-       return 0;
+        /* Perhaps the mailbox was closed and the authentication
+           failed or was cancelled? err is set already, we just
+           return. */
+        return 0;
     }
 
-    macd.msg_iterator = msg_iterator;
+    macd.msg_iterator  = msg_iterator;
     macd.iterator_data = arg;
-    macd.outstream = NULL;
-    macd.outfiles = NULL;
-    macd.err = err;
-    macd.copied = 0;
+    macd.outstream     = NULL;
+    macd.outfiles      = NULL;
+    macd.err           = err;
+    macd.copied        = 0;
     imap_sequence_init(&uid_sequence);
-    rc = imap_mbox_append_multi(handle,        mimap->path,
-                               multi_append_cb, &macd, &uid_sequence);
+    rc = imap_mbox_append_multi(handle, mimap->path,
+                                multi_append_cb, &macd, &uid_sequence);
     libbalsa_mailbox_imap_release_handle(mimap);
     macd_clear(&macd);
 
-    if(!imap_sequence_empty(&uid_sequence) &&
-       g_list_length(macd.outfiles) == imap_sequence_length(&uid_sequence)) {
-       /* Hurray, server returned UID data on appended messages! */
-       LibBalsaServer *s      = LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mailbox);
-       LibBalsaImapServer *is = LIBBALSA_IMAP_SERVER(s);
-       gboolean is_persistent = libbalsa_imap_server_has_persistent_cache(is);
-       struct append_to_cache_data atcd;
-       gchar *cache_dir;
-
-       atcd.user = libbalsa_server_get_username(s);
-       atcd.host = libbalsa_server_get_host(s);
-       atcd.path = mimap->path ? mimap->path : "INBOX";
-       atcd.cache_dir = cache_dir = get_cache_dir(is_persistent);
-       atcd.curr_name = macd.outfiles;
-       atcd.uid_validity = uid_sequence.uid_validity;
-
-       imap_sequence_foreach(&uid_sequence, append_to_cache, &atcd);
-       imap_sequence_release(&uid_sequence);
-       g_free(cache_dir);
+    if (!imap_sequence_empty(&uid_sequence) &&
+        (g_list_length(macd.outfiles) == imap_sequence_length(&uid_sequence))) {
+        /* Hurray, server returned UID data on appended messages! */
+        LibBalsaServer *s      = LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mailbox);
+        LibBalsaImapServer *is = LIBBALSA_IMAP_SERVER(s);
+        gboolean is_persistent = libbalsa_imap_server_has_persistent_cache(is);
+        struct append_to_cache_data atcd;
+        gchar *cache_dir;
+
+        atcd.user         = libbalsa_server_get_username(s);
+        atcd.host         = libbalsa_server_get_host(s);
+        atcd.path         = mimap->path ? mimap->path : "INBOX";
+        atcd.cache_dir    = cache_dir = get_cache_dir(is_persistent);
+        atcd.curr_name    = macd.outfiles;
+        atcd.uid_validity = uid_sequence.uid_validity;
+
+        imap_sequence_foreach(&uid_sequence, append_to_cache, &atcd);
+        imap_sequence_release(&uid_sequence);
+        g_free(cache_dir);
     }
 
     macd_destroy(&macd);
     return rc == IMR_OK ? macd.copied : 0;
 }
+
+
 #endif
 
 static void
-transform_flags(LibBalsaMessageFlag set, LibBalsaMessageFlag clr,
-                ImapMsgFlag *flg_set, ImapMsgFlag *flg_clr)
+transform_flags(LibBalsaMessageFlag set,
+                LibBalsaMessageFlag clr,
+                ImapMsgFlag        *flg_set,
+                ImapMsgFlag        *flg_clr)
 {
     *flg_set = 0;
     *flg_clr = 0;
 
-    if (set & LIBBALSA_MESSAGE_FLAG_REPLIED)
+    if (set & LIBBALSA_MESSAGE_FLAG_REPLIED) {
         *flg_set |= IMSGF_ANSWERED;
-    if (clr & LIBBALSA_MESSAGE_FLAG_REPLIED)
-       *flg_clr |= IMSGF_ANSWERED;
-    if (set & LIBBALSA_MESSAGE_FLAG_NEW)
-       *flg_clr |= IMSGF_SEEN;
-    if (clr & LIBBALSA_MESSAGE_FLAG_NEW)
-       *flg_set |= IMSGF_SEEN;
-    if (set & LIBBALSA_MESSAGE_FLAG_FLAGGED)
-       *flg_set |= IMSGF_FLAGGED;
-    if (clr & LIBBALSA_MESSAGE_FLAG_FLAGGED)
-       *flg_clr |= IMSGF_FLAGGED;
-    if (set & LIBBALSA_MESSAGE_FLAG_DELETED)
-       *flg_set |= IMSGF_DELETED;
-    if (clr & LIBBALSA_MESSAGE_FLAG_DELETED)
-       *flg_clr |= IMSGF_DELETED;
+    }
+    if (clr & LIBBALSA_MESSAGE_FLAG_REPLIED) {
+        *flg_clr |= IMSGF_ANSWERED;
+    }
+    if (set & LIBBALSA_MESSAGE_FLAG_NEW) {
+        *flg_clr |= IMSGF_SEEN;
+    }
+    if (clr & LIBBALSA_MESSAGE_FLAG_NEW) {
+        *flg_set |= IMSGF_SEEN;
+    }
+    if (set & LIBBALSA_MESSAGE_FLAG_FLAGGED) {
+        *flg_set |= IMSGF_FLAGGED;
+    }
+    if (clr & LIBBALSA_MESSAGE_FLAG_FLAGGED) {
+        *flg_clr |= IMSGF_FLAGGED;
+    }
+    if (set & LIBBALSA_MESSAGE_FLAG_DELETED) {
+        *flg_set |= IMSGF_DELETED;
+    }
+    if (clr & LIBBALSA_MESSAGE_FLAG_DELETED) {
+        *flg_clr |= IMSGF_DELETED;
+    }
 }
 
+
 static void
-lbm_imap_change_user_flags(LibBalsaMailbox * mailbox, GArray * seqno,
+lbm_imap_change_user_flags(LibBalsaMailbox    *mailbox,
+                           GArray             *seqno,
                            LibBalsaMessageFlag set,
-                          LibBalsaMessageFlag clear)
+                           LibBalsaMessageFlag clear)
 {
     gint i;
     LibBalsaMailboxImap *mimap = LIBBALSA_MAILBOX_IMAP(mailbox);
 
     set   &= ~LIBBALSA_MESSAGE_FLAGS_REAL;
     clear &= ~LIBBALSA_MESSAGE_FLAGS_REAL;
-    if (!set && !clear)
-       return;
+    if (!set && !clear) {
+        return;
+    }
 
     for (i = seqno->len; --i >= 0;) {
-       guint msgno = g_array_index(seqno, guint, i);
-        struct message_info *msg_info = 
+        guint msgno                   = g_array_index(seqno, guint, i);
+        struct message_info *msg_info =
             message_info_from_msgno(mimap, msgno);
         if (msg_info) {
             msg_info->user_flags |= set;
@@ -3057,21 +3421,26 @@ lbm_imap_change_user_flags(LibBalsaMailbox * mailbox, GArray * seqno,
     }
 }
 
+
 static gboolean
-lbm_imap_messages_change_flags(LibBalsaMailbox * mailbox, GArray * seqno,
-                              LibBalsaMessageFlag set,
-                              LibBalsaMessageFlag clear)
+lbm_imap_messages_change_flags(LibBalsaMailbox    *mailbox,
+                               GArray             *seqno,
+                               LibBalsaMessageFlag set,
+                               LibBalsaMessageFlag clear)
 {
     ImapMsgFlag flag_set, flag_clr;
-    ImapResponse rc = IMR_OK;
+    ImapResponse rc        = IMR_OK;
     ImapMboxHandle *handle = LIBBALSA_MAILBOX_IMAP(mailbox)->handle;
 
-    if(seqno->len == 0) return TRUE;
+    if (seqno->len == 0) {
+        return TRUE;
+    }
     lbm_imap_change_user_flags(mailbox, seqno, set, clear);
 
-    if (!((set | clear) & LIBBALSA_MESSAGE_FLAGS_REAL))
-       /* No real flags. */
-       return TRUE;
+    if (!((set | clear) & LIBBALSA_MESSAGE_FLAGS_REAL)) {
+        /* No real flags. */
+        return TRUE;
+    }
 
     g_array_sort(seqno, cmp_msgno);
     transform_flags(set, clear, &flag_set, &flag_clr);
@@ -3079,21 +3448,25 @@ lbm_imap_messages_change_flags(LibBalsaMailbox * mailbox, GArray * seqno,
        to unsolicited EXPUNGE responses are resolved. The issues are
        pretty much of a theoretical character but we do not want to
        risk the mail store integrity, do we? */
-    if (flag_set)
+    if (flag_set) {
         II(rc, handle,
            imap_mbox_store_flag(handle,
                                 seqno->len, (guint *) seqno->data,
                                 flag_set, TRUE));
-    if (rc && flag_clr)
+    }
+    if (rc && flag_clr) {
         II(rc, handle,
            imap_mbox_store_flag(handle,
                                 seqno->len, (guint *) seqno->data,
                                 flag_clr, FALSE));
+    }
     return rc == IMR_OK;
 }
 
+
 static gboolean
-libbalsa_mailbox_imap_msgno_has_flags(LibBalsaMailbox * m, unsigned msgno,
+libbalsa_mailbox_imap_msgno_has_flags(LibBalsaMailbox    *m,
+                                      unsigned            msgno,
                                       LibBalsaMessageFlag set,
                                       LibBalsaMessageFlag unset)
 {
@@ -3102,20 +3475,22 @@ libbalsa_mailbox_imap_msgno_has_flags(LibBalsaMailbox * m, unsigned msgno,
     LibBalsaMailboxImap *mimap = LIBBALSA_MAILBOX_IMAP(m);
     ImapMboxHandle *handle;
 
-    user_set   = set   & ~LIBBALSA_MESSAGE_FLAGS_REAL;
+    user_set   = set & ~LIBBALSA_MESSAGE_FLAGS_REAL;
     user_unset = unset & ~LIBBALSA_MESSAGE_FLAGS_REAL;
     if (user_set || user_unset) {
         struct message_info *msg_info =
             message_info_from_msgno(mimap, msgno);
         if (!msg_info ||
-            (msg_info->user_flags & user_set) != user_set ||
-            (msg_info->user_flags & user_unset) != 0)
+            ((msg_info->user_flags & user_set) != user_set) ||
+            ((msg_info->user_flags & user_unset) != 0)) {
             return FALSE;
+        }
     }
 
     transform_flags(set, unset, &flag_set, &flag_unset);
-    if (!flag_set && !flag_unset)
+    if (!flag_set && !flag_unset) {
         return TRUE;
+    }
 
     handle = mimap->handle;
     g_return_val_if_fail(handle, FALSE);
@@ -3123,26 +3498,31 @@ libbalsa_mailbox_imap_msgno_has_flags(LibBalsaMailbox * m, unsigned msgno,
                                             flag_unset);
 }
 
+
 static gboolean
-libbalsa_mailbox_imap_can_do(LibBalsaMailbox* mbox,
+libbalsa_mailbox_imap_can_do(LibBalsaMailbox               *mbox,
                              enum LibBalsaMailboxCapability c)
 {
     LibBalsaMailboxImap *mimap;
-    if(!mbox)
+    if (!mbox) {
         return TRUE;
+    }
     mimap = LIBBALSA_MAILBOX_IMAP(mbox);
-    switch(c) {
+    switch (c) {
 #if !ENABLE_CLIENT_SIDE_SORT
     case LIBBALSA_MAILBOX_CAN_SORT:
         return imap_mbox_handle_can_do(mimap->handle, IMCAP_SORT);
+
 #endif
     case LIBBALSA_MAILBOX_CAN_THREAD:
         return imap_mbox_handle_can_do(mimap->handle, IMCAP_THREAD_REFERENCES);
+
     default:
         return TRUE;
     }
 }
 
+
 static ImapSortKey
 lbmi_get_imap_sort_key(LibBalsaMailbox *mbox)
 {
@@ -3150,77 +3530,94 @@ lbmi_get_imap_sort_key(LibBalsaMailbox *mbox)
 
     switch (libbalsa_mailbox_get_view(mbox)->sort_field) {
     default:
-    case LB_MAILBOX_SORT_NO:     key = IMSO_MSGNO;   break;
-    case LB_MAILBOX_SORT_SENDER:    
+    case LB_MAILBOX_SORT_NO:      key = IMSO_MSGNO;
+        break;
+
+    case LB_MAILBOX_SORT_SENDER:
         key = libbalsa_mailbox_get_view(mbox)->show == LB_MAILBOX_SHOW_TO
-            ? IMSO_TO : IMSO_FROM;                   break;
-    case LB_MAILBOX_SORT_SUBJECT: key = IMSO_SUBJECT; break;
-    case LB_MAILBOX_SORT_DATE:    key = IMSO_DATE;    break;
-    case LB_MAILBOX_SORT_SIZE:    key = IMSO_SIZE;    break;
+            ? IMSO_TO : IMSO_FROM;
+        break;
+
+    case LB_MAILBOX_SORT_SUBJECT: key = IMSO_SUBJECT;
+        break;
+
+    case LB_MAILBOX_SORT_DATE:    key = IMSO_DATE;
+        break;
+
+    case LB_MAILBOX_SORT_SIZE:    key = IMSO_SIZE;
+        break;
     }
 
     return key;
 }
-     
+
+
 static void
-libbalsa_mailbox_imap_set_threading(LibBalsaMailbox *mailbox,
-                                   LibBalsaMailboxThreadingType thread_type)
+libbalsa_mailbox_imap_set_threading(LibBalsaMailbox             *mailbox,
+                                    LibBalsaMailboxThreadingType thread_type)
 {
     LibBalsaMailboxImap *mimap = LIBBALSA_MAILBOX_IMAP(mailbox);
-    GNode * new_tree = NULL;
+    GNode *new_tree            = NULL;
     guint msgno;
     ImapSearchKey *filter =
         lbmi_build_imap_query(libbalsa_mailbox_get_view_filter(mailbox, FALSE), NULL);
     ImapResponse rc;
-    
+
     libbalsa_mailbox_get_view(mailbox)->threading_type = thread_type;
-    switch(thread_type) {
+    switch (thread_type) {
     case LB_MAILBOX_THREADING_SIMPLE:
     case LB_MAILBOX_THREADING_JWZ:
-        II(rc,mimap->handle,
+        II(rc, mimap->handle,
            imap_mbox_thread(mimap->handle, "REFERENCES", filter));
-        if(rc == IMR_OK) {
+        if (rc == IMR_OK) {
             new_tree =
                 g_node_copy(imap_mbox_handle_get_thread_root(mimap->handle));
             break;
-        } else 
+        } else {
             libbalsa_information(LIBBALSA_INFORMATION_WARNING,
-                            _("Server-side threading not supported."));
-        /* fall through */
+                                 _("Server-side threading not supported."));
+        }
+
+    /* fall through */
     case LB_MAILBOX_THREADING_FLAT:
-        if(filter) {
-            II(rc,mimap->handle,
+        if (filter) {
+            II(rc, mimap->handle,
                imap_mbox_sort_filter(mimap->handle,
                                      lbmi_get_imap_sort_key(mailbox),
                                      libbalsa_mailbox_get_view(mailbox)->sort_type ==
                                      LB_MAILBOX_SORT_TYPE_ASC,
                                      filter));
-            if(rc == IMR_OK)
+            if (rc == IMR_OK) {
                 new_tree =
                     g_node_copy
-                    (imap_mbox_handle_get_thread_root(mimap->handle));
+                        (imap_mbox_handle_get_thread_root(mimap->handle));
+            }
         }
-        if(!new_tree) { /* fall back */
+        if (!new_tree) { /* fall back */
             new_tree = g_node_new(NULL);
-            for(msgno = 1; msgno <= mimap->messages_info->len; msgno++)
+            for (msgno = 1; msgno <= mimap->messages_info->len; msgno++) {
                 g_node_append_data(new_tree, GUINT_TO_POINTER(msgno));
+            }
         }
         break;
+
     default:
-       g_assert_not_reached();
-       new_tree = NULL;
+        g_assert_not_reached();
+        new_tree = NULL;
     }
     imap_search_key_free(filter);
 
     libbalsa_mailbox_set_msg_tree(mailbox, new_tree);
 }
 
+
 static void
 lbm_imap_update_view_filter(LibBalsaMailbox   *mailbox,
                             LibBalsaCondition *view_filter)
 {
 }
 
+
 /* Sorting
  *
  * To avoid multiple server queries when the view is threaded, we sort
@@ -3232,9 +3629,9 @@ lbm_imap_update_view_filter(LibBalsaMailbox   *mailbox,
  * (set to -1) whenever the cached ranks might be out of date.
  */
 static gint
-lbmi_compare_func(const SortTuple * a,
-                 const SortTuple * b,
-                 LibBalsaMailboxImap * mimap)
+lbmi_compare_func(const SortTuple     *a,
+                  const SortTuple     *b,
+                  LibBalsaMailboxImap *mimap)
 {
     unsigned seqnoa, seqnob;
     int retval;
@@ -3245,48 +3642,53 @@ lbmi_compare_func(const SortTuple * a,
     seqnob = GPOINTER_TO_UINT(b->node->data);
     g_assert(seqnob <= mimap->sort_ranks->len);
     retval = g_array_index(mimap->sort_ranks, guint, seqnoa - 1) -
-       g_array_index(mimap->sort_ranks, guint, seqnob - 1);
+        g_array_index(mimap->sort_ranks, guint, seqnob - 1);
 
     return libbalsa_mailbox_get_view(mbox)->sort_type == LB_MAILBOX_SORT_TYPE_ASC ?
-        retval : -retval;
+           retval : -retval;
 }
 
+
 static void
-libbalsa_mailbox_imap_sort(LibBalsaMailbox *mbox, GArray *array)
+libbalsa_mailbox_imap_sort(LibBalsaMailbox *mbox,
+                           GArray          *array)
 {
     LibBalsaMailboxImap *mimap;
 
     mimap = LIBBALSA_MAILBOX_IMAP(mbox);
     if (mimap->sort_field != libbalsa_mailbox_get_view(mbox)->sort_field) {
-       /* Cached ranks are invalid. */
+        /* Cached ranks are invalid. */
         unsigned *msgno_arr;
         guint i, len;
 
-        len = mimap->messages_info->len;
+        len       = mimap->messages_info->len;
         msgno_arr = g_malloc(len * sizeof(unsigned));
-        for (i = 0; i < len; i++)
+        for (i = 0; i < len; i++) {
             msgno_arr[i] = i + 1;
+        }
         if (libbalsa_mailbox_get_view(mbox)->sort_field != LB_MAILBOX_SORT_NO) {
             ImapResponse rc;
-           /* Server-side sort of the whole mailbox. */
+            /* Server-side sort of the whole mailbox. */
             II(rc, LIBBALSA_MAILBOX_IMAP(mbox)->handle,
                imap_mbox_sort_msgno(LIBBALSA_MAILBOX_IMAP(mbox)->handle,
                                     lbmi_get_imap_sort_key(mbox), TRUE,
                                     msgno_arr, len)); /* ignore errors */
         }
         g_array_set_size(mimap->sort_ranks, len);
-        for (i = 0; i < len; i++)
-           g_array_index(mimap->sort_ranks, guint, msgno_arr[i] - 1) = i;
-       g_free(msgno_arr);
-       /* Validate the cache. */
+        for (i = 0; i < len; i++) {
+            g_array_index(mimap->sort_ranks, guint, msgno_arr[i] - 1) = i;
+        }
+        g_free(msgno_arr);
+        /* Validate the cache. */
         mimap->sort_field = libbalsa_mailbox_get_view(mbox)->sort_field;
     }
     g_array_sort_with_data(array, (GCompareDataFunc) lbmi_compare_func,
                            mimap);
 }
 
+
 static guint
-libbalsa_mailbox_imap_total_messages(LibBalsaMailbox * mailbox)
+libbalsa_mailbox_imap_total_messages(LibBalsaMailbox *mailbox)
 {
     LibBalsaMailboxImap *mimap = (LibBalsaMailboxImap *) mailbox;
     guint cnt;
@@ -3295,115 +3697,122 @@ libbalsa_mailbox_imap_total_messages(LibBalsaMailbox * mailbox)
     return cnt;
 }
 
+
 /* Copy messages in the list to dest; use server-side copy if mailbox
  * and dest are on the same server, fall back to parent method
  * otherwise.
  */
 static gboolean
-libbalsa_mailbox_imap_messages_copy(LibBalsaMailbox * mailbox,
-                                   GArray * msgnos,
-                                   LibBalsaMailbox * dest, GError **err)
+libbalsa_mailbox_imap_messages_copy(LibBalsaMailbox *mailbox,
+                                    GArray          *msgnos,
+                                    LibBalsaMailbox *dest,
+                                    GError         **err)
 {
     if (LIBBALSA_IS_MAILBOX_IMAP(dest) &&
-       LIBBALSA_MAILBOX_REMOTE_GET_SERVER(dest) ==
-       LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mailbox)) {
+        (LIBBALSA_MAILBOX_REMOTE_GET_SERVER(dest) ==
+         LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mailbox))) {
         gboolean ret;
-       LibBalsaMailboxImap *mimap = LIBBALSA_MAILBOX_IMAP(mailbox);
-       ImapMboxHandle *handle = LIBBALSA_MAILBOX_IMAP(mailbox)->handle;
-       ImapSequence uid_sequence;
-       unsigned *seqno = (unsigned*)msgnos->data, *uids;
-       unsigned im;
-       g_return_val_if_fail(handle, FALSE);
-       
-       imap_sequence_init(&uid_sequence);
-       /* User server-side copy. */
-       g_array_sort(msgnos, cmp_msgno);
-       uids = g_new(unsigned, msgnos->len);
-       for(im=0; im<msgnos->len; im++) {
-           ImapMessage * imsg = imap_mbox_handle_get_msg(handle, seqno[im]);
-           uids[im] = imsg ? imsg->uid : 0;
-       }
-           
-       ret = imap_mbox_handle_copy(handle, msgnos->len,
+        LibBalsaMailboxImap *mimap = LIBBALSA_MAILBOX_IMAP(mailbox);
+        ImapMboxHandle *handle     = LIBBALSA_MAILBOX_IMAP(mailbox)->handle;
+        ImapSequence uid_sequence;
+        unsigned *seqno = (unsigned *)msgnos->data, *uids;
+        unsigned im;
+        g_return_val_if_fail(handle, FALSE);
+
+        imap_sequence_init(&uid_sequence);
+        /* User server-side copy. */
+        g_array_sort(msgnos, cmp_msgno);
+        uids = g_new(unsigned, msgnos->len);
+        for (im = 0; im < msgnos->len; im++) {
+            ImapMessage *imsg = imap_mbox_handle_get_msg(handle, seqno[im]);
+            uids[im] = imsg ? imsg->uid : 0;
+        }
+
+        ret = imap_mbox_handle_copy(handle, msgnos->len,
                                     (guint *) msgnos->data,
                                     LIBBALSA_MAILBOX_IMAP(dest)->path,
-                                   &uid_sequence)
-           == IMR_OK;
-        if(!ret) {
+                                    &uid_sequence)
+            == IMR_OK;
+        if (!ret) {
             gchar *msg = imap_mbox_handle_get_last_msg(handle);
             g_set_error(err, LIBBALSA_MAILBOX_ERROR,
                         LIBBALSA_MAILBOX_COPY_ERROR,
                         "%s", msg);
             g_free(msg);
-        } else if(!imap_sequence_empty(&uid_sequence)) {
-           /* Copy cache files. */
-           GDir *dir;
-           LibBalsaServer *s      = LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mailbox);
-           LibBalsaImapServer *is = LIBBALSA_IMAP_SERVER(s);
-           LibBalsaMailboxImap *dst_imap = LIBBALSA_MAILBOX_IMAP(dest);
-           gboolean is_persistent =
-               libbalsa_imap_server_has_persistent_cache(is);
-           gchar *dir_name = get_cache_dir(is_persistent);
-           gchar *src_prefix = g_strdup_printf("%s@%s-%s-%u-",
-                                               libbalsa_server_get_username(s), libbalsa_server_get_host(s),
-                                               (mimap->path 
-                                                ? mimap->path : "INBOX"),
-                                               mimap->uid_validity);
-           gchar *encoded_path = libbalsa_urlencode(src_prefix);
-           g_free(src_prefix);
-           dir = g_dir_open(dir_name, 0, NULL);
-           if(dir) {
-               const gchar *filename;
-               size_t prefix_length = strlen(encoded_path);
-               unsigned nth;
-               while ((filename = g_dir_read_name(dir)) != NULL) {
-                   unsigned msg_uid;
-                   gchar *tail;
-                   if(strncmp(encoded_path, filename, prefix_length))
-                       continue;
-                   msg_uid = strtol(filename + prefix_length, &tail, 10);
-                   for(im = 0; im<msgnos->len; im++) {
-                       if(uids[im]>msg_uid) break;
-                       else if(uids[im]==msg_uid &&
-                               (nth = imap_sequence_nth(&uid_sequence, im))
-                                ) {
-                           gchar *src =
-                               g_build_filename(dir_name, filename, NULL);
-                           gchar *dst_prefix =
-                               g_strdup_printf("%s@%s-%s-%u-%u%s",
-                                               libbalsa_server_get_username(s),
+        } else if (!imap_sequence_empty(&uid_sequence)) {
+            /* Copy cache files. */
+            GDir *dir;
+            LibBalsaServer *s             = LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mailbox);
+            LibBalsaImapServer *is        = LIBBALSA_IMAP_SERVER(s);
+            LibBalsaMailboxImap *dst_imap = LIBBALSA_MAILBOX_IMAP(dest);
+            gboolean is_persistent        =
+                libbalsa_imap_server_has_persistent_cache(is);
+            gchar *dir_name   = get_cache_dir(is_persistent);
+            gchar *src_prefix = g_strdup_printf("%s@%s-%s-%u-",
+                                                libbalsa_server_get_username(s),
+                                                libbalsa_server_get_host(s),
+                                                (mimap->path
+                                                 ? mimap->path : "INBOX"),
+                                                mimap->uid_validity);
+            gchar *encoded_path = libbalsa_urlencode(src_prefix);
+            g_free(src_prefix);
+            dir = g_dir_open(dir_name, 0, NULL);
+            if (dir) {
+                const gchar *filename;
+                size_t prefix_length = strlen(encoded_path);
+                unsigned nth;
+                while ((filename = g_dir_read_name(dir)) != NULL) {
+                    unsigned msg_uid;
+                    gchar *tail;
+                    if (strncmp(encoded_path, filename, prefix_length)) {
+                        continue;
+                    }
+                    msg_uid = strtol(filename + prefix_length, &tail, 10);
+                    for (im = 0; im < msgnos->len; im++) {
+                        if (uids[im] > msg_uid) {
+                            break;
+                        } else if ((uids[im] == msg_uid) &&
+                                   (nth = imap_sequence_nth(&uid_sequence, im))
+                                   ) {
+                            gchar *src =
+                                g_build_filename(dir_name, filename, NULL);
+                            gchar *dst_prefix =
+                                g_strdup_printf("%s@%s-%s-%u-%u%s",
+                                                libbalsa_server_get_username(s),
                                                 libbalsa_server_get_host(s),
-                                               (dst_imap->path
-                                                ? dst_imap->path : "INBOX"),
-                                               uid_sequence.uid_validity,
-                                               nth, tail);
-
-                           create_cache_copy(src, dir_name, dst_prefix);
-                           g_free(dst_prefix);
-                           break;
-                       }
-                   }
-               }
-               g_dir_close(dir);
-           }
-           g_free(dir_name);
-       }
-       g_free(uids);
-       imap_sequence_release(&uid_sequence);
+                                                (dst_imap->path
+                                                 ? dst_imap->path : "INBOX"),
+                                                uid_sequence.uid_validity,
+                                                nth, tail);
+
+                            create_cache_copy(src, dir_name, dst_prefix);
+                            g_free(dst_prefix);
+                            break;
+                        }
+                    }
+                }
+                g_dir_close(dir);
+            }
+            g_free(dir_name);
+        }
+        g_free(uids);
+        imap_sequence_release(&uid_sequence);
         return ret;
     }
 
     /* Couldn't use server-side copy, fall back to default method. */
     return LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_imap_parent_class)->
-        messages_copy(mailbox, msgnos, dest, err);
+           messages_copy(mailbox, msgnos, dest, err);
 }
 
+
 void
 libbalsa_imap_set_cache_size(off_t cache_size)
 {
     ImapCacheSize = cache_size;
 }
 
+
 /** Purges the temporary directory used for non-persistent message
    caching. */
 void
@@ -3414,6 +3823,7 @@ libbalsa_imap_purge_temp_dir(off_t cache_size)
     g_free(dir_name);
 }
 
+
 /* ===================================================================
    ImapCacheManager implementation.  The main task of the
    ImapCacheManager is to reuse msgno->UID mappings. This is useful
@@ -3426,7 +3836,7 @@ libbalsa_imap_purge_temp_dir(off_t cache_size)
 
    The general scheme is that libimap does not cache any data
    persistently based on UIDs - this task is left to ImapCacheManager.
- .
+   .
    ICM provides two main functions:
 
    - init_on_select() - preloads ImapMboxHandle msgno-based cache with
@@ -3443,24 +3853,25 @@ libbalsa_imap_purge_temp_dir(off_t cache_size)
  */
 struct ImapCacheManager {
     GHashTable *headers;
-    GArray     *uidmap;
-    uint32_t    uidvalidity;
-    uint32_t    uidnext;
-    uint32_t    exists;
+    GArray *uidmap;
+    uint32_t uidvalidity;
+    uint32_t uidnext;
+    uint32_t exists;
 };
 
-static struct ImapCacheManager*
+static struct ImapCacheManager *
 imap_cache_manager_new(guint cnt)
 {
     struct ImapCacheManager *icm = g_new0(struct ImapCacheManager, 1);
-    icm->exists = cnt;
-    icm->headers = 
+    icm->exists  = cnt;
+    icm->headers =
         g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
-    icm->uidmap = g_array_sized_new(FALSE,  TRUE, sizeof(uint32_t), cnt);
+    icm->uidmap = g_array_sized_new(FALSE, TRUE, sizeof(uint32_t), cnt);
     return icm;
 }
 
-static struct ImapCacheManager*
+
+static struct ImapCacheManager *
 imap_cache_manager_new_from_file(const char *header_cache_path)
 {
     /* The cache data should be transferable between 32- and 64-bit
@@ -3469,46 +3880,49 @@ imap_cache_manager_new_from_file(const char *header_cache_path)
     ImapUID uid;
     struct ImapCacheManager *icm;
     FILE *f = fopen(header_cache_path, "rb");
-    if(!f) {
-       return NULL;
+    if (!f) {
+        return NULL;
     }
-    if(fread(&i, sizeof(i), 1, f) != 1) {
-       printf("Could not read cache table size.\n");
+    if (fread(&i, sizeof(i), 1, f) != 1) {
+        printf("Could not read cache table size.\n");
         fclose(f);
-       return NULL;
+        return NULL;
     }
-    
+
     icm = imap_cache_manager_new(i);
-    if(fread(&icm->uidvalidity, sizeof(uint32_t), 1, f) != 1 ||
-       fread(&icm->uidnext,     sizeof(uint32_t), 1, f) != 1 ||
-       fread(&icm->exists,      sizeof(uint32_t), 1, f) != 1) {
-       imap_cache_manager_free(icm);
-       printf("Couldn't read cache - aborting…\n");
+    if ((fread(&icm->uidvalidity, sizeof(uint32_t), 1, f) != 1) ||
+        (fread(&icm->uidnext, sizeof(uint32_t), 1, f) != 1) ||
+        (fread(&icm->exists, sizeof(uint32_t), 1, f) != 1)) {
+        imap_cache_manager_free(icm);
+        printf("Couldn't read cache - aborting…\n");
         fclose(f);
-       return NULL;
+        return NULL;
     }
 
     i = 0;
-    while(fread(&uid, sizeof(uid), 1, f) == 1) {
-       if(uid) {
-           uint32_t slen; /* Architecture-independent size */
-           gchar *s;
-           if(fread(&slen, sizeof(slen), 1, f) != 1)
-               break;
-           s = g_malloc(slen+1); /* slen would be sufficient? */
-           if(fread(s, 1, slen, f) != slen)
+    while (fread(&uid, sizeof(uid), 1, f) == 1) {
+        if (uid) {
+            uint32_t slen; /* Architecture-independent size */
+            gchar *s;
+            if (fread(&slen, sizeof(slen), 1, f) != 1) {
+                break;
+            }
+            s = g_malloc(slen + 1); /* slen would be sufficient? */
+            if (fread(s, 1, slen, f) != slen) {
                 break;
-           s[slen] = '\0'; /* Unneeded? */
-           g_hash_table_insert(icm->headers, GUINT_TO_POINTER(uid), s);
-       }
+            }
+            s[slen] = '\0'; /* Unneeded? */
+            g_hash_table_insert(icm->headers, GUINT_TO_POINTER(uid), s);
+        }
         g_array_append_val(icm->uidmap, uid);
-       i++;
+        i++;
     }
     fclose(f);
 
     return icm;
 }
 
+
 static void
 imap_cache_manager_free(struct ImapCacheManager *icm)
 {
@@ -3517,32 +3931,38 @@ imap_cache_manager_free(struct ImapCacheManager *icm)
     g_free(icm);
 }
 
+
 /* icm_init_on_select_() preloads header cache of the ImapMboxHandle object.
    It currently handles following cases:
    a). uidvalidity different - entire cache has to be invalidated.
    b). cache->exists == h->exists && cache->uidnext == h->uidnext:
    nothing has changed - feed entire cache.
    else fetch the message numbers for the UIDs in cache.
-*/
+ */
 static void
-set_uid(ImapMboxHandle *handle, unsigned seqno, void *arg)
+set_uid(ImapMboxHandle *handle,
+        unsigned        seqno,
+        void           *arg)
 {
-    GArray *a = (GArray*)arg;
+    GArray *a = (GArray *)arg;
     g_array_append_val(a, seqno);
 }
 
+
 static void
-icm_restore_from_cache(ImapMboxHandle *h, struct ImapCacheManager *icm)
+icm_restore_from_cache(ImapMboxHandle          *h,
+                       struct ImapCacheManager *icm)
 {
     unsigned exists, uidvalidity, uidnext;
     unsigned i;
 
-    if(!icm || ! h)
+    if (!icm || !h) {
         return;
+    }
     uidvalidity = imap_mbox_handle_get_validity(h);
-    exists  = imap_mbox_handle_get_exists(h);
-    uidnext = imap_mbox_handle_get_uidnext(h);
-    if(icm->uidvalidity != uidvalidity) {
+    exists      = imap_mbox_handle_get_exists(h);
+    uidnext     = imap_mbox_handle_get_uidnext(h);
+    if (icm->uidvalidity != uidvalidity) {
         printf("Different validities old: %u new: %u - cache invalidated\n",
                icm->uidvalidity, uidvalidity);
         return;
@@ -3551,117 +3971,140 @@ icm_restore_from_cache(ImapMboxHandle *h, struct ImapCacheManager *icm)
     /* There were some modifications to the mailbox but the situation
      * is not hopeless, we just need to get the seqnos of messages in
      * the cache. */
-    if(exists - icm->exists !=  uidnext - icm->uidnext) {
+    if (exists - icm->exists != uidnext - icm->uidnext) {
         ImapResponse rc;
         GArray *uidmap = g_array_sized_new(FALSE, TRUE,
                                            sizeof(uint32_t), icm->exists);
         ImapSearchKey *k;
-        unsigned lo = icm->uidmap->len+1, hi = 0;
+        unsigned lo = icm->uidmap->len + 1, hi = 0;
         /* printf("UIDSYNC:Searching range [1:%u]\n", icm->uidmap->len); */
-        for(i=1; i<=icm->uidmap->len; i++)
-            if(g_array_index(icm->uidmap, uint32_t, i-1)) {lo=i; break; }
-        for(i=icm->uidmap->len; i>=lo; i--)
-            if(g_array_index(icm->uidmap, uint32_t, i-1)) {hi=i; break; }
+        for (i = 1; i <= icm->uidmap->len; i++) {
+            if (g_array_index(icm->uidmap, uint32_t, i - 1)) {
+                lo = i;
+                break;
+            }
+        }
+        for (i = icm->uidmap->len; i >= lo; i--) {
+            if (g_array_index(icm->uidmap, uint32_t, i - 1)) {
+                hi = i;
+                break;
+            }
+        }
 
         k = imap_search_key_new_range(FALSE, FALSE, lo, hi);
         /* printf("UIDSYNC: Old vs new: exists: %u %u uidnext: %u %u "
                "- syncing uid map for msgno [%u:%u].\n",
                icm->exists, exists, icm->uidnext, uidnext, lo, hi); */
-        if(k) {
-            uidmap->len = lo-1;
-            rc = imap_search_exec(h, TRUE, k, set_uid, uidmap);
+        if (k) {
+            uidmap->len = lo - 1;
+            rc          = imap_search_exec(h, TRUE, k, set_uid, uidmap);
             imap_search_key_free(k);
-        } else rc = IMR_NO;
-        if(rc != IMR_OK) {
+        } else {
+            rc = IMR_NO;
+        }
+        if (rc != IMR_OK) {
             g_array_free(uidmap, TRUE);
             return;
         }
-        g_array_free(icm->uidmap, TRUE); icm->uidmap = uidmap;
+        g_array_free(icm->uidmap, TRUE);
+        icm->uidmap = uidmap;
         /* printf("New uidmap has length: %u\n", icm->uidmap->len); */
     }
     /* One way or another, we have a valid uid->seqno map now;
      * The mailbox data can be resynced easily. */
 
-    for(i=1; i<=icm->exists; i++) {
-        uint32_t uid = g_array_index(icm->uidmap, uint32_t, i-1);
-        void *data = g_hash_table_lookup(icm->headers,
-                                         GUINT_TO_POINTER(uid));
-        if(data) /* if uid known */
+    for (i = 1; i <= icm->exists; i++) {
+        uint32_t uid = g_array_index(icm->uidmap, uint32_t, i - 1);
+        void *data   = g_hash_table_lookup(icm->headers,
+                                           GUINT_TO_POINTER(uid));
+        if (data) { /* if uid known */
             imap_mbox_handle_msg_deserialize(h, i, data);
+        }
     }
 }
 
+
 /** Stores (possibly persistently) data associated with given handle.
     This allows for quick restore between IMAP sessions and reduces
     synchronization overhead. */
-static struct ImapCacheManager*
+static struct ImapCacheManager *
 icm_store_cached_data(ImapMboxHandle *handle)
 {
     struct ImapCacheManager *icm;
     unsigned cnt, i;
 
-    if(!handle)
+    if (!handle) {
         return NULL;
+    }
 
-    cnt = imap_mbox_handle_get_exists(handle);
-    icm = imap_cache_manager_new(cnt);
+    cnt              = imap_mbox_handle_get_exists(handle);
+    icm              = imap_cache_manager_new(cnt);
     icm->uidvalidity = imap_mbox_handle_get_validity(handle);
     icm->uidnext     = imap_mbox_handle_get_uidnext(handle);
 
-    for(i=0; i<cnt; i++) {
+    for (i = 0; i < cnt; i++) {
         void *ptr;
-        ImapMessage *imsg = imap_mbox_handle_get_msg(handle, i+1);
+        ImapMessage *imsg = imap_mbox_handle_get_msg(handle, i + 1);
         unsigned uid;
-        if(imsg && (ptr = imap_message_serialize(imsg)) != NULL) {
+        if (imsg && ((ptr = imap_message_serialize(imsg)) != NULL)) {
             g_hash_table_insert(icm->headers,
                                 GUINT_TO_POINTER(imsg->uid), ptr);
             uid = imsg->uid;
-        } else uid = 0;
+        } else {
+            uid = 0;
+        }
         g_array_append_val(icm->uidmap, uid);
     }
     return icm;
 }
 
+
 static gboolean
-icm_save_header(uint32_t uid, gpointer value, FILE *f)
+icm_save_header(uint32_t uid,
+                gpointer value,
+                FILE    *f)
 {
-    if(fwrite(&uid, sizeof(uid), 1, f) != 1) return FALSE;
-    if(uid) {
-       uint32_t slen = imap_serialized_message_size(value);
-       if(fwrite(&slen, sizeof(slen), 1, f) != 1 ||
-           fwrite(value, 1, slen, f) != slen)
+    if (fwrite(&uid, sizeof(uid), 1, f) != 1) {
+        return FALSE;
+    }
+    if (uid) {
+        uint32_t slen = imap_serialized_message_size(value);
+        if ((fwrite(&slen, sizeof(slen), 1, f) != 1) ||
+            (fwrite(value, 1, slen, f) != slen)) {
             return FALSE;
+        }
     }
     return TRUE;
 }
 
 
 static gboolean
-icm_save_to_file(struct ImapCacheManager *icm, const gchar *file_name)
+icm_save_to_file(struct ImapCacheManager *icm,
+                 const gchar             *file_name)
 {
     gboolean success;
     FILE *f = fopen(file_name, "wb");
 
     success = f != NULL;
-    if(success) {
-       uint32_t i = icm->uidmap->len;
-       if(fwrite(&i, sizeof(i), 1, f) != 1                       ||
-           fwrite(&icm->uidvalidity, sizeof(uint32_t), 1, f) != 1 ||
-           fwrite(&icm->uidnext,     sizeof(uint32_t), 1, f) != 1 ||
-           fwrite(&icm->exists,      sizeof(uint32_t), 1, f) != 1) {
+    if (success) {
+        uint32_t i = icm->uidmap->len;
+        if ((fwrite(&i, sizeof(i), 1, f) != 1) ||
+            (fwrite(&icm->uidvalidity, sizeof(uint32_t), 1, f) != 1) ||
+            (fwrite(&icm->uidnext, sizeof(uint32_t), 1, f) != 1) ||
+            (fwrite(&icm->exists, sizeof(uint32_t), 1, f) != 1)) {
             success = FALSE;
         } else {
-            for(i = 0; i<icm->uidmap->len; i++) {
-                uint32_t uid = g_array_index(icm->uidmap, uint32_t, i);
+            for (i = 0; i < icm->uidmap->len; i++) {
+                uint32_t uid   = g_array_index(icm->uidmap, uint32_t, i);
                 gpointer value = g_hash_table_lookup(icm->headers,
                                                      GUINT_TO_POINTER(uid));
-                if(!icm_save_header(uid, value, f)) {
+                if (!icm_save_header(uid, value, f)) {
                     success = FALSE;
                     break;
                 }
             }
         }
-       fclose(f);
+        fclose(f);
     }
     return success;
 }
diff --git a/libbalsa/mailbox_imap.h b/libbalsa/mailbox_imap.h
index 4792d9a..f68515f 100644
--- a/libbalsa/mailbox_imap.h
+++ b/libbalsa/mailbox_imap.h
@@ -5,14 +5,14 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option) 
+ * the Free Software Foundation; either version 2, or (at your option)
  * any later version.
- *  
+ *
  * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of 
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *  
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
@@ -31,48 +31,54 @@ G_DECLARE_FINAL_TYPE(LibBalsaMailboxImap,
 #define POINTER_TO_UID(p) GPOINTER_TO_UINT(p)
 #define UID_TO_POINTER(p) GUINT_TO_POINTER(p)
 
-LibBalsaMailbox *libbalsa_mailbox_imap_new(void);
+LibBalsaMailbox * libbalsa_mailbox_imap_new(void);
 
-void libbalsa_mailbox_imap_update_url(LibBalsaMailboxImap* mailbox);
-void libbalsa_mailbox_imap_set_path(LibBalsaMailboxImap * mailbox,
-                                   const gchar * path);
-const gchar* libbalsa_mailbox_imap_get_path(LibBalsaMailboxImap * mailbox);
+void         libbalsa_mailbox_imap_update_url(LibBalsaMailboxImap *mailbox);
+void         libbalsa_mailbox_imap_set_path(LibBalsaMailboxImap *mailbox,
+                                            const gchar         *path);
+const gchar *libbalsa_mailbox_imap_get_path(LibBalsaMailboxImap *mailbox);
 
-gboolean libbalsa_mailbox_imap_subscribe(LibBalsaMailboxImap * mailbox, 
-                                         gboolean subscribe);
+gboolean     libbalsa_mailbox_imap_subscribe(LibBalsaMailboxImap *mailbox,
+                                             gboolean             subscribe);
 
-GHashTable * libbalsa_mailbox_imap_get_matchings(LibBalsaMailboxImap* mbox,
-                                                LibBalsaCondition *condition,
-                                                gboolean only_recent,
-                                                gboolean * err);
+GHashTable *libbalsa_mailbox_imap_get_matchings(LibBalsaMailboxImap *mbox,
+                                                LibBalsaCondition   *condition,
+                                                gboolean             only_recent,
+                                                gboolean            *err);
 
-void libbalsa_mailbox_imap_noop(LibBalsaMailboxImap* mbox);
+void     libbalsa_mailbox_imap_noop(LibBalsaMailboxImap *mbox);
 
-void libbalsa_mailbox_imap_force_disconnect(LibBalsaMailboxImap* mimap);
-gboolean libbalsa_mailbox_imap_is_connected(LibBalsaMailboxImap* mimap);
-void libbalsa_mailbox_imap_reconnect(LibBalsaMailboxImap* mimap);
-void libbalsa_imap_close_all_connections(void);
+void     libbalsa_mailbox_imap_force_disconnect(LibBalsaMailboxImap *mimap);
+gboolean libbalsa_mailbox_imap_is_connected(LibBalsaMailboxImap *mimap);
+void     libbalsa_mailbox_imap_reconnect(LibBalsaMailboxImap *mimap);
+void     libbalsa_imap_close_all_connections(void);
 
-gboolean libbalsa_imap_new_subfolder(const gchar *parent, const gchar *folder,
-                                     gboolean subscribe,
-                                     LibBalsaServer *server, GError **err);
+gboolean libbalsa_imap_new_subfolder(const gchar    *parent,
+                                     const gchar    *folder,
+                                     gboolean        subscribe,
+                                     LibBalsaServer *server,
+                                     GError        **err);
 
-gboolean libbalsa_imap_rename_subfolder(LibBalsaMailboxImap* mbox,
-                                        const gchar *new_parent,
-                                        const gchar *folder, gboolean subscr,
-                                        GError **err);
+gboolean libbalsa_imap_rename_subfolder(LibBalsaMailboxImap *mbox,
+                                        const gchar         *new_parent,
+                                        const gchar         *folder,
+                                        gboolean             subscr,
+                                        GError             **err);
 
-gboolean libbalsa_imap_delete_folder(LibBalsaMailboxImap * mailbox,
-                                     GError **err);
+gboolean libbalsa_imap_delete_folder(LibBalsaMailboxImap *mailbox,
+                                     GError             **err);
 
-gboolean libbalsa_imap_get_quota(LibBalsaMailboxImap * mailbox,
-                                 gulong *max_kbyte, gulong *used_kbyte);
+gboolean libbalsa_imap_get_quota(LibBalsaMailboxImap *mailbox,
+                                 gulong              *max_kbyte,
+                                 gulong              *used_kbyte);
 
-gchar *libbalsa_imap_get_rights(LibBalsaMailboxImap * mailbox);
-gchar **libbalsa_imap_get_acls(LibBalsaMailboxImap * mailbox);
+gchar  *libbalsa_imap_get_rights(LibBalsaMailboxImap *mailbox);
+gchar **libbalsa_imap_get_acls(LibBalsaMailboxImap *mailbox);
 
-gchar *libbalsa_imap_url(LibBalsaServer * server, const gchar * path);
+gchar  *libbalsa_imap_url(LibBalsaServer *server,
+                          const gchar    *path);
 
 void libbalsa_imap_set_cache_size(off_t cache_size);
 void libbalsa_imap_purge_temp_dir(off_t cache_size);
-#endif                         /* __LIBBALSA_MAILBOX_IMAP_H__ */
+
+#endif                          /* __LIBBALSA_MAILBOX_IMAP_H__ */
diff --git a/libbalsa/mailbox_local.c b/libbalsa/mailbox_local.c
index 624cfad..2683868 100644
--- a/libbalsa/mailbox_local.c
+++ b/libbalsa/mailbox_local.c
@@ -6,20 +6,20 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option) 
+ * the Free Software Foundation; either version 2, or (at your option)
  * any later version.
- *  
+ *
  * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of 
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *  
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H
-# include "config.h"
+#   include "config.h"
 #endif                          /* HAVE_CONFIG_H */
 
 #include <sys/types.h>
@@ -53,29 +53,30 @@ struct _LibBalsaMailboxLocalPrivate {
     guint pool_seqno;
 };
 
-static void libbalsa_mailbox_local_dispose(GObject * object);
-static void libbalsa_mailbox_local_finalize(GObject * object);
+static void libbalsa_mailbox_local_dispose(GObject *object);
+static void libbalsa_mailbox_local_finalize(GObject *object);
 
-static void libbalsa_mailbox_local_changed(LibBalsaMailbox * mailbox);
-static void libbalsa_mailbox_local_save_config(LibBalsaMailbox * mailbox,
-                                              const gchar * prefix);
-static void libbalsa_mailbox_local_load_config(LibBalsaMailbox * mailbox,
-                                              const gchar * prefix);
+static void libbalsa_mailbox_local_changed(LibBalsaMailbox *mailbox);
+static void libbalsa_mailbox_local_save_config(LibBalsaMailbox *mailbox,
+                                               const gchar     *prefix);
+static void libbalsa_mailbox_local_load_config(LibBalsaMailbox *mailbox,
+                                               const gchar     *prefix);
 
-static void libbalsa_mailbox_local_close_mailbox(LibBalsaMailbox * mailbox,
-                                                 gboolean expunge);
+static void             libbalsa_mailbox_local_close_mailbox(LibBalsaMailbox *mailbox,
+                                                             gboolean         expunge);
 static LibBalsaMessage *libbalsa_mailbox_local_get_message(LibBalsaMailbox
-                                                           * mailbox,
+                                                                *mailbox,
                                                            guint msgno);
 static gboolean libbalsa_mailbox_local_message_match(LibBalsaMailbox *
-                                                    mailbox, guint msgno,
-                                                    LibBalsaMailboxSearchIter
-                                                    * iter);
+                                                     mailbox,
+                                                     guint msgno,
+                                                     LibBalsaMailboxSearchIter
+                                                          *iter);
 
 static void libbalsa_mailbox_local_set_threading(LibBalsaMailbox *mailbox,
-                                                LibBalsaMailboxThreadingType
-                                                thread_type);
-static void lbm_local_update_view_filter(LibBalsaMailbox * mailbox,
+                                                 LibBalsaMailboxThreadingType
+                                                 thread_type);
+static void lbm_local_update_view_filter(LibBalsaMailbox   *mailbox,
                                          LibBalsaCondition *view_filter);
 
 static gboolean libbalsa_mailbox_local_prepare_threading(LibBalsaMailbox *
@@ -92,23 +93,22 @@ static void libbalsa_mailbox_local_fetch_headers(LibBalsaMailbox *mailbox,
                                                  LibBalsaMessage *message);
 
 static gboolean libbalsa_mailbox_local_get_msg_part(LibBalsaMessage *msg,
-                                                   LibBalsaMessageBody *,
-                                                    GError **err);
-
-static void lbm_local_sort(LibBalsaMailbox * mailbox, GArray *sort_array);
-static guint
-libbalsa_mailbox_local_add_messages(LibBalsaMailbox          * mailbox,
-                                    LibBalsaAddMessageIterator msg_iterator,
-                                    gpointer                   iter_data,
-                                    GError                  ** err);
-
-static GArray *libbalsa_mailbox_local_duplicate_msgnos(LibBalsaMailbox *
-                                                       mailbox);
-static gboolean
-libbalsa_mailbox_local_messages_change_flags(LibBalsaMailbox * mailbox,
-                                             GArray * msgnos,
-                                             LibBalsaMessageFlag set,
-                                             LibBalsaMessageFlag clear);
+                                                    LibBalsaMessageBody *,
+                                                    GError         **err);
+
+static void  lbm_local_sort(LibBalsaMailbox *mailbox,
+                            GArray          *sort_array);
+static guint libbalsa_mailbox_local_add_messages(LibBalsaMailbox           *mailbox,
+                                                 LibBalsaAddMessageIterator msg_iterator,
+                                                 gpointer                   iter_data,
+                                                 GError                   **err);
+
+static GArray  *libbalsa_mailbox_local_duplicate_msgnos(LibBalsaMailbox *
+                                                        mailbox);
+static gboolean libbalsa_mailbox_local_messages_change_flags(LibBalsaMailbox    *mailbox,
+                                                             GArray             *msgnos,
+                                                             LibBalsaMessageFlag set,
+                                                             LibBalsaMessageFlag clear);
 static gboolean libbalsa_mailbox_local_msgno_has_flags(LibBalsaMailbox *
                                                        mailbox,
                                                        guint msgno,
@@ -116,54 +116,54 @@ static gboolean libbalsa_mailbox_local_msgno_has_flags(LibBalsaMailbox *
                                                        set,
                                                        LibBalsaMessageFlag
                                                        unset);
-static void libbalsa_mailbox_local_test_can_reach(LibBalsaMailbox          * mailbox,
-                                                  LibBalsaCanReachCallback * cb,
-                                                  gpointer                   cb_data);
+static void libbalsa_mailbox_local_test_can_reach(LibBalsaMailbox          *mailbox,
+                                                  LibBalsaCanReachCallback *cb,
+                                                  gpointer                  cb_data);
 
 /* LibBalsaMailboxLocal class method: */
-static void lbm_local_real_remove_files(LibBalsaMailboxLocal * local);
+static void lbm_local_real_remove_files(LibBalsaMailboxLocal *local);
 
 G_DEFINE_TYPE_WITH_PRIVATE(LibBalsaMailboxLocal, libbalsa_mailbox_local,
                            LIBBALSA_TYPE_MAILBOX)
 
 static void
-libbalsa_mailbox_local_class_init(LibBalsaMailboxLocalClass * klass)
+libbalsa_mailbox_local_class_init(LibBalsaMailboxLocalClass *klass)
 {
     GObjectClass *object_class;
     LibBalsaMailboxClass *libbalsa_mailbox_class;
 
-    object_class = G_OBJECT_CLASS(klass);
+    object_class           = G_OBJECT_CLASS(klass);
     libbalsa_mailbox_class = LIBBALSA_MAILBOX_CLASS(klass);
 
     object_class->dispose  = libbalsa_mailbox_local_dispose;
     object_class->finalize = libbalsa_mailbox_local_finalize;
 
     libbalsa_mailbox_class->changed =
-       libbalsa_mailbox_local_changed;
+        libbalsa_mailbox_local_changed;
     libbalsa_mailbox_class->save_config =
-       libbalsa_mailbox_local_save_config;
+        libbalsa_mailbox_local_save_config;
     libbalsa_mailbox_class->load_config =
-       libbalsa_mailbox_local_load_config;
+        libbalsa_mailbox_local_load_config;
 
     libbalsa_mailbox_class->close_mailbox =
-       libbalsa_mailbox_local_close_mailbox;
+        libbalsa_mailbox_local_close_mailbox;
     libbalsa_mailbox_class->get_message =
-       libbalsa_mailbox_local_get_message;
-    libbalsa_mailbox_class->message_match = 
+        libbalsa_mailbox_local_get_message;
+    libbalsa_mailbox_class->message_match =
         libbalsa_mailbox_local_message_match;
     libbalsa_mailbox_class->set_threading =
-       libbalsa_mailbox_local_set_threading;
+        libbalsa_mailbox_local_set_threading;
     libbalsa_mailbox_class->update_view_filter =
         lbm_local_update_view_filter;
     libbalsa_mailbox_class->prepare_threading =
         libbalsa_mailbox_local_prepare_threading;
-    libbalsa_mailbox_class->fetch_message_structure = 
+    libbalsa_mailbox_class->fetch_message_structure =
         libbalsa_mailbox_local_fetch_structure;
-    libbalsa_mailbox_class->fetch_headers = 
+    libbalsa_mailbox_class->fetch_headers =
         libbalsa_mailbox_local_fetch_headers;
-    libbalsa_mailbox_class->get_message_part = 
+    libbalsa_mailbox_class->get_message_part =
         libbalsa_mailbox_local_get_msg_part;
-    libbalsa_mailbox_class->sort = lbm_local_sort;
+    libbalsa_mailbox_class->sort         = lbm_local_sort;
     libbalsa_mailbox_class->add_messages =
         libbalsa_mailbox_local_add_messages;
     libbalsa_mailbox_class->messages_change_flags =
@@ -179,48 +179,52 @@ libbalsa_mailbox_local_class_init(LibBalsaMailboxLocalClass * klass)
     klass->remove_files = lbm_local_real_remove_files;
 }
 
+
 static void
-libbalsa_mailbox_local_init(LibBalsaMailboxLocal * local)
+libbalsa_mailbox_local_init(LibBalsaMailboxLocal *local)
 {
     LibBalsaMailboxLocalPrivate *priv =
         libbalsa_mailbox_local_get_instance_private(local);
 
-    priv->sync_id   = 0;
-    priv->sync_time = 0;
-    priv->sync_cnt  = 0;
-    priv->thread_id = 0;
+    priv->sync_id      = 0;
+    priv->sync_time    = 0;
+    priv->sync_cnt     = 0;
+    priv->thread_id    = 0;
     priv->save_tree_id = 0;
 }
 
+
 LibBalsaMailbox *
-libbalsa_mailbox_local_new(const gchar * path, gboolean create)
+libbalsa_mailbox_local_new(const gchar *path,
+                           gboolean     create)
 {
     GType magic_type = libbalsa_mailbox_type_from_path(path);
 
-    if(magic_type == LIBBALSA_TYPE_MAILBOX_MBOX)
-       return libbalsa_mailbox_mbox_new(path, create);
-    else if(magic_type == LIBBALSA_TYPE_MAILBOX_MH)
-       return libbalsa_mailbox_mh_new(path, create);
-    else if(magic_type == LIBBALSA_TYPE_MAILBOX_MAILDIR)
-       return libbalsa_mailbox_maildir_new(path, create);
-    else if(magic_type == LIBBALSA_TYPE_MAILBOX_IMAP) {
+    if (magic_type == LIBBALSA_TYPE_MAILBOX_MBOX) {
+        return libbalsa_mailbox_mbox_new(path, create);
+    } else if (magic_type == LIBBALSA_TYPE_MAILBOX_MH) {
+        return libbalsa_mailbox_mh_new(path, create);
+    } else if (magic_type == LIBBALSA_TYPE_MAILBOX_MAILDIR) {
+        return libbalsa_mailbox_maildir_new(path, create);
+    } else if (magic_type == LIBBALSA_TYPE_MAILBOX_IMAP) {
         g_warning("IMAP path given as a path to local mailbox.\n");
         return NULL;
-    } else {           /* mailbox non-existent or unreadable */
-       if(create) 
-           return libbalsa_mailbox_mbox_new(path, TRUE);
-        else {
+    } else {            /* mailbox non-existent or unreadable */
+        if (create) {
+            return libbalsa_mailbox_mbox_new(path, TRUE);
+        } else {
             g_warning("Unknown mailbox type\n");
             return NULL;
         }
     }
 }
 
+
 /*
  * libbalsa_mailbox_local_get_path
  */
 const gchar *
-libbalsa_mailbox_local_get_path(LibBalsaMailboxLocal * local)
+libbalsa_mailbox_local_get_path(LibBalsaMailboxLocal *local)
 {
     static const gchar prefix[] = "file://";
     const gchar *url;
@@ -231,13 +235,15 @@ libbalsa_mailbox_local_get_path(LibBalsaMailboxLocal * local)
     return url + sizeof prefix - 1;
 }
 
+
 /* libbalsa_mailbox_local_set_path:
    returrns errno on error, 0 on success
    FIXME: proper suport for maildir and mh
-*/
+ */
 gint
-libbalsa_mailbox_local_set_path(LibBalsaMailboxLocal * mailbox,
-                                const gchar * path, gboolean create)
+libbalsa_mailbox_local_set_path(LibBalsaMailboxLocal *mailbox,
+                                const gchar          *path,
+                                gboolean              create)
 {
     int i;
     LibBalsaMailboxLocalClass *klass;
@@ -250,32 +256,37 @@ libbalsa_mailbox_local_set_path(LibBalsaMailboxLocal * mailbox,
 
     if (libbalsa_mailbox_get_url(LIBBALSA_MAILBOX(mailbox)) != NULL) {
         const gchar *cur_path = libbalsa_mailbox_local_get_path(mailbox);
-        if (strcmp(path, cur_path) == 0)
+        if (strcmp(path, cur_path) == 0) {
             return 0;
-        else if (access(path, F_OK) == 0)       /* 0 == file does exist */
+        } else if (access(path, F_OK) == 0) {   /* 0 == file does exist */
             return EEXIST;
-        else
+        } else {
             i = rename(cur_path, path);
-    } else
+        }
+    } else {
         i = klass->check_files(path, create);
+    }
 
     /* update mailbox data */
     if (i == 0) {
         gchar *url;
 
-        if (klass->set_path)
+        if (klass->set_path) {
             klass->set_path(mailbox, path);
+        }
         url = g_strconcat("file://", path, NULL);
         libbalsa_mailbox_set_url(LIBBALSA_MAILBOX(mailbox), url);
         g_free(url);
 
         return 0;
-    } else
+    } else {
         return errno ? errno : -1;
+    }
 }
 
+
 void
-libbalsa_mailbox_local_remove_files(LibBalsaMailboxLocal * local)
+libbalsa_mailbox_local_remove_files(LibBalsaMailboxLocal *local)
 {
     g_return_if_fail(LIBBALSA_IS_MAILBOX_LOCAL(local));
     g_assert(LIBBALSA_MAILBOX_LOCAL_GET_CLASS(local) != NULL);
@@ -283,13 +294,14 @@ libbalsa_mailbox_local_remove_files(LibBalsaMailboxLocal * local)
     LIBBALSA_MAILBOX_LOCAL_GET_CLASS(local)->remove_files(local);
 }
 
+
 /* libbalsa_mailbox_load_message:
    MAKE sure the mailbox is LOCKed before entering this routine.
-*/
+ */
 
 static void
-lbml_add_message_to_pool(LibBalsaMailboxLocal * local,
-                         LibBalsaMessage * message)
+lbml_add_message_to_pool(LibBalsaMailboxLocal *local,
+                         LibBalsaMessage      *message)
 {
     LibBalsaMailboxLocalPrivate *priv =
         libbalsa_mailbox_local_get_instance_private(local);
@@ -303,17 +315,19 @@ lbml_add_message_to_pool(LibBalsaMailboxLocal * local,
             item->pool_seqno = priv->pool_seqno;
             return;
         }
-        if (item->pool_seqno < oldest->pool_seqno)
+        if (item->pool_seqno < oldest->pool_seqno) {
             oldest = item;
+        }
     }
 
     g_set_object(&oldest->message, message);
     oldest->pool_seqno = priv->pool_seqno;
 }
 
+
 static void
-lbm_local_get_message_with_msg_info(LibBalsaMailboxLocal * local,
-                                    guint msgno,
+lbm_local_get_message_with_msg_info(LibBalsaMailboxLocal *local,
+                                    guint                 msgno,
                                     LibBalsaMailboxLocalMessageInfo *
                                     msg_info)
 {
@@ -323,18 +337,22 @@ lbm_local_get_message_with_msg_info(LibBalsaMailboxLocal * local,
     g_object_add_weak_pointer(G_OBJECT(message),
                               (gpointer) & msg_info->message);
 
-    message->flags = msg_info->flags & LIBBALSA_MESSAGE_FLAGS_REAL;
+    message->flags   = msg_info->flags & LIBBALSA_MESSAGE_FLAGS_REAL;
     message->mailbox = LIBBALSA_MAILBOX(local);
-    message->msgno = msgno;
+    message->msgno   = msgno;
     libbalsa_message_load_envelope(message);
     lbml_add_message_to_pool(local, message);
 }
 
-static gboolean message_match_real(LibBalsaMailbox * mailbox, guint msgno,
-                                   LibBalsaCondition * cond);
+
+static gboolean message_match_real(LibBalsaMailbox   *mailbox,
+                                   guint              msgno,
+                                   LibBalsaCondition *cond);
+
 static void
-libbalsa_mailbox_local_load_message(LibBalsaMailboxLocal * local,
-                                    GNode ** sibling, guint msgno,
+libbalsa_mailbox_local_load_message(LibBalsaMailboxLocal *local,
+                                    GNode               **sibling,
+                                    guint                 msgno,
                                     LibBalsaMailboxLocalMessageInfo *
                                     msg_info)
 {
@@ -347,15 +365,17 @@ libbalsa_mailbox_local_load_message(LibBalsaMailboxLocal * local,
     if ((msg_info->flags & LIBBALSA_MESSAGE_FLAG_NEW)
         && !(msg_info->flags & LIBBALSA_MESSAGE_FLAG_DELETED)) {
         libbalsa_mailbox_add_to_unread_messages(mbx, 1);
-        if (libbalsa_mailbox_get_first_unread(mbx) == 0)
+        if (libbalsa_mailbox_get_first_unread(mbx) == 0) {
             libbalsa_mailbox_set_first_unread(mbx, msgno);
+        }
     }
 
     if (msg_info->flags & LIBBALSA_MESSAGE_FLAG_RECENT) {
         gchar *id;
 
-        if (!msg_info->message)
+        if (!msg_info->message) {
             lbm_local_get_message_with_msg_info(local, msgno, msg_info);
+        }
 
         if (libbalsa_message_is_partial(msg_info->message, &id)) {
             libbalsa_mailbox_try_reassemble(mbx, id);
@@ -364,17 +384,20 @@ libbalsa_mailbox_local_load_message(LibBalsaMailboxLocal * local,
     }
 
     view_filter = libbalsa_mailbox_get_view_filter(mbx, FALSE);
-    if (view_filter == NULL)
+    if (view_filter == NULL) {
         match = TRUE;
-    else if (!libbalsa_condition_is_flag_only(view_filter,
-                                              mbx, msgno, &match))
+    } else if (!libbalsa_condition_is_flag_only(view_filter,
+                                                mbx, msgno, &match)) {
         match = message_match_real(mbx, msgno, view_filter);
+    }
 
-    if (match)
+    if (match) {
         libbalsa_mailbox_msgno_inserted(mbx, msgno, libbalsa_mailbox_get_msg_tree(mbx),
                                         sibling);
+    }
 }
 
+
 /* Threading info. */
 typedef struct {
     gchar *message_id;
@@ -383,7 +406,7 @@ typedef struct {
 } LibBalsaMailboxLocalInfo;
 
 static void
-lbm_local_free_info(LibBalsaMailboxLocalInfo * info)
+lbm_local_free_info(LibBalsaMailboxLocalInfo *info)
 {
     if (info != NULL) {
         g_free(info->message_id);
@@ -393,10 +416,11 @@ lbm_local_free_info(LibBalsaMailboxLocalInfo * info)
     }
 }
 
+
 static void
-libbalsa_mailbox_local_dispose(GObject * object)
+libbalsa_mailbox_local_dispose(GObject *object)
 {
-    LibBalsaMailboxLocal *local = (LibBalsaMailboxLocal *) object;
+    LibBalsaMailboxLocal *local       = (LibBalsaMailboxLocal *) object;
     LibBalsaMailboxLocalPrivate *priv =
         libbalsa_mailbox_local_get_instance_private(local);
 
@@ -410,36 +434,38 @@ libbalsa_mailbox_local_dispose(GObject * object)
     G_OBJECT_CLASS(libbalsa_mailbox_local_parent_class)->dispose(object);
 }
 
+
 static void
-libbalsa_mailbox_local_finalize(GObject * object)
+libbalsa_mailbox_local_finalize(GObject *object)
 {
-    LibBalsaMailboxLocal *local = (LibBalsaMailboxLocal *) object;
+    LibBalsaMailboxLocal *local       = (LibBalsaMailboxLocal *) object;
     LibBalsaMailboxLocalPrivate *priv =
         libbalsa_mailbox_local_get_instance_private(local);
 
     g_return_if_fail(LIBBALSA_IS_MAILBOX_LOCAL(object));
 
     if (priv->threading_info != NULL) {
-       /* The memory owned by priv->threading_info was freed on closing,
-        * so we free only the array itself. */
-       g_ptr_array_free(priv->threading_info, TRUE);
+        /* The memory owned by priv->threading_info was freed on closing,
+         * so we free only the array itself. */
+        g_ptr_array_free(priv->threading_info, TRUE);
     }
 
     G_OBJECT_CLASS(libbalsa_mailbox_local_parent_class)->finalize(object);
 }
 
 
-static void lbm_local_queue_save_tree(LibBalsaMailboxLocal * local);
+static void lbm_local_queue_save_tree(LibBalsaMailboxLocal *local);
 
 static void
-libbalsa_mailbox_local_changed(LibBalsaMailbox * mailbox)
+libbalsa_mailbox_local_changed(LibBalsaMailbox *mailbox)
 {
     lbm_local_queue_save_tree(LIBBALSA_MAILBOX_LOCAL(mailbox));
 }
 
+
 static void
-libbalsa_mailbox_local_save_config(LibBalsaMailbox * mailbox,
-                                  const gchar * prefix)
+libbalsa_mailbox_local_save_config(LibBalsaMailbox *mailbox,
+                                   const gchar     *prefix)
 {
     LibBalsaMailboxLocal *local;
 
@@ -449,37 +475,44 @@ libbalsa_mailbox_local_save_config(LibBalsaMailbox * mailbox,
 
     libbalsa_conf_set_string("Path", libbalsa_mailbox_local_get_path(local));
 
-    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_local_parent_class)->save_config)
-       LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_local_parent_class)->save_config(mailbox, prefix);
+    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_local_parent_class)->save_config) {
+        LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_local_parent_class)->save_config(mailbox,
+                                                                                 prefix);
+    }
 }
 
+
 static void
-libbalsa_mailbox_local_load_config(LibBalsaMailbox * mailbox,
-                                  const gchar * prefix)
+libbalsa_mailbox_local_load_config(LibBalsaMailbox *mailbox,
+                                   const gchar     *prefix)
 {
-    gchar* path;
+    gchar *path;
     gchar *url;
 
     g_return_if_fail(LIBBALSA_IS_MAILBOX_LOCAL(mailbox));
 
 
     path = libbalsa_conf_get_string("Path");
-    url = g_strconcat("file://", path, NULL);
+    url  = g_strconcat("file://", path, NULL);
     libbalsa_mailbox_set_url(mailbox, url);
     g_free(url);
     g_free(path);
 
-    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_local_parent_class)->load_config)
-       LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_local_parent_class)->load_config(mailbox, prefix);
+    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_local_parent_class)->load_config) {
+        LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_local_parent_class)->load_config(mailbox,
+                                                                                 prefix);
+    }
 }
 
+
 /*
  * Save and restore the message tree.
  */
 
 typedef struct {
-    GArray * array;
-    guint (*fileno)(LibBalsaMailboxLocal * local, guint msgno);
+    GArray *array;
+    guint (*fileno)(LibBalsaMailboxLocal *local,
+                    guint                 msgno);
     LibBalsaMailboxLocal *local;
 } LibBalsaMailboxLocalSaveTreeInfo;
 
@@ -495,41 +528,45 @@ typedef struct {
  * Save one item; return TRUE on error, to terminate the traverse.
  */
 static gboolean
-lbm_local_save_tree_item(guint msgno, guint a,
-                         LibBalsaMailboxLocalSaveTreeInfo * save_info)
+lbm_local_save_tree_item(guint                             msgno,
+                         guint                             a,
+                         LibBalsaMailboxLocalSaveTreeInfo *save_info)
 {
     LibBalsaMailboxLocalTreeInfo info;
 
     if (msgno == 0) {
-        info.msgno = msgno;
+        info.msgno       = msgno;
         info.value.total = a;
     } else if (save_info->fileno) {
-        info.msgno = save_info->fileno(save_info->local, msgno);
+        info.msgno        = save_info->fileno(save_info->local, msgno);
         info.value.parent = save_info->fileno(save_info->local, a);
     } else {
-        info.msgno = msgno;
+        info.msgno        = msgno;
         info.value.parent = a;
     }
 
     return g_array_append_val(save_info->array, info) == NULL;
 }
 
+
 static gboolean
-lbm_local_save_tree_func(GNode * node, gpointer data)
+lbm_local_save_tree_func(GNode   *node,
+                         gpointer data)
 {
     return node->parent ?
-        lbm_local_save_tree_item(GPOINTER_TO_UINT(node->data),
-                                 GPOINTER_TO_UINT(node->parent->data),
-                                 data) :
-        FALSE;
+           lbm_local_save_tree_item(GPOINTER_TO_UINT(node->data),
+                                    GPOINTER_TO_UINT(node->parent->data),
+                                    data) :
+           FALSE;
 }
 
+
 static gchar *
-lbm_local_get_cache_filename(LibBalsaMailboxLocal * local)
+lbm_local_get_cache_filename(LibBalsaMailboxLocal *local)
 {
     gchar *encoded_path;
     gchar *filename;
-    
+
     encoded_path =
         libbalsa_urlencode(libbalsa_mailbox_local_get_path(local));
     filename =
@@ -539,8 +576,9 @@ lbm_local_get_cache_filename(LibBalsaMailboxLocal * local)
     return filename;
 }
 
+
 static void
-lbm_local_save_tree(LibBalsaMailboxLocal * local)
+lbm_local_save_tree(LibBalsaMailboxLocal *local)
 {
     LibBalsaMailbox *mailbox = LIBBALSA_MAILBOX(local);
     gchar *filename;
@@ -550,25 +588,26 @@ lbm_local_save_tree(LibBalsaMailboxLocal * local)
     g_assert(LIBBALSA_MAILBOX_LOCAL_GET_CLASS(local) != NULL);
 
     if (!libbalsa_mailbox_get_msg_tree(mailbox) ||
-        !libbalsa_mailbox_get_msg_tree_changed(mailbox))
+        !libbalsa_mailbox_get_msg_tree_changed(mailbox)) {
         return;
+    }
     libbalsa_mailbox_set_msg_tree_changed(mailbox, FALSE);
 
     filename = lbm_local_get_cache_filename(local);
 
     if (!libbalsa_mailbox_get_msg_tree(mailbox)->children
-        || (libbalsa_mailbox_get_threading_type(mailbox) ==
-            LB_MAILBOX_THREADING_FLAT
-            && libbalsa_mailbox_get_sort_field(mailbox) ==
-            LB_MAILBOX_SORT_NO)) {
+        || ((libbalsa_mailbox_get_threading_type(mailbox) ==
+             LB_MAILBOX_THREADING_FLAT)
+            && (libbalsa_mailbox_get_sort_field(mailbox) ==
+                LB_MAILBOX_SORT_NO))) {
         unlink(filename);
         g_free(filename);
         return;
     }
 
     save_info.fileno = LIBBALSA_MAILBOX_LOCAL_GET_CLASS(local)->fileno;
-    save_info.local = local;
-    save_info.array =
+    save_info.local  = local;
+    save_info.array  =
         g_array_new(FALSE, FALSE, sizeof(LibBalsaMailboxLocalTreeInfo));
     lbm_local_save_tree_item(0, libbalsa_mailbox_get_total(mailbox),
                              &save_info);
@@ -590,8 +629,10 @@ lbm_local_save_tree(LibBalsaMailboxLocal * local)
     g_free(filename);
 }
 
+
 static gboolean
-lbm_local_restore_tree(LibBalsaMailboxLocal * local, guint * total)
+lbm_local_restore_tree(LibBalsaMailboxLocal *local,
+                       guint                *total)
 {
     LibBalsaMailbox *mailbox = LIBBALSA_MAILBOX(local);
     gchar *filename;
@@ -609,19 +650,20 @@ lbm_local_restore_tree(LibBalsaMailboxLocal * local, guint * total)
 
     g_assert(LIBBALSA_MAILBOX_LOCAL_GET_CLASS(local) != NULL);
 
-    filename = lbm_local_get_cache_filename(local);
+    filename     = lbm_local_get_cache_filename(local);
     mailbox_name = libbalsa_mailbox_get_name(mailbox);
-    name = mailbox_name != NULL ? g_strdup(mailbox_name) :
+    name         = mailbox_name != NULL ? g_strdup(mailbox_name) :
         g_path_get_basename(libbalsa_mailbox_local_get_path(local));
 
-    if (stat(filename, &st) < 0
-        || st.st_mtime < libbalsa_mailbox_get_mtime(mailbox)) {
+    if ((stat(filename, &st) < 0)
+        || (st.st_mtime < libbalsa_mailbox_get_mtime(mailbox))) {
         /* No error, but we return FALSE so the caller can grab all the
          * message info needed to rethread from scratch. */
-        if (libbalsa_mailbox_total_messages(mailbox) > 0)
+        if (libbalsa_mailbox_total_messages(mailbox) > 0) {
             libbalsa_information(LIBBALSA_INFORMATION_DEBUG,
                                  _("Cache file for mailbox %s "
                                    "will be created"), name);
+        }
         g_free(filename);
         g_free(name);
         return FALSE;
@@ -640,12 +682,12 @@ lbm_local_restore_tree(LibBalsaMailboxLocal * local, guint * total)
 
     info = (LibBalsaMailboxLocalTreeInfo *) contents;
     /* Sanity checks: first the file should have >= 1 record. */
-    if (length < sizeof(LibBalsaMailboxLocalTreeInfo)
+    if ((length < sizeof(LibBalsaMailboxLocalTreeInfo))
         /* First record is (0, total): */
-        || info->msgno != 0
+        || (info->msgno != 0)
         /* Total must be > 0 (no file is created for empty tree). */
-        || info->value.total == 0
-        || info->value.total > libbalsa_mailbox_total_messages(mailbox)) {
+        || (info->value.total == 0)
+        || (info->value.total > libbalsa_mailbox_total_messages(mailbox))) {
         libbalsa_information(LIBBALSA_INFORMATION_DEBUG,
                              _("Cache file for mailbox %s "
                                "will be repaired"), name);
@@ -655,13 +697,13 @@ lbm_local_restore_tree(LibBalsaMailboxLocal * local, guint * total)
     }
     *total = info->value.total;
 
-    seen = g_new0(guint8, *total);
-    parent = libbalsa_mailbox_get_msg_tree(mailbox);
-    sibling = NULL;
+    seen     = g_new0(guint8, *total);
+    parent   = libbalsa_mailbox_get_msg_tree(mailbox);
+    sibling  = NULL;
     get_info = LIBBALSA_MAILBOX_LOCAL_GET_CLASS(local)->get_info;
     while (++info < (LibBalsaMailboxLocalTreeInfo *) (contents + length)) {
         LibBalsaMailboxLocalMessageInfo *msg_info;
-        if (info->msgno == 0 || info->msgno > *total
+        if ((info->msgno == 0) || (info->msgno > *total)
             || seen[info->msgno - 1]) {
             libbalsa_information(LIBBALSA_INFORMATION_DEBUG,
                                  _("Cache file for mailbox %s "
@@ -674,16 +716,16 @@ lbm_local_restore_tree(LibBalsaMailboxLocal * local, guint * total)
         seen[info->msgno - 1] = TRUE;
 
         if (sibling
-            && info->value.parent == GPOINTER_TO_UINT(sibling->data)) {
+            && (info->value.parent == GPOINTER_TO_UINT(sibling->data))) {
             /* This message is the first child of the previous one. */
-            parent = sibling;
+            parent  = sibling;
             sibling = NULL;
         } else {
             /* Find the parent of this message. */
             while (info->value.parent != GPOINTER_TO_UINT(parent->data)) {
                 /* Check one level higher. */
                 sibling = parent;
-                parent = parent->parent;
+                parent  = parent->parent;
                 if (!parent) {
                     /* We got to the root without finding the parent. */
                     libbalsa_information(LIBBALSA_INFORMATION_DEBUG,
@@ -699,20 +741,20 @@ lbm_local_restore_tree(LibBalsaMailboxLocal * local, guint * total)
         libbalsa_mailbox_msgno_inserted(mailbox, info->msgno,
                                         parent, &sibling);
 
-        msg_info = get_info(local, info->msgno);
+        msg_info         = get_info(local, info->msgno);
         msg_info->loaded = TRUE;
 
         if (libbalsa_mailbox_msgno_has_flags(mailbox, info->msgno,
                                              LIBBALSA_MESSAGE_FLAG_NEW,
-                                             LIBBALSA_MESSAGE_FLAG_DELETED))
-        {
+                                             LIBBALSA_MESSAGE_FLAG_DELETED)) {
             guint first_unread;
 
             libbalsa_mailbox_add_to_unread_messages(mailbox, 1);
 
             first_unread = libbalsa_mailbox_get_first_unread(mailbox);
-            if (first_unread == 0 || first_unread > info->msgno)
+            if ((first_unread == 0) || (first_unread > info->msgno)) {
                 libbalsa_mailbox_set_first_unread(mailbox, info->msgno);
+            }
         }
     }
 
@@ -723,8 +765,9 @@ lbm_local_restore_tree(LibBalsaMailboxLocal * local, guint * total)
     return TRUE;
 }
 
+
 static void
-lbm_local_save_tree_real(LibBalsaMailboxLocal * local)
+lbm_local_save_tree_real(LibBalsaMailboxLocal *local)
 {
     LibBalsaMailboxLocalPrivate *priv =
         libbalsa_mailbox_local_get_instance_private(local);
@@ -732,43 +775,48 @@ lbm_local_save_tree_real(LibBalsaMailboxLocal * local)
 
     libbalsa_lock_mailbox(mailbox);
 
-    if (MAILBOX_OPEN(mailbox) && libbalsa_mailbox_get_msg_tree_changed(mailbox))
+    if (MAILBOX_OPEN(mailbox) && libbalsa_mailbox_get_msg_tree_changed(mailbox)) {
         lbm_local_save_tree(local);
+    }
     priv->save_tree_id = 0;
 
     libbalsa_unlock_mailbox(mailbox);
 }
 
+
 static gboolean
-lbm_local_save_tree_idle(LibBalsaMailboxLocal * local)
+lbm_local_save_tree_idle(LibBalsaMailboxLocal *local)
 {
     lbm_local_save_tree_real(local);
 
     return FALSE;
 }
 
+
 static void
-lbm_local_queue_save_tree(LibBalsaMailboxLocal * local)
+lbm_local_queue_save_tree(LibBalsaMailboxLocal *local)
 {
     LibBalsaMailboxLocalPrivate *priv =
         libbalsa_mailbox_local_get_instance_private(local);
 
     libbalsa_lock_mailbox((LibBalsaMailbox *) local);
-    if (!priv->save_tree_id)
+    if (!priv->save_tree_id) {
         priv->save_tree_id =
             g_idle_add((GSourceFunc) lbm_local_save_tree_idle, local);
+    }
     libbalsa_unlock_mailbox((LibBalsaMailbox *) local);
 }
 
-/* 
+
+/*
  * End of save and restore the message tree.
  */
 
 static void
-libbalsa_mailbox_local_close_mailbox(LibBalsaMailbox * mailbox,
-                                     gboolean expunge)
+libbalsa_mailbox_local_close_mailbox(LibBalsaMailbox *mailbox,
+                                     gboolean         expunge)
 {
-    LibBalsaMailboxLocal *local = LIBBALSA_MAILBOX_LOCAL(mailbox);
+    LibBalsaMailboxLocal *local       = LIBBALSA_MAILBOX_LOCAL(mailbox);
     LibBalsaMailboxLocalPrivate *priv =
         libbalsa_mailbox_local_get_instance_private(local);
     guint i;
@@ -790,13 +838,13 @@ libbalsa_mailbox_local_close_mailbox(LibBalsaMailbox * mailbox,
         libbalsa_mailbox_set_threading(mailbox, cur_type);
     }
 
-        /* Save immediately. */
+    /* Save immediately. */
     libbalsa_clear_source_id(&priv->save_tree_id);
     lbm_local_save_tree(local);
 
     if (priv->threading_info) {
-       /* Free the memory owned by priv->threading_info, but neither
-        * free nor truncate the array. */
+        /* Free the memory owned by priv->threading_info, but neither
+         * free nor truncate the array. */
         for (i = priv->threading_info->len; i > 0;) {
             gpointer *entry =
                 &g_ptr_array_index(priv->threading_info, --i);
@@ -812,15 +860,18 @@ libbalsa_mailbox_local_close_mailbox(LibBalsaMailbox * mailbox,
     }
     priv->pool_seqno = 0;
 
-    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_local_parent_class)->close_mailbox)
+    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_local_parent_class)->close_mailbox) {
         LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_local_parent_class)->close_mailbox(mailbox,
-                                                            expunge);
+                                                                                   expunge);
+    }
 }
 
+
 /* LibBalsaMailbox get_message class method */
 
 static LibBalsaMessage *
-libbalsa_mailbox_local_get_message(LibBalsaMailbox * mailbox, guint msgno)
+libbalsa_mailbox_local_get_message(LibBalsaMailbox *mailbox,
+                                   guint            msgno)
 {
     LibBalsaMailboxLocal *local = LIBBALSA_MAILBOX_LOCAL(mailbox);
     LibBalsaMailboxLocalMessageInfo *msg_info;
@@ -828,31 +879,34 @@ libbalsa_mailbox_local_get_message(LibBalsaMailbox * mailbox, guint msgno)
     g_assert(LIBBALSA_MAILBOX_LOCAL_GET_CLASS(local) != NULL);
     msg_info = LIBBALSA_MAILBOX_LOCAL_GET_CLASS(local)->get_info(local, msgno);
 
-    if (msg_info->message)
+    if (msg_info->message) {
         return g_object_ref(msg_info->message);
+    }
 
     lbm_local_get_message_with_msg_info(local, msgno, msg_info);
 
     return msg_info->message;
 }
 
+
 /* Search iters. We do not use the fallback version because it does
    lot of reparsing. Instead, we use LibBalsaMailboxIndex entry
    whenever possible - it is so quite frequently. This is a big
    improvement for mailboxes of several megabytes and few thousand
    messages.
-*/
+ */
 
 static gboolean
-message_match_real(LibBalsaMailbox *mailbox, guint msgno,
+message_match_real(LibBalsaMailbox   *mailbox,
+                   guint              msgno,
                    LibBalsaCondition *cond)
 {
-    LibBalsaMailboxLocal *local = (LibBalsaMailboxLocal *) mailbox;
+    LibBalsaMailboxLocal *local       = (LibBalsaMailboxLocal *) mailbox;
     LibBalsaMailboxLocalPrivate *priv =
         libbalsa_mailbox_local_get_instance_private(local);
-    LibBalsaMessage *message = NULL;
-    gboolean match = FALSE;
-    gboolean is_refed = FALSE;
+    LibBalsaMessage *message         = NULL;
+    gboolean match                   = FALSE;
+    gboolean is_refed                = FALSE;
     LibBalsaMailboxIndexEntry *entry =
         libbalsa_mailbox_get_index_entry(mailbox, msgno);
     LibBalsaMailboxLocalInfo *info =
@@ -864,25 +918,29 @@ message_match_real(LibBalsaMailbox *mailbox, guint msgno,
      * fetch it here, and that will also populate entry and info. */
     if (!entry || !info) {
         message = libbalsa_mailbox_get_message(mailbox, msgno);
-        if (!message)
+        if (!message) {
             return FALSE;
+        }
         libbalsa_mailbox_local_cache_message(local, msgno, message);
         entry = libbalsa_mailbox_get_index_entry(mailbox, msgno);
         info  = g_ptr_array_index(priv->threading_info, msgno - 1);
     }
 
-    if (entry->idle_pending)
+    if (entry->idle_pending) {
         return FALSE;   /* Can't match. */
 
+    }
     switch (cond->type) {
     case CONDITION_STRING:
         if (CONDITION_CHKMATCH(cond, (CONDITION_MATCH_TO |
                                       CONDITION_MATCH_CC |
                                       CONDITION_MATCH_BODY))) {
-            if (!message)
+            if (!message) {
                 message = libbalsa_mailbox_get_message(mailbox, msgno);
-            if (!message)
+            }
+            if (!message) {
                 return FALSE;
+            }
             is_refed = libbalsa_message_body_ref(message, FALSE, FALSE);
             if (!is_refed) {
                 libbalsa_information(LIBBALSA_INFORMATION_ERROR,
@@ -894,7 +952,7 @@ message_match_real(LibBalsaMailbox *mailbox, guint msgno,
         }
 
         /* do the work */
-       if (CONDITION_CHKMATCH(cond,CONDITION_MATCH_TO)) {
+        if (CONDITION_CHKMATCH(cond, CONDITION_MATCH_TO)) {
             g_assert(is_refed);
             if (message->headers->to_list) {
                 gchar *str =
@@ -903,25 +961,26 @@ message_match_real(LibBalsaMailbox *mailbox, guint msgno,
                 match =
                     libbalsa_utf8_strstr(str, cond->match.string.string);
                 g_free(str);
-                if (match)
+                if (match) {
                     break;
+                }
             }
-       }
+        }
         if (CONDITION_CHKMATCH(cond, CONDITION_MATCH_FROM)) {
-           if (libbalsa_utf8_strstr(info->sender,
-                                     cond->match.string.string)) { 
+            if (libbalsa_utf8_strstr(info->sender,
+                                     cond->match.string.string)) {
                 match = TRUE;
                 break;
             }
         }
-       if (CONDITION_CHKMATCH(cond,CONDITION_MATCH_SUBJECT)) {
-           if (libbalsa_utf8_strstr(entry->subject,
-                                     cond->match.string.string)) { 
+        if (CONDITION_CHKMATCH(cond, CONDITION_MATCH_SUBJECT)) {
+            if (libbalsa_utf8_strstr(entry->subject,
+                                     cond->match.string.string)) {
                 match = TRUE;
                 break;
             }
-       }
-       if (CONDITION_CHKMATCH(cond,CONDITION_MATCH_CC)) {
+        }
+        if (CONDITION_CHKMATCH(cond, CONDITION_MATCH_CC)) {
             g_assert(is_refed);
             if (message->headers->cc_list) {
                 gchar *str =
@@ -930,18 +989,21 @@ message_match_real(LibBalsaMailbox *mailbox, guint msgno,
                 match =
                     libbalsa_utf8_strstr(str, cond->match.string.string);
                 g_free(str);
-                if (match)
+                if (match) {
                     break;
+                }
             }
-       }
-       if (CONDITION_CHKMATCH(cond,CONDITION_MATCH_US_HEAD)) {
+        }
+        if (CONDITION_CHKMATCH(cond, CONDITION_MATCH_US_HEAD)) {
             if (cond->match.string.user_header) {
                 const gchar *header;
 
-                if (!message)
+                if (!message) {
                     message = libbalsa_mailbox_get_message(mailbox, msgno);
-                if (!message)
+                }
+                if (!message) {
                     return FALSE;
+                }
                 header =
                     libbalsa_message_get_user_header(message,
                                                      cond->match.string.
@@ -952,66 +1014,78 @@ message_match_real(LibBalsaMailbox *mailbox, guint msgno,
                     break;
                 }
             }
-       }
-       if (CONDITION_CHKMATCH(cond,CONDITION_MATCH_BODY)) {
+        }
+        if (CONDITION_CHKMATCH(cond, CONDITION_MATCH_BODY)) {
             GString *body;
             g_assert(is_refed);
-           if (!message->mailbox) {
+            if (!message->mailbox) {
                 /* No need to body-unref */
                 g_object_unref(message);
-               return FALSE; /* We don't want to match if an error occurred */
+                return FALSE; /* We don't want to match if an error occurred */
             }
             body = content2reply(message->body_list, NULL, 0, FALSE, FALSE);
-           if (body) {
-               if (body->str)
+            if (body) {
+                if (body->str) {
                     match = libbalsa_utf8_strstr(body->str,
                                                  cond->match.string.string);
-               g_string_free(body,TRUE);
-           }
-       }
-       break;
+                }
+                g_string_free(body, TRUE);
+            }
+        }
+        break;
+
     case CONDITION_REGEX:
         break;
+
     case CONDITION_DATE:
-        match = 
+        match =
             entry->msg_date >= cond->match.date.date_low &&
-            (cond->match.date.date_high==0 || 
-             entry->msg_date<=cond->match.date.date_high);
+            (cond->match.date.date_high == 0 ||
+             entry->msg_date <= cond->match.date.date_high);
         break;
+
     case CONDITION_FLAG:
         match = libbalsa_mailbox_msgno_has_flags(mailbox, msgno,
                                                  cond->match.flags, 0);
         break;
+
     case CONDITION_AND:
         match =
             message_match_real(mailbox, msgno, cond->match.andor.left) &&
             message_match_real(mailbox, msgno, cond->match.andor.right);
         break;
+
     case CONDITION_OR:
         match =
             message_match_real(mailbox, msgno, cond->match.andor.left) ||
             message_match_real(mailbox, msgno, cond->match.andor.right);
         break;
+
     /* To avoid warnings */
     case CONDITION_NONE:
         break;
     }
-    if(message) {
-        if(is_refed) libbalsa_message_body_unref(message);
+    if (message) {
+        if (is_refed) {
+            libbalsa_message_body_unref(message);
+        }
         g_object_unref(message);
     }
     return cond->negate ? !match : match;
 }
+
+
 static gboolean
-libbalsa_mailbox_local_message_match(LibBalsaMailbox * mailbox,
-                                    guint msgno,
-                                    LibBalsaMailboxSearchIter * iter)
+libbalsa_mailbox_local_message_match(LibBalsaMailbox           *mailbox,
+                                     guint                      msgno,
+                                     LibBalsaMailboxSearchIter *iter)
 {
     return message_match_real(mailbox, msgno, iter->condition);
 }
 
+
 /*
- * private 
+ * private
  * PS: called by mail_progress_notify_cb:
  * loads incrementally new messages, if any.
  *  Mailbox lock MUST BE HELD before calling this function.
@@ -1021,55 +1095,63 @@ libbalsa_mailbox_local_message_match(LibBalsaMailbox * mailbox,
  *  other info.
  */
 void
-libbalsa_mailbox_local_cache_message(LibBalsaMailboxLocal * local,
-                                     guint msgno,
-                                     LibBalsaMessage * message)
+libbalsa_mailbox_local_cache_message(LibBalsaMailboxLocal *local,
+                                     guint                 msgno,
+                                     LibBalsaMessage      *message)
 {
     LibBalsaMailboxLocalPrivate *priv =
         libbalsa_mailbox_local_get_instance_private(local);
     gpointer *entry;
     LibBalsaMailboxLocalInfo *info;
 
-    if (!message)
+    if (!message) {
         return;
+    }
 
     libbalsa_mailbox_cache_message(LIBBALSA_MAILBOX(local), msgno,
                                    message);
 
-    if (!priv->threading_info)
+    if (!priv->threading_info) {
         return;
+    }
 
-    while (priv->threading_info->len < msgno)
+    while (priv->threading_info->len < msgno) {
         g_ptr_array_add(priv->threading_info, NULL);
+    }
     entry = &g_ptr_array_index(priv->threading_info, msgno - 1);
 
-    if (*entry)
+    if (*entry) {
         return;
+    }
 
-    *entry = info = g_new(LibBalsaMailboxLocalInfo, 1);
-    info->message_id = g_strdup(message->message_id);
+    *entry                   = info = g_new(LibBalsaMailboxLocalInfo, 1);
+    info->message_id         = g_strdup(message->message_id);
     info->refs_for_threading =
         libbalsa_message_refs_for_threading(message);
 
     info->sender = NULL;
-    if (message->headers->from)
+    if (message->headers->from) {
         info->sender =
             internet_address_list_to_string(message->headers->from, FALSE);
-    if (!info->sender)
+    }
+    if (!info->sender) {
         info->sender = g_strdup("");
+    }
 }
 
+
 static gboolean
-lbml_load_messages_idle_cb(LibBalsaMailbox * mailbox)
+lbml_load_messages_idle_cb(LibBalsaMailbox *mailbox)
 {
-    LibBalsaMailboxLocal *local = (LibBalsaMailboxLocal *) mailbox;
+    LibBalsaMailboxLocal *local       = (LibBalsaMailboxLocal *) mailbox;
     LibBalsaMailboxLocalPrivate *priv =
         libbalsa_mailbox_local_get_instance_private(local);
     guint msgno;
     guint new_messages;
     guint lastno;
     GNode *lastn;
-    LibBalsaMailboxLocalMessageInfo *(*get_info) (LibBalsaMailboxLocal *, guint);
+    LibBalsaMailboxLocalMessageInfo *(*get_info) (LibBalsaMailboxLocal *,
+                                                  guint);
 
     g_assert(LIBBALSA_MAILBOX_LOCAL_GET_CLASS(local) != NULL);
 
@@ -1077,42 +1159,44 @@ lbml_load_messages_idle_cb(LibBalsaMailbox * mailbox)
     priv->load_messages_id = 0;
 
     if (!libbalsa_mailbox_get_msg_tree(mailbox)) {
-       /* Mailbox is closed, or no view has been created. */
+        /* Mailbox is closed, or no view has been created. */
         libbalsa_unlock_mailbox(mailbox);
-       return FALSE;
+        return FALSE;
     }
 
-    lastno = libbalsa_mailbox_total_messages(mailbox);
-    msgno = priv->msgno;
+    lastno       = libbalsa_mailbox_total_messages(mailbox);
+    msgno        = priv->msgno;
     new_messages = lastno - msgno;
-    lastn = g_node_last_child(libbalsa_mailbox_get_msg_tree(mailbox));
-    get_info = LIBBALSA_MAILBOX_LOCAL_GET_CLASS(local)->get_info;
-    while (++msgno <= lastno){
+    lastn        = g_node_last_child(libbalsa_mailbox_get_msg_tree(mailbox));
+    get_info     = LIBBALSA_MAILBOX_LOCAL_GET_CLASS(local)->get_info;
+    while (++msgno <= lastno) {
         LibBalsaMailboxLocalMessageInfo *msg_info = get_info(local, msgno);
 
-       libbalsa_mailbox_local_load_message(local, &lastn, msgno, msg_info);
+        libbalsa_mailbox_local_load_message(local, &lastn, msgno, msg_info);
 
-       if (msg_info->message)
+        if (msg_info->message) {
             libbalsa_mailbox_local_cache_message(local, msgno,
                                                  msg_info->message);
+        }
     }
 
     if (new_messages) {
-       libbalsa_mailbox_run_filters_on_reception(mailbox);
-       libbalsa_mailbox_set_unread_messages_flag(mailbox,
-                                                 libbalsa_mailbox_get_unread_messages
-                                                  (mailbox) > 0);
+        libbalsa_mailbox_run_filters_on_reception(mailbox);
+        libbalsa_mailbox_set_unread_messages_flag(mailbox,
+                                                  libbalsa_mailbox_get_unread_messages
+                                                      (mailbox) > 0);
     }
 
     libbalsa_unlock_mailbox(mailbox);
     return FALSE;
 }
 
+
 void
 libbalsa_mailbox_local_load_messages(LibBalsaMailbox *mailbox,
-                                     guint msgno)
+                                     guint            msgno)
 {
-    LibBalsaMailboxLocal *local = (LibBalsaMailboxLocal *) mailbox;
+    LibBalsaMailboxLocal *local       = (LibBalsaMailboxLocal *) mailbox;
     LibBalsaMailboxLocalPrivate *priv =
         libbalsa_mailbox_local_get_instance_private(local);
 
@@ -1120,39 +1204,43 @@ libbalsa_mailbox_local_load_messages(LibBalsaMailbox *mailbox,
 
     libbalsa_lock_mailbox(mailbox);
     if (!priv->load_messages_id) {
-        priv->msgno = msgno;
+        priv->msgno            = msgno;
         priv->load_messages_id =
             g_idle_add((GSourceFunc) lbml_load_messages_idle_cb, mailbox);
     }
     libbalsa_unlock_mailbox(mailbox);
 }
 
+
 /*
  * Threading
  */
 
-static void lbml_threading_jwz(LibBalsaMailbox * mailbox);
-static void lbml_threading_simple(LibBalsaMailbox * mailbox,
-                                 LibBalsaMailboxThreadingType th_type);
+static void lbml_threading_jwz(LibBalsaMailbox *mailbox);
+static void lbml_threading_simple(LibBalsaMailbox             *mailbox,
+                                  LibBalsaMailboxThreadingType th_type);
 
-void 
-libbalsa_mailbox_local_set_threading_info(LibBalsaMailboxLocal * local)
+void
+libbalsa_mailbox_local_set_threading_info(LibBalsaMailboxLocal *local)
 {
     LibBalsaMailboxLocalPrivate *priv =
         libbalsa_mailbox_local_get_instance_private(local);
 
-    if (!priv->threading_info)
+    if (!priv->threading_info) {
         priv->threading_info = g_ptr_array_new();
+    }
 }
 
+
 static void
-lbml_set_threading(LibBalsaMailbox * mailbox,
+lbml_set_threading(LibBalsaMailbox             *mailbox,
                    LibBalsaMailboxThreadingType thread_type)
 {
     switch (thread_type) {
     case LB_MAILBOX_THREADING_JWZ:
         lbml_threading_jwz(mailbox);
         break;
+
     case LB_MAILBOX_THREADING_FLAT:
     case LB_MAILBOX_THREADING_SIMPLE:
         lbml_threading_simple(mailbox, thread_type);
@@ -1160,13 +1248,14 @@ lbml_set_threading(LibBalsaMailbox * mailbox,
     }
 }
 
+
 typedef struct {
     LibBalsaMailbox *mailbox;
     LibBalsaMailboxThreadingType thread_type;
 } LbmlSetThreadingInfo;
 
 static gboolean
-lbml_set_threading_idle_cb(LbmlSetThreadingInfo * info)
+lbml_set_threading_idle_cb(LbmlSetThreadingInfo *info)
 {
     lbml_set_threading(info->mailbox, info->thread_type);
     g_object_unref(info->mailbox);
@@ -1174,8 +1263,9 @@ lbml_set_threading_idle_cb(LbmlSetThreadingInfo * info)
     return FALSE;
 }
 
+
 static void
-libbalsa_mailbox_local_set_threading(LibBalsaMailbox * mailbox,
+libbalsa_mailbox_local_set_threading(LibBalsaMailbox *mailbox,
                                      LibBalsaMailboxThreadingType
                                      thread_type)
 {
@@ -1186,7 +1276,7 @@ libbalsa_mailbox_local_set_threading(LibBalsaMailbox * mailbox,
     printf("before load_messages: time=%lu\n", (unsigned long) time(NULL));
 #endif
     if (!libbalsa_mailbox_get_msg_tree(mailbox)) {   /* first reference */
-        guint total = 0;
+        guint total      = 0;
         gboolean natural = (thread_type == LB_MAILBOX_THREADING_FLAT
                             && libbalsa_mailbox_get_sort_field(mailbox) ==
                             LB_MAILBOX_SORT_NO);
@@ -1200,27 +1290,29 @@ libbalsa_mailbox_local_set_threading(LibBalsaMailbox * mailbox,
         libbalsa_mailbox_set_msg_tree_changed (mailbox, FALSE);
 
         if (total < libbalsa_mailbox_total_messages(mailbox)) {
-            if (!natural)
+            if (!natural) {
                 /* Get message info for all messages that weren't restored,
                  * so we can thread and sort them correctly before the
                  * mailbox is displayed. */
                 libbalsa_mailbox_prepare_threading(mailbox, total);
+            }
             libbalsa_mailbox_local_load_messages(mailbox, total);
         }
 
 #if defined(DEBUG_LOADING_AND_THREADING)
         printf("after load messages: time=%lu\n", (unsigned long) time(NULL));
 #endif
-        if (natural)
+        if (natural) {
             /* No need to thread. */
             return;
+        }
     }
 
     if (libbalsa_am_i_subthread()) {
         LbmlSetThreadingInfo *info;
 
-        info = g_slice_new(LbmlSetThreadingInfo);
-        info->mailbox = g_object_ref(mailbox);
+        info              = g_slice_new(LbmlSetThreadingInfo);
+        info->mailbox     = g_object_ref(mailbox);
         info->thread_type = thread_type;
         g_idle_add((GSourceFunc) lbml_set_threading_idle_cb, info);
     } else {
@@ -1233,28 +1325,30 @@ libbalsa_mailbox_local_set_threading(LibBalsaMailbox * mailbox,
     lbm_local_queue_save_tree(local);
 }
 
+
 void
-libbalsa_mailbox_local_msgno_removed(LibBalsaMailbox * mailbox,
-                                    guint msgno)
+libbalsa_mailbox_local_msgno_removed(LibBalsaMailbox *mailbox,
+                                     guint            msgno)
 {
-    LibBalsaMailboxLocal *local = LIBBALSA_MAILBOX_LOCAL(mailbox);
+    LibBalsaMailboxLocal *local       = LIBBALSA_MAILBOX_LOCAL(mailbox);
     LibBalsaMailboxLocalPrivate *priv =
         libbalsa_mailbox_local_get_instance_private(local);
 
     /* local might not have a threading-info array, and even if it does,
      * it might not be populated; we check both. */
-    if (priv->threading_info && msgno <= priv->threading_info->len) {
-       lbm_local_free_info(g_ptr_array_index(priv->threading_info,
-                                             msgno - 1));
-       g_ptr_array_remove_index(priv->threading_info, msgno - 1);
+    if (priv->threading_info && (msgno <= priv->threading_info->len)) {
+        lbm_local_free_info(g_ptr_array_index(priv->threading_info,
+                                              msgno - 1));
+        g_ptr_array_remove_index(priv->threading_info, msgno - 1);
     }
 
     libbalsa_mailbox_msgno_removed(mailbox, msgno);
 }
 
+
 static void
-lbm_local_update_view_filter(LibBalsaMailbox * mailbox,
-                             LibBalsaCondition * view_filter)
+lbm_local_update_view_filter(LibBalsaMailbox   *mailbox,
+                             LibBalsaCondition *view_filter)
 {
     guint total;
     LibBalsaProgress progress = LIBBALSA_PROGRESS_INIT;
@@ -1285,10 +1379,12 @@ lbm_local_update_view_filter(LibBalsaMailbox * mailbox,
 
     /* If this is not a flags-only filter, the new mailbox tree is
      * temporary, so we don't want to save it. */
-    if (is_flag_only)
+    if (is_flag_only) {
         lbm_local_queue_save_tree(LIBBALSA_MAILBOX_LOCAL(mailbox));
+    }
 }
 
+
 /*
  * Prepare-threading method: brute force--create and destroy the
  * LibBalsaMessage; the back end is responsible for caching it here and
@@ -1298,20 +1394,23 @@ lbm_local_update_view_filter(LibBalsaMailbox * mailbox,
 /* Helper: returns TRUE if msgno was not already cached, which means we
  * have new data for sorting or threading. */
 static gboolean
-lbm_local_prepare_msgno(LibBalsaMailboxLocal * local, guint msgno)
+lbm_local_prepare_msgno(LibBalsaMailboxLocal *local,
+                        guint                 msgno)
 {
     LibBalsaMailboxLocalPrivate *priv =
         libbalsa_mailbox_local_get_instance_private(local);
     LibBalsaMessage *message;
 
-    if (msgno <= priv->threading_info->len
-        && g_ptr_array_index(priv->threading_info, msgno - 1))
+    if ((msgno <= priv->threading_info->len)
+        && g_ptr_array_index(priv->threading_info, msgno - 1)) {
         return FALSE;
+    }
 
     message =
         libbalsa_mailbox_get_message((LibBalsaMailbox *) local, msgno);
-    if (!message)
+    if (!message) {
         return FALSE;
+    }
 
     libbalsa_mailbox_local_cache_message(local, msgno, message);
     g_object_unref(message);
@@ -1319,9 +1418,10 @@ lbm_local_prepare_msgno(LibBalsaMailboxLocal * local, guint msgno)
     return TRUE;
 }
 
+
 /* Idle handler. */
 static gboolean
-lbm_local_thread_idle(LibBalsaMailboxLocal * local)
+lbm_local_thread_idle(LibBalsaMailboxLocal *local)
 {
     LibBalsaMailboxLocalPrivate *priv =
         libbalsa_mailbox_local_get_instance_private(local);
@@ -1343,13 +1443,14 @@ lbm_local_thread_idle(LibBalsaMailboxLocal * local)
     return FALSE;
 }
 
+
 /* The class method; prepare messages from start + 1 to the end of the
  * mailbox; return TRUE if successful. */
 static gboolean
-libbalsa_mailbox_local_prepare_threading(LibBalsaMailbox * mailbox,
-                                         guint start)
+libbalsa_mailbox_local_prepare_threading(LibBalsaMailbox *mailbox,
+                                         guint            start)
 {
-    LibBalsaMailboxLocal *local = LIBBALSA_MAILBOX_LOCAL(mailbox);
+    LibBalsaMailboxLocal *local       = LIBBALSA_MAILBOX_LOCAL(mailbox);
     LibBalsaMailboxLocalPrivate *priv =
         libbalsa_mailbox_local_get_instance_private(local);
     guint msgno;
@@ -1357,12 +1458,12 @@ libbalsa_mailbox_local_prepare_threading(LibBalsaMailbox * mailbox,
     gchar *text;
     guint total;
     LibBalsaProgress progress = LIBBALSA_PROGRESS_INIT;
-    gboolean retval = TRUE;
+    gboolean retval           = TRUE;
 
     libbalsa_lock_mailbox(mailbox);
     libbalsa_mailbox_local_set_threading_info(local);
 
-    text = g_strdup_printf(_("Preparing %s"), libbalsa_mailbox_get_name(mailbox));
+    text  = g_strdup_printf(_("Preparing %s"), libbalsa_mailbox_get_name(mailbox));
     total = libbalsa_mailbox_total_messages(mailbox);
     libbalsa_progress_set_text(&progress, text, total - start);
     g_free(text);
@@ -1384,10 +1485,10 @@ libbalsa_mailbox_local_prepare_threading(LibBalsaMailbox * mailbox,
     libbalsa_progress_set_text(&progress, NULL, 0);
 
     if (retval && need_thread && !priv->thread_id) {
-        if (libbalsa_mailbox_get_threading_type(mailbox) !=
-            LB_MAILBOX_THREADING_FLAT
-            || libbalsa_mailbox_get_sort_field(mailbox) !=
-            LB_MAILBOX_SORT_NO) {
+        if ((libbalsa_mailbox_get_threading_type(mailbox) !=
+             LB_MAILBOX_THREADING_FLAT)
+            || (libbalsa_mailbox_get_sort_field(mailbox) !=
+                LB_MAILBOX_SORT_NO)) {
             g_object_ref(local);
             priv->thread_id =
                 g_idle_add((GSourceFunc) lbm_local_thread_idle, local);
@@ -1398,30 +1499,32 @@ libbalsa_mailbox_local_prepare_threading(LibBalsaMailbox * mailbox,
     return retval;
 }
 
+
 /* fetch message structure method: all local mailboxes have their own
  * methods, which ensure that message->mime_msg != NULL, then chain up
  * to this one.
  */
 
 static gboolean
-libbalsa_mailbox_local_fetch_structure(LibBalsaMailbox *mailbox,
-                                       LibBalsaMessage *message,
+libbalsa_mailbox_local_fetch_structure(LibBalsaMailbox  *mailbox,
+                                       LibBalsaMessage  *message,
                                        LibBalsaFetchFlag flags)
 {
     GMimeMessage *mime_message = message->mime_msg;
 
-    if (!mime_message || !mime_message->mime_part)
-       return FALSE;
+    if (!mime_message || !mime_message->mime_part) {
+        return FALSE;
+    }
 
-    if(flags & LB_FETCH_STRUCTURE) {
+    if (flags & LB_FETCH_STRUCTURE) {
         LibBalsaMessageBody *body = libbalsa_message_body_new(message);
         libbalsa_message_body_set_mime_body(body,
                                             mime_message->mime_part);
         libbalsa_message_append_part(message, body);
         libbalsa_message_headers_from_gmime(message->headers, mime_message);
     }
-    if(flags & LB_FETCH_RFC822_HEADERS) {
-        message->headers->user_hdrs = 
+    if (flags & LB_FETCH_RFC822_HEADERS) {
+        message->headers->user_hdrs =
             libbalsa_message_user_hdrs_from_gmime(mime_message);
         message->has_all_headers = 1;
     }
@@ -1429,45 +1532,48 @@ libbalsa_mailbox_local_fetch_structure(LibBalsaMailbox *mailbox,
     return TRUE;
 }
 
+
 static void
-libbalsa_mailbox_local_fetch_headers(LibBalsaMailbox * mailbox,
-                                    LibBalsaMessage * message)
+libbalsa_mailbox_local_fetch_headers(LibBalsaMailbox *mailbox,
+                                     LibBalsaMessage *message)
 {
     g_return_if_fail(message->headers->user_hdrs == NULL);
 
-    if (message->mime_msg)
-       message->headers->user_hdrs =
-           libbalsa_message_user_hdrs_from_gmime(message->mime_msg);
-    else {
-       libbalsa_mailbox_fetch_message_structure(mailbox, message,
-                                                LB_FETCH_RFC822_HEADERS);
-       libbalsa_mailbox_release_message(mailbox, message);
+    if (message->mime_msg) {
+        message->headers->user_hdrs =
+            libbalsa_message_user_hdrs_from_gmime(message->mime_msg);
+    } else {
+        libbalsa_mailbox_fetch_message_structure(mailbox, message,
+                                                 LB_FETCH_RFC822_HEADERS);
+        libbalsa_mailbox_release_message(mailbox, message);
     }
 }
 
+
 static gboolean
-libbalsa_mailbox_local_get_msg_part(LibBalsaMessage *msg,
+libbalsa_mailbox_local_get_msg_part(LibBalsaMessage     *msg,
                                     LibBalsaMessageBody *part,
-                                    GError **err)
+                                    GError             **err)
 {
     g_return_val_if_fail(part->mime_part, FALSE);
 
     return GMIME_IS_PART(part->mime_part)
-        || GMIME_IS_MULTIPART(part->mime_part)
-       || GMIME_IS_MESSAGE_PART(part->mime_part);
+           || GMIME_IS_MULTIPART(part->mime_part)
+           || GMIME_IS_MESSAGE_PART(part->mime_part);
 }
 
+
 /*--------------------------------*/
 /*  Start of threading functions  */
 /*--------------------------------*/
 /*
  * This code includes two message threading functions.
  * The first is the implementation of jwz's algorithm describled at
- * http://www.jwz.org/doc/threading.html . The another is very simple and 
- * trivial one. If you confirm that your mailbox includes every threaded 
+ * http://www.jwz.org/doc/threading.html . The another is very simple and
+ * trivial one. If you confirm that your mailbox includes every threaded
  * messages, the later will be enough. Those functions are selectable on
  * each mailbox by setting the 'type' member in BalsaIndex. If you don't need
- * message threading functionality, just specify 'LB_MAILBOX_THREADING_FLAT'. 
+ * message threading functionality, just specify 'LB_MAILBOX_THREADING_FLAT'.
  *
  * ymnk jcraft com
  */
@@ -1481,41 +1587,52 @@ struct _ThreadingInfo {
 };
 typedef struct _ThreadingInfo ThreadingInfo;
 
-static gboolean lbml_set_parent(GNode * node, ThreadingInfo * ti);
-static GNode *lbml_insert_node(GNode * node,
-                               LibBalsaMailboxLocalInfo * info,
-                               ThreadingInfo * ti);
-static GNode *lbml_find_parent(LibBalsaMailboxLocalInfo * info,
-                              ThreadingInfo * ti);
-static gboolean lbml_prune(GNode * node, ThreadingInfo * ti);
-static void lbml_subject_gather(GNode * node, ThreadingInfo * ti);
-static void lbml_subject_merge(GNode * node, ThreadingInfo * ti);
-static const gchar *lbml_chop_re(const gchar * str);
-static gboolean lbml_construct(GNode * node, ThreadingInfo * ti);
+static gboolean lbml_set_parent(GNode         *node,
+                                ThreadingInfo *ti);
+static GNode   *lbml_insert_node(GNode                    *node,
+                                 LibBalsaMailboxLocalInfo *info,
+                                 ThreadingInfo            *ti);
+static GNode       *lbml_find_parent(LibBalsaMailboxLocalInfo *info,
+                                     ThreadingInfo            *ti);
+static gboolean     lbml_prune(GNode         *node,
+                               ThreadingInfo *ti);
+static void         lbml_subject_gather(GNode         *node,
+                                        ThreadingInfo *ti);
+static void         lbml_subject_merge(GNode         *node,
+                                       ThreadingInfo *ti);
+static const gchar *lbml_chop_re(const gchar *str);
+static gboolean     lbml_construct(GNode         *node,
+                                   ThreadingInfo *ti);
+
 #ifdef MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT
-static void lbml_clear_empty(GNode * root);
-#endif                         /* MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT */
+static void lbml_clear_empty(GNode *root);
+
+#endif                          /* MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT */
 
 static void
-lbml_info_setup(LibBalsaMailbox * mailbox, ThreadingInfo * ti)
+lbml_info_setup(LibBalsaMailbox *mailbox,
+                ThreadingInfo   *ti)
 {
-    ti->mailbox = mailbox;
-    ti->root = g_node_new(libbalsa_mailbox_get_msg_tree(mailbox));
-    ti->id_table = g_hash_table_new(g_str_hash, g_str_equal);
+    ti->mailbox       = mailbox;
+    ti->root          = g_node_new(libbalsa_mailbox_get_msg_tree(mailbox));
+    ti->id_table      = g_hash_table_new(g_str_hash, g_str_equal);
     ti->subject_table = NULL;
 }
 
+
 static void
-lbml_info_free(ThreadingInfo * ti)
+lbml_info_free(ThreadingInfo *ti)
 {
     g_hash_table_destroy(ti->id_table);
-    if (ti->subject_table)
-       g_hash_table_destroy(ti->subject_table);
+    if (ti->subject_table) {
+        g_hash_table_destroy(ti->subject_table);
+    }
     g_node_destroy(ti->root);
 }
 
+
 static void
-lbml_threading_jwz(LibBalsaMailbox * mailbox)
+lbml_threading_jwz(LibBalsaMailbox *mailbox)
 {
     /* This implementation of JWZ's algorithm uses a second tree, rooted
      * at ti.root, for the message IDs.  Each node in the second tree
@@ -1530,17 +1647,17 @@ lbml_threading_jwz(LibBalsaMailbox * mailbox)
 
     /* Traverse the mailbox's msg_tree, to build the second tree. */
     g_node_traverse(libbalsa_mailbox_get_msg_tree(mailbox), G_POST_ORDER, G_TRAVERSE_ALL, -1,
-                   (GNodeTraverseFunc) lbml_set_parent, &ti);
+                    (GNodeTraverseFunc) lbml_set_parent, &ti);
     /* Prune the second tree. */
     g_node_traverse(ti.root, G_POST_ORDER, G_TRAVERSE_ALL, -1,
-                   (GNodeTraverseFunc) lbml_prune, &ti);
+                    (GNodeTraverseFunc) lbml_prune, &ti);
 
     /* Do the evil subject gather and merge on the second tree. */
     ti.subject_table = g_hash_table_new(g_str_hash, g_str_equal);
     g_node_children_foreach(ti.root, G_TRAVERSE_ALL,
-                           (GNodeForeachFunc) lbml_subject_gather, &ti);
+                            (GNodeForeachFunc) lbml_subject_gather, &ti);
     g_node_children_foreach(ti.root, G_TRAVERSE_ALL,
-                           (GNodeForeachFunc) lbml_subject_merge, &ti);
+                            (GNodeForeachFunc) lbml_subject_merge, &ti);
 
     /* Traverse the second tree and reparent corresponding nodes in the
      * mailbox's msg_tree. */
@@ -1549,59 +1666,71 @@ lbml_threading_jwz(LibBalsaMailbox * mailbox)
 
 #ifdef MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT
     lbml_clear_empty(ti.root);
-#endif                         /* MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT */
+#endif                          /* MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT */
 
     lbml_info_free(&ti);
 }
 
+
 static LibBalsaMailboxLocalInfo *
-lbml_get_info(GNode * node, ThreadingInfo * ti)
+lbml_get_info(GNode         *node,
+              ThreadingInfo *ti)
 {
-    LibBalsaMailboxLocal *local = LIBBALSA_MAILBOX_LOCAL(ti->mailbox);
+    LibBalsaMailboxLocal *local       = LIBBALSA_MAILBOX_LOCAL(ti->mailbox);
     LibBalsaMailboxLocalPrivate *priv =
         libbalsa_mailbox_local_get_instance_private(local);
     guint msgno = GPOINTER_TO_UINT(node->data);
     LibBalsaMailboxLocalInfo *info;
 
-    if (msgno == 0 || msgno > priv->threading_info->len)
+    if ((msgno == 0) || (msgno > priv->threading_info->len)) {
         return NULL;
+    }
 
     info = g_ptr_array_index(priv->threading_info, msgno - 1);
 
     return info;
 }
 
+
 static void
-lbml_unlink_and_prepend(GNode * node, GNode * parent)
+lbml_unlink_and_prepend(GNode *node,
+                        GNode *parent)
 {
     g_node_unlink(node);
     g_node_prepend(parent, node);
 }
 
+
 static void
-lbml_move_children(GNode * node, GNode * parent)
+lbml_move_children(GNode *node,
+                   GNode *parent)
 {
     GNode *child;
 
-    while ((child = node->children))
-       lbml_unlink_and_prepend(child, parent);
+    while ((child = node->children)) {
+        lbml_unlink_and_prepend(child, parent);
+    }
 }
 
+
 static gboolean
-lbml_set_parent(GNode * msg_node, ThreadingInfo * ti)
+lbml_set_parent(GNode         *msg_node,
+                ThreadingInfo *ti)
 {
     LibBalsaMailboxLocalInfo *info;
     GNode *node;
     GNode *parent;
     GNode *child;
 
-    if (!msg_node->parent)
-       return FALSE;
+    if (!msg_node->parent) {
+        return FALSE;
+    }
 
     info = lbml_get_info(msg_node, ti);
 
-    if (!info) /* FIXME assert this? */
-       return FALSE;
+    if (!info) { /* FIXME assert this? */
+        return FALSE;
+    }
 
     node = lbml_insert_node(msg_node, info, ti);
 
@@ -1628,25 +1757,26 @@ lbml_set_parent(GNode * msg_node, ThreadingInfo * ti)
 
     parent = lbml_find_parent(info, ti);
 
-    if (node->parent == parent
-       /* Nothing to do... */
-       || node == parent)
-       /* This message listed itself as its parent! Oh well... */
-       return FALSE;
+    if ((node->parent == parent)
+        /* Nothing to do... */
+        || (node == parent)) {
+        /* This message listed itself as its parent! Oh well... */
+        return FALSE;
+    }
 
     child = node->children;
     while (child) {
-       GNode *next = child->next;
-       if (child == parent || g_node_is_ancestor(child, parent)) {
-           /* Prepending node to parent would create a
-            * loop; in lbml_find_parent, we just omit making
-            * the link, but here we really want to link the
-            * message's node to its parent, so we'll fix
-            * the tree: unlink the offending child and prepend it
-            * to the node's parent. */
-           lbml_unlink_and_prepend(child, node->parent);
-       }
-       child = next;
+        GNode *next = child->next;
+        if ((child == parent) || g_node_is_ancestor(child, parent)) {
+            /* Prepending node to parent would create a
+             * loop; in lbml_find_parent, we just omit making
+             * the link, but here we really want to link the
+             * message's node to its parent, so we'll fix
+             * the tree: unlink the offending child and prepend it
+             * to the node's parent. */
+            lbml_unlink_and_prepend(child, node->parent);
+        }
+        child = next;
     }
 
     lbml_unlink_and_prepend(node, parent);
@@ -1654,8 +1784,10 @@ lbml_set_parent(GNode * msg_node, ThreadingInfo * ti)
     return FALSE;
 }
 
+
 static GNode *
-lbml_find_parent(LibBalsaMailboxLocalInfo * info, ThreadingInfo * ti)
+lbml_find_parent(LibBalsaMailboxLocalInfo *info,
+                 ThreadingInfo            *ti)
 {
     /*
      * For each element in the message's References field:
@@ -1676,36 +1808,42 @@ lbml_find_parent(LibBalsaMailboxLocalInfo * info, ThreadingInfo * ti)
     GHashTable *id_table = ti->id_table;
 
     for (reference = info->refs_for_threading; reference;
-        reference = reference->next) {
-       gchar *id = reference->data;
-       GNode *foo = g_hash_table_lookup(id_table, id);
+         reference = reference->next) {
+        gchar *id  = reference->data;
+        GNode *foo = g_hash_table_lookup(id_table, id);
 
-       if (foo == NULL) {
-           foo = g_node_new(NULL);
-           g_hash_table_insert(id_table, id, foo);
-       }
+        if (foo == NULL) {
+            foo = g_node_new(NULL);
+            g_hash_table_insert(id_table, id, foo);
+        }
 
-       /* Avoid nasty surprises. */
-       if (foo != parent && !g_node_is_ancestor(foo, parent))
-           if (!foo->parent || foo->parent == ti->root)
-               lbml_unlink_and_prepend(foo, parent);
+        /* Avoid nasty surprises. */
+        if ((foo != parent) && !g_node_is_ancestor(foo, parent)) {
+            if (!foo->parent || (foo->parent == ti->root)) {
+                lbml_unlink_and_prepend(foo, parent);
+            }
+        }
 
-       parent = foo;
+        parent = foo;
     }
     return parent;
 }
 
+
 static gboolean
-lbml_is_replied(GNode * msg_node, ThreadingInfo * ti)
+lbml_is_replied(GNode         *msg_node,
+                ThreadingInfo *ti)
 {
     guint msgno = GPOINTER_TO_UINT(msg_node->data);
     return libbalsa_mailbox_msgno_get_status(ti->mailbox, msgno)
-       == LIBBALSA_MESSAGE_STATUS_REPLIED;
+           == LIBBALSA_MESSAGE_STATUS_REPLIED;
 }
 
+
 static GNode *
-lbml_insert_node(GNode * msg_node, LibBalsaMailboxLocalInfo * info,
-                ThreadingInfo * ti)
+lbml_insert_node(GNode                    *msg_node,
+                 LibBalsaMailboxLocalInfo *info,
+                 ThreadingInfo            *ti)
 {
     /*
      * If id_table contains an *empty* Container for this ID:
@@ -1716,79 +1854,91 @@ lbml_insert_node(GNode * msg_node, LibBalsaMailboxLocalInfo * info,
      */
     /* We'll make sure that we thread off a replied-to message, if there
      * is one. */
-    GNode *node = NULL;
-    gchar *id = info->message_id;
+    GNode *node          = NULL;
+    gchar *id            = info->message_id;
     GHashTable *id_table = ti->id_table;
 
-    if (id)
-       node = g_hash_table_lookup(id_table, id);
+    if (id) {
+        node = g_hash_table_lookup(id_table, id);
+    }
 
     if (node) {
-       GNode *prev_msg_node = node->data;
-       /* If this message has not been replied to, or if the container
-        * is empty, store it in the container. If there was a message
-        * in the container already, swap it with this one, otherwise
-        * set the current one to NULL. */
-       if (!lbml_is_replied(msg_node, ti) || !prev_msg_node) {
-           node->data = msg_node;
-           msg_node = prev_msg_node;
-       }
+        GNode *prev_msg_node = node->data;
+        /* If this message has not been replied to, or if the container
+         * is empty, store it in the container. If there was a message
+         * in the container already, swap it with this one, otherwise
+         * set the current one to NULL. */
+        if (!lbml_is_replied(msg_node, ti) || !prev_msg_node) {
+            node->data = msg_node;
+            msg_node   = prev_msg_node;
+        }
     }
     /* If we already stored the message in a previously empty container,
      * msg_node is NULL. If either the previous message or the current
      * one has been replied to, msg_node now points to a replied-to
      * message. */
-    if (msg_node)
-       node = g_node_new(msg_node);
+    if (msg_node) {
+        node = g_node_new(msg_node);
+    }
 
-    if (id)
-       g_hash_table_insert(id_table, id, node);
+    if (id) {
+        g_hash_table_insert(id_table, id, node);
+    }
 
     return node;
 }
 
+
 static gboolean
-lbml_prune(GNode * node, ThreadingInfo * ti)
+lbml_prune(GNode         *node,
+           ThreadingInfo *ti)
 {
     /*
-     * Recursively walk all containers under the root set. For each container: 
+     * Recursively walk all containers under the root set. For each container:
      *
-     * + If it is an empty container with no children, nuke it. 
-     * + If the Container has no Message, but does have children, 
-     *   remove this container but promote its children to this level 
-     *  (that is, splice them in to the current child list.) 
+     * + If it is an empty container with no children, nuke it.
+     * + If the Container has no Message, but does have children,
+     *   remove this container but promote its children to this level
+     *  (that is, splice them in to the current child list.)
      *
-     * Do not promote the children if doing so would promote them to 
-     * the root set -- unless there is only one child, in which case, do. 
+     * Do not promote the children if doing so would promote them to
+     * the root set -- unless there is only one child, in which case, do.
      */
 
-    if (node->data != NULL || node == ti->root)
-       return FALSE;
+    if ((node->data != NULL) || (node == ti->root)) {
+        return FALSE;
+    }
 
 #ifdef MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT
-    if (node->children != NULL
-       && (node->parent != ti->root || node->children->next == NULL))
-       lbml_move_children(node, node->parent);
+    if ((node->children != NULL)
+        && ((node->parent != ti->root) || (node->children->next == NULL))) {
+        lbml_move_children(node, node->parent);
+    }
 
-    if (node->children == NULL)
-       g_node_destroy(node);
-#else                          /* MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT */
+    if (node->children == NULL) {
+        g_node_destroy(node);
+    }
+#else                           /* MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT */
     lbml_move_children(node, node->parent);
     g_node_destroy(node);
-#endif                         /* MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT */
+#endif                          /* MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT */
 
     return FALSE;
 }
 
+
 static const gchar *
-lbml_get_subject(GNode * node, ThreadingInfo * ti)
+lbml_get_subject(GNode         *node,
+                 ThreadingInfo *ti)
 {
     guint msgno = GPOINTER_TO_UINT(((GNode *) node->data)->data);
     return libbalsa_mailbox_msgno_get_subject(ti->mailbox, msgno);
 }
 
+
 static void
-lbml_subject_gather(GNode * node, ThreadingInfo * ti)
+lbml_subject_gather(GNode         *node,
+                    ThreadingInfo *ti)
 {
     const gchar *subject = NULL, *old_subject;
     const gchar *chopped_subject = NULL;
@@ -1796,107 +1946,113 @@ lbml_subject_gather(GNode * node, ThreadingInfo * ti)
     GHashTable *subject_table = ti->subject_table;
 
     /*
-     * If any two members of the root set have the same subject, merge them. 
-     * This is so that messages which don't have References headers at all 
-     * still get threaded (to the extent possible, at least.) 
+     * If any two members of the root set have the same subject, merge them.
+     * This is so that messages which don't have References headers at all
+     * still get threaded (to the extent possible, at least.)
      *
-     * + Construct a new hash table, subject_table, which associates subject 
-     *   strings with Container objects. 
+     * + Construct a new hash table, subject_table, which associates subject
+     *   strings with Container objects.
      *
-     * + For each Container in the root set: 
+     * + For each Container in the root set:
      *
-     *   Find the subject of that sub-tree: 
+     *   Find the subject of that sub-tree:
      *   + If there is a message in the Container, the subject is the subject of
-     *     that message. 
+     *     that message.
      *   + If there is no message in the Container, then the Container will have
      *     at least one child Container, and that Container will have a message.
-     *     Use the subject of that message instead. 
-     *   + Strip ``Re:'', ``RE:'', ``RE[5]:'', ``Re: Re[4]: Re:'' and so on. 
-     *   + If the subject is now "", give up on this 
-     *   + Add this Container to the subject_table if: Container. 
-     *     + There is no container in the table with this subject, or 
-     *     + This one is an empty container and the old one is not: the empty 
-     *       one is more interesting as a root, so put it in the table instead. 
+     *     Use the subject of that message instead.
+     *   + Strip ``Re:'', ``RE:'', ``RE[5]:'', ``Re: Re[4]: Re:'' and so on.
+     *   + If the subject is now "", give up on this
+     *   + Add this Container to the subject_table if: Container.
+     *     + There is no container in the table with this subject, or
+     *     + This one is an empty container and the old one is not: the empty
+     *       one is more interesting as a root, so put it in the table instead.
      *     + The container in the table has a ``Re:'' version of this subject,
      *       and this container has a non-``Re:'' version of this subject.
-     *       The non-re version is the more interesting of the two. 
+     *       The non-re version is the more interesting of the two.
+     *
+     * + Now the subject_table is populated with one entry for each subject
+     *   which occurs in the root set. Now iterate over the root set,
+     *   and gather together the difference.
+     *
+     *   For each Container in the root set:
      *
-     * + Now the subject_table is populated with one entry for each subject 
-     *   which occurs in the root set. Now iterate over the root set, 
-     *   and gather together the difference. 
-     * 
-     *   For each Container in the root set: 
-     * 
-     *   Find the subject of this Container (as above.) 
-     *   Look up the Container of that subject in the table. 
-     *   If it is null, or if it is this container, continue. 
-     *   Otherwise, we want to group together this Container and the one 
-     *   in the table. There are a few possibilities: 
-     *     + If both are dummies, prepend one's children to the other, and 
-     *       remove the now-empty container. 
-     * 
-     *     + If one container is a empty and the other is not, make the 
-     *       non-empty one be a child of the empty, and a sibling of the 
+     *   Find the subject of this Container (as above.)
+     *   Look up the Container of that subject in the table.
+     *   If it is null, or if it is this container, continue.
+     *   Otherwise, we want to group together this Container and the one
+     *   in the table. There are a few possibilities:
+     *     + If both are dummies, prepend one's children to the other, and
+     *       remove the now-empty container.
+     *
+     *     + If one container is a empty and the other is not, make the
+     *       non-empty one be a child of the empty, and a sibling of the
      *       other ``real'' messages with the
-     *       same subject (the empty's children.) 
-     *     + If that container is a non-empty, and that message's subject 
+     *       same subject (the empty's children.)
+     *     + If that container is a non-empty, and that message's subject
      *       does not begin with ``Re:'', but this message's subject does,
-     *       then make this be a child of the other. 
-     *     + If that container is a non-empty, and that message's subject 
-     *       begins with ``Re:'', but this message's subject does not, 
-     *       then make that be a child of this one -- they were misordered. 
-     *       (This happens somewhat implicitly, since if there are two 
+     *       then make this be a child of the other.
+     *     + If that container is a non-empty, and that message's subject
+     *       begins with ``Re:'', but this message's subject does not,
+     *       then make that be a child of this one -- they were misordered.
+     *       (This happens somewhat implicitly, since if there are two
      *       messages, one with Re: and one without, the one without
-     *       will be in the hash table, regardless of the order in which 
-     *       they were seen.) 
-     * 
+     *       will be in the hash table, regardless of the order in which
+     *       they were seen.)
+     *
      *     + Otherwise, make a new empty container and make both msgs be
-     *       a child of it. This catches the both-are-replies and 
+     *       a child of it. This catches the both-are-replies and
      *       neither-are-replies cases, and makes them be siblings instead of
-     *       asserting a hierarchical relationship which might not be true. 
-     * 
+     *       asserting a hierarchical relationship which might not be true.
+     *
      *     (People who reply to messages without using ``Re:'' and without
-     *     using a References line will break this slightly. Those people suck.) 
-     * 
+     *     using a References line will break this slightly. Those people suck.)
+     *
      *     (It has occurred to me that taking the date or message number into
      *     account would be one way of resolving some of the ambiguous cases,
-     *     but that's not altogether straightforward either.) 
+     *     but that's not altogether straightforward either.)
      */
 
     subject = lbml_get_subject(node, ti);
-    if (subject == NULL)
-       return;
+    if (subject == NULL) {
+        return;
+    }
     chopped_subject = lbml_chop_re(subject);
-    if (chopped_subject == NULL
-       || !strcmp(chopped_subject, _("(No subject)")))
-       return;
+    if ((chopped_subject == NULL)
+        || !strcmp(chopped_subject, _("(No subject)"))) {
+        return;
+    }
 
     old = g_hash_table_lookup(subject_table, chopped_subject);
 #ifdef MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT
-    if (old == NULL || (node->data == NULL && old->data != NULL)) {
-       g_hash_table_insert(subject_table, (char *) chopped_subject,
-                           node);
-       return;
+    if ((old == NULL) || ((node->data == NULL) && (old->data != NULL))) {
+        g_hash_table_insert(subject_table, (char *) chopped_subject,
+                            node);
+        return;
     }
-#else                          /* MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT */
+#else                           /* MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT */
     if (old == NULL) {
-       g_hash_table_insert(subject_table, (char *) chopped_subject,
-                           node);
-       return;
+        g_hash_table_insert(subject_table, (char *) chopped_subject,
+                            node);
+        return;
     }
-#endif                         /* MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT */
+#endif                          /* MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT */
 
     old_subject = lbml_get_subject(old, ti);
 
-    if (old_subject != lbml_chop_re(old_subject)
-       && subject == chopped_subject)
-       g_hash_table_insert(subject_table, (gchar *) chopped_subject,
-                           node);
+    if ((old_subject != lbml_chop_re(old_subject))
+        && (subject == chopped_subject)) {
+        g_hash_table_insert(subject_table, (gchar *) chopped_subject,
+                            node);
+    }
 }
 
+
 /* Swap data and children. */
 static void
-lbml_swap(GNode * node1, GNode * node2, ThreadingInfo * ti)
+lbml_swap(GNode         *node1,
+          GNode         *node2,
+          ThreadingInfo *ti)
 {
     GNode *tmp_node = g_node_new(NULL);
     gpointer tmp_data;
@@ -1906,113 +2062,125 @@ lbml_swap(GNode * node1, GNode * node2, ThreadingInfo * ti)
     lbml_move_children(tmp_node, node2);
     g_node_destroy(tmp_node);
 
-    tmp_data = node1->data;
+    tmp_data    = node1->data;
     node1->data = node2->data;
     node2->data = tmp_data;
 }
 
+
 static void
-lbml_subject_merge(GNode * node, ThreadingInfo * ti)
+lbml_subject_merge(GNode         *node,
+                   ThreadingInfo *ti)
 {
     const gchar *subject, *subject2;
     const gchar *chopped_subject, *chopped_subject2;
     GNode *node2;
 
     subject = lbml_get_subject(node, ti);
-    if (subject == NULL)
-       return;
+    if (subject == NULL) {
+        return;
+    }
     chopped_subject = lbml_chop_re(subject);
-    if (chopped_subject == NULL)
-       return;
+    if (chopped_subject == NULL) {
+        return;
+    }
 
     node2 = g_hash_table_lookup(ti->subject_table, chopped_subject);
-    if (node2 == NULL || node2 == node)
-       return;
+    if ((node2 == NULL) || (node2 == node)) {
+        return;
+    }
 
 #ifdef MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT
-    if (node->data == NULL && node2->data == NULL) {
-       lbml_move_children(node, node2);
-       g_node_destroy(node);
-       return;
+    if ((node->data == NULL) && (node2->data == NULL)) {
+        lbml_move_children(node, node2);
+        g_node_destroy(node);
+        return;
     }
 
-    if (node->data == NULL)
-       /* node2 should be made a child of node, but unlinking node2
-        * could mess up the foreach, so we'll swap them and fall
-        * through to the next case. */
-       lbml_swap(node, node2, ti);
+    if (node->data == NULL) {
+        /* node2 should be made a child of node, but unlinking node2
+         * could mess up the foreach, so we'll swap them and fall
+         * through to the next case. */
+        lbml_swap(node, node2, ti);
+    }
 
     if (node2->data == NULL) {
-       lbml_unlink_and_prepend(node, node2);
-       return;
+        lbml_unlink_and_prepend(node, node2);
+        return;
     }
-#endif                         /* MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT */
+#endif                          /* MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT */
 
-    subject2 = lbml_get_subject(node2, ti);
+    subject2         = lbml_get_subject(node2, ti);
     chopped_subject2 = lbml_chop_re(subject2);
 
-    if ((subject2 == chopped_subject2) && subject != chopped_subject)
-       /* Make node a child of node2. */
-       lbml_unlink_and_prepend(node, node2);
-    else if ((subject2 != chopped_subject2)
-            && subject == chopped_subject) {
-       /* Make node2 a child of node; as above, swap them to avoid
-        * unlinking node2. */
-       lbml_swap(node, node2, ti);
-       lbml_unlink_and_prepend(node, node2);
+    if ((subject2 == chopped_subject2) && (subject != chopped_subject)) {
+        /* Make node a child of node2. */
+        lbml_unlink_and_prepend(node, node2);
+    } else if ((subject2 != chopped_subject2)
+               && (subject == chopped_subject)) {
+        /* Make node2 a child of node; as above, swap them to avoid
+         * unlinking node2. */
+        lbml_swap(node, node2, ti);
+        lbml_unlink_and_prepend(node, node2);
 #ifdef MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT
     } else {
-       /* Make both node and node2 children of a new empty node; as
-        * above, swap node2 and the new node to avoid unlinking node2.
-        */
-       GNode *new_node = g_node_new(NULL);
-
-       lbml_move_children(node2, new_node);
-       new_node->data = node2->data;
-       node2->data = NULL;
-       lbml_unlink_and_prepend(node, node2);
-       lbml_unlink_and_prepend(new_node, node2);
-#endif                         /* MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT */
+        /* Make both node and node2 children of a new empty node; as
+         * above, swap node2 and the new node to avoid unlinking node2.
+         */
+        GNode *new_node = g_node_new(NULL);
+
+        lbml_move_children(node2, new_node);
+        new_node->data = node2->data;
+        node2->data    = NULL;
+        lbml_unlink_and_prepend(node, node2);
+        lbml_unlink_and_prepend(new_node, node2);
+#endif                          /* MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT */
     }
 }
 
+
 /* The more heuristics should be added. */
 static const gchar *
-lbml_chop_re(const gchar * str)
+lbml_chop_re(const gchar *str)
 {
     const gchar *p = str;
     while (*p) {
-       while (*p && g_ascii_isspace((int) *p))
-           p++;
-       if (!*p)
-           break;
-
-       if (g_ascii_strncasecmp(p, "re:", 3) == 0
-           || g_ascii_strncasecmp(p, "aw:", 3) == 0) {
-           p += 3;
-           continue;
-       } else if (g_ascii_strncasecmp(p, _("Re:"), strlen(_("Re:"))) == 0) {
-           /* should "re" be localized ? */
-           p += strlen(_("Re:"));
-           continue;
-       }
-       break;
+        while (*p && g_ascii_isspace((int) *p)) {
+            p++;
+        }
+        if (!*p) {
+            break;
+        }
+
+        if ((g_ascii_strncasecmp(p, "re:", 3) == 0)
+            || (g_ascii_strncasecmp(p, "aw:", 3) == 0)) {
+            p += 3;
+            continue;
+        } else if (g_ascii_strncasecmp(p, _("Re:"), strlen(_("Re:"))) == 0) {
+            /* should "re" be localized ? */
+            p += strlen(_("Re:"));
+            continue;
+        }
+        break;
     }
     return p;
 }
 
+
 static gboolean
-lbml_construct(GNode * node, ThreadingInfo * ti)
+lbml_construct(GNode         *node,
+               ThreadingInfo *ti)
 {
     GNode *msg_node;
 
     if (node->parent && (msg_node = node->data)) {
         GNode *msg_parent = node->parent->data;
 
-        if (msg_parent && msg_node->parent != msg_parent
-            && !g_node_is_ancestor(msg_node, msg_parent))
+        if (msg_parent && (msg_node->parent != msg_parent)
+            && !g_node_is_ancestor(msg_node, msg_parent)) {
             libbalsa_mailbox_unlink_and_prepend(ti->mailbox, msg_node,
                                                 msg_parent);
+        }
     }
 
     return FALSE;
@@ -2021,117 +2189,139 @@ lbml_construct(GNode * node, ThreadingInfo * ti)
 
 #ifdef MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT
 static void
-lbml_clear_empty(GNode * msg_tree)
+lbml_clear_empty(GNode *msg_tree)
 {
     GNode *node = msg_tree->children;
     while (node) {
-       GNode *next = node->next;
-       if (!node->data && !node->children)
-           g_node_destroy(node);
-       node = next;
+        GNode *next = node->next;
+        if (!node->data && !node->children) {
+            g_node_destroy(node);
+        }
+        node = next;
     }
 }
-#endif                         /* MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT */
+
+
+#endif                          /* MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT */
 
 /* yet another message threading function */
 
-static gboolean lbml_insert_message(GNode * node, ThreadingInfo * ti);
-static gboolean lbml_thread_message(GNode * node, ThreadingInfo * ti);
+static gboolean lbml_insert_message(GNode         *node,
+                                    ThreadingInfo *ti);
+static gboolean lbml_thread_message(GNode         *node,
+                                    ThreadingInfo *ti);
 
 static void
-lbml_threading_simple(LibBalsaMailbox * mailbox,
-                     LibBalsaMailboxThreadingType type)
+lbml_threading_simple(LibBalsaMailbox             *mailbox,
+                      LibBalsaMailboxThreadingType type)
 {
     GNode *msg_tree = libbalsa_mailbox_get_msg_tree(mailbox);
     ThreadingInfo ti;
 
     lbml_info_setup(mailbox, &ti);
 
-    if (type == LB_MAILBOX_THREADING_SIMPLE)
-       g_node_traverse(msg_tree, G_POST_ORDER, G_TRAVERSE_ALL,
-                       -1, (GNodeTraverseFunc) lbml_insert_message, &ti);
+    if (type == LB_MAILBOX_THREADING_SIMPLE) {
+        g_node_traverse(msg_tree, G_POST_ORDER, G_TRAVERSE_ALL,
+                        -1, (GNodeTraverseFunc) lbml_insert_message, &ti);
+    }
 
     ti.type = type;
     g_node_traverse(msg_tree, G_POST_ORDER, G_TRAVERSE_ALL, -1,
-                   (GNodeTraverseFunc) lbml_thread_message, &ti);
+                    (GNodeTraverseFunc) lbml_thread_message, &ti);
 
 #ifdef MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT
     lbml_clear_empty(msg_tree);
-#endif                         /* MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT */
+#endif                          /* MAKE_EMPTY_CONTAINER_FOR_MISSING_PARENT */
 
     lbml_info_free(&ti);
 }
 
+
 static gboolean
-lbml_insert_message(GNode * node, ThreadingInfo * ti)
+lbml_insert_message(GNode         *node,
+                    ThreadingInfo *ti)
 {
     LibBalsaMailboxLocalInfo *info;
 
-    if (!node->parent)
-       return FALSE;
+    if (!node->parent) {
+        return FALSE;
+    }
 
     info = lbml_get_info(node, ti);
-    if (!info)
-       return FALSE;
+    if (!info) {
+        return FALSE;
+    }
 
-    if (info->message_id)
-       g_hash_table_insert(ti->id_table, info->message_id, node);
+    if (info->message_id) {
+        g_hash_table_insert(ti->id_table, info->message_id, node);
+    }
 
     return FALSE;
 }
 
+
 static gboolean
-lbml_thread_message(GNode * node, ThreadingInfo * ti)
+lbml_thread_message(GNode         *node,
+                    ThreadingInfo *ti)
 {
-    if (!node->parent)
+    if (!node->parent) {
         return FALSE;
+    }
 
     if (ti->type == LB_MAILBOX_THREADING_FLAT) {
-        if (node->parent != libbalsa_mailbox_get_msg_tree(ti->mailbox))
+        if (node->parent != libbalsa_mailbox_get_msg_tree(ti->mailbox)) {
             libbalsa_mailbox_unlink_and_prepend(ti->mailbox, node,
                                                 libbalsa_mailbox_get_msg_tree
-                                                (ti->mailbox));
+                                                    (ti->mailbox));
+        }
     } else {
         LibBalsaMailboxLocalInfo *info;
         GList *refs;
         GNode *parent = NULL;
 
         info = lbml_get_info(node, ti);
-        if (!info)
+        if (!info) {
             return FALSE;
+        }
 
         refs = info->refs_for_threading;
-        if (refs)
+        if (refs) {
             parent = g_hash_table_lookup(ti->id_table,
                                          g_list_last(refs)->data);
+        }
 
-        if (!parent)
+        if (!parent) {
             parent = libbalsa_mailbox_get_msg_tree(ti->mailbox);
-        if (parent != node->parent && parent != node
-            && !g_node_is_ancestor(node, parent))
+        }
+        if ((parent != node->parent) && (parent != node)
+            && !g_node_is_ancestor(node, parent)) {
             libbalsa_mailbox_unlink_and_prepend(ti->mailbox, node, parent);
+        }
     }
 
     return FALSE;
 }
+
+
 /*------------------------------*/
 /*  End of threading functions  */
 /*------------------------------*/
 
 /* Helper for maildir and mh. */
 GMimeMessage *
-libbalsa_mailbox_local_get_mime_message(LibBalsaMailbox * mailbox,
-                                        const gchar * name1,
-                                        const gchar * name2)
+libbalsa_mailbox_local_get_mime_message(LibBalsaMailbox *mailbox,
+                                        const gchar     *name1,
+                                        const gchar     *name2)
 {
     GMimeStream *mime_stream;
     GMimeParser *mime_parser;
     GMimeMessage *mime_message;
 
     mime_stream =
-       libbalsa_mailbox_local_get_message_stream(mailbox, name1, name2);
-    if (!mime_stream)
-       return NULL;
+        libbalsa_mailbox_local_get_message_stream(mailbox, name1, name2);
+    if (!mime_stream) {
+        return NULL;
+    }
 
     mime_parser = g_mime_parser_new_with_stream(mime_stream);
     g_mime_parser_set_scan_from(mime_parser, FALSE);
@@ -2143,84 +2333,91 @@ libbalsa_mailbox_local_get_mime_message(LibBalsaMailbox * mailbox,
     return mime_message;
 }
 
+
 GMimeStream *
-libbalsa_mailbox_local_get_message_stream(LibBalsaMailbox * mailbox,
-                                          const gchar * name1,
-                                          const gchar * name2)
+libbalsa_mailbox_local_get_message_stream(LibBalsaMailbox *mailbox,
+                                          const gchar     *name1,
+                                          const gchar     *name2)
 {
     const gchar *path;
     gchar *filename;
     int fd;
     GMimeStream *stream = NULL;
 
-    path = libbalsa_mailbox_local_get_path(LIBBALSA_MAILBOX_LOCAL(mailbox));
+    path     = libbalsa_mailbox_local_get_path(LIBBALSA_MAILBOX_LOCAL(mailbox));
     filename = g_build_filename(path, name1, name2, NULL);
 
     fd = open(filename, O_RDONLY);
     if (fd != -1) {
-       stream = g_mime_stream_fs_new(fd);
-       if (!stream)
-           libbalsa_information(LIBBALSA_INFORMATION_ERROR,
-                                _("Open of %s failed. Errno = %d, "),
-                                filename, errno);
+        stream = g_mime_stream_fs_new(fd);
+        if (!stream) {
+            libbalsa_information(LIBBALSA_INFORMATION_ERROR,
+                                 _("Open of %s failed. Errno = %d, "),
+                                 filename, errno);
+        }
     }
     g_free(filename);
 
     return stream;
 }
 
+
 /* Queued sync. */
 
 static void
-lbm_local_sync_real(LibBalsaMailboxLocal * local)
+lbm_local_sync_real(LibBalsaMailboxLocal *local)
 {
     LibBalsaMailboxLocalPrivate *priv =
         libbalsa_mailbox_local_get_instance_private(local);
-    LibBalsaMailbox *mailbox = (LibBalsaMailbox*)local;
+    LibBalsaMailbox *mailbox = (LibBalsaMailbox *)local;
     time_t tstart;
 
     time(&tstart);
     libbalsa_lock_mailbox(mailbox);
     if (priv->sync_id &&                       /* request still pending */
         MAILBOX_OPEN(mailbox) &&                   /* mailbox still open */
-        !libbalsa_mailbox_sync_storage(mailbox, FALSE))   /* cannot sync */
-       libbalsa_information(LIBBALSA_INFORMATION_WARNING,
-                            _("Failed to sync mailbox “%s”"),
-                            libbalsa_mailbox_get_name(mailbox));
-    priv->sync_id = 0;
-    priv->sync_time += time(NULL)-tstart;
+        !libbalsa_mailbox_sync_storage(mailbox, FALSE)) { /* cannot sync */
+        libbalsa_information(LIBBALSA_INFORMATION_WARNING,
+                             _("Failed to sync mailbox “%s”"),
+                             libbalsa_mailbox_get_name(mailbox));
+    }
+    priv->sync_id    = 0;
+    priv->sync_time += time(NULL) - tstart;
     priv->sync_cnt++;
     libbalsa_unlock_mailbox(mailbox);
     g_object_unref(local);
 }
 
+
 static gboolean
-lbm_local_sync_idle(LibBalsaMailboxLocal * local)
+lbm_local_sync_idle(LibBalsaMailboxLocal *local)
 {
     GThread *sync_thread;
 
     sync_thread =
-       g_thread_new("lbm_local_sync_real", (GThreadFunc) lbm_local_sync_real, local);
+        g_thread_new("lbm_local_sync_real", (GThreadFunc) lbm_local_sync_real, local);
     g_thread_unref(sync_thread);
 
     return FALSE;
 }
 
+
 static void
-lbm_local_sync_queue(LibBalsaMailboxLocal * local)
+lbm_local_sync_queue(LibBalsaMailboxLocal *local)
 {
     LibBalsaMailboxLocalPrivate *priv =
         libbalsa_mailbox_local_get_instance_private(local);
     guint schedule_delay;
 
     /* The optimal behavior here would be to keep rescheduling
-    * requests.  But think of following: the idle handler started and
-    * triggered lbm_local_sync_real thread. While it waits for the lock,
-    * another queue request is filed but it is too late for removal of
-    * the sync thread. And we get two sync threads executing one after
-    * another, etc. So it is better to do sync bit too often... */
-    if (priv->sync_id) 
+     * requests.  But think of following: the idle handler started and
+     * triggered lbm_local_sync_real thread. While it waits for the lock,
+     * another queue request is filed but it is too late for removal of
+     * the sync thread. And we get two sync threads executing one after
+     * another, etc. So it is better to do sync bit too often... */
+    if (priv->sync_id) {
         return;
+    }
     g_object_ref(local);
     /* queue sync job so that the delay is at least five times longer
      * than the syncing time. Otherwise large mailbox owners will be
@@ -2228,12 +2425,14 @@ lbm_local_sync_queue(LibBalsaMailboxLocal * local)
     schedule_delay =
         priv->sync_cnt ? (priv->sync_time * 5000) / priv->sync_cnt : 0;
     priv->sync_id = g_timeout_add_full(G_PRIORITY_LOW, schedule_delay,
-                                        (GSourceFunc)lbm_local_sync_idle,
-                                        local, NULL);
+                                       (GSourceFunc)lbm_local_sync_idle,
+                                       local, NULL);
 }
 
+
 static void
-lbm_local_sort(LibBalsaMailbox * mailbox, GArray *sort_array)
+lbm_local_sort(LibBalsaMailbox *mailbox,
+               GArray          *sort_array)
 {
     g_assert(LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_local_parent_class) != NULL);
 
@@ -2241,11 +2440,12 @@ lbm_local_sort(LibBalsaMailbox * mailbox, GArray *sort_array)
     lbm_local_queue_save_tree(LIBBALSA_MAILBOX_LOCAL(mailbox));
 }
 
+
 static guint
-libbalsa_mailbox_local_add_messages(LibBalsaMailbox          * mailbox,
+libbalsa_mailbox_local_add_messages(LibBalsaMailbox           *mailbox,
                                     LibBalsaAddMessageIterator msg_iterator,
                                     gpointer                   iter_data,
-                                    GError                  ** err)
+                                    GError                   **err)
 {
     LibBalsaMessageFlag flag;
     GMimeStream *stream;
@@ -2256,32 +2456,35 @@ libbalsa_mailbox_local_add_messages(LibBalsaMailbox          * mailbox,
     local = LIBBALSA_MAILBOX_LOCAL(mailbox);
     g_assert(LIBBALSA_MAILBOX_LOCAL_GET_CLASS(local) != NULL);
 
-    cnt = 0;
+    cnt         = 0;
     add_message = LIBBALSA_MAILBOX_LOCAL_GET_CLASS(local)->add_message;
     while (msg_iterator(&flag, &stream, iter_data)) {
         gboolean success;
 
         success = (*add_message)(local, stream, flag, err);
         g_object_unref(stream);
-        if (!success)
+        if (!success) {
             break;
+        }
         cnt++;
     }
 
     return cnt;
 }
 
+
 #define FLAGS_REALLY_DIFFER(flags0, flags1) \
-        (((flags0 ^ flags1) & LIBBALSA_MESSAGE_FLAGS_REAL) != 0)
+    (((flags0 ^ flags1) & LIBBALSA_MESSAGE_FLAGS_REAL) != 0)
 
 static gboolean
-libbalsa_mailbox_local_messages_change_flags(LibBalsaMailbox * mailbox,
-                                             GArray * msgnos,
+libbalsa_mailbox_local_messages_change_flags(LibBalsaMailbox    *mailbox,
+                                             GArray             *msgnos,
                                              LibBalsaMessageFlag set,
                                              LibBalsaMessageFlag clear)
 {
     LibBalsaMailboxLocal *local = LIBBALSA_MAILBOX_LOCAL(mailbox);
-    LibBalsaMailboxLocalMessageInfo *(*get_info) (LibBalsaMailboxLocal *, guint);
+    LibBalsaMailboxLocalMessageInfo *(*get_info) (LibBalsaMailboxLocal *,
+                                                  guint);
     guint i;
     guint changed = 0;
 
@@ -2294,23 +2497,25 @@ libbalsa_mailbox_local_messages_change_flags(LibBalsaMailbox * mailbox,
         LibBalsaMailboxLocalMessageInfo *msg_info;
         LibBalsaMessageFlag old_flags;
 
-        if (!(msgno > 0
-              && msgno <= libbalsa_mailbox_total_messages(mailbox))) {
+        if (!((msgno > 0)
+              && (msgno <= libbalsa_mailbox_total_messages(mailbox)))) {
             g_warning("msgno %u out of range", msgno);
             continue;
         }
 
-        msg_info = get_info(local, msgno);
-        old_flags = msg_info->flags;
+        msg_info         = get_info(local, msgno);
+        old_flags        = msg_info->flags;
         msg_info->flags |= set;
         msg_info->flags &= ~clear;
-        if (!FLAGS_REALLY_DIFFER(msg_info->flags, old_flags))
+        if (!FLAGS_REALLY_DIFFER(msg_info->flags, old_flags)) {
             /* No real flags changed. */
             continue;
+        }
         ++changed;
 
-        if (msg_info->message)
+        if (msg_info->message) {
             msg_info->message->flags = msg_info->flags;
+        }
 
         libbalsa_mailbox_index_set_flags(mailbox, msgno, msg_info->flags);
 
@@ -2324,24 +2529,25 @@ libbalsa_mailbox_local_messages_change_flags(LibBalsaMailbox * mailbox,
                 (msg_info->flags & LIBBALSA_MESSAGE_FLAG_NEW)
                 && !(msg_info->flags & LIBBALSA_MESSAGE_FLAG_DELETED);
             libbalsa_mailbox_add_to_unread_messages(mailbox,
-                is_unread_undeleted - was_unread_undeleted);
+                                                    is_unread_undeleted - was_unread_undeleted);
         }
     }
     libbalsa_unlock_mailbox(mailbox);
 
     if (changed > 0) {
-       libbalsa_mailbox_set_unread_messages_flag(mailbox,
-                                                 libbalsa_mailbox_get_unread_messages
-                                                  (mailbox) > 0);
+        libbalsa_mailbox_set_unread_messages_flag(mailbox,
+                                                  libbalsa_mailbox_get_unread_messages
+                                                      (mailbox) > 0);
         lbm_local_sync_queue(local);
     }
 
     return TRUE;
 }
 
+
 static gboolean
-libbalsa_mailbox_local_msgno_has_flags(LibBalsaMailbox * mailbox,
-                                       guint msgno,
+libbalsa_mailbox_local_msgno_has_flags(LibBalsaMailbox    *mailbox,
+                                       guint               msgno,
                                        LibBalsaMessageFlag set,
                                        LibBalsaMessageFlag unset)
 {
@@ -2354,24 +2560,27 @@ libbalsa_mailbox_local_msgno_has_flags(LibBalsaMailbox * mailbox,
     return (msg_info->flags & set) == set && (msg_info->flags & unset) == 0;
 }
 
+
 static GArray *
-libbalsa_mailbox_local_duplicate_msgnos(LibBalsaMailbox * mailbox)
+libbalsa_mailbox_local_duplicate_msgnos(LibBalsaMailbox *mailbox)
 {
-    LibBalsaMailboxLocal *local = (LibBalsaMailboxLocal *) mailbox;
+    LibBalsaMailboxLocal *local       = (LibBalsaMailboxLocal *) mailbox;
     LibBalsaMailboxLocalPrivate *priv =
         libbalsa_mailbox_local_get_instance_private(local);
     GHashTable *table;
     guint i;
     GArray *msgnos;
 
-    if (!priv->threading_info)
+    if (!priv->threading_info) {
         return NULL;
+    }
 
     /* We need all the message-ids. */
-    if (!libbalsa_mailbox_prepare_threading(mailbox, 0))
+    if (!libbalsa_mailbox_prepare_threading(mailbox, 0)) {
         return NULL;
+    }
 
-    table = g_hash_table_new(g_str_hash, g_str_equal);
+    table  = g_hash_table_new(g_str_hash, g_str_equal);
     msgnos = g_array_new(FALSE, FALSE, sizeof(guint));
 
     for (i = 0; i < priv->threading_info->len; i++) {
@@ -2380,14 +2589,16 @@ libbalsa_mailbox_local_duplicate_msgnos(LibBalsaMailbox * mailbox)
         guint master, msgno = i + 1;
 
         if (libbalsa_mailbox_msgno_has_flags
-            (mailbox, msgno, LIBBALSA_MESSAGE_FLAG_DELETED, 0))
+                (mailbox, msgno, LIBBALSA_MESSAGE_FLAG_DELETED, 0)) {
             continue;
+        }
 
         info = g_ptr_array_index(priv->threading_info, i);
-        if (!info || !info->message_id)
+        if (!info || !info->message_id) {
             continue;
+        }
 
-        tmp = g_hash_table_lookup(table, info->message_id);
+        tmp    = g_hash_table_lookup(table, info->message_id);
         master = tmp ? GPOINTER_TO_UINT(tmp) : 0;
         if (!master ||
             libbalsa_mailbox_msgno_has_flags(mailbox, msgno,
@@ -2398,25 +2609,28 @@ libbalsa_mailbox_local_duplicate_msgnos(LibBalsaMailbox * mailbox)
             msgno = master;
         }
 
-        if (msgno)
+        if (msgno) {
             g_array_append_val(msgnos, msgno);
+        }
     }
     g_hash_table_destroy(table);
 
     return msgnos;
 }
 
+
 static void
-libbalsa_mailbox_local_test_can_reach(LibBalsaMailbox          * mailbox,
-                                      LibBalsaCanReachCallback * cb,
-                                      gpointer                   cb_data)
+libbalsa_mailbox_local_test_can_reach(LibBalsaMailbox          *mailbox,
+                                      LibBalsaCanReachCallback *cb,
+                                      gpointer                  cb_data)
 {
     cb((GObject *) mailbox, TRUE, cb_data);
 }
 
+
 /* LibBalsaMailboxLocal class method: */
 static void
-lbm_local_real_remove_files(LibBalsaMailboxLocal * local)
+lbm_local_real_remove_files(LibBalsaMailboxLocal *local)
 {
     gchar *filename = lbm_local_get_cache_filename(local);
     unlink(filename);
diff --git a/libbalsa/mailbox_local.h b/libbalsa/mailbox_local.h
index a411e15..1924c3d 100644
--- a/libbalsa/mailbox_local.h
+++ b/libbalsa/mailbox_local.h
@@ -6,14 +6,14 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option) 
+ * the Free Software Foundation; either version 2, or (at your option)
  * any later version.
- *  
+ *
  * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of 
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *  
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
@@ -32,7 +32,7 @@ G_DECLARE_DERIVABLE_TYPE(LibBalsaMailboxLocal,
                          LibBalsaMailbox)
 
 struct _LibBalsaMailboxLocalPool {
-    LibBalsaMessage * message;
+    LibBalsaMessage *message;
     guint pool_seqno;
 };
 typedef struct _LibBalsaMailboxLocalPool LibBalsaMailboxLocalPool;
@@ -45,50 +45,54 @@ struct _LibBalsaMailboxLocalMessageInfo {
 };
 typedef struct _LibBalsaMailboxLocalMessageInfo LibBalsaMailboxLocalMessageInfo;
 
-typedef gboolean LibBalsaMailboxLocalAddMessageFunc(LibBalsaMailboxLocal *
-                                                    local,
-                                                    GMimeStream * stream,
-                                                    LibBalsaMessageFlag
-                                                    flags, GError ** err);
+typedef gboolean LibBalsaMailboxLocalAddMessageFunc (LibBalsaMailboxLocal *
+                                                     local,
+                                                     GMimeStream *stream,
+                                                     LibBalsaMessageFlag
+                                                     flags, GError **err);
 
 struct _LibBalsaMailboxLocalClass {
     LibBalsaMailboxClass klass;
 
-    gint (*check_files)(const gchar * path, gboolean create);
-    void (*set_path)(LibBalsaMailboxLocal * local, const gchar * path);
-    void (*remove_files)(LibBalsaMailboxLocal * local);
-    guint (*fileno)(LibBalsaMailboxLocal * local, guint msgno);
-    LibBalsaMailboxLocalMessageInfo *(*get_info)(LibBalsaMailboxLocal * local,
-                                                 guint msgno);
+    gint (*check_files)(const gchar *path,
+                        gboolean     create);
+    void (*set_path)(LibBalsaMailboxLocal *local,
+                     const gchar          *path);
+    void (*remove_files)(LibBalsaMailboxLocal *local);
+    guint (*fileno)(LibBalsaMailboxLocal *local,
+                    guint                 msgno);
+    LibBalsaMailboxLocalMessageInfo *(*get_info)(LibBalsaMailboxLocal *local,
+                                                 guint                 msgno);
     LibBalsaMailboxLocalAddMessageFunc *add_message;
 };
 
-LibBalsaMailbox *libbalsa_mailbox_local_new(const gchar * path,
-                                            gboolean      create);
-gint libbalsa_mailbox_local_set_path(LibBalsaMailboxLocal * mailbox,
-                                    const gchar * path, gboolean create);
+LibBalsaMailbox *libbalsa_mailbox_local_new(const gchar *path,
+                                            gboolean     create);
+gint             libbalsa_mailbox_local_set_path(LibBalsaMailboxLocal *mailbox,
+                                                 const gchar          *path,
+                                                 gboolean              create);
 void libbalsa_mailbox_local_set_threading_info(LibBalsaMailboxLocal *
                                                local);
 
-const gchar *libbalsa_mailbox_local_get_path(LibBalsaMailboxLocal * local);
+const gchar *libbalsa_mailbox_local_get_path(LibBalsaMailboxLocal *local);
 
-void libbalsa_mailbox_local_load_messages(LibBalsaMailbox * mailbox,
-                                         guint last_msgno);
-void libbalsa_mailbox_local_cache_message(LibBalsaMailboxLocal * local,
-                                          guint msgno,
-                                          LibBalsaMessage * message);
-void libbalsa_mailbox_local_msgno_removed(LibBalsaMailbox * mailbox,
-                                         guint msgno);
+void         libbalsa_mailbox_local_load_messages(LibBalsaMailbox *mailbox,
+                                                  guint            last_msgno);
+void         libbalsa_mailbox_local_cache_message(LibBalsaMailboxLocal *local,
+                                                  guint                 msgno,
+                                                  LibBalsaMessage      *message);
+void libbalsa_mailbox_local_msgno_removed(LibBalsaMailbox *mailbox,
+                                          guint            msgno);
 void libbalsa_mailbox_local_remove_files(LibBalsaMailboxLocal *mailbox);
 
 /* Helpers for maildir and mh. */
 GMimeMessage *libbalsa_mailbox_local_get_mime_message(LibBalsaMailbox *
-                                                     mailbox,
-                                                     const gchar * name1,
-                                                     const gchar * name2);
+                                                      mailbox,
+                                                      const gchar *name1,
+                                                      const gchar *name2);
 GMimeStream *libbalsa_mailbox_local_get_message_stream(LibBalsaMailbox *
-                                                      mailbox,
-                                                      const gchar * name1,
-                                                      const gchar * name2);
+                                                       mailbox,
+                                                       const gchar *name1,
+                                                       const gchar *name2);
 
-#endif                         /* __LIBBALSA_MAILBOX_LOCAL_H__ */
+#endif                          /* __LIBBALSA_MAILBOX_LOCAL_H__ */
diff --git a/libbalsa/mailbox_maildir.c b/libbalsa/mailbox_maildir.c
index 5de5471..674e494 100644
--- a/libbalsa/mailbox_maildir.c
+++ b/libbalsa/mailbox_maildir.c
@@ -6,20 +6,20 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option) 
+ * the Free Software Foundation; either version 2, or (at your option)
  * any later version.
- *  
+ *
  * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of 
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *  
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H
-# include "config.h"
+#   include "config.h"
 #endif                          /* HAVE_CONFIG_H */
 
 
@@ -56,56 +56,59 @@ struct message_info {
     FLAGS_REALLY_DIFFER(msg_info->orig_flags, msg_info->local_info.flags)
 
 /* Object class method */
-static void libbalsa_mailbox_maildir_finalize(GObject * object);
+static void libbalsa_mailbox_maildir_finalize(GObject *object);
 
 /* Mailbox class methods */
-static void libbalsa_mailbox_maildir_load_config(LibBalsaMailbox * mailbox,
-                                                const gchar * prefix);
+static void libbalsa_mailbox_maildir_load_config(LibBalsaMailbox *mailbox,
+                                                 const gchar     *prefix);
 
 static GMimeStream *libbalsa_mailbox_maildir_get_message_stream(LibBalsaMailbox *
-                                                          mailbox,
-                                                               guint msgno,
-                                                               gboolean peek);
-
-static gboolean libbalsa_mailbox_maildir_open(LibBalsaMailbox * mailbox,
-                                             GError **err);
-static void libbalsa_mailbox_maildir_close_mailbox(LibBalsaMailbox *
-                                                   mailbox,
-                                                   gboolean expunge);
-static void libbalsa_mailbox_maildir_check(LibBalsaMailbox * mailbox);
-static gboolean libbalsa_mailbox_maildir_sync(LibBalsaMailbox * mailbox,
-                                              gboolean expunge);
-static gboolean
-libbalsa_mailbox_maildir_fetch_message_structure(LibBalsaMailbox * mailbox,
-                                                LibBalsaMessage * message,
-                                                LibBalsaFetchFlag flags);
-static guint
-libbalsa_mailbox_maildir_total_messages(LibBalsaMailbox * mailbox);
+                                                                mailbox,
+                                                                guint    msgno,
+                                                                gboolean peek);
+
+static gboolean libbalsa_mailbox_maildir_open(LibBalsaMailbox *mailbox,
+                                              GError         **err);
+static void     libbalsa_mailbox_maildir_close_mailbox(LibBalsaMailbox *
+                                                       mailbox,
+                                                       gboolean expunge);
+static void     libbalsa_mailbox_maildir_check(LibBalsaMailbox *mailbox);
+static gboolean libbalsa_mailbox_maildir_sync(LibBalsaMailbox *mailbox,
+                                              gboolean         expunge);
+static gboolean libbalsa_mailbox_maildir_fetch_message_structure(LibBalsaMailbox  *mailbox,
+                                                                 LibBalsaMessage  *message,
+                                                                 LibBalsaFetchFlag flags);
+static guint libbalsa_mailbox_maildir_total_messages(LibBalsaMailbox *mailbox);
 
 /* LibBalsaMailboxLocal class methods */
-static gint lbm_maildir_check_files(const gchar * path, gboolean create);
-static void lbm_maildir_set_path(LibBalsaMailboxLocal * local,
-                                 const gchar * path);
-static void lbm_maildir_remove_files(LibBalsaMailboxLocal * local);
-static guint lbm_maildir_fileno(LibBalsaMailboxLocal * local, guint msgno);
+static gint  lbm_maildir_check_files(const gchar *path,
+                                     gboolean     create);
+static void  lbm_maildir_set_path(LibBalsaMailboxLocal *local,
+                                  const gchar          *path);
+static void  lbm_maildir_remove_files(LibBalsaMailboxLocal *local);
+static guint lbm_maildir_fileno(LibBalsaMailboxLocal *local,
+                                guint                 msgno);
 static LibBalsaMailboxLocalMessageInfo
-    *lbm_maildir_get_info(LibBalsaMailboxLocal * local, guint msgno);
+*lbm_maildir_get_info(LibBalsaMailboxLocal *local,
+                      guint                 msgno);
+
 static LibBalsaMailboxLocalAddMessageFunc lbm_maildir_add_message;
 
 /* util functions */
 static struct message_info *message_info_from_msgno(LibBalsaMailboxMaildir
-                                                    * mdir, guint msgno);
+                                                         *mdir,
+                                                    guint msgno);
 static LibBalsaMessageFlag parse_filename(const gchar *subdir,
-                                         const gchar *filename);
-static void free_message_info(struct message_info *msg_info);
-static int libbalsa_mailbox_maildir_open_temp (const gchar *dest_path,
-                                         char **name_used);
+                                          const gchar *filename);
+static void                free_message_info(struct message_info *msg_info);
+static int                 libbalsa_mailbox_maildir_open_temp(const gchar *dest_path,
+                                                              char       **name_used);
 
 struct _LibBalsaMailboxMaildir {
     LibBalsaMailboxLocal parent;
 
-    GHashTable* messages_info;
-    GPtrArray* msgno_2_msg_info;
+    GHashTable *messages_info;
+    GPtrArray *msgno_2_msg_info;
     gchar *curdir;
     gchar *newdir;
     gchar *tmpdir;
@@ -120,33 +123,33 @@ G_DEFINE_TYPE(LibBalsaMailboxMaildir,
               LIBBALSA_TYPE_MAILBOX_LOCAL)
 
 static void
-libbalsa_mailbox_maildir_class_init(LibBalsaMailboxMaildirClass * klass)
+libbalsa_mailbox_maildir_class_init(LibBalsaMailboxMaildirClass *klass)
 {
     GObjectClass *object_class;
     LibBalsaMailboxClass *libbalsa_mailbox_class;
     LibBalsaMailboxLocalClass *libbalsa_mailbox_local_class;
 
-    object_class = G_OBJECT_CLASS(klass);
-    libbalsa_mailbox_class = LIBBALSA_MAILBOX_CLASS(klass);
+    object_class                 = G_OBJECT_CLASS(klass);
+    libbalsa_mailbox_class       = LIBBALSA_MAILBOX_CLASS(klass);
     libbalsa_mailbox_local_class = LIBBALSA_MAILBOX_LOCAL_CLASS(klass);
 
     object_class->finalize = libbalsa_mailbox_maildir_finalize;
 
     libbalsa_mailbox_class->load_config =
-               libbalsa_mailbox_maildir_load_config;
+        libbalsa_mailbox_maildir_load_config;
     libbalsa_mailbox_class->get_message_stream =
-       libbalsa_mailbox_maildir_get_message_stream;
+        libbalsa_mailbox_maildir_get_message_stream;
 
     libbalsa_mailbox_class->open_mailbox = libbalsa_mailbox_maildir_open;
-    libbalsa_mailbox_class->check = libbalsa_mailbox_maildir_check;
+    libbalsa_mailbox_class->check        = libbalsa_mailbox_maildir_check;
 
-    libbalsa_mailbox_class->sync = libbalsa_mailbox_maildir_sync;
+    libbalsa_mailbox_class->sync          = libbalsa_mailbox_maildir_sync;
     libbalsa_mailbox_class->close_mailbox =
-       libbalsa_mailbox_maildir_close_mailbox;
+        libbalsa_mailbox_maildir_close_mailbox;
     libbalsa_mailbox_class->fetch_message_structure =
-       libbalsa_mailbox_maildir_fetch_message_structure;
+        libbalsa_mailbox_maildir_fetch_message_structure;
     libbalsa_mailbox_class->total_messages =
-       libbalsa_mailbox_maildir_total_messages;
+        libbalsa_mailbox_maildir_total_messages;
 
     libbalsa_mailbox_local_class->check_files  = lbm_maildir_check_files;
     libbalsa_mailbox_local_class->set_path     = lbm_maildir_set_path;
@@ -156,13 +159,16 @@ libbalsa_mailbox_maildir_class_init(LibBalsaMailboxMaildirClass * klass)
     libbalsa_mailbox_local_class->add_message  = lbm_maildir_add_message;
 }
 
+
 static void
-libbalsa_mailbox_maildir_init(LibBalsaMailboxMaildir * mdir)
+libbalsa_mailbox_maildir_init(LibBalsaMailboxMaildir *mdir)
 {
 }
 
+
 static gint
-lbm_maildir_check_files(const gchar * path, gboolean create)
+lbm_maildir_check_files(const gchar *path,
+                        gboolean     create)
 {
     g_return_val_if_fail(path != NULL, -1);
 
@@ -217,14 +223,17 @@ lbm_maildir_check_files(const gchar * path, gboolean create)
             rmdir(path);
             return -1;
         }
-    } else
+    } else {
         return -1;
+    }
 
     return 0;
 }
 
+
 static void
-lbm_maildir_set_subdirs(LibBalsaMailboxMaildir * mdir, const gchar * path)
+lbm_maildir_set_subdirs(LibBalsaMailboxMaildir *mdir,
+                        const gchar            *path)
 {
     g_free(mdir->curdir);
     mdir->curdir = g_build_filename(path, "cur", NULL);
@@ -234,14 +243,18 @@ lbm_maildir_set_subdirs(LibBalsaMailboxMaildir * mdir, const gchar * path)
     mdir->tmpdir = g_build_filename(path, "tmp", NULL);
 }
 
+
 static void
-lbm_maildir_set_path(LibBalsaMailboxLocal * local, const gchar * path)
+lbm_maildir_set_path(LibBalsaMailboxLocal *local,
+                     const gchar          *path)
 {
     lbm_maildir_set_subdirs(LIBBALSA_MAILBOX_MAILDIR(local), path);
 }
 
+
 LibBalsaMailbox *
-libbalsa_mailbox_maildir_new(const gchar * path, gboolean create)
+libbalsa_mailbox_maildir_new(const gchar *path,
+                             gboolean     create)
 {
     LibBalsaMailbox *mailbox;
 
@@ -258,8 +271,9 @@ libbalsa_mailbox_maildir_new(const gchar * path, gboolean create)
     return mailbox;
 }
 
+
 static void
-libbalsa_mailbox_maildir_finalize(GObject * object)
+libbalsa_mailbox_maildir_finalize(GObject *object)
 {
     LibBalsaMailboxMaildir *mdir = LIBBALSA_MAILBOX_MAILDIR(object);
     g_free(mdir->curdir);
@@ -272,9 +286,10 @@ libbalsa_mailbox_maildir_finalize(GObject * object)
     G_OBJECT_CLASS(libbalsa_mailbox_maildir_parent_class)->finalize(object);
 }
 
+
 static void
-libbalsa_mailbox_maildir_load_config(LibBalsaMailbox * mailbox,
-                                    const gchar * prefix)
+libbalsa_mailbox_maildir_load_config(LibBalsaMailbox *mailbox,
+                                     const gchar     *prefix)
 {
     LibBalsaMailboxMaildir *mdir = LIBBALSA_MAILBOX_MAILDIR(mailbox);
     gchar *path;
@@ -286,9 +301,11 @@ libbalsa_mailbox_maildir_load_config(LibBalsaMailbox * mailbox,
     LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_maildir_parent_class)->load_config(mailbox, prefix);
 }
 
+
 static GMimeStream *
-libbalsa_mailbox_maildir_get_message_stream(LibBalsaMailbox * mailbox,
-                                           guint msgno, gboolean peek)
+libbalsa_mailbox_maildir_get_message_stream(LibBalsaMailbox *mailbox,
+                                            guint            msgno,
+                                            gboolean         peek)
 {
     struct message_info *msg_info;
 
@@ -296,18 +313,20 @@ libbalsa_mailbox_maildir_get_message_stream(LibBalsaMailbox * mailbox,
 
     msg_info =
         message_info_from_msgno((LibBalsaMailboxMaildir *) mailbox, msgno);
-    if (!msg_info)
-       return NULL;
+    if (!msg_info) {
+        return NULL;
+    }
 
     return libbalsa_mailbox_local_get_message_stream(mailbox,
-                                                    msg_info->subdir,
-                                                    msg_info->filename);
+                                                     msg_info->subdir,
+                                                     msg_info->filename);
 }
 
+
 static void
 lbm_maildir_remove_files(LibBalsaMailboxLocal *mailbox)
 {
-    const gchar* path;
+    const gchar *path;
 
     g_return_if_fail(LIBBALSA_IS_MAILBOX_MAILDIR(mailbox));
 
@@ -315,60 +334,63 @@ lbm_maildir_remove_files(LibBalsaMailboxLocal *mailbox)
     g_print("DELETE MAILDIR\n");
 
     if (!libbalsa_delete_directory_contents(path)) {
-       libbalsa_information(LIBBALSA_INFORMATION_ERROR,
-                            _("Could not remove contents of %s:\n%s"),
-                            path, strerror(errno));
-       return;
+        libbalsa_information(LIBBALSA_INFORMATION_ERROR,
+                             _("Could not remove contents of %s:\n%s"),
+                             path, strerror(errno));
+        return;
     }
     if ( rmdir(path) == -1 ) {
-       libbalsa_information(LIBBALSA_INFORMATION_ERROR,
-                            _("Could not remove %s:\n%s"),
-                            path, strerror(errno));
+        libbalsa_information(LIBBALSA_INFORMATION_ERROR,
+                             _("Could not remove %s:\n%s"),
+                             path, strerror(errno));
     }
     LIBBALSA_MAILBOX_LOCAL_CLASS(libbalsa_mailbox_maildir_parent_class)->remove_files(mailbox);
 }
 
-static LibBalsaMessageFlag parse_filename(const gchar *subdir,
-                                         const gchar *filename)
+
+static LibBalsaMessageFlag
+parse_filename(const gchar *subdir,
+               const gchar *filename)
 {
     const gchar *p;
     LibBalsaMessageFlag flags;
 
     flags = LIBBALSA_MESSAGE_FLAG_NEW;
-    if (strcmp(subdir, "cur") != 0)
-       flags |= LIBBALSA_MESSAGE_FLAG_RECENT;
-
-    if ((p = strrchr (filename, ':')) != NULL && strncmp (p + 1, "2,", 2) == 0)
-    {
-       p += 3;
-       while (*p)
-       {
-           switch (*p)
-           {
-               case 'F':
-                   flags |= LIBBALSA_MESSAGE_FLAG_FLAGGED;
-                   break;
-       
-               case 'S': /* seen */
-                   flags &= ~LIBBALSA_MESSAGE_FLAG_NEW;
-                   break;
-
-               case 'R': /* replied */
-                   flags |= LIBBALSA_MESSAGE_FLAG_REPLIED;
-                   break;
-
-               case 'T': /* trashed */
-                   flags |= LIBBALSA_MESSAGE_FLAG_DELETED;
-                   break;
-           }
-           p++;
-       }
+    if (strcmp(subdir, "cur") != 0) {
+        flags |= LIBBALSA_MESSAGE_FLAG_RECENT;
+    }
+
+    if (((p = strrchr (filename, ':')) != NULL) && (strncmp (p + 1, "2,", 2) == 0)) {
+        p += 3;
+        while (*p) {
+            switch (*p) {
+            case 'F':
+                flags |= LIBBALSA_MESSAGE_FLAG_FLAGGED;
+                break;
+
+            case 'S':     /* seen */
+                flags &= ~LIBBALSA_MESSAGE_FLAG_NEW;
+                break;
+
+            case 'R':     /* replied */
+                flags |= LIBBALSA_MESSAGE_FLAG_REPLIED;
+                break;
+
+            case 'T':     /* trashed */
+                flags |= LIBBALSA_MESSAGE_FLAG_DELETED;
+                break;
+            }
+            p++;
+        }
     }
     return flags;
 }
 
-static void lbm_maildir_parse(LibBalsaMailboxMaildir * mdir,
-                              const gchar *subdir, guint * fileno)
+
+static void
+lbm_maildir_parse(LibBalsaMailboxMaildir *mdir,
+                  const gchar            *subdir,
+                  guint                  *fileno)
 {
     const gchar *local_path;
     gchar *path;
@@ -382,58 +404,62 @@ static void lbm_maildir_parse(LibBalsaMailboxMaildir * mdir,
     LibBalsaMailbox *mailbox = (LibBalsaMailbox *) mdir;
 
     local_path = libbalsa_mailbox_local_get_path((LibBalsaMailboxLocal *) mailbox);
-    path = g_build_filename(local_path, subdir, NULL);
-    dir = g_dir_open(path, 0, NULL);
+    path       = g_build_filename(local_path, subdir, NULL);
+    dir        = g_dir_open(path, 0, NULL);
     g_free(path);
-    if (dir == NULL)
-       return;
+    if (dir == NULL) {
+        return;
+    }
 
-    messages_info = mdir->messages_info;
+    messages_info    = mdir->messages_info;
     msgno_2_msg_info = mdir->msgno_2_msg_info;
-    while ((filename = g_dir_read_name(dir)) != NULL)
-    {
-       struct message_info *msg_info;
-       if (filename[0] == '.')
-           continue;
-
-       key = g_strdup(filename);
-       /* strip flags of filename */
-       if ((p = strrchr(key, ':')) && !strncmp(p, ":2,", 3))
-           *p = '\0';
-
-       flags = parse_filename(subdir, filename);
-       msg_info = g_hash_table_lookup(messages_info, key);
-       if (msg_info) {
-           g_free(key);
-           g_free(msg_info->filename);
-           msg_info->filename = g_strdup(filename);
-           if (FLAGS_REALLY_DIFFER(msg_info->orig_flags, flags)) {
+    while ((filename = g_dir_read_name(dir)) != NULL) {
+        struct message_info *msg_info;
+        if (filename[0] == '.') {
+            continue;
+        }
+
+        key = g_strdup(filename);
+        /* strip flags of filename */
+        if ((p = strrchr(key, ':')) && !strncmp(p, ":2,", 3)) {
+            *p = '\0';
+        }
+
+        flags    = parse_filename(subdir, filename);
+        msg_info = g_hash_table_lookup(messages_info, key);
+        if (msg_info) {
+            g_free(key);
+            g_free(msg_info->filename);
+            msg_info->filename = g_strdup(filename);
+            if (FLAGS_REALLY_DIFFER(msg_info->orig_flags, flags)) {
 #undef DEBUG /* #define DEBUG TRUE */
 #ifdef DEBUG
-               g_message("Message flags for “%s” changed\n",
+                g_message("Message flags for “%s” changed\n",
                           msg_info->key);
 #endif
-               msg_info->orig_flags = flags;
-           }
-       } else {
-           msg_info = g_new0(struct message_info, 1);
-           g_hash_table_insert(messages_info, key, msg_info);
-           g_ptr_array_add(msgno_2_msg_info, msg_info);
-           msg_info->key=key;
-           msg_info->filename=g_strdup(filename);
-           msg_info->local_info.flags = msg_info->orig_flags = flags;
-           msg_info->fileno = 0;
-       }
-       msg_info->subdir = subdir;
-        if (!msg_info->fileno)
+                msg_info->orig_flags = flags;
+            }
+        } else {
+            msg_info = g_new0(struct message_info, 1);
+            g_hash_table_insert(messages_info, key, msg_info);
+            g_ptr_array_add(msgno_2_msg_info, msg_info);
+            msg_info->key              = key;
+            msg_info->filename         = g_strdup(filename);
+            msg_info->local_info.flags = msg_info->orig_flags = flags;
+            msg_info->fileno           = 0;
+        }
+        msg_info->subdir = subdir;
+        if (!msg_info->fileno) {
             /* First time we saw this key. */
-           msg_info->fileno = ++*fileno;
+            msg_info->fileno = ++*fileno;
+        }
     }
     g_dir_close(dir);
 }
 
+
 static void
-lbm_maildir_parse_subdirs(LibBalsaMailboxMaildir * mdir)
+lbm_maildir_parse_subdirs(LibBalsaMailboxMaildir *mdir)
 {
     guint msgno, fileno = 0;
 
@@ -452,12 +478,14 @@ lbm_maildir_parse_subdirs(LibBalsaMailboxMaildir * mdir)
     lbm_maildir_parse(mdir, "new", &fileno);
 }
 
+
 static gboolean
-libbalsa_mailbox_maildir_open(LibBalsaMailbox * mailbox, GError **err)
+libbalsa_mailbox_maildir_open(LibBalsaMailbox *mailbox,
+                              GError         **err)
 {
     struct stat st;
     LibBalsaMailboxMaildir *mdir;
-    const gchar* path;
+    const gchar *path;
 
     g_return_val_if_fail(LIBBALSA_IS_MAILBOX_MAILDIR(mailbox), FALSE);
 
@@ -465,36 +493,38 @@ libbalsa_mailbox_maildir_open(LibBalsaMailbox * mailbox, GError **err)
     path = libbalsa_mailbox_local_get_path((LibBalsaMailboxLocal *) mailbox);
 
     if (stat(path, &st) == -1) {
-       g_set_error(err, LIBBALSA_MAILBOX_ERROR, LIBBALSA_MAILBOX_OPEN_ERROR,
-                   _("Mailbox does not exist."));
-       return FALSE;
+        g_set_error(err, LIBBALSA_MAILBOX_ERROR, LIBBALSA_MAILBOX_OPEN_ERROR,
+                    _("Mailbox does not exist."));
+        return FALSE;
     }
 
     mdir->messages_info = g_hash_table_new_full(g_str_hash, g_str_equal,
-                                 NULL, (GDestroyNotify)free_message_info);
+                                                NULL, (GDestroyNotify)free_message_info);
     mdir->msgno_2_msg_info = g_ptr_array_new();
 
-    if (stat(mdir->tmpdir, &st) != -1)
-       libbalsa_mailbox_set_mtime(mailbox, st.st_mtime);
+    if (stat(mdir->tmpdir, &st) != -1) {
+        libbalsa_mailbox_set_mtime(mailbox, st.st_mtime);
+    }
 
     libbalsa_mailbox_set_readonly(mailbox,
-       !(access(mdir->curdir, W_OK) == 0 &&
-          access(mdir->newdir, W_OK) == 0 &&
-          access(mdir->tmpdir, W_OK) == 0));
+                                  !(access(mdir->curdir, W_OK) == 0 &&
+                                    access(mdir->newdir, W_OK) == 0 &&
+                                    access(mdir->tmpdir, W_OK) == 0));
 
     libbalsa_mailbox_clear_unread_messages(mailbox);
     lbm_maildir_parse_subdirs(mdir);
 #ifdef DEBUG
     g_print(_("%s: Opening %s Refcount: %d\n"),
-           "LibBalsaMailboxMaildir", libbalsa_mailbox_get_name(mailbox),
+            "LibBalsaMailboxMaildir", libbalsa_mailbox_get_name(mailbox),
             libbalsa_mailbox_get_open_ref(mailbox));
 #endif
     return TRUE;
 }
 
+
 /* Check for a new message in subdir. */
 static gboolean
-lbm_maildir_check(const gchar * subdir)
+lbm_maildir_check(const gchar *subdir)
 {
     GDir *dir;
     const gchar *filename;
@@ -502,24 +532,25 @@ lbm_maildir_check(const gchar * subdir)
     gboolean retval = FALSE;
 
     if ((dir = g_dir_open(subdir, 0, NULL))) {
-       while ((filename = g_dir_read_name(dir))) {
-           if (*filename != '.' && (!(p = strstr(filename, ":2,"))
-                                    || !(strchr(p + 3, 'S')
-                                         || strchr(p + 3, 'T')))) {
-               /* One new message is enough. */
-               retval = TRUE;
-               break;
-           }
-       }
-       g_dir_close(dir);
+        while ((filename = g_dir_read_name(dir))) {
+            if ((*filename != '.') && (!(p = strstr(filename, ":2,"))
+                                       || !(strchr(p + 3, 'S')
+                                            || strchr(p + 3, 'T')))) {
+                /* One new message is enough. */
+                retval = TRUE;
+                break;
+            }
+        }
+        g_dir_close(dir);
     }
 
     return retval;
 }
 
+
 /* Called with mailbox locked. */
 static void
-libbalsa_mailbox_maildir_check(LibBalsaMailbox * mailbox)
+libbalsa_mailbox_maildir_check(LibBalsaMailbox *mailbox)
 {
     struct stat st;
     LibBalsaMailboxMaildir *mdir;
@@ -532,54 +563,58 @@ libbalsa_mailbox_maildir_check(LibBalsaMailbox * mailbox)
 
     mdir = LIBBALSA_MAILBOX_MAILDIR(mailbox);
 
-    if (stat(mdir->tmpdir, &st) == -1)
-       return;
+    if (stat(mdir->tmpdir, &st) == -1) {
+        return;
+    }
 
     if ((mtime = libbalsa_mailbox_get_mtime(mailbox)) == 0) {
-       /* First check--just cache the mtime. */
-       libbalsa_mailbox_set_mtime(mailbox, st.st_mtime);
+        /* First check--just cache the mtime. */
+        libbalsa_mailbox_set_mtime(mailbox, st.st_mtime);
+        return;
+    }
+    if (st.st_mtime == mtime) {
         return;
     }
-    if (st.st_mtime == mtime)
-       return;
 
     libbalsa_mailbox_set_mtime(mailbox, st.st_mtime);
 
     if (!MAILBOX_OPEN(mailbox)) {
-       libbalsa_mailbox_set_unread_messages_flag(mailbox,
-                                                 lbm_maildir_check(mdir->
-                                                                   newdir)
-                                                 ||
-                                                 lbm_maildir_check(mdir->
-                                                                   curdir));
-       return;
+        libbalsa_mailbox_set_unread_messages_flag(mailbox,
+                                                  lbm_maildir_check(mdir->
+                                                                    newdir)
+                                                  ||
+                                                  lbm_maildir_check(mdir->
+                                                                    curdir));
+        return;
     }
 
     /* Was any message removed? */
-    path = libbalsa_mailbox_local_get_path((LibBalsaMailboxLocal *) mailbox);
+    path     = libbalsa_mailbox_local_get_path((LibBalsaMailboxLocal *) mailbox);
     renumber = mdir->msgno_2_msg_info->len + 1;
     for (msgno = 1; msgno <= mdir->msgno_2_msg_info->len; ) {
-       gchar *filename;
+        gchar *filename;
 
         msg_info = message_info_from_msgno(mdir, msgno);
-       filename = g_build_filename(path, msg_info->subdir,
-                                   msg_info->filename, NULL);
-       if (access(filename, F_OK) == 0)
-           msgno++;
-       else {
-           g_ptr_array_remove(mdir->msgno_2_msg_info, msg_info);
-           g_hash_table_remove(mdir->messages_info, msg_info->key);
-           libbalsa_mailbox_local_msgno_removed(mailbox, msgno);
-           if (renumber > msgno)
-               /* First message that needs renumbering. */
-               renumber = msgno;
-       }
-       g_free(filename);
+        filename = g_build_filename(path, msg_info->subdir,
+                                    msg_info->filename, NULL);
+        if (access(filename, F_OK) == 0) {
+            msgno++;
+        } else {
+            g_ptr_array_remove(mdir->msgno_2_msg_info, msg_info);
+            g_hash_table_remove(mdir->messages_info, msg_info->key);
+            libbalsa_mailbox_local_msgno_removed(mailbox, msgno);
+            if (renumber > msgno) {
+                /* First message that needs renumbering. */
+                renumber = msgno;
+            }
+        }
+        g_free(filename);
     }
     for (msgno = renumber; msgno <= mdir->msgno_2_msg_info->len; msgno++) {
-       msg_info = message_info_from_msgno(mdir, msgno);
-       if (msg_info->local_info.message)
-           msg_info->local_info.message->msgno = msgno;
+        msg_info = message_info_from_msgno(mdir, msgno);
+        if (msg_info->local_info.message) {
+            msg_info->local_info.message->msgno = msgno;
+        }
     }
 
     msgno = mdir->msgno_2_msg_info->len;
@@ -587,37 +622,42 @@ libbalsa_mailbox_maildir_check(LibBalsaMailbox * mailbox)
     libbalsa_mailbox_local_load_messages(mailbox, msgno);
 }
 
+
 static void
 free_message_info(struct message_info *msg_info)
 {
-    if (!msg_info)
-       return;
+    if (!msg_info) {
+        return;
+    }
     g_free(msg_info->key);
     g_free(msg_info->filename);
     if (msg_info->local_info.message) {
-       msg_info->local_info.message->mailbox = NULL;
-       msg_info->local_info.message->msgno   = 0;
-       g_object_remove_weak_pointer(G_OBJECT(msg_info->local_info.message),
-                                    (gpointer) & msg_info->local_info.message);
+        msg_info->local_info.message->mailbox = NULL;
+        msg_info->local_info.message->msgno   = 0;
+        g_object_remove_weak_pointer(G_OBJECT(msg_info->local_info.message),
+                                     (gpointer) & msg_info->local_info.message);
     }
     g_free(msg_info);
 }
 
+
 static void
-libbalsa_mailbox_maildir_close_mailbox(LibBalsaMailbox * mailbox,
-                                       gboolean expunge)
+libbalsa_mailbox_maildir_close_mailbox(LibBalsaMailbox *mailbox,
+                                       gboolean         expunge)
 {
     LibBalsaMailboxMaildir *mdir = LIBBALSA_MAILBOX_MAILDIR(mailbox);
     guint len;
 
     len = mdir->msgno_2_msg_info->len;
     libbalsa_mailbox_maildir_sync(mailbox, expunge);
-    if (mdir->msgno_2_msg_info->len != len)
+    if (mdir->msgno_2_msg_info->len != len) {
         libbalsa_mailbox_changed(mailbox);
+    }
 
-    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_maildir_parent_class)->close_mailbox)
+    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_maildir_parent_class)->close_mailbox) {
         LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_maildir_parent_class)->close_mailbox(mailbox,
-                                                            expunge);
+                                                                                     expunge);
+    }
 
     /* Now it's safe to free the message info. */
     g_hash_table_destroy(mdir->messages_info);
@@ -627,6 +667,7 @@ libbalsa_mailbox_maildir_close_mailbox(LibBalsaMailbox * mailbox,
     mdir->msgno_2_msg_info = NULL;
 }
 
+
 static gchar *
 lbm_mdir_get_key(void)
 {
@@ -636,32 +677,35 @@ lbm_mdir_get_key(void)
                            counter++);
 }
 
+
 static int
 libbalsa_mailbox_maildir_open_temp(const gchar *dest_path,
-                                   char **name_used)
+                                   char       **name_used)
 {
     int fd;
     gchar *filename;
 
     do {
-       gchar *key = lbm_mdir_get_key();
-       filename = g_build_filename(dest_path, "tmp", key, NULL);
-       g_free(key);
-       fd = open (filename, O_WRONLY | O_EXCL | O_CREAT, 0600);
-       if (fd == -1)
-       {
-           g_free(filename);
-           if (errno != EEXIST)
-               return -1;
-       }
+        gchar *key = lbm_mdir_get_key();
+        filename = g_build_filename(dest_path, "tmp", key, NULL);
+        g_free(key);
+        fd = open (filename, O_WRONLY | O_EXCL | O_CREAT, 0600);
+        if (fd == -1) {
+            g_free(filename);
+            if (errno != EEXIST) {
+                return -1;
+            }
+        }
     } while (fd == -1);
     *name_used = filename;
     return fd;
 }
 
+
 /* Sync: flush flags and expunge. */
 static gboolean
-maildir_sync_add(struct message_info *msg_info, const gchar * path)
+maildir_sync_add(struct message_info *msg_info,
+                 const gchar         *path)
 {
     gchar new_flags[10];
     int len;
@@ -673,27 +717,31 @@ maildir_sync_add(struct message_info *msg_info, const gchar * path)
 
     len = 0;
 
-    if ((msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_FLAGGED) != 0)
-       new_flags[len++] = 'F';
-    if ((msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_NEW) == 0)
-       new_flags[len++] = 'S';
-    if ((msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_REPLIED) != 0)
-       new_flags[len++] = 'R';
-    if ((msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_DELETED) != 0)
-       new_flags[len++] = 'T';
+    if ((msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_FLAGGED) != 0) {
+        new_flags[len++] = 'F';
+    }
+    if ((msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_NEW) == 0) {
+        new_flags[len++] = 'S';
+    }
+    if ((msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_REPLIED) != 0) {
+        new_flags[len++] = 'R';
+    }
+    if ((msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_DELETED) != 0) {
+        new_flags[len++] = 'T';
+    }
 
     new_flags[len] = '\0';
 
-    subdir = msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_RECENT ? "new" : "cur";
+    subdir   = msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_RECENT ? "new" : "cur";
     filename =
         g_strconcat(msg_info->key, (len ? ":2," : ""), new_flags, NULL);
-    new = g_build_filename(path, subdir, filename, NULL);
+    new  = g_build_filename(path, subdir, filename, NULL);
     orig =
         g_build_filename(path, msg_info->subdir, msg_info->filename, NULL);
     if (strcmp(orig, new)) {
         while (g_file_test(new, G_FILE_TEST_EXISTS)) {
 #ifdef DEBUG
-           g_message("File “%s” exists, requesting new key.\n", new);
+            g_message("File “%s” exists, requesting new key.\n", new);
 #endif
             g_free(msg_info->key);
             msg_info->key = lbm_mdir_get_key();
@@ -704,27 +752,29 @@ maildir_sync_add(struct message_info *msg_info, const gchar * path)
             g_free(new);
             new = g_build_filename(path, subdir, filename, NULL);
         }
-       if (rename(orig, new) >= 0) /* FIXME: change to safe_rename??? */
-           msg_info->subdir = subdir;
-       else {
+        if (rename(orig, new) >= 0) { /* FIXME: change to safe_rename??? */
+            msg_info->subdir = subdir;
+        } else {
 #ifdef DEBUG
             g_message("Rename “%s” “%s”: %s\n", orig, new,
                       g_strerror(errno));
 #endif
-           retval = FALSE;
-       }
+            retval = FALSE;
+        }
     }
     g_free(orig);
     g_free(new);
     g_free(msg_info->filename);
-    msg_info->filename = filename;
+    msg_info->filename   = filename;
     msg_info->orig_flags = REAL_FLAGS(msg_info->local_info.flags);
 
     return retval;
 }
 
+
 static gboolean
-libbalsa_mailbox_maildir_sync(LibBalsaMailbox * mailbox, gboolean expunge)
+libbalsa_mailbox_maildir_sync(LibBalsaMailbox *mailbox,
+                              gboolean         expunge)
 {
     /*
      * foreach message_info
@@ -734,64 +784,69 @@ libbalsa_mailbox_maildir_sync(LibBalsaMailbox * mailbox, gboolean expunge)
      * record mtime of dirs
      */
     LibBalsaMailboxMaildir *mdir = LIBBALSA_MAILBOX_MAILDIR(mailbox);
-    const gchar *path = libbalsa_mailbox_local_get_path((LibBalsaMailboxLocal *) mailbox);
+    const gchar *path            = libbalsa_mailbox_local_get_path(
+            (LibBalsaMailboxLocal *) mailbox);
     GSList *removed_list = NULL;
-    gboolean ok = TRUE;
+    gboolean ok          = TRUE;
     GSList *l;
     guint renumber, msgno;
     struct message_info *msg_info;
     guint changes = 0;
 
     for (msgno = 1; msgno <= mdir->msgno_2_msg_info->len; msgno++) {
-       msg_info = message_info_from_msgno(mdir, msgno);
+        msg_info = message_info_from_msgno(mdir, msgno);
 
-       if (expunge && (msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_DELETED)) {
-           /* skip this block if the message should only be renamed */
-           gchar *orig = g_build_filename(path, msg_info->subdir,
+        if (expunge && (msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_DELETED)) {
+            /* skip this block if the message should only be renamed */
+            gchar *orig = g_build_filename(path, msg_info->subdir,
                                            msg_info->filename, NULL);
-           unlink (orig);
-           g_free(orig);
-           removed_list =
-               g_slist_prepend(removed_list, GUINT_TO_POINTER(msgno));
-           ++changes;
-           continue;
-       }
-
-       if (libbalsa_mailbox_get_state(mailbox) == LB_MAILBOX_STATE_CLOSING)
-           msg_info->local_info.flags &= ~LIBBALSA_MESSAGE_FLAG_RECENT;
-       if (((msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_RECENT)
-             && strcmp(msg_info->subdir, "new") != 0)
+            unlink (orig);
+            g_free(orig);
+            removed_list =
+                g_slist_prepend(removed_list, GUINT_TO_POINTER(msgno));
+            ++changes;
+            continue;
+        }
+
+        if (libbalsa_mailbox_get_state(mailbox) == LB_MAILBOX_STATE_CLOSING) {
+            msg_info->local_info.flags &= ~LIBBALSA_MESSAGE_FLAG_RECENT;
+        }
+        if (((msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_RECENT)
+             && (strcmp(msg_info->subdir, "new") != 0))
             || (!(msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_RECENT)
-                && strcmp(msg_info->subdir, "cur") != 0)
+                && (strcmp(msg_info->subdir, "cur") != 0))
             || FLAGS_CHANGED(msg_info)) {
-           if (!maildir_sync_add(msg_info, path))
-               ok = FALSE;
-           ++changes;
-       }
+            if (!maildir_sync_add(msg_info, path)) {
+                ok = FALSE;
+            }
+            ++changes;
+        }
     }
 
     if (!ok) {
-       g_slist_free(removed_list);
-       return FALSE;
+        g_slist_free(removed_list);
+        return FALSE;
     }
 
     renumber = mdir->msgno_2_msg_info->len + 1;
     for (l = removed_list; l; l = l->next) {
-       msgno = GPOINTER_TO_UINT(l->data);
-       if (renumber > msgno)
-           renumber = msgno;
-       msg_info = message_info_from_msgno(mdir, msgno);
+        msgno = GPOINTER_TO_UINT(l->data);
+        if (renumber > msgno) {
+            renumber = msgno;
+        }
+        msg_info = message_info_from_msgno(mdir, msgno);
 
-       g_ptr_array_remove(mdir->msgno_2_msg_info, msg_info);
-       libbalsa_mailbox_local_msgno_removed(mailbox, msgno);
-       /* This will free removed: */
-       g_hash_table_remove(mdir->messages_info, msg_info->key);
+        g_ptr_array_remove(mdir->msgno_2_msg_info, msg_info);
+        libbalsa_mailbox_local_msgno_removed(mailbox, msgno);
+        /* This will free removed: */
+        g_hash_table_remove(mdir->messages_info, msg_info->key);
     }
     g_slist_free(removed_list);
     for (msgno = renumber; msgno <= mdir->msgno_2_msg_info->len; msgno++) {
-       msg_info = message_info_from_msgno(mdir, msgno);
-       if (msg_info->local_info.message)
-           msg_info->local_info.message->msgno = msgno;
+        msg_info = message_info_from_msgno(mdir, msgno);
+        if (msg_info->local_info.message) {
+            msg_info->local_info.message->msgno = msgno;
+        }
     }
 
     if (changes) {              /* Record mtime of dir. */
@@ -801,15 +856,18 @@ libbalsa_mailbox_maildir_sync(LibBalsaMailbox * mailbox, gboolean expunge)
         lbm_maildir_parse_subdirs(mdir);
         libbalsa_mailbox_set_msg_tree_changed(mailbox, TRUE);
 
-        if (stat(mdir->tmpdir, &st) == 0)
+        if (stat(mdir->tmpdir, &st) == 0) {
             libbalsa_mailbox_set_mtime(mailbox, st.st_mtime);
+        }
     }
 
     return TRUE;
 }
 
+
 static struct message_info *
-message_info_from_msgno(LibBalsaMailboxMaildir * mdir, guint msgno)
+message_info_from_msgno(LibBalsaMailboxMaildir *mdir,
+                        guint                   msgno)
 {
     g_assert(msgno > 0 && msgno <= mdir->msgno_2_msg_info->len);
 
@@ -820,31 +878,34 @@ message_info_from_msgno(LibBalsaMailboxMaildir * mdir, guint msgno)
 
 
 static gboolean
-libbalsa_mailbox_maildir_fetch_message_structure(LibBalsaMailbox * mailbox,
-                                                LibBalsaMessage * message,
-                                                LibBalsaFetchFlag flags)
+libbalsa_mailbox_maildir_fetch_message_structure(LibBalsaMailbox  *mailbox,
+                                                 LibBalsaMessage  *message,
+                                                 LibBalsaFetchFlag flags)
 {
     if (!message->mime_msg) {
-       struct message_info *msg_info =
+        struct message_info *msg_info =
             message_info_from_msgno((LibBalsaMailboxMaildir *) mailbox,
                                     message->msgno);
-       message->mime_msg =
-           libbalsa_mailbox_local_get_mime_message(mailbox,
-                                                   msg_info->subdir,
-                                                   msg_info->filename);
+        message->mime_msg =
+            libbalsa_mailbox_local_get_mime_message(mailbox,
+                                                    msg_info->subdir,
+                                                    msg_info->filename);
     }
 
     return LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_maildir_parent_class)->
-        fetch_message_structure(mailbox, message, flags);
+           fetch_message_structure(mailbox, message, flags);
 }
 
+
 static guint
-lbm_maildir_fileno(LibBalsaMailboxLocal * local, guint msgno)
+lbm_maildir_fileno(LibBalsaMailboxLocal *local,
+                   guint                 msgno)
 {
     struct message_info *msg_info;
 
-    if (!msgno)
+    if (!msgno) {
         return 0;
+    }
 
     msg_info =
         message_info_from_msgno((LibBalsaMailboxMaildir *) local, msgno);
@@ -852,8 +913,10 @@ lbm_maildir_fileno(LibBalsaMailboxLocal * local, guint msgno)
     return msg_info->fileno;
 }
 
+
 static LibBalsaMailboxLocalMessageInfo *
-lbm_maildir_get_info(LibBalsaMailboxLocal * local, guint msgno)
+lbm_maildir_get_info(LibBalsaMailboxLocal *local,
+                     guint                 msgno)
 {
     struct message_info *msg_info;
 
@@ -863,12 +926,13 @@ lbm_maildir_get_info(LibBalsaMailboxLocal * local, guint msgno)
     return &msg_info->local_info;
 }
 
+
 /* Called with mailbox locked. */
 static gboolean
-lbm_maildir_add_message(LibBalsaMailboxLocal * local,
-                        GMimeStream          * stream,
-                        LibBalsaMessageFlag    flags,
-                        GError              ** err)
+lbm_maildir_add_message(LibBalsaMailboxLocal *local,
+                        GMimeStream          *stream,
+                        LibBalsaMessageFlag   flags,
+                        GError              **err)
 {
     LibBalsaMailbox *mailbox = (LibBalsaMailbox *) local;
     const char *path;
@@ -884,18 +948,19 @@ lbm_maildir_add_message(LibBalsaMailboxLocal * local,
 
     /* open tempfile */
     path = libbalsa_mailbox_local_get_path(local);
-    fd = libbalsa_mailbox_maildir_open_temp(path, &tmp);
-    if (fd == -1)
-       return FALSE;
+    fd   = libbalsa_mailbox_maildir_open_temp(path, &tmp);
+    if (fd == -1) {
+        return FALSE;
+    }
     out_stream = g_mime_stream_fs_new(fd);
 
-    in_stream = g_mime_stream_filter_new(stream);
+    in_stream  = g_mime_stream_filter_new(stream);
     crlffilter =
         g_mime_filter_crlf_new(FALSE,
                                FALSE);
     g_mime_stream_filter_add(GMIME_STREAM_FILTER(in_stream), crlffilter);
     g_object_unref(crlffilter);
- 
+
     libbalsa_mime_stream_shared_lock(stream);
     retval = g_mime_stream_write_to_stream(in_stream, out_stream);
     libbalsa_mime_stream_shared_unlock(stream);
@@ -903,39 +968,42 @@ lbm_maildir_add_message(LibBalsaMailboxLocal * local,
     g_object_unref(out_stream);
 
     if (retval < 0) {
-       unlink (tmp);
-       g_free(tmp);
+        unlink (tmp);
+        g_free(tmp);
         g_set_error(err, LIBBALSA_MAILBOX_ERROR,
                     LIBBALSA_MAILBOX_COPY_ERROR,
                     _("Data copy error"));
-       return FALSE;
+        return FALSE;
     }
 
     new_filename = strrchr(tmp, '/');
-    if (new_filename)
-       new_filename++;
-    else
-       new_filename = tmp;
-    msg_info = g_new0(struct message_info, 1);
-    msg_info->subdir = "tmp";
-    msg_info->key = g_strdup(new_filename);
-    msg_info->filename = g_strdup(new_filename);
+    if (new_filename) {
+        new_filename++;
+    } else {
+        new_filename = tmp;
+    }
+    msg_info                   = g_new0(struct message_info, 1);
+    msg_info->subdir           = "tmp";
+    msg_info->key              = g_strdup(new_filename);
+    msg_info->filename         = g_strdup(new_filename);
     msg_info->local_info.flags = flags | LIBBALSA_MESSAGE_FLAG_RECENT;
-    retval = maildir_sync_add(msg_info, path);
+    retval                     = maildir_sync_add(msg_info, path);
     free_message_info(msg_info);
     g_free(tmp);
 
-    if ((mtime = libbalsa_mailbox_get_mtime(mailbox)) != 0)
-       /* If we checked or synced the mailbox less than 1 second ago,
-        * the cached modification time could be the same as the new
-        * modification time, so we'll invalidate the cached time. */
-       libbalsa_mailbox_set_mtime(mailbox, --mtime);
+    if ((mtime = libbalsa_mailbox_get_mtime(mailbox)) != 0) {
+        /* If we checked or synced the mailbox less than 1 second ago,
+         * the cached modification time could be the same as the new
+         * modification time, so we'll invalidate the cached time. */
+        libbalsa_mailbox_set_mtime(mailbox, --mtime);
+    }
 
     return retval;
 }
 
+
 static guint
-libbalsa_mailbox_maildir_total_messages(LibBalsaMailbox * mailbox)
+libbalsa_mailbox_maildir_total_messages(LibBalsaMailbox *mailbox)
 {
     LibBalsaMailboxMaildir *mdir = (LibBalsaMailboxMaildir *) mailbox;
 
diff --git a/libbalsa/mailbox_maildir.h b/libbalsa/mailbox_maildir.h
index ef6ad42..51fbcbc 100644
--- a/libbalsa/mailbox_maildir.h
+++ b/libbalsa/mailbox_maildir.h
@@ -6,14 +6,14 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option) 
+ * the Free Software Foundation; either version 2, or (at your option)
  * any later version.
- *  
+ *
  * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of 
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *  
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
@@ -29,8 +29,7 @@ G_DECLARE_FINAL_TYPE(LibBalsaMailboxMaildir,
                      MAILBOX_MAILDIR,
                      LibBalsaMailboxLocal)
 
-LibBalsaMailbox *libbalsa_mailbox_maildir_new(const gchar * path,
-                                              gboolean      create);
+LibBalsaMailbox * libbalsa_mailbox_maildir_new(const gchar * path,
+                                               gboolean create);
 
 #endif
-
diff --git a/libbalsa/mailbox_mbox.c b/libbalsa/mailbox_mbox.c
index 9d9efc9..19ec09e 100644
--- a/libbalsa/mailbox_mbox.c
+++ b/libbalsa/mailbox_mbox.c
@@ -6,20 +6,20 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option) 
+ * the Free Software Foundation; either version 2, or (at your option)
  * any later version.
- *  
+ *
  * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of 
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *  
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H
-# include "config.h"
+#   include "config.h"
 #endif                          /* HAVE_CONFIG_H */
 
 
@@ -50,9 +50,9 @@ struct message_info {
     LibBalsaMailboxLocalMessageInfo local_info;
     LibBalsaMessageFlag orig_flags;     /* Has only real flags */
     off_t start;
-    off_t status;              /* Offset of the "Status:" header. */
-    off_t x_status;            /* Offset of the "X-Status:" header. */
-    off_t mime_version;                /* Offset of the "MIME-Version:" header. */
+    off_t status;               /* Offset of the "Status:" header. */
+    off_t x_status;             /* Offset of the "X-Status:" header. */
+    off_t mime_version;         /* Offset of the "MIME-Version:" header. */
     off_t end;
     size_t from_len;
 };
@@ -61,38 +61,39 @@ struct message_info {
 #define FLAGS_REALLY_DIFFER(orig_flags, flags) \
     ((((orig_flags) ^ (flags)) & LIBBALSA_MESSAGE_FLAGS_REAL) != 0)
 
-static void libbalsa_mailbox_mbox_class_init(LibBalsaMailboxMboxClass *klass);
-static void libbalsa_mailbox_mbox_init(LibBalsaMailboxMbox * mailbox);
-static void libbalsa_mailbox_mbox_dispose(GObject * object);
+static void         libbalsa_mailbox_mbox_class_init(LibBalsaMailboxMboxClass *klass);
+static void         libbalsa_mailbox_mbox_init(LibBalsaMailboxMbox *mailbox);
+static void         libbalsa_mailbox_mbox_dispose(GObject *object);
 
 static GMimeStream *libbalsa_mailbox_mbox_get_message_stream(LibBalsaMailbox *
-                                                            mailbox,
-                                                            guint msgno,
-                                                            gboolean peek);
-static gint lbm_mbox_check_files(const gchar * path, gboolean create);
-static void libbalsa_mailbox_mbox_remove_files(LibBalsaMailboxLocal *mailbox);
-
-static gboolean libbalsa_mailbox_mbox_open(LibBalsaMailbox * mailbox,
-                                          GError **err);
-static void libbalsa_mailbox_mbox_close_mailbox(LibBalsaMailbox * mailbox,
-                                                gboolean expunge);
-static void libbalsa_mailbox_mbox_check(LibBalsaMailbox * mailbox);
-static gboolean libbalsa_mailbox_mbox_sync(LibBalsaMailbox * mailbox,
-                                           gboolean expunge);
+                                                             mailbox,
+                                                             guint    msgno,
+                                                             gboolean peek);
+static gint     lbm_mbox_check_files(const gchar *path,
+                                     gboolean     create);
+static void     libbalsa_mailbox_mbox_remove_files(LibBalsaMailboxLocal *mailbox);
+
+static gboolean libbalsa_mailbox_mbox_open(LibBalsaMailbox *mailbox,
+                                           GError         **err);
+static void     libbalsa_mailbox_mbox_close_mailbox(LibBalsaMailbox *mailbox,
+                                                    gboolean         expunge);
+static void     libbalsa_mailbox_mbox_check(LibBalsaMailbox *mailbox);
+static gboolean libbalsa_mailbox_mbox_sync(LibBalsaMailbox *mailbox,
+                                           gboolean         expunge);
 
 /* LibBalsaMailboxLocal class methods */
 static LibBalsaMailboxLocalMessageInfo
-    *lbm_mbox_get_info(LibBalsaMailboxLocal * local, guint msgno);
+*lbm_mbox_get_info(LibBalsaMailboxLocal *local,
+                   guint                 msgno);
+
 static LibBalsaMailboxLocalAddMessageFunc lbm_mbox_add_message;
 
-static gboolean
-libbalsa_mailbox_mbox_fetch_message_structure(LibBalsaMailbox * mailbox,
-                                              LibBalsaMessage * message,
-                                              LibBalsaFetchFlag flags);
-static guint
-libbalsa_mailbox_mbox_total_messages(LibBalsaMailbox * mailbox);
-static void libbalsa_mailbox_mbox_lock_store(LibBalsaMailbox * mailbox,
-                                             gboolean lock);
+static gboolean libbalsa_mailbox_mbox_fetch_message_structure(LibBalsaMailbox  *mailbox,
+                                                              LibBalsaMessage  *message,
+                                                              LibBalsaFetchFlag flags);
+static guint libbalsa_mailbox_mbox_total_messages(LibBalsaMailbox *mailbox);
+static void  libbalsa_mailbox_mbox_lock_store(LibBalsaMailbox *mailbox,
+                                              gboolean         lock);
 
 struct _LibBalsaMailboxMboxClass {
     LibBalsaMailboxLocalClass klass;
@@ -112,58 +113,61 @@ G_DEFINE_TYPE(LibBalsaMailboxMbox,
               LIBBALSA_TYPE_MAILBOX_LOCAL)
 
 static void
-libbalsa_mailbox_mbox_class_init(LibBalsaMailboxMboxClass * klass)
+libbalsa_mailbox_mbox_class_init(LibBalsaMailboxMboxClass *klass)
 {
     GObjectClass *object_class;
     LibBalsaMailboxClass *libbalsa_mailbox_class;
     LibBalsaMailboxLocalClass *libbalsa_mailbox_local_class;
 
-    object_class = G_OBJECT_CLASS(klass);
-    libbalsa_mailbox_class = LIBBALSA_MAILBOX_CLASS(klass);
+    object_class                 = G_OBJECT_CLASS(klass);
+    libbalsa_mailbox_class       = LIBBALSA_MAILBOX_CLASS(klass);
     libbalsa_mailbox_local_class = LIBBALSA_MAILBOX_LOCAL_CLASS(klass);
 
     libbalsa_mailbox_class->get_message_stream =
-       libbalsa_mailbox_mbox_get_message_stream;
+        libbalsa_mailbox_mbox_get_message_stream;
 
     libbalsa_mailbox_class->open_mailbox = libbalsa_mailbox_mbox_open;
-    libbalsa_mailbox_class->check = libbalsa_mailbox_mbox_check;
+    libbalsa_mailbox_class->check        = libbalsa_mailbox_mbox_check;
 
-    libbalsa_mailbox_class->sync = libbalsa_mailbox_mbox_sync;
+    libbalsa_mailbox_class->sync          = libbalsa_mailbox_mbox_sync;
     libbalsa_mailbox_class->close_mailbox =
-       libbalsa_mailbox_mbox_close_mailbox;
+        libbalsa_mailbox_mbox_close_mailbox;
     libbalsa_mailbox_class->fetch_message_structure =
-       libbalsa_mailbox_mbox_fetch_message_structure;
+        libbalsa_mailbox_mbox_fetch_message_structure;
     libbalsa_mailbox_class->total_messages =
-       libbalsa_mailbox_mbox_total_messages;
+        libbalsa_mailbox_mbox_total_messages;
     libbalsa_mailbox_class->lock_store = libbalsa_mailbox_mbox_lock_store;
 
     libbalsa_mailbox_local_class->check_files  = lbm_mbox_check_files;
-    libbalsa_mailbox_local_class->remove_files = 
-       libbalsa_mailbox_mbox_remove_files;
+    libbalsa_mailbox_local_class->remove_files =
+        libbalsa_mailbox_mbox_remove_files;
 
-    libbalsa_mailbox_local_class->get_info = lbm_mbox_get_info;
+    libbalsa_mailbox_local_class->get_info    = lbm_mbox_get_info;
     libbalsa_mailbox_local_class->add_message = lbm_mbox_add_message;
-    object_class->dispose = libbalsa_mailbox_mbox_dispose;
+    object_class->dispose                     = libbalsa_mailbox_mbox_dispose;
 }
 
 
-
 static void
-libbalsa_mailbox_mbox_init(LibBalsaMailboxMbox * mbox)
+libbalsa_mailbox_mbox_init(LibBalsaMailboxMbox *mbox)
 {
 }
 
+
 static void
-libbalsa_mailbox_mbox_dispose(GObject * object)
+libbalsa_mailbox_mbox_dispose(GObject *object)
 {
-    if(MAILBOX_OPEN(LIBBALSA_MAILBOX(object)))
-       libbalsa_mailbox_mbox_close_mailbox(LIBBALSA_MAILBOX(object), FALSE);
+    if (MAILBOX_OPEN(LIBBALSA_MAILBOX(object))) {
+        libbalsa_mailbox_mbox_close_mailbox(LIBBALSA_MAILBOX(object), FALSE);
+    }
 
     G_OBJECT_CLASS(libbalsa_mailbox_mbox_parent_class)->dispose(object);
 }
 
+
 static gint
-lbm_mbox_check_files(const gchar * path, gboolean create)
+lbm_mbox_check_files(const gchar *path,
+                     gboolean     create)
 {
     g_return_val_if_fail(path != NULL, -1);
 
@@ -184,16 +188,20 @@ lbm_mbox_check_files(const gchar * path, gboolean create)
                       "create the mailbox “%s”\n",
                       strerror(errno), path);
             return -1;
-        } else
+        } else {
             close(fd);
-    } else
+        }
+    } else {
         return -1;
+    }
 
     return 0;
 }
 
+
 LibBalsaMailbox *
-libbalsa_mailbox_mbox_new(const gchar * path, gboolean create)
+libbalsa_mailbox_mbox_new(const gchar *path,
+                          gboolean     create)
 {
     LibBalsaMailbox *mailbox;
 
@@ -203,17 +211,19 @@ libbalsa_mailbox_mbox_new(const gchar * path, gboolean create)
 
     if (libbalsa_mailbox_local_set_path(LIBBALSA_MAILBOX_LOCAL(mailbox),
                                         path, create) != 0) {
-       g_object_unref(mailbox);
-       return NULL;
+        g_object_unref(mailbox);
+        return NULL;
     }
 
     return mailbox;
 }
 
+
 /* Helper: seek to offset, and return TRUE if the seek succeeds and a
  * message begins there. */
 static gboolean
-lbm_mbox_stream_seek_to_message(GMimeStream * stream, off_t offset)
+lbm_mbox_stream_seek_to_message(GMimeStream *stream,
+                                off_t        offset)
 {
     char buffer[5];
     ssize_t nread = 0;
@@ -224,8 +234,9 @@ lbm_mbox_stream_seek_to_message(GMimeStream * stream, off_t offset)
         == sizeof buffer
         && strncmp("From ", buffer, 5) == 0;
     if (!retval) {
-        if (nread == sizeof buffer)
+        if (nread == sizeof buffer) {
             --nread;
+        }
         buffer[nread] = 0;
 #if DEBUG_SEEK
         g_print("%s at %ld failed: read %ld chars, saw “%s”\n", __func__,
@@ -238,11 +249,13 @@ lbm_mbox_stream_seek_to_message(GMimeStream * stream, off_t offset)
     return retval;
 }
 
+
 static gboolean
-lbm_mbox_seek_to_message(LibBalsaMailboxMbox * mbox, off_t offset)
+lbm_mbox_seek_to_message(LibBalsaMailboxMbox *mbox,
+                         off_t                offset)
 {
     gboolean retval;
-    
+
     libbalsa_mime_stream_shared_lock(mbox->gmime_stream);
     retval = lbm_mbox_stream_seek_to_message(mbox->gmime_stream, offset);
     libbalsa_mime_stream_shared_unlock(mbox->gmime_stream);
@@ -250,8 +263,10 @@ lbm_mbox_seek_to_message(LibBalsaMailboxMbox * mbox, off_t offset)
     return retval;
 }
 
+
 static struct message_info *
-message_info_from_msgno(LibBalsaMailboxMbox * mbox, guint msgno)
+message_info_from_msgno(LibBalsaMailboxMbox *mbox,
+                        guint                msgno)
 {
     g_assert(msgno > 0 && msgno <= mbox->msgno_2_msg_info->len);
 
@@ -260,40 +275,48 @@ message_info_from_msgno(LibBalsaMailboxMbox * mbox, guint msgno)
                                                      msgno - 1);
 }
 
+
 static GMimeStream *
-libbalsa_mailbox_mbox_get_message_stream(LibBalsaMailbox * mailbox,
-                                         guint msgno, gboolean peek)
+libbalsa_mailbox_mbox_get_message_stream(LibBalsaMailbox *mailbox,
+                                         guint            msgno,
+                                         gboolean         peek)
 {
     LibBalsaMailboxMbox *mbox;
     struct message_info *msg_info;
 
     g_return_val_if_fail(LIBBALSA_IS_MAILBOX_MBOX(mailbox), NULL);
 
-    mbox = LIBBALSA_MAILBOX_MBOX(mailbox);
+    mbox     = LIBBALSA_MAILBOX_MBOX(mailbox);
     msg_info = message_info_from_msgno(mbox, msgno);
 
-    if (!msg_info || !lbm_mbox_seek_to_message(mbox, msg_info->start))
+    if (!msg_info || !lbm_mbox_seek_to_message(mbox, msg_info->start)) {
         return NULL;
+    }
 
     return g_mime_stream_substream(mbox->gmime_stream,
                                    msg_info->start + msg_info->from_len,
                                    msg_info->end);
 }
 
+
 static void
 libbalsa_mailbox_mbox_remove_files(LibBalsaMailboxLocal *mailbox)
 {
     g_return_if_fail (LIBBALSA_IS_MAILBOX_MBOX(mailbox));
 
-    if ( unlink(libbalsa_mailbox_local_get_path(mailbox)) == -1 )
-       libbalsa_information(LIBBALSA_INFORMATION_ERROR, 
-                            _("Could not remove %s:\n%s"), 
-                            libbalsa_mailbox_local_get_path(mailbox), 
-                            strerror(errno));
+    if ( unlink(libbalsa_mailbox_local_get_path(mailbox)) == -1 ) {
+        libbalsa_information(LIBBALSA_INFORMATION_ERROR,
+                             _("Could not remove %s:\n%s"),
+                             libbalsa_mailbox_local_get_path(mailbox),
+                             strerror(errno));
+    }
     LIBBALSA_MAILBOX_LOCAL_CLASS(libbalsa_mailbox_mbox_parent_class)->remove_files(mailbox);
 }
 
-static int mbox_lock(LibBalsaMailbox * mailbox, GMimeStream *stream)
+
+static int
+mbox_lock(LibBalsaMailbox *mailbox,
+          GMimeStream     *stream)
 {
     const gchar *path =
         libbalsa_mailbox_local_get_path(LIBBALSA_MAILBOX_LOCAL(mailbox));
@@ -301,7 +324,10 @@ static int mbox_lock(LibBalsaMailbox * mailbox, GMimeStream *stream)
     return libbalsa_lock_file(path, fd, FALSE, TRUE, 1);
 }
 
-static void mbox_unlock(LibBalsaMailbox * mailbox, GMimeStream *stream)
+
+static void
+mbox_unlock(LibBalsaMailbox *mailbox,
+            GMimeStream     *stream)
 {
     const gchar *path =
         libbalsa_mailbox_local_get_path(LIBBALSA_MAILBOX_LOCAL(mailbox));
@@ -309,36 +335,41 @@ static void mbox_unlock(LibBalsaMailbox * mailbox, GMimeStream *stream)
     libbalsa_unlock_file(path, fd, 1);
 }
 
+
 /* GMimeParserHeaderRegexFunc callback; save the header's offset if it's
  * "Status", "X-Status", or "MIME-Version".  Save only the first one, to
  * avoid headers in encapsulated messages.
- * 
+ *
  * If a message has no status headers but an encapsulated message does,
  * we may save the offset of the encapsulated header; we check for that
  * later.
- * 
+ *
  * We use the offset of the "MIME-Version" header as the location to
  * insert status headers, if necessary.
  */
 static void
-lbm_mbox_header_cb(GMimeParser * parser, const char *header,
-                   const char *value, gint64 offset,
-                   gpointer user_data)
+lbm_mbox_header_cb(GMimeParser *parser,
+                   const char  *header,
+                   const char  *value,
+                   gint64       offset,
+                   gpointer     user_data)
 {
     struct message_info *msg_info = *(struct message_info **) user_data;
 
-    if (g_ascii_strcasecmp(header, "Status") == 0 && msg_info->status < 0)
+    if ((g_ascii_strcasecmp(header, "Status") == 0) && (msg_info->status < 0)) {
         msg_info->status = offset;
-    else if (g_ascii_strcasecmp(header, "X-Status") == 0
-             && msg_info->x_status < 0)
+    } else if ((g_ascii_strcasecmp(header, "X-Status") == 0)
+               && (msg_info->x_status < 0)) {
         msg_info->x_status = offset;
-    else if (g_ascii_strcasecmp(header, "MIME-Version") == 0
-             && msg_info->mime_version < 0)
+    } else if ((g_ascii_strcasecmp(header, "MIME-Version") == 0)
+               && (msg_info->mime_version < 0)) {
         msg_info->mime_version = offset;
+    }
 }
 
+
 static gchar *
-lbm_mbox_get_cache_filename(LibBalsaMailboxMbox * mbox)
+lbm_mbox_get_cache_filename(LibBalsaMailboxMbox *mbox)
 {
     gchar *encoded_path;
     gchar *filename;
@@ -346,7 +377,7 @@ lbm_mbox_get_cache_filename(LibBalsaMailboxMbox * mbox)
 
     encoded_path =
         libbalsa_urlencode(libbalsa_mailbox_local_get_path
-                           (LIBBALSA_MAILBOX_LOCAL(mbox)));
+                               (LIBBALSA_MAILBOX_LOCAL(mbox)));
     basename = g_strconcat("mbox", encoded_path, NULL);
     g_free(encoded_path);
     filename =
@@ -356,16 +387,18 @@ lbm_mbox_get_cache_filename(LibBalsaMailboxMbox * mbox)
     return filename;
 }
 
+
 static void
-lbm_mbox_save(LibBalsaMailboxMbox * mbox)
+lbm_mbox_save(LibBalsaMailboxMbox *mbox)
 {
     gchar *filename;
 #if !defined(__APPLE__)
     GError *err = NULL;
 #endif                          /* !defined(__APPLE__) */
 
-    if (!mbox->messages_info_changed)
+    if (!mbox->messages_info_changed) {
         return;
+    }
 
     mbox->messages_info_changed = FALSE;
 
@@ -373,7 +406,7 @@ lbm_mbox_save(LibBalsaMailboxMbox * mbox)
 
     if (mbox->msgno_2_msg_info->len > 0) {
         GArray *messages_info =
-            g_array_sized_new(FALSE, FALSE, sizeof(struct message_info), 
+            g_array_sized_new(FALSE, FALSE, sizeof(struct message_info),
                               mbox->msgno_2_msg_info->len);
         guint msgno;
 #if defined(__APPLE__)
@@ -398,11 +431,11 @@ lbm_mbox_save(LibBalsaMailboxMbox * mbox)
         }
 #else                           /* !defined(__APPLE__) */
         template = g_strconcat(filename, ":XXXXXX", NULL);
-        fd = g_mkstemp(template);
-        if (fd < 0 || write(fd, messages_info->data,
-                            messages_info->len *
-                            sizeof(struct message_info)) <
-            (ssize_t) messages_info->len) {
+        fd       = g_mkstemp(template);
+        if ((fd < 0) || (write(fd, messages_info->data,
+                               messages_info->len *
+                               sizeof(struct message_info)) <
+                         (ssize_t) messages_info->len)) {
             libbalsa_information(LIBBALSA_INFORMATION_WARNING,
                                  _("Failed to create temporary file "
                                    "“%s”: %s"), template,
@@ -412,59 +445,63 @@ lbm_mbox_save(LibBalsaMailboxMbox * mbox)
             g_array_free(messages_info, TRUE);
             return;
         }
-        if (close(fd) != 0
-            || (unlink(filename) != 0 && errno != ENOENT)
-            || libbalsa_safe_rename(template, filename) != 0)
+        if ((close(fd) != 0)
+            || ((unlink(filename) != 0) && (errno != ENOENT))
+            || (libbalsa_safe_rename(template, filename) != 0)) {
             libbalsa_information(LIBBALSA_INFORMATION_WARNING,
                                  _("Failed to save cache file “%s”: %s. "
                                    "New version saved as “%s”"),
                                  filename, strerror(errno), template);
+        }
         g_free(template);
 #endif                          /* !defined(__APPLE__) */
         g_array_free(messages_info, TRUE);
-    } else if (unlink(filename) < 0)
+    } else if (unlink(filename) < 0) {
         libbalsa_information(LIBBALSA_INFORMATION_WARNING,
                              _("Could not unlink file %s: %s"),
                              filename, strerror(errno));
+    }
 
     g_free(filename);
 #ifdef DEBUG
-    g_print("%s:    %s    saved %d messages\n", __func__, 
+    g_print("%s:    %s    saved %d messages\n", __func__,
             LIBBALSA_MAILBOX(mbox)->name,
             mbox->msgno_2_msg_info->len);
 #endif
 }
 
-static LibBalsaMessage *lbm_mbox_message_new(GMimeMessage * mime_message,
-                                            struct message_info
-                                            *msg_info);
+
+static LibBalsaMessage *lbm_mbox_message_new(GMimeMessage *mime_message,
+                                             struct message_info
+                                                          *msg_info);
+
 static void
-parse_mailbox(LibBalsaMailboxMbox * mbox)
+parse_mailbox(LibBalsaMailboxMbox *mbox)
 {
     LibBalsaMailboxLocal *local = LIBBALSA_MAILBOX_LOCAL(mbox);
     GMimeParser *gmime_parser;
     struct message_info msg_info;
-    struct message_info * msg_info_p = &msg_info;
-    unsigned msgno = mbox->msgno_2_msg_info->len;
+    struct message_info *msg_info_p = &msg_info;
+    unsigned msgno                  = mbox->msgno_2_msg_info->len;
 
     gmime_parser = g_mime_parser_new_with_stream(mbox->gmime_stream);
     g_mime_parser_set_scan_from(gmime_parser, TRUE);
     g_mime_parser_set_respect_content_length(gmime_parser, TRUE);
     g_mime_parser_set_header_regex(gmime_parser,
                                    "^Status|^X-Status|^MIME-Version",
-                                  lbm_mbox_header_cb, &msg_info_p);
+                                   lbm_mbox_header_cb, &msg_info_p);
 
     libbalsa_mailbox_local_set_threading_info(local);
     msg_info.local_info.message = NULL;
     msg_info.local_info.loaded  = FALSE;
     while (!g_mime_parser_eos(gmime_parser)) {
-       GMimeMessage *mime_message;
+        GMimeMessage *mime_message;
         LibBalsaMessage *msg;
         gchar *from;
         off_t offset;
 
         msg_info.status = msg_info.x_status = msg_info.mime_version = -1;
-        mime_message   = g_mime_parser_construct_message(gmime_parser);
+        mime_message    = g_mime_parser_construct_message(gmime_parser);
         if (mime_message == NULL) {
             /* Skip to the next message, if any */
             GMimeStream *mbox_stream;
@@ -473,58 +510,65 @@ parse_mailbox(LibBalsaMailboxMbox * mbox)
             while (!g_mime_stream_eos(mbox_stream)) {
                 gchar c;
 
-                while (g_mime_stream_read(mbox_stream, &c, 1) == 1)
-                    if (c == '\n')
+                while (g_mime_stream_read(mbox_stream, &c, 1) == 1) {
+                    if (c == '\n') {
                         break;
+                    }
+                }
 
                 if (lbm_mbox_stream_seek_to_message(mbox_stream,
-                                                    g_mime_stream_tell(mbox_stream)))
+                                                    g_mime_stream_tell(mbox_stream))) {
                     break;
+                }
             }
             g_mime_parser_init_with_stream(gmime_parser, mbox_stream);
             continue;
         }
         msg_info.start = g_mime_parser_get_from_offset(gmime_parser);
         msg_info.end   = g_mime_parser_tell(gmime_parser);
-        if (msg_info.end <= msg_info.start
+        if ((msg_info.end <= msg_info.start)
             || !(from = g_mime_parser_get_from(gmime_parser))) {
-           g_object_unref(mime_message);
+            g_object_unref(mime_message);
             continue;
-       }
+        }
         msg_info.from_len = strlen(from) + 1;
         g_free(from);
 
-       /* Make sure we don't have offsets for any encapsulated headers. */
-       if (!g_mime_object_get_header(GMIME_OBJECT(mime_message),
-                                      "Status"))
-           msg_info.status = -1;
-       if (!g_mime_object_get_header(GMIME_OBJECT(mime_message),
-                                      "X-Status"))
-           msg_info.x_status = -1;
-       if (!g_mime_object_get_header(GMIME_OBJECT(mime_message),
-                                      "MIME-Version"))
-           msg_info.mime_version = -1;
+        /* Make sure we don't have offsets for any encapsulated headers. */
+        if (!g_mime_object_get_header(GMIME_OBJECT(mime_message),
+                                      "Status")) {
+            msg_info.status = -1;
+        }
+        if (!g_mime_object_get_header(GMIME_OBJECT(mime_message),
+                                      "X-Status")) {
+            msg_info.x_status = -1;
+        }
+        if (!g_mime_object_get_header(GMIME_OBJECT(mime_message),
+                                      "MIME-Version")) {
+            msg_info.mime_version = -1;
+        }
 
         msg = lbm_mbox_message_new(mime_message, &msg_info);
         g_object_unref(mime_message);
-        if (!msg)
+        if (!msg) {
             continue;
+        }
 
         msg_info.local_info.flags = msg_info.orig_flags;
         g_ptr_array_add(mbox->msgno_2_msg_info,
                         g_memdup(&msg_info, sizeof(msg_info)));
         mbox->messages_info_changed = TRUE;
 
-        msg->flags = msg_info.orig_flags;
-        msg->length = msg_info.end - (msg_info.start + msg_info.from_len);
+        msg->flags   = msg_info.orig_flags;
+        msg->length  = msg_info.end - (msg_info.start + msg_info.from_len);
         msg->mailbox = LIBBALSA_MAILBOX(mbox);
-        msg->msgno = ++msgno;
-       /* We must drop the mime-stream lock to call
+        msg->msgno   = ++msgno;
+        /* We must drop the mime-stream lock to call
          * libbalsa_mailbox_local_cache_message, which calls
-        * libbalsa_mailbox_cache_message(), as it may grab the
-        * gdk lock to emit gtk signals; we save and restore the current
-        * stream position, in case someone changes it while we're not
-        * holding the lock. */
+         * libbalsa_mailbox_cache_message(), as it may grab the
+         * gdk lock to emit gtk signals; we save and restore the current
+         * stream position, in case someone changes it while we're not
+         * holding the lock. */
         offset = g_mime_stream_tell(mbox->gmime_stream);
         libbalsa_mime_stream_shared_unlock(mbox->gmime_stream);
         libbalsa_mailbox_local_cache_message(local, msgno, msg);
@@ -538,21 +582,23 @@ parse_mailbox(LibBalsaMailboxMbox * mbox)
     lbm_mbox_save(mbox);
 }
 
+
 static void
 free_message_info(struct message_info *msg_info)
 {
     if (msg_info->local_info.message) {
-       msg_info->local_info.message->mailbox = NULL;
-       msg_info->local_info.message->msgno   = 0;
+        msg_info->local_info.message->mailbox = NULL;
+        msg_info->local_info.message->msgno   = 0;
         g_object_remove_weak_pointer(G_OBJECT(msg_info->local_info.message),
                                      (gpointer) & msg_info->local_info.message);
-       msg_info->local_info.message = NULL;
+        msg_info->local_info.message = NULL;
     }
     g_free(msg_info);
 }
 
+
 static void
-free_messages_info(GPtrArray * msgno_2_msg_info)
+free_messages_info(GPtrArray *msgno_2_msg_info)
 {
     guint i;
 
@@ -564,8 +610,9 @@ free_messages_info(GPtrArray * msgno_2_msg_info)
     g_ptr_array_free(msgno_2_msg_info, TRUE);
 }
 
+
 static void
-lbm_mbox_restore(LibBalsaMailboxMbox * mbox)
+lbm_mbox_restore(LibBalsaMailboxMbox *mbox)
 {
     gchar *filename;
     struct stat st;
@@ -576,8 +623,8 @@ lbm_mbox_restore(LibBalsaMailboxMbox * mbox)
     GMimeStream *mbox_stream;
 
     filename = lbm_mbox_get_cache_filename(mbox);
-    if (stat(filename, &st) < 0 
-        || st.st_mtime < libbalsa_mailbox_get_mtime(LIBBALSA_MAILBOX(mbox))
+    if ((stat(filename, &st) < 0)
+        || (st.st_mtime < libbalsa_mailbox_get_mtime(LIBBALSA_MAILBOX(mbox)))
         || !g_file_get_contents(filename, &contents, &length, NULL)) {
         /* No cache file, stale cache, or read error. */
         g_free(filename);
@@ -610,20 +657,23 @@ lbm_mbox_restore(LibBalsaMailboxMbox * mbox)
     do {
         msg_info->local_info.message = NULL;
         msg_info->local_info.loaded  = FALSE;
-        if (msg_info->start != end)
+        if (msg_info->start != end) {
             /* Error: this message doesn't start at the end of the
              * previous one. */
             break;
+        }
         end = msg_info->end;
-        if (msg_info->from_len < 6
-            || (off_t) (msg_info->start + msg_info->from_len) >= end
-            || end > mbox->size)
+        if ((msg_info->from_len < 6)
+            || ((off_t) (msg_info->start + msg_info->from_len) >= end)
+            || (end > mbox->size)) {
             /* Error: various. */
             break;
-        if (end < mbox->size
-            && !lbm_mbox_seek_to_message(mbox, msg_info->end))
+        }
+        if ((end < mbox->size)
+            && !lbm_mbox_seek_to_message(mbox, msg_info->end)) {
             /* Error: no message following this one. */
             break;
+        }
         g_ptr_array_add(mbox->msgno_2_msg_info,
                         g_memdup(msg_info, sizeof *msg_info));
     } while (++msg_info < (struct message_info *) (contents + length));
@@ -650,24 +700,29 @@ lbm_mbox_restore(LibBalsaMailboxMbox * mbox)
         gchar c;
 
         if (lbm_mbox_stream_seek_to_message(mbox_stream,
-                                            g_mime_stream_tell(mbox_stream)))
+                                            g_mime_stream_tell(mbox_stream))) {
             break;
+        }
 
-        while (g_mime_stream_read(mbox_stream, &c, 1) == 1)
-            if (c == '\n')
+        while (g_mime_stream_read(mbox_stream, &c, 1) == 1) {
+            if (c == '\n') {
                 break;
+            }
+        }
     }
     libbalsa_mime_stream_shared_unlock(mbox_stream);
 
     g_free(contents);
 }
 
+
 static gboolean
-libbalsa_mailbox_mbox_open(LibBalsaMailbox * mailbox, GError **err)
+libbalsa_mailbox_mbox_open(LibBalsaMailbox *mailbox,
+                           GError         **err)
 {
     LibBalsaMailboxMbox *mbox = LIBBALSA_MAILBOX_MBOX(mailbox);
     struct stat st;
-    const gchar* path;
+    const gchar *path;
     gboolean readonly;
     int fd;
     GMimeStream *gmime_stream;
@@ -676,23 +731,23 @@ libbalsa_mailbox_mbox_open(LibBalsaMailbox * mailbox, GError **err)
     path = libbalsa_mailbox_local_get_path(LIBBALSA_MAILBOX_LOCAL(mailbox));
 
     if (stat(path, &st) == -1) {
-       g_set_error(err, LIBBALSA_MAILBOX_ERROR, LIBBALSA_MAILBOX_OPEN_ERROR,
-                   _("Mailbox does not exist."));
-       return FALSE;
+        g_set_error(err, LIBBALSA_MAILBOX_ERROR, LIBBALSA_MAILBOX_OPEN_ERROR,
+                    _("Mailbox does not exist."));
+        return FALSE;
     }
 
     readonly = access (path, W_OK);
     libbalsa_mailbox_set_readonly(mailbox, readonly);
     fd = open(path, readonly ? O_RDONLY : O_RDWR);
     if (fd == -1) {
-       g_set_error(err, LIBBALSA_MAILBOX_ERROR, LIBBALSA_MAILBOX_OPEN_ERROR,
-                   _("Cannot open mailbox."));
-       return FALSE;
+        g_set_error(err, LIBBALSA_MAILBOX_ERROR, LIBBALSA_MAILBOX_OPEN_ERROR,
+                    _("Cannot open mailbox."));
+        return FALSE;
     }
     gmime_stream = libbalsa_mime_stream_shared_new(fd);
 
     libbalsa_mime_stream_shared_lock(gmime_stream);
-    if (st.st_size > 0
+    if ((st.st_size > 0)
         && !lbm_mbox_stream_seek_to_message(gmime_stream, 0)) {
         libbalsa_mime_stream_shared_unlock(gmime_stream);
         g_object_unref(gmime_stream);
@@ -704,10 +759,10 @@ libbalsa_mailbox_mbox_open(LibBalsaMailbox * mailbox, GError **err)
 
     if (mbox_lock(mailbox, gmime_stream)) {
         libbalsa_mime_stream_shared_unlock(gmime_stream);
-       g_object_unref(gmime_stream);
-       g_set_error(err, LIBBALSA_MAILBOX_ERROR, LIBBALSA_MAILBOX_OPEN_ERROR,
-                   _("Cannot lock mailbox."));
-       return FALSE;
+        g_object_unref(gmime_stream);
+        g_set_error(err, LIBBALSA_MAILBOX_ERROR, LIBBALSA_MAILBOX_OPEN_ERROR,
+                    _("Cannot lock mailbox."));
+        return FALSE;
     }
 
     mbox->size = st.st_size;
@@ -732,11 +787,12 @@ libbalsa_mailbox_mbox_open(LibBalsaMailbox * mailbox, GError **err)
     libbalsa_mime_stream_shared_unlock(gmime_stream);
 #ifdef DEBUG
     g_print(_("%s: Opening %s Refcount: %d\n"),
-           "LibBalsaMailboxMbox", mailbox->name, mailbox->open_ref);
+            "LibBalsaMailboxMbox", mailbox->name, mailbox->open_ref);
 #endif
     return TRUE;
 }
 
+
 /* Check for new mail in a closed mbox, using a crude parser. */
 /*
  * Lightweight replacement for GMimeStreamBuffer
@@ -749,13 +805,14 @@ typedef struct {
 } LbmMboxStreamBuffer;
 
 static off_t
-lbm_mbox_seek(LbmMboxStreamBuffer * buffer, off_t offset)
+lbm_mbox_seek(LbmMboxStreamBuffer *buffer,
+              off_t                offset)
 {
     if (offset >= 0) {
         buffer->start =
             buffer->end - (g_mime_stream_tell(buffer->stream) - offset);
 
-        if (buffer->start < 0 || buffer->start > buffer->end) {
+        if ((buffer->start < 0) || (buffer->start > buffer->end)) {
             offset =
                 g_mime_stream_seek(buffer->stream, offset,
                                    GMIME_STREAM_SEEK_SET);
@@ -766,8 +823,10 @@ lbm_mbox_seek(LbmMboxStreamBuffer * buffer, off_t offset)
     return offset;
 }
 
+
 static guint
-lbm_mbox_readln(LbmMboxStreamBuffer * buffer, GByteArray * line)
+lbm_mbox_readln(LbmMboxStreamBuffer *buffer,
+                GByteArray          *line)
 {
     gchar *p, *q, *r;
 
@@ -776,20 +835,22 @@ lbm_mbox_readln(LbmMboxStreamBuffer * buffer, GByteArray * line)
     do {
         if (buffer->start >= buffer->end) {
             buffer->start = 0;
-            buffer->end = g_mime_stream_read(buffer->stream, buffer->buf,
-                                             sizeof buffer->buf);
+            buffer->end   = g_mime_stream_read(buffer->stream, buffer->buf,
+                                               sizeof buffer->buf);
             if (buffer->end < 0) {
                 g_warning("%s: Read error", __func__);
                 break;
             }
-            if (buffer->end == 0)
+            if (buffer->end == 0) {
                 break;
+            }
         }
 
         p = q = buffer->buf + buffer->start;
         r = buffer->buf + buffer->end;
-        while (p < r && *p++ != '\n')
-            /* Nothing */;
+        while (p < r && *p++ != '\n') {
+            /* Nothing */
+        }
 
         g_byte_array_append(line, (guint8 *) q, p - q);
         buffer->start += p - q;
@@ -798,12 +859,14 @@ lbm_mbox_readln(LbmMboxStreamBuffer * buffer, GByteArray * line)
     return line->len;
 }
 
+
 /*
  * Look for an unread, undeleted message using the cache file.
  */
 static gboolean
-lbm_mbox_check_cache(LibBalsaMailboxMbox * mbox,
-                     LbmMboxStreamBuffer * buffer, GByteArray * line)
+lbm_mbox_check_cache(LibBalsaMailboxMbox *mbox,
+                     LbmMboxStreamBuffer *buffer,
+                     GByteArray          *line)
 {
     gchar *filename;
     gboolean tmp;
@@ -813,55 +876,63 @@ lbm_mbox_check_cache(LibBalsaMailboxMbox * mbox,
     gboolean retval = FALSE;
 
     filename = lbm_mbox_get_cache_filename(mbox);
-    tmp = g_file_get_contents(filename, &contents, &length, NULL);
+    tmp      = g_file_get_contents(filename, &contents, &length, NULL);
     g_free(filename);
-    if (!tmp)
+    if (!tmp) {
         return retval;
+    }
 
     for (msg_info = (struct message_info *) contents;
          msg_info < (struct message_info *) (contents + length);
          msg_info++) {
-        if (lbm_mbox_seek(buffer, msg_info->status) >= 0
+        if ((lbm_mbox_seek(buffer, msg_info->status) >= 0)
             && lbm_mbox_readln(buffer, line)) {
             if (g_ascii_strncasecmp((gchar *) line->data,
-                                    "Status: ", 8) != 0)
+                                    "Status: ", 8) != 0) {
                 /* Bad cache. */
                 break;
-            if (strchr((gchar *) line->data + 8, 'R'))
+            }
+            if (strchr((gchar *) line->data + 8, 'R')) {
                 /* Message has been read. */
                 continue;
+            }
         }
-        if (lbm_mbox_seek(buffer, msg_info->x_status) >= 0
+        if ((lbm_mbox_seek(buffer, msg_info->x_status) >= 0)
             && lbm_mbox_readln(buffer, line)) {
             if (g_ascii_strncasecmp((gchar *) line->data,
-                                    "X-Status: ", 10) != 0)
+                                    "X-Status: ", 10) != 0) {
                 /* Bad cache. */
                 break;
-            if (strchr((gchar *) line->data + 10, 'D'))
+            }
+            if (strchr((gchar *) line->data + 10, 'D')) {
                 /* Message has been read. */
                 continue;
+            }
         }
         /* Message is unread and undeleted. */
         retval = TRUE;
         break;
     }
-    if (!retval)
+    if (!retval) {
         /* Seek to the end of the last message we checked. */
         lbm_mbox_seek(buffer, msg_info > (struct message_info *) contents ?
-                      (msg_info-1)->end : 0);
+                      (msg_info - 1)->end : 0);
+    }
     g_free(contents); /* msg_info points to contents, cannot free too early */
 
 
     return retval;
 }
 
+
 /*
  * Look for an unread, undeleted message in the mbox file, beyond the
  * messages we found in the cache file.
  */
 static gboolean
-lbm_mbox_check_file(LibBalsaMailboxMbox * mbox,
-                    LbmMboxStreamBuffer * buffer, GByteArray * line)
+lbm_mbox_check_file(LibBalsaMailboxMbox *mbox,
+                    LbmMboxStreamBuffer *buffer,
+                    GByteArray          *line)
 {
     gboolean retval = FALSE;
 
@@ -873,30 +944,36 @@ lbm_mbox_check_file(LibBalsaMailboxMbox * mbox,
          * by an embedded Content-Length header, we may be misled, but a
          * full GMime parse takes too long. */
         while (lbm_mbox_readln(buffer, line)
-               && strncmp((gchar *) line->data, "From ", 5) != 0)
-            /* Nothing. */ ;
-        if (line->len == 0)
+               && strncmp((gchar *) line->data, "From ", 5) != 0) {
+            /* Nothing. */
+        }
+        if (line->len == 0) {
             break;
+        }
 
         /* Scan headers. */
         do {
             /* Blank line ends headers. */
             if (!lbm_mbox_readln(buffer, line)
-                || line->data[0] == '\n')
+                || (line->data[0] == '\n')) {
                 break;
+            }
 
             line->data[line->len - 1] = '\0';
             if (g_ascii_strncasecmp((gchar *) line->data,
                                     "Status: ", 8) == 0) {
-                if (strchr((gchar *) line->data + 8, 'R'))
+                if (strchr((gchar *) line->data + 8, 'R')) {
                     ++old_or_deleted;
+                }
             } else if (g_ascii_strncasecmp((gchar *) line->data,
                                            "X-Status: ", 10) == 0) {
-                if (strchr((gchar *) line->data + 10, 'D'))
+                if (strchr((gchar *) line->data + 10, 'D')) {
                     ++old_or_deleted;
+                }
             } else if (g_ascii_strncasecmp((gchar *) line->data,
-                                           "Content-Length: ", 16) == 0)
+                                           "Content-Length: ", 16) == 0) {
                 content_length = atoi((gchar *) line->data + 16);
+            }
         } while (!(old_or_deleted && content_length));
 
         if (!old_or_deleted) {
@@ -910,7 +987,7 @@ lbm_mbox_check_file(LibBalsaMailboxMbox * mbox,
             off_t remaining;
 
             buffer->start += content_length;
-            remaining = (off_t) buffer->end - (off_t) buffer->start;
+            remaining      = (off_t) buffer->end - (off_t) buffer->start;
             if (remaining < 0) {
                 g_mime_stream_seek(buffer->stream, -remaining,
                                    GMIME_STREAM_SEEK_CUR);
@@ -922,17 +999,22 @@ lbm_mbox_check_file(LibBalsaMailboxMbox * mbox,
     return retval;
 }
 
+
 static gboolean
-lbm_mbox_check(LibBalsaMailbox * mailbox, const gchar * path)
+lbm_mbox_check(LibBalsaMailbox *mailbox,
+               const gchar     *path)
 {
     LibBalsaMailboxMbox *mbox = LIBBALSA_MAILBOX_MBOX(mailbox);
     int fd;
-    gboolean retval = FALSE;
-    LbmMboxStreamBuffer buffer = { 0, 0 };
+    gboolean retval            = FALSE;
+    LbmMboxStreamBuffer buffer = {
+        0, 0
+    };
     GByteArray *line;
 
-    if (!(fd = open(path, O_RDONLY)))
+    if (!(fd = open(path, O_RDONLY))) {
         return retval;
+    }
 
     buffer.stream = g_mime_stream_fs_new(fd);
 
@@ -944,8 +1026,9 @@ lbm_mbox_check(LibBalsaMailbox * mailbox, const gchar * path)
     line = g_byte_array_sized_new(80);
 
     retval = lbm_mbox_check_cache(mbox, &buffer, line);
-    if (!retval)
+    if (!retval) {
         retval = lbm_mbox_check_file(mbox, &buffer, line);
+    }
 
     g_byte_array_free(line, TRUE);
     mbox_unlock(mailbox, buffer.stream);
@@ -954,9 +1037,10 @@ lbm_mbox_check(LibBalsaMailbox * mailbox, const gchar * path)
     return retval;
 }
 
+
 /* Called with mailbox locked. */
 static void
-libbalsa_mailbox_mbox_check(LibBalsaMailbox * mailbox)
+libbalsa_mailbox_mbox_check(LibBalsaMailbox *mailbox)
 {
     struct stat st;
     const gchar *path;
@@ -973,46 +1057,48 @@ libbalsa_mailbox_mbox_check(LibBalsaMailbox * mailbox)
     if (mbox->gmime_stream ?
         fstat(GMIME_STREAM_FS(mbox->gmime_stream)->fd, &st) :
         stat(path, &st)) {
-       perror(path);
-       return;
+        perror(path);
+        return;
     }
 
     mtime = libbalsa_mailbox_get_mtime(mailbox);
     if (mtime == 0) {
-       /* First check--just cache the mtime and size. */
+        /* First check--just cache the mtime and size. */
         libbalsa_mailbox_set_mtime(mailbox, st.st_mtime);
-       mbox->size = st.st_size;
+        mbox->size = st.st_size;
 #if DEBUG_SEEK
         g_print("%s %s set size from stat %d\n", __func__, mailbox->name,
                 mbox->size);
 #endif
-       return;
+        return;
+    }
+    if ((st.st_mtime == mtime) && (st.st_size == mbox->size)) {
+        return;
     }
-    if (st.st_mtime == mtime && st.st_size == mbox->size)
-       return;
 
     libbalsa_mailbox_set_mtime(mailbox, st.st_mtime);
 
     if (!MAILBOX_OPEN(mailbox)) {
-       libbalsa_mailbox_set_unread_messages_flag(mailbox,
-                                                 lbm_mbox_check(mailbox,
-                                                                path));
-       /* Cache the file size, so we don't check the next time. */
-       mbox->size = st.st_size;
+        libbalsa_mailbox_set_unread_messages_flag(mailbox,
+                                                  lbm_mbox_check(mailbox,
+                                                                 path));
+        /* Cache the file size, so we don't check the next time. */
+        mbox->size = st.st_size;
 #if DEBUG_SEEK
         g_print("%s %s set size from stat %d\n", __func__, mailbox->name,
                 mbox->size);
 #endif
-       return;
+        return;
     }
 
     mbox_stream = mbox->gmime_stream;
-    if (mbox_lock(mailbox, mbox_stream) != 0)
-       /* we couldn't lock the mailbox, but nothing serious happened:
-        * probably the new mail arrived: no reason to wait till we can
-        * parse it: we'll get it on the next pass
-        */
-       return;
+    if (mbox_lock(mailbox, mbox_stream) != 0) {
+        /* we couldn't lock the mailbox, but nothing serious happened:
+         * probably the new mail arrived: no reason to wait till we can
+         * parse it: we'll get it on the next pass
+         */
+        return;
+    }
 
     /* Find a good place to start parsing the mailbox.  If the only
      * change is that message(s) were appended to this file, we should
@@ -1032,47 +1118,52 @@ libbalsa_mailbox_mbox_check(LibBalsaMailbox * mailbox)
     start = mbox->size + 1;
 #if DEBUG_SEEK
     g_print("%s %s looking where to start parsing.\n",
-              __func__, mailbox->name);
+            __func__, mailbox->name);
     if (!lbm_mbox_stream_seek_to_message(mbox_stream, start)) {
         g_print(" did not find a message at offset %ld\n", (long) start);
         --start;
-        if (lbm_mbox_stream_seek_to_message(mbox_stream, start))
+        if (lbm_mbox_stream_seek_to_message(mbox_stream, start)) {
             g_print(" found a message at offset %ld\n", (long) start);
-        else
+        } else {
             g_print(" did not find a message at offset %ld\n", (long) start);
-    } else
+        }
+    } else {
         g_print(" found a message at offset %ld\n", (long) start);
+    }
 #else
-    if (!lbm_mbox_stream_seek_to_message(mbox_stream, start))
+    if (!lbm_mbox_stream_seek_to_message(mbox_stream, start)) {
         /* Sometimes we seem to be off by 1: */
         --start;
+    }
 #endif
 
     while ((msgno = mbox->msgno_2_msg_info->len) > 0) {
-       off_t offset;
+        off_t offset;
         struct message_info *msg_info;
 
-        if (lbm_mbox_stream_seek_to_message(mbox_stream, start))
-           /* A message begins here, so it must(?) be
-            * the first new message--start parsing here. */
+        if (lbm_mbox_stream_seek_to_message(mbox_stream, start)) {
+            /* A message begins here, so it must(?) be
+             * the first new message--start parsing here. */
             break;
+        }
 
 #if DEBUG_SEEK
         g_print(" backing up over message %d\n", msgno);
 #endif
-       /* Back up over this message and try again. */
+        /* Back up over this message and try again. */
         msg_info = message_info_from_msgno(mbox, msgno);
-        start = msg_info->start;
+        start    = msg_info->start;
 
         if ((msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_NEW)
-            && !(msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_DELETED))
+            && !(msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_DELETED)) {
             libbalsa_mailbox_add_to_unread_messages(mailbox, -1);
+        }
 
-       /* We must drop the mime-stream lock to call
-        * libbalsa_mailbox_local_msgno_removed(), as it will grab the
-        * gdk lock to emit gtk signals; we save and restore the current
-        * stream position, in case someone changes it while we're not
-        * holding the lock. */
+        /* We must drop the mime-stream lock to call
+         * libbalsa_mailbox_local_msgno_removed(), as it will grab the
+         * gdk lock to emit gtk signals; we save and restore the current
+         * stream position, in case someone changes it while we're not
+         * holding the lock. */
         offset = g_mime_stream_tell(mbox_stream);
         libbalsa_mime_stream_shared_unlock(mbox_stream);
         libbalsa_mailbox_local_msgno_removed(mailbox, msgno);
@@ -1083,8 +1174,9 @@ libbalsa_mailbox_mbox_check(LibBalsaMailbox * mailbox)
         g_ptr_array_remove_index(mbox->msgno_2_msg_info, msgno - 1);
         mbox->messages_info_changed = TRUE;
     }
-    if(msgno == 0)
+    if (msgno == 0) {
         g_mime_stream_seek(mbox_stream, 0, GMIME_STREAM_SEEK_SET);
+    }
 #ifdef DEBUG
     g_print("%s: start parsing at msgno %d of %d\n", __func__, msgno,
             mbox->msgno_2_msg_info->len);
@@ -1100,21 +1192,24 @@ libbalsa_mailbox_mbox_check(LibBalsaMailbox * mailbox)
     libbalsa_mailbox_local_load_messages(mailbox, msgno);
 }
 
+
 static void
-libbalsa_mailbox_mbox_close_mailbox(LibBalsaMailbox * mailbox,
-                                    gboolean expunge)
+libbalsa_mailbox_mbox_close_mailbox(LibBalsaMailbox *mailbox,
+                                    gboolean         expunge)
 {
     LibBalsaMailboxMbox *mbox = LIBBALSA_MAILBOX_MBOX(mailbox);
     guint len;
 
     len = mbox->msgno_2_msg_info->len;
     libbalsa_mailbox_mbox_sync(mailbox, expunge);
-    if (mbox->msgno_2_msg_info->len != len)
+    if (mbox->msgno_2_msg_info->len != len) {
         libbalsa_mailbox_changed(mailbox);
+    }
 
-    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_mbox_parent_class)->close_mailbox)
+    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_mbox_parent_class)->close_mailbox) {
         LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_mbox_parent_class)->close_mailbox(mailbox,
-                                                            expunge);
+                                                                                  expunge);
+    }
 
     /* Now it's safe to close the stream and free the message info. */
     if (mbox->gmime_stream) {
@@ -1126,17 +1221,19 @@ libbalsa_mailbox_mbox_close_mailbox(LibBalsaMailbox * mailbox,
     mbox->msgno_2_msg_info = NULL;
 }
 
+
 static GMimeMessage *
-lbm_mbox_get_mime_message(LibBalsaMailbox * mailbox,
-                         guint msgno)
+lbm_mbox_get_mime_message(LibBalsaMailbox *mailbox,
+                          guint            msgno)
 {
     GMimeStream *stream;
     GMimeParser *parser;
     GMimeMessage *mime_message;
 
     stream = libbalsa_mailbox_mbox_get_message_stream(mailbox, msgno, TRUE);
-    if (!stream)
-       return NULL;
+    if (!stream) {
+        return NULL;
+    }
     libbalsa_mime_stream_shared_lock(stream);
     parser = g_mime_parser_new_with_stream(stream);
 
@@ -1148,128 +1245,151 @@ lbm_mbox_get_mime_message(LibBalsaMailbox * mailbox,
     return mime_message;
 }
 
+
 /* Write one or two newlines to stream. */
 static gint
-lbm_mbox_newline(GMimeStream * stream)
+lbm_mbox_newline(GMimeStream *stream)
 {
     gint retval;
     static const gchar newlines[] = "\n\n";
 
     if (g_mime_stream_seek(stream, -1, GMIME_STREAM_SEEK_CUR) < 0) {
-       retval = -1;
+        retval = -1;
     } else {
         gchar buf;
 
-       retval = g_mime_stream_read(stream, &buf, 1);
-       if (retval == 1) {
-               retval =
-                       g_mime_stream_write(stream, newlines, buf == '\n' ? 1 : 2);
-       }
+        retval = g_mime_stream_read(stream, &buf, 1);
+        if (retval == 1) {
+            retval =
+                g_mime_stream_write(stream, newlines, buf == '\n' ? 1 : 2);
+        }
     }
 
     return retval;
 }
 
+
 /* Store the message status flags in str, padded with spaces to a minimum
  * length of len.
  */
 static void
-lbm_mbox_status_hdr(LibBalsaMessageFlag flags, guint len, GString * str)
+lbm_mbox_status_hdr(LibBalsaMessageFlag flags,
+                    guint               len,
+                    GString            *str)
 {
-    if ((flags & LIBBALSA_MESSAGE_FLAG_NEW) == 0)
-       g_string_append_c(str, 'R');
-    if ((flags & LIBBALSA_MESSAGE_FLAG_RECENT) == 0)
-       g_string_append_c(str, 'O');
-    while (str->len < len)
-       g_string_append_c(str, ' ');
+    if ((flags & LIBBALSA_MESSAGE_FLAG_NEW) == 0) {
+        g_string_append_c(str, 'R');
+    }
+    if ((flags & LIBBALSA_MESSAGE_FLAG_RECENT) == 0) {
+        g_string_append_c(str, 'O');
+    }
+    while (str->len < len) {
+        g_string_append_c(str, ' ');
+    }
 }
 
+
 /* Store the message x-status flags in str, padded with spaces to a
  * minimum length of len.
  */
 static void
-lbm_mbox_x_status_hdr(LibBalsaMessageFlag flags, guint len, GString * str)
+lbm_mbox_x_status_hdr(LibBalsaMessageFlag flags,
+                      guint               len,
+                      GString            *str)
 {
-    if ((flags & LIBBALSA_MESSAGE_FLAG_REPLIED) != 0)
-       g_string_append_c(str, 'A');
-    if ((flags & LIBBALSA_MESSAGE_FLAG_FLAGGED) != 0)
-       g_string_append_c(str, 'F');
-    if ((flags & LIBBALSA_MESSAGE_FLAG_DELETED) != 0)
-       g_string_append_c(str, 'D');
-    while (str->len < len)
-       g_string_append_c(str, ' ');
+    if ((flags & LIBBALSA_MESSAGE_FLAG_REPLIED) != 0) {
+        g_string_append_c(str, 'A');
+    }
+    if ((flags & LIBBALSA_MESSAGE_FLAG_FLAGGED) != 0) {
+        g_string_append_c(str, 'F');
+    }
+    if ((flags & LIBBALSA_MESSAGE_FLAG_DELETED) != 0) {
+        g_string_append_c(str, 'D');
+    }
+    while (str->len < len) {
+        g_string_append_c(str, ' ');
+    }
 }
 
+
 /* Helper for lbm_mbox_rewrite_in_place.
  *
  * offset:     the offset of a header in the mbox file;
  * stream:     mbox stream;
  * header:     a GString containing flags to be stored as the value of
- *             the header;
+ *              the header;
  * buf:                buffer to hold the whole text of the header;
  * len:                buffer length;
  * start:      offset into buf for storing the flags.
  *
  * Returns TRUE if the rewrite can be carried out in place,
- *        FALSE otherwise.
+ *         FALSE otherwise.
  *
  * If TRUE, on return, buf contains the new header text.
  */
 static gboolean
-lbm_mbox_rewrite_helper(off_t offset, GMimeStream * stream,
-                       GString * header, gchar * buf, guint len,
-                       const gchar * name)
+lbm_mbox_rewrite_helper(off_t        offset,
+                        GMimeStream *stream,
+                        GString     *header,
+                        gchar       *buf,
+                        guint        len,
+                        const gchar *name)
 {
     guint name_len = strlen(name);
     guint i;
 
     g_assert(name_len < len);
 
-    if (offset < 0)
-       /* No existing header, so we can rewrite in place only if no
-        * flags need to be set. */
-       return header->len == 0;
+    if (offset < 0) {
+        /* No existing header, so we can rewrite in place only if no
+         * flags need to be set. */
+        return header->len == 0;
+    }
 
-    if (g_mime_stream_seek(stream, offset, GMIME_STREAM_SEEK_SET) < 0
-       || g_mime_stream_read(stream, buf, len) < (gint) len
-       || g_ascii_strncasecmp(buf, name, name_len) != 0)
-       return FALSE;
+    if ((g_mime_stream_seek(stream, offset, GMIME_STREAM_SEEK_SET) < 0)
+        || (g_mime_stream_read(stream, buf, len) < (gint) len)
+        || (g_ascii_strncasecmp(buf, name, name_len) != 0)) {
+        return FALSE;
+    }
 
     /* Copy the flags into the buffer. */
     for (i = 0; i < header->len; i++) {
-       if (buf[name_len + i] == '\n')
-           /* The original header is too short to hold all the flags. */
-           return FALSE;
-       buf[name_len + i] = header->str[i];
+        if (buf[name_len + i] == '\n') {
+            /* The original header is too short to hold all the flags. */
+            return FALSE;
+        }
+        buf[name_len + i] = header->str[i];
     }
 
     /* Fill with spaces to the end of the original header line. */
     while (buf[name_len + i] != '\n') {
-       if (name_len + i >= len - 1)
-           /* Hit the end of the buffer before finding the end of the
-            * line--the header must have some extra garbage. */
-           return FALSE;
-       buf[name_len + i++] = ' ';
+        if (name_len + i >= len - 1) {
+            /* Hit the end of the buffer before finding the end of the
+             * line--the header must have some extra garbage. */
+            return FALSE;
+        }
+        buf[name_len + i++] = ' ';
     }
 
     return TRUE;
 }
 
+
 /* Rewrite message status headers in place, if possible.
  *
  * msg_info:   struct message_info for the message;
  * stream:     mbox stream--must be locked by caller.
  *
  * Returns TRUE if it was possible to rewrite in place,
- *        FALSE otherwise.
+ *         FALSE otherwise.
  */
 static gboolean
 lbm_mbox_rewrite_in_place(struct message_info *msg_info,
-                         GMimeStream * stream)
+                          GMimeStream         *stream)
 {
     GString *header;
-    gchar status_buf[12];      /* "Status: XXX\n" */
-    gchar x_status_buf[14];    /* "X-Status: XXX\n" */
+    gchar status_buf[12];       /* "Status: XXX\n" */
+    gchar x_status_buf[14];     /* "X-Status: XXX\n" */
 
     /* Get the flags for the "Status" header. */
     header = g_string_new(NULL);
@@ -1277,10 +1397,10 @@ lbm_mbox_rewrite_in_place(struct message_info *msg_info,
     g_assert(header->len <= 3);
 
     if (!lbm_mbox_rewrite_helper(msg_info->status, stream, header,
-                                status_buf, sizeof(status_buf),
-                                "Status: ")) {
-       g_string_free(header, TRUE);
-       return FALSE;
+                                 status_buf, sizeof(status_buf),
+                                 "Status: ")) {
+        g_string_free(header, TRUE);
+        return FALSE;
     }
 
     /* Get the flags for the "X-Status" header. */
@@ -1289,34 +1409,36 @@ lbm_mbox_rewrite_in_place(struct message_info *msg_info,
     g_assert(header->len <= 3);
 
     if (!lbm_mbox_rewrite_helper(msg_info->x_status, stream, header,
-                                x_status_buf, sizeof(x_status_buf),
-                                "X-Status: ")) {
-       g_string_free(header, TRUE);
-       return FALSE;
+                                 x_status_buf, sizeof(x_status_buf),
+                                 "X-Status: ")) {
+        g_string_free(header, TRUE);
+        return FALSE;
     }
 
     g_string_free(header, TRUE);
 
     /* Both headers are OK to rewrite, if they exist. */
     if (msg_info->status >= 0) {
-       g_mime_stream_seek(stream, msg_info->status, GMIME_STREAM_SEEK_SET);
-       g_mime_stream_write(stream, status_buf, sizeof(status_buf));
+        g_mime_stream_seek(stream, msg_info->status, GMIME_STREAM_SEEK_SET);
+        g_mime_stream_write(stream, status_buf, sizeof(status_buf));
     }
     if (msg_info->x_status >= 0) {
-       g_mime_stream_seek(stream, msg_info->x_status, GMIME_STREAM_SEEK_SET);
-       g_mime_stream_write(stream, x_status_buf, sizeof(x_status_buf));
+        g_mime_stream_seek(stream, msg_info->x_status, GMIME_STREAM_SEEK_SET);
+        g_mime_stream_write(stream, x_status_buf, sizeof(x_status_buf));
     }
     msg_info->orig_flags = REAL_FLAGS(msg_info->local_info.flags);
     return TRUE;
 }
 
+
 /* Length of the line beginning at offset, including trailing '\n'.
  * Returns -1 if no '\n' found, or if seek to offset fails. */
 static gint
-lbm_mbox_line_len(LibBalsaMailboxMbox * mbox, off_t offset)
+lbm_mbox_line_len(LibBalsaMailboxMbox *mbox,
+                  off_t                offset)
 {
     GMimeStream *stream = mbox->gmime_stream;
-    gint retval = -1;
+    gint retval         = -1;
 
     libbalsa_mime_stream_shared_lock(mbox->gmime_stream);
     if (g_mime_stream_seek(stream, offset, GMIME_STREAM_SEEK_SET) >= 0) {
@@ -1326,16 +1448,17 @@ lbm_mbox_line_len(LibBalsaMailboxMbox * mbox, off_t offset)
             gchar buf[80];
 
             len = g_mime_stream_read(stream, buf, sizeof buf);
-            if (len <= 0)
+            if (len <= 0) {
                 break;
+            }
 
             i = 0;
-            do
+            do {
                 if (buf[i++] == '\n') {
                     retval = old + i;
                     break;
                 }
-            while (i < len);
+            } while (i < len);
             old += len;
         }
     }
@@ -1344,15 +1467,19 @@ lbm_mbox_line_len(LibBalsaMailboxMbox * mbox, off_t offset)
     return retval;
 }
 
+
 static gboolean
-lbm_mbox_copy_stream(LibBalsaMailboxMbox * mbox, off_t start, off_t end,
-                    GMimeStream * dest)
+lbm_mbox_copy_stream(LibBalsaMailboxMbox *mbox,
+                     off_t                start,
+                     off_t                end,
+                     GMimeStream         *dest)
 {
     GMimeStream *substream;
     gboolean retval;
 
-    if (start >= end)
-       return TRUE;
+    if (start >= end) {
+        return TRUE;
+    }
 
     substream = g_mime_stream_substream(mbox->gmime_stream, start, end);
     libbalsa_mime_stream_shared_lock(substream);
@@ -1363,37 +1490,44 @@ lbm_mbox_copy_stream(LibBalsaMailboxMbox * mbox, off_t start, off_t end,
     return retval;
 }
 
+
 /* Write a (X-)Status header to the stream. */
 static gboolean
-lbm_mbox_write_status_hdr(GMimeStream * stream, LibBalsaMessageFlag flags)
+lbm_mbox_write_status_hdr(GMimeStream        *stream,
+                          LibBalsaMessageFlag flags)
 {
     gboolean retval;
     GString *header = g_string_new("Status: ");
     lbm_mbox_status_hdr(flags, header->len + 2, header);
     g_string_append_c(header, '\n');
     retval = g_mime_stream_write(stream, header->str,
-                                header->len) == (gint) header->len;
+                                 header->len) == (gint) header->len;
     g_string_free(header, TRUE);
     return retval;
 }
 
+
 static gboolean
-lbm_mbox_write_x_status_hdr(GMimeStream * stream, LibBalsaMessageFlag flags)
+lbm_mbox_write_x_status_hdr(GMimeStream        *stream,
+                            LibBalsaMessageFlag flags)
 {
     gboolean retval;
     GString *header = g_string_new("X-Status: ");
     lbm_mbox_x_status_hdr(flags, header->len + 3, header);
     g_string_append_c(header, '\n');
     retval = g_mime_stream_write(stream, header->str,
-                                header->len) == (gint) header->len;
+                                 header->len) == (gint) header->len;
     g_string_free(header, TRUE);
     return retval;
 }
 
-static void update_message_status_headers(GMimeMessage *message,
-                                         LibBalsaMessageFlag flags);
+
+static void update_message_status_headers(GMimeMessage       *message,
+                                          LibBalsaMessageFlag flags);
+
 static gboolean
-libbalsa_mailbox_mbox_sync(LibBalsaMailbox * mailbox, gboolean expunge)
+libbalsa_mailbox_mbox_sync(LibBalsaMailbox *mailbox,
+                           gboolean         expunge)
 {
     const gchar *path;
     struct stat st;
@@ -1419,21 +1553,23 @@ libbalsa_mailbox_mbox_sync(LibBalsaMailbox * mailbox, gboolean expunge)
      */
     libbalsa_mailbox_mbox_check(mailbox);
     mbox = LIBBALSA_MAILBOX_MBOX(mailbox);
-    if (mbox->msgno_2_msg_info->len == 0)
-       return TRUE;
+    if (mbox->msgno_2_msg_info->len == 0) {
+        return TRUE;
+    }
     mbox_stream = mbox->gmime_stream;
 
     path = libbalsa_mailbox_local_get_path(LIBBALSA_MAILBOX_LOCAL(mailbox));
 
     /* lock mailbox file */
-    if (mbox_lock(mailbox, mbox_stream) != 0)
-       return FALSE;
+    if (mbox_lock(mailbox, mbox_stream) != 0) {
+        return FALSE;
+    }
 
     /* Check to make sure that the file hasn't changed on disk */
-    if (fstat(GMIME_STREAM_FS(mbox_stream)->fd, &st) != 0
-        || st.st_size != mbox->size) {
-       mbox_unlock(mailbox, mbox_stream);
-       return FALSE;
+    if ((fstat(GMIME_STREAM_FS(mbox_stream)->fd, &st) != 0)
+        || (st.st_size != mbox->size)) {
+        mbox_unlock(mailbox, mbox_stream);
+        return FALSE;
     }
 
     /* Find where we need to start rewriting the mailbox.  We save a lot
@@ -1444,267 +1580,284 @@ libbalsa_mailbox_mbox_sync(LibBalsaMailbox * mailbox, gboolean expunge)
      * rewrites.
      */
     messages = mbox->msgno_2_msg_info->len;
-    first = -1;
-    for (i = j = 0; i < messages; i++)
-    {
-       msg_info = message_info_from_msgno(mbox, i + 1);
-       if (libbalsa_mailbox_get_state(mailbox) == LB_MAILBOX_STATE_CLOSING)
-           msg_info->local_info.flags &= ~LIBBALSA_MESSAGE_FLAG_RECENT;
-       if (expunge && (msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_DELETED))
-           break;
-       if (first < 0 && (msg_info->status < 0 || msg_info->x_status < 0))
-           first = i;
+    first    = -1;
+    for (i = j = 0; i < messages; i++) {
+        msg_info = message_info_from_msgno(mbox, i + 1);
+        if (libbalsa_mailbox_get_state(mailbox) == LB_MAILBOX_STATE_CLOSING) {
+            msg_info->local_info.flags &= ~LIBBALSA_MESSAGE_FLAG_RECENT;
+        }
+        if (expunge && (msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_DELETED)) {
+            break;
+        }
+        if ((first < 0) && ((msg_info->status < 0) || (msg_info->x_status < 0))) {
+            first = i;
+        }
         if (FLAGS_REALLY_DIFFER(msg_info->orig_flags,
                                 msg_info->local_info.flags)) {
-           gboolean can_rewrite_in_place;
-
-           libbalsa_mime_stream_shared_lock(mbox_stream);
-           can_rewrite_in_place =
-               lbm_mbox_rewrite_in_place(msg_info, mbox_stream);
-           libbalsa_mime_stream_shared_unlock(mbox_stream);
-           if (!can_rewrite_in_place)
-               break;
+            gboolean can_rewrite_in_place;
+
+            libbalsa_mime_stream_shared_lock(mbox_stream);
+            can_rewrite_in_place =
+                lbm_mbox_rewrite_in_place(msg_info, mbox_stream);
+            libbalsa_mime_stream_shared_unlock(mbox_stream);
+            if (!can_rewrite_in_place) {
+                break;
+            }
             mbox->messages_info_changed = TRUE;
-           ++j;
-       }
+            ++j;
+        }
     }
     if (i >= messages) {
-       if (j > 0) {
-           struct utimbuf utimebuf;
-           /* Restore the previous access/modification times */
-           utimebuf.actime = st.st_atime;
-           utimebuf.modtime = st.st_mtime;
-           utime(path, &utimebuf);
-       }
-       if (g_mime_stream_flush(mbox_stream) < 0)
-           g_warning("can't flush mailbox stream\n");
-       if (fstat(GMIME_STREAM_FS(mbox_stream)->fd, &st))
-           g_warning("can't stat “%s”", path);
-       else
+        if (j > 0) {
+            struct utimbuf utimebuf;
+            /* Restore the previous access/modification times */
+            utimebuf.actime  = st.st_atime;
+            utimebuf.modtime = st.st_mtime;
+            utime(path, &utimebuf);
+        }
+        if (g_mime_stream_flush(mbox_stream) < 0) {
+            g_warning("can't flush mailbox stream\n");
+        }
+        if (fstat(GMIME_STREAM_FS(mbox_stream)->fd, &st)) {
+            g_warning("can't stat “%s”", path);
+        } else {
             libbalsa_mailbox_set_mtime(mailbox, st.st_mtime);
+        }
         lbm_mbox_save(mbox);
-       mbox_unlock(mailbox, mbox_stream);
-       return TRUE;
+        mbox_unlock(mailbox, mbox_stream);
+        return TRUE;
     }
 
     /* save the index of the first changed/deleted message */
-    if (first < 0)
-       first = i; 
+    if (first < 0) {
+        first = i;
+    }
     /* where to start overwriting */
     offset = message_info_from_msgno(mbox, first + 1)->start;
 
     /* Create a temporary file to write the new version of the mailbox in. */
     i = g_file_open_tmp("balsa-tmp-mbox-XXXXXX", &tempfile, &error);
-    if (i == -1)
-    {
-       g_warning("Could not create temporary file: %s", error->message);
-       g_error_free (error);
-       mbox_unlock(mailbox, mbox_stream);
-       return FALSE;
+    if (i == -1) {
+        g_warning("Could not create temporary file: %s", error->message);
+        g_error_free (error);
+        mbox_unlock(mailbox, mbox_stream);
+        return FALSE;
     }
     temp_stream = g_mime_stream_fs_new(i);
 
     for (i = first; i < messages; i++) {
-       gint status_len, x_status_len;
+        gint status_len, x_status_len;
 
-       msg_info = message_info_from_msgno(mbox, i + 1);
-       if (expunge && (msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_DELETED))
-           continue;
+        msg_info = message_info_from_msgno(mbox, i + 1);
+        if (expunge && (msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_DELETED)) {
+            continue;
+        }
 
-       if (msg_info->status >= 0) {
-           status_len = lbm_mbox_line_len(mbox, msg_info->status);
-           if (status_len < 0)
-               break;
-       } else {
+        if (msg_info->status >= 0) {
+            status_len = lbm_mbox_line_len(mbox, msg_info->status);
+            if (status_len < 0) {
+                break;
+            }
+        } else {
             msg_info->status = msg_info->mime_version >= 0 ?
-               msg_info->mime_version :
+                msg_info->mime_version :
                 (off_t) (msg_info->start + msg_info->from_len);
-           
-           status_len = 0;
-       }
-
-       if (msg_info->x_status >= 0) {
-           x_status_len = lbm_mbox_line_len(mbox, msg_info->x_status);
-           if (x_status_len < 0)
-               break;
-       } else {
-           msg_info->x_status = msg_info->status;
-           x_status_len = 0;
-       }
-
-       if (msg_info->status <= msg_info->x_status) {
-           if (!lbm_mbox_copy_stream(mbox, msg_info->start,
-                                     msg_info->status, temp_stream)
-               || !lbm_mbox_write_status_hdr(temp_stream, msg_info->local_info.flags)
-               || !lbm_mbox_copy_stream(mbox,
-                                        msg_info->status + status_len,
-                                        msg_info->x_status, temp_stream)
-               || !lbm_mbox_write_x_status_hdr(temp_stream,
-                                               msg_info->local_info.flags)
-               || !lbm_mbox_copy_stream(mbox,
-                                        msg_info->x_status +
-                                        x_status_len, msg_info->end,
-                                        temp_stream))
-               break;
-       } else {
-           if (!lbm_mbox_copy_stream(mbox, msg_info->start,
-                                     msg_info->x_status, temp_stream)
-               || !lbm_mbox_write_x_status_hdr(temp_stream,
-                                               msg_info->local_info.flags)
-               || !lbm_mbox_copy_stream(mbox,
-                                        msg_info->x_status +
-                                        x_status_len,
-                                        msg_info->status, temp_stream)
-               || !lbm_mbox_write_status_hdr(temp_stream, msg_info->local_info.flags)
-               || !lbm_mbox_copy_stream(mbox,
-                                        msg_info->status + status_len,
-                                        msg_info->end, temp_stream))
-               break;
-       }
+
+            status_len = 0;
+        }
+
+        if (msg_info->x_status >= 0) {
+            x_status_len = lbm_mbox_line_len(mbox, msg_info->x_status);
+            if (x_status_len < 0) {
+                break;
+            }
+        } else {
+            msg_info->x_status = msg_info->status;
+            x_status_len       = 0;
+        }
+
+        if (msg_info->status <= msg_info->x_status) {
+            if (!lbm_mbox_copy_stream(mbox, msg_info->start,
+                                      msg_info->status, temp_stream)
+                || !lbm_mbox_write_status_hdr(temp_stream, msg_info->local_info.flags)
+                || !lbm_mbox_copy_stream(mbox,
+                                         msg_info->status + status_len,
+                                         msg_info->x_status, temp_stream)
+                || !lbm_mbox_write_x_status_hdr(temp_stream,
+                                                msg_info->local_info.flags)
+                || !lbm_mbox_copy_stream(mbox,
+                                         msg_info->x_status +
+                                         x_status_len, msg_info->end,
+                                         temp_stream)) {
+                break;
+            }
+        } else {
+            if (!lbm_mbox_copy_stream(mbox, msg_info->start,
+                                      msg_info->x_status, temp_stream)
+                || !lbm_mbox_write_x_status_hdr(temp_stream,
+                                                msg_info->local_info.flags)
+                || !lbm_mbox_copy_stream(mbox,
+                                         msg_info->x_status +
+                                         x_status_len,
+                                         msg_info->status, temp_stream)
+                || !lbm_mbox_write_status_hdr(temp_stream, msg_info->local_info.flags)
+                || !lbm_mbox_copy_stream(mbox,
+                                         msg_info->status + status_len,
+                                         msg_info->end, temp_stream)) {
+                break;
+            }
+        }
     }
 
     if (i < messages) {
-       /* We broke on an error. */
-       g_warning("error making temporary copy\n");
-       g_object_unref(temp_stream);
-       unlink(tempfile);
-       g_free(tempfile);
-       mbox_unlock(mailbox, mbox_stream);
-       return FALSE;
+        /* We broke on an error. */
+        g_warning("error making temporary copy\n");
+        g_object_unref(temp_stream);
+        unlink(tempfile);
+        g_free(tempfile);
+        mbox_unlock(mailbox, mbox_stream);
+        return FALSE;
     }
 
     g_mime_stream_set_bounds(mbox_stream, 0, -1);
-    if (g_mime_stream_flush(temp_stream) == -1)
-    {
-       g_warning("can't flush temporary copy\n");
-       g_object_unref(temp_stream);
-       unlink(tempfile);
-       g_free(tempfile);
-       mbox_unlock(mailbox, mbox_stream);
-       return FALSE;
+    if (g_mime_stream_flush(temp_stream) == -1) {
+        g_warning("can't flush temporary copy\n");
+        g_object_unref(temp_stream);
+        unlink(tempfile);
+        g_free(tempfile);
+        mbox_unlock(mailbox, mbox_stream);
+        return FALSE;
     }
 
     save_failed = TRUE;
     libbalsa_mime_stream_shared_lock(mbox_stream);
     if (g_mime_stream_reset(temp_stream) == -1) {
         g_warning("mbox_sync: can't rewind temporary copy.\n");
-    } else if (!lbm_mbox_stream_seek_to_message(mbox_stream, offset))
+    } else if (!lbm_mbox_stream_seek_to_message(mbox_stream, offset)) {
         g_warning("mbox_sync: message not in expected position.\n");
-    else if (g_mime_stream_write_to_stream(temp_stream, mbox_stream) != -1) {
+    } else if (g_mime_stream_write_to_stream(temp_stream, mbox_stream) != -1) {
         mbox->size = g_mime_stream_tell(mbox_stream);
 #if DEBUG_SEEK
         g_print("%s %s set size from tell %d\n", __func__, mailbox->name,
                 mbox->size);
 #endif
-        if (ftruncate(GMIME_STREAM_FS(mbox_stream)->fd, mbox->size) == 0)
+        if (ftruncate(GMIME_STREAM_FS(mbox_stream)->fd, mbox->size) == 0) {
             save_failed = FALSE;
+        }
     }
     g_object_unref(temp_stream);
     mbox_unlock(mailbox, mbox_stream);
-    if (g_mime_stream_flush(mbox_stream) == -1)
+    if (g_mime_stream_flush(mbox_stream) == -1) {
         save_failed = TRUE;
+    }
     libbalsa_mime_stream_shared_unlock(mbox_stream);
     if (save_failed) {
-       /*
-        * error occurred while writing the mailbox back,
-        * so keep the temp copy around
-        */
-       char *savefile;
-       {
-           gchar *foo = g_path_get_basename(path);
-           savefile = g_strdup_printf ("%s/saved-mbox.%s-%s-%d", g_get_tmp_dir(),
-                        g_get_user_name(), foo, getpid ());
-           g_free(foo);
-       }
-       rename (tempfile, savefile);
-       g_warning("Write failed!  Saved partial mailbox to %s", savefile);
-       g_free(savefile);
-       g_free(tempfile);
-       return FALSE;
+        /*
+         * error occurred while writing the mailbox back,
+         * so keep the temp copy around
+         */
+        char *savefile;
+        {
+            gchar *foo = g_path_get_basename(path);
+            savefile = g_strdup_printf ("%s/saved-mbox.%s-%s-%d", g_get_tmp_dir(),
+                                        g_get_user_name(), foo, getpid ());
+            g_free(foo);
+        }
+        rename (tempfile, savefile);
+        g_warning("Write failed!  Saved partial mailbox to %s", savefile);
+        g_free(savefile);
+        g_free(tempfile);
+        return FALSE;
     }
 
     {
-       struct utimbuf utimebuf;
-       /* Restore the previous access/modification times */
-       utimebuf.actime = st.st_atime;
-       utimebuf.modtime = st.st_mtime;
-       utime (path, &utimebuf);
+        struct utimbuf utimebuf;
+        /* Restore the previous access/modification times */
+        utimebuf.actime  = st.st_atime;
+        utimebuf.modtime = st.st_mtime;
+        utime (path, &utimebuf);
     }
 
     unlink(tempfile); /* remove partial copy of the mailbox */
     g_free(tempfile);
 
     if (libbalsa_mailbox_get_state(mailbox) == LB_MAILBOX_STATE_CLOSING) {
-       /* Just shorten the msg_info array. */
-       for (j = first; j < mbox->msgno_2_msg_info->len; ) {
-           msg_info = message_info_from_msgno(mbox, j + 1);
-           if (expunge &&
-               (msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_DELETED)) {
-               libbalsa_mailbox_local_msgno_removed(mailbox, j + 1);
-               free_message_info(msg_info);
-               g_ptr_array_remove_index(mbox->msgno_2_msg_info, j);
+        /* Just shorten the msg_info array. */
+        for (j = first; j < mbox->msgno_2_msg_info->len; ) {
+            msg_info = message_info_from_msgno(mbox, j + 1);
+            if (expunge &&
+                (msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_DELETED)) {
+                libbalsa_mailbox_local_msgno_removed(mailbox, j + 1);
+                free_message_info(msg_info);
+                g_ptr_array_remove_index(mbox->msgno_2_msg_info, j);
                 mbox->messages_info_changed = TRUE;
-           } else
-               j++;
-       }
+            } else {
+                j++;
+            }
+        }
         lbm_mbox_save(mbox);
-       return TRUE;
+        return TRUE;
     }
 
     /* update the rewritten messages */
     libbalsa_mime_stream_shared_lock(mbox_stream);
     if (g_mime_stream_seek(mbox_stream, offset, GMIME_STREAM_SEEK_SET)
-       == -1) {
-       g_warning("Can't update message info");
-       libbalsa_mime_stream_shared_unlock(mbox_stream);
-       return FALSE;
+        == -1) {
+        g_warning("Can't update message info");
+        libbalsa_mime_stream_shared_unlock(mbox_stream);
+        return FALSE;
     }
     gmime_parser = g_mime_parser_new_with_stream(mbox_stream);
     g_mime_parser_set_scan_from(gmime_parser, TRUE);
     g_mime_parser_set_respect_content_length(gmime_parser, TRUE);
     g_mime_parser_set_header_regex(gmime_parser,
                                    "^Status|^X-Status|^MIME-Version",
-                                  lbm_mbox_header_cb, &msg_info);
+                                   lbm_mbox_header_cb, &msg_info);
     for (j = first; j < mbox->msgno_2_msg_info->len; ) {
-       GMimeMessage *mime_msg;
+        GMimeMessage *mime_msg;
         gchar *from;
 
-       msg_info = message_info_from_msgno(mbox, j + 1);
-       if (expunge && (msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_DELETED)) {
-           /* We must drop the mime-stream lock to call
-            * libbalsa_mailbox_local_msgno_removed(), as it will grab
-            * the gdk lock to emit gtk signals; we save and restore the
-            * current file position, in case someone changes it while
-            * we're not holding the lock. */
-           offset = g_mime_stream_tell(mbox_stream);
-           libbalsa_mime_stream_shared_unlock(mbox_stream);
-           libbalsa_mailbox_local_msgno_removed(mailbox, j + 1);
-           libbalsa_mime_stream_shared_lock(mbox_stream);
-           g_mime_stream_seek(mbox_stream, offset, GMIME_STREAM_SEEK_SET);
-           free_message_info(msg_info);
-           g_ptr_array_remove_index(mbox->msgno_2_msg_info, j);
+        msg_info = message_info_from_msgno(mbox, j + 1);
+        if (expunge && (msg_info->local_info.flags & LIBBALSA_MESSAGE_FLAG_DELETED)) {
+            /* We must drop the mime-stream lock to call
+             * libbalsa_mailbox_local_msgno_removed(), as it will grab
+             * the gdk lock to emit gtk signals; we save and restore the
+             * current file position, in case someone changes it while
+             * we're not holding the lock. */
+            offset = g_mime_stream_tell(mbox_stream);
+            libbalsa_mime_stream_shared_unlock(mbox_stream);
+            libbalsa_mailbox_local_msgno_removed(mailbox, j + 1);
+            libbalsa_mime_stream_shared_lock(mbox_stream);
+            g_mime_stream_seek(mbox_stream, offset, GMIME_STREAM_SEEK_SET);
+            free_message_info(msg_info);
+            g_ptr_array_remove_index(mbox->msgno_2_msg_info, j);
             mbox->messages_info_changed = TRUE;
-           continue;
-       }
-       if (msg_info->local_info.message)
-           msg_info->local_info.message->msgno = j + 1;
-
-       msg_info->status = msg_info->x_status = msg_info->mime_version = -1;
-       mime_msg = g_mime_parser_construct_message(gmime_parser);
-        if (!mime_msg)
+            continue;
+        }
+        if (msg_info->local_info.message) {
+            msg_info->local_info.message->msgno = j + 1;
+        }
+
+        msg_info->status = msg_info->x_status = msg_info->mime_version = -1;
+        mime_msg         = g_mime_parser_construct_message(gmime_parser);
+        if (!mime_msg) {
             /* Try to recover */
             continue;
+        }
         msg_info->start = g_mime_parser_get_from_offset(gmime_parser);
 
-       /* Make sure we don't have offsets for any encapsulated headers. */
-       if (!g_mime_object_get_header(GMIME_OBJECT(mime_msg), "Status"))
-           msg_info->status = -1;
-       if (!g_mime_object_get_header(GMIME_OBJECT(mime_msg), "X-Status"))
-           msg_info->x_status = -1;
-       if (!g_mime_object_get_header(GMIME_OBJECT(mime_msg), "MIME-Version"))
-           msg_info->mime_version = -1;
+        /* Make sure we don't have offsets for any encapsulated headers. */
+        if (!g_mime_object_get_header(GMIME_OBJECT(mime_msg), "Status")) {
+            msg_info->status = -1;
+        }
+        if (!g_mime_object_get_header(GMIME_OBJECT(mime_msg), "X-Status")) {
+            msg_info->x_status = -1;
+        }
+        if (!g_mime_object_get_header(GMIME_OBJECT(mime_msg), "MIME-Version")) {
+            msg_info->mime_version = -1;
+        }
 
-       from = g_mime_parser_get_from(gmime_parser);
+        from = g_mime_parser_get_from(gmime_parser);
         if (!from) {
             /* Try to recover */
             g_object_unref(mime_msg);
@@ -1713,22 +1866,22 @@ libbalsa_mailbox_mbox_sync(LibBalsaMailbox * mailbox, gboolean expunge)
 
         msg_info->from_len = strlen(from) + 1;
         g_free(from);
-       msg_info->end = g_mime_parser_tell(gmime_parser);
-       msg_info->orig_flags = REAL_FLAGS(msg_info->local_info.flags);
-       g_assert(mime_msg->mime_part != NULL);
-       if (!msg_info->local_info.message || !msg_info->local_info.message->mime_msg)
-           g_object_unref(mime_msg);
-       else {
-           g_object_unref(msg_info->local_info.message->mime_msg);
-           msg_info->local_info.message->mime_msg = mime_msg;
-           /*
-            * reinit the message parts info
-            */
-           libbalsa_message_body_set_mime_body(msg_info->local_info.message->body_list,
-                                               mime_msg->mime_part);
-       }
-
-       j++;
+        msg_info->end        = g_mime_parser_tell(gmime_parser);
+        msg_info->orig_flags = REAL_FLAGS(msg_info->local_info.flags);
+        g_assert(mime_msg->mime_part != NULL);
+        if (!msg_info->local_info.message || !msg_info->local_info.message->mime_msg) {
+            g_object_unref(mime_msg);
+        } else {
+            g_object_unref(msg_info->local_info.message->mime_msg);
+            msg_info->local_info.message->mime_msg = mime_msg;
+            /*
+             * reinit the message parts info
+             */
+            libbalsa_message_body_set_mime_body(msg_info->local_info.message->body_list,
+                                                mime_msg->mime_part);
+        }
+
+        j++;
     }
     libbalsa_mime_stream_shared_unlock(mbox_stream);
     mbox->msgno_2_msg_info->len = j;
@@ -1738,27 +1891,32 @@ libbalsa_mailbox_mbox_sync(LibBalsaMailbox * mailbox, gboolean expunge)
     return TRUE;
 }
 
+
 static LibBalsaMailboxLocalMessageInfo *
-lbm_mbox_get_info(LibBalsaMailboxLocal * local, guint msgno)
+lbm_mbox_get_info(LibBalsaMailboxLocal *local,
+                  guint                 msgno)
 {
-    LibBalsaMailboxMbox *mbox = LIBBALSA_MAILBOX_MBOX(local);
+    LibBalsaMailboxMbox *mbox     = LIBBALSA_MAILBOX_MBOX(local);
     struct message_info *msg_info = message_info_from_msgno(mbox, msgno);
 
     return &msg_info->local_info;
 }
 
+
 static gboolean
-libbalsa_mailbox_mbox_fetch_message_structure(LibBalsaMailbox * mailbox,
-                                             LibBalsaMessage * message,
-                                             LibBalsaFetchFlag flags)
+libbalsa_mailbox_mbox_fetch_message_structure(LibBalsaMailbox  *mailbox,
+                                              LibBalsaMessage  *message,
+                                              LibBalsaFetchFlag flags)
 {
-    if (!message->mime_msg)
-       message->mime_msg = lbm_mbox_get_mime_message(mailbox, message->msgno);
+    if (!message->mime_msg) {
+        message->mime_msg = lbm_mbox_get_mime_message(mailbox, message->msgno);
+    }
 
     return LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_mbox_parent_class)->
-        fetch_message_structure(mailbox, message, flags);
+           fetch_message_structure(mailbox, message, flags);
 }
 
+
 /* Create the LibBalsaMessage and call libbalsa_message_init_from_gmime
  * to populate the headers we need for the display:
  *   headers->from
@@ -1773,8 +1931,8 @@ libbalsa_mailbox_mbox_fetch_message_structure(LibBalsaMailbox * mailbox,
  *   in_reply_to
  */
 static LibBalsaMessage *
-lbm_mbox_message_new(GMimeMessage * mime_message,
-                    struct message_info *msg_info)
+lbm_mbox_message_new(GMimeMessage        *mime_message,
+                     struct message_info *msg_info)
 {
     LibBalsaMessage *message;
     const char *header;
@@ -1782,9 +1940,9 @@ lbm_mbox_message_new(GMimeMessage * mime_message,
 
 #if defined(THIS_HAS_BEEN_TESTED)
     if (mime_message->subject &&
-       !strcmp(mime_message->subject,
-               "DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA")) {
-       return NULL;
+        !strcmp(mime_message->subject,
+                "DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA")) {
+        return NULL;
     }
 #endif
 
@@ -1792,22 +1950,29 @@ lbm_mbox_message_new(GMimeMessage * mime_message,
 
     header = g_mime_object_get_header (GMIME_OBJECT(mime_message), "Status");
     if (header) {
-       if (strchr(header, 'R') == NULL) /* not found == not READ */
-           flags |= LIBBALSA_MESSAGE_FLAG_NEW;
-       if (strchr(header, 'r') != NULL) /* found == REPLIED */
-           flags |= LIBBALSA_MESSAGE_FLAG_REPLIED;
-       if (strchr(header, 'O') == NULL) /* not found == RECENT */
-           flags |= LIBBALSA_MESSAGE_FLAG_RECENT;
-    } else
-           flags |= LIBBALSA_MESSAGE_FLAG_NEW |  LIBBALSA_MESSAGE_FLAG_RECENT;
+        if (strchr(header, 'R') == NULL) { /* not found == not READ */
+            flags |= LIBBALSA_MESSAGE_FLAG_NEW;
+        }
+        if (strchr(header, 'r') != NULL) { /* found == REPLIED */
+            flags |= LIBBALSA_MESSAGE_FLAG_REPLIED;
+        }
+        if (strchr(header, 'O') == NULL) { /* not found == RECENT */
+            flags |= LIBBALSA_MESSAGE_FLAG_RECENT;
+        }
+    } else {
+        flags |= LIBBALSA_MESSAGE_FLAG_NEW | LIBBALSA_MESSAGE_FLAG_RECENT;
+    }
     header = g_mime_object_get_header (GMIME_OBJECT(mime_message), "X-Status");
     if (header) {
-       if (strchr(header, 'D') != NULL) /* found == DELETED */
-           flags |= LIBBALSA_MESSAGE_FLAG_DELETED;
-       if (strchr(header, 'F') != NULL) /* found == FLAGGED */
-           flags |= LIBBALSA_MESSAGE_FLAG_FLAGGED;
-       if (strchr(header, 'A') != NULL) /* found == REPLIED */
-           flags |= LIBBALSA_MESSAGE_FLAG_REPLIED;
+        if (strchr(header, 'D') != NULL) { /* found == DELETED */
+            flags |= LIBBALSA_MESSAGE_FLAG_DELETED;
+        }
+        if (strchr(header, 'F') != NULL) { /* found == FLAGGED */
+            flags |= LIBBALSA_MESSAGE_FLAG_FLAGGED;
+        }
+        if (strchr(header, 'A') != NULL) { /* found == REPLIED */
+            flags |= LIBBALSA_MESSAGE_FLAG_REPLIED;
+        }
     }
     msg_info->orig_flags = flags;
 
@@ -1816,8 +1981,10 @@ lbm_mbox_message_new(GMimeMessage * mime_message,
     return message;
 }
 
-static void update_message_status_headers(GMimeMessage *message,
-                                         LibBalsaMessageFlag flags)
+
+static void
+update_message_status_headers(GMimeMessage       *message,
+                              LibBalsaMessageFlag flags)
 {
     GString *new_header = g_string_new(NULL);
 
@@ -1833,7 +2000,7 @@ static void update_message_status_headers(GMimeMessage *message,
 
 
 static GMimeObject *
-lbm_mbox_armored_object(GMimeStream * stream)
+lbm_mbox_armored_object(GMimeStream *stream)
 {
     GMimeParser *parser;
     GMimeObject *object;
@@ -1846,16 +2013,17 @@ lbm_mbox_armored_object(GMimeStream * stream)
     return object;
 }
 
+
 static GMimeStream *
-lbm_mbox_armored_stream(GMimeStream * stream)
+lbm_mbox_armored_stream(GMimeStream *stream)
 {
     GMimeStream *fstream;
     GMimeFilter *filter;
-    
+
     fstream = g_mime_stream_filter_new(stream);
 
     filter = g_mime_filter_crlf_new(FALSE,
-                                   FALSE);
+                                    FALSE);
     g_mime_stream_filter_add(GMIME_STREAM_FILTER(fstream), filter);
     g_object_unref(filter);
 
@@ -1866,12 +2034,13 @@ lbm_mbox_armored_stream(GMimeStream * stream)
     return fstream;
 }
 
+
 /* Called with mailbox locked. */
 static gboolean
-lbm_mbox_add_message(LibBalsaMailboxLocal * local,
-                     GMimeStream          * stream,
-                     LibBalsaMessageFlag    flags,
-                     GError              ** err)
+lbm_mbox_add_message(LibBalsaMailboxLocal *local,
+                     GMimeStream          *stream,
+                     LibBalsaMessageFlag   flags,
+                     GError              **err)
 {
     LibBalsaMailbox *mailbox = (LibBalsaMailbox *) local;
     LibBalsaMessage *message;
@@ -1894,24 +2063,25 @@ lbm_mbox_add_message(LibBalsaMailboxLocal * local,
     ctime_r(&(message->headers->date), date_string);
 
     sender = message->headers->from ?
-       internet_address_list_to_string(message->headers->from, FALSE) :
-       g_strdup("none");
+        internet_address_list_to_string(message->headers->from, FALSE) :
+        g_strdup("none");
 
     g_object_unref(message);
 
-    if ( (brack = strrchr( sender, '<' )) ) {
-        gchar * a = strrchr ( brack , '>' );
-        if (a)
+    if ((brack = strrchr( sender, '<' ))) {
+        gchar *a = strrchr ( brack, '>' );
+        if (a) {
             address = g_strndup(brack + 1, a - brack - 1);
-        else
+        } else {
             address = g_strdup("none");
-       g_free(sender);
+        }
+        g_free(sender);
     } else {
         address = sender;
     }
     from = g_strdup_printf ("From %s %s", address, date_string );
     g_free(address);
-    
+
     path = libbalsa_mailbox_local_get_path(local);
     /* open in read-write mode */
     fd = open(path, O_RDWR);
@@ -1922,26 +2092,26 @@ lbm_mbox_add_message(LibBalsaMailboxLocal * local,
         g_free(from);
         return FALSE;
     }
-    
+
     orig_length = lseek (fd, 0, SEEK_END);
     lseek (fd, 0, SEEK_SET);
     dest = g_mime_stream_fs_new (fd);
     if (!dest) {
-       g_free(from);
+        g_free(from);
         g_set_error(err, LIBBALSA_MAILBOX_ERROR,
                     LIBBALSA_MAILBOX_APPEND_ERROR,
                     _("%s: could not get new MIME stream."),
                     "MBOX");
-       return FALSE;
+        return FALSE;
     }
-    if (orig_length > 0 && !lbm_mbox_stream_seek_to_message(dest, 0)) {
-       g_object_unref(dest);
+    if ((orig_length > 0) && !lbm_mbox_stream_seek_to_message(dest, 0)) {
+        g_object_unref(dest);
         g_set_error(err, LIBBALSA_MAILBOX_ERROR,
                     LIBBALSA_MAILBOX_APPEND_ERROR,
                     _("%s: %s is not in mbox format."),
                     "MBOX", path);
-       g_free(from);
-       return FALSE;
+        g_free(from);
+        return FALSE;
     }
     mbox_lock ( mailbox, dest );
 
@@ -1956,44 +2126,50 @@ lbm_mbox_add_message(LibBalsaMailboxLocal * local,
     armored_dest = lbm_mbox_armored_stream(dest);
 
     retval = g_mime_stream_seek(dest, 0, GMIME_STREAM_SEEK_END);
-    if (retval > 0)
+    if (retval > 0) {
         retval = lbm_mbox_newline(dest);
-    if (retval < 0
-        || g_mime_stream_write_string(dest, from) < (gint) strlen(from)
-       || g_mime_object_write_to_stream(armored_object, armored_dest) < 0) {
+    }
+    if ((retval < 0)
+        || (g_mime_stream_write_string(dest, from) < (gint) strlen(from))
+        || (g_mime_object_write_to_stream(armored_object, armored_dest) < 0)) {
         g_set_error(err, LIBBALSA_MAILBOX_ERROR,
                     LIBBALSA_MAILBOX_APPEND_ERROR, _("Data copy error"));
-       retval = -1;
+        retval = -1;
     }
     g_free(from);
     g_object_unref(armored_object);
     libbalsa_mime_stream_shared_unlock(stream);
     g_object_unref(armored_dest);
 
-    if (retval < 0 && truncate(path, orig_length) < 0)
+    if ((retval < 0) && (truncate(path, orig_length) < 0)) {
         retval = -2;
+    }
     mbox_unlock (mailbox, dest);
     g_object_unref(dest);
 
     return retval >= 0;
 }
 
+
 static guint
-libbalsa_mailbox_mbox_total_messages(LibBalsaMailbox * mailbox)
+libbalsa_mailbox_mbox_total_messages(LibBalsaMailbox *mailbox)
 {
     LibBalsaMailboxMbox *mbox = (LibBalsaMailboxMbox *) mailbox;
 
     return mbox->msgno_2_msg_info ? mbox->msgno_2_msg_info->len : 0;
 }
 
+
 static void
-libbalsa_mailbox_mbox_lock_store(LibBalsaMailbox * mailbox, gboolean lock)
+libbalsa_mailbox_mbox_lock_store(LibBalsaMailbox *mailbox,
+                                 gboolean         lock)
 {
     LibBalsaMailboxMbox *mbox = (LibBalsaMailboxMbox *) mailbox;
-    GMimeStream *stream = mbox->gmime_stream;
+    GMimeStream *stream       = mbox->gmime_stream;
 
-    if (lock)
+    if (lock) {
         libbalsa_mime_stream_shared_lock(stream);
-    else
+    } else {
         libbalsa_mime_stream_shared_unlock(stream);
+    }
 }
diff --git a/libbalsa/mailbox_mbox.h b/libbalsa/mailbox_mbox.h
index a7bf098..06d7924 100644
--- a/libbalsa/mailbox_mbox.h
+++ b/libbalsa/mailbox_mbox.h
@@ -6,14 +6,14 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option) 
+ * the Free Software Foundation; either version 2, or (at your option)
  * any later version.
- *  
+ *
  * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of 
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *  
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
@@ -29,7 +29,7 @@ G_DECLARE_FINAL_TYPE(LibBalsaMailboxMbox,
                      MAILBOX_MBOX,
                      LibBalsaMailboxLocal)
 
-LibBalsaMailbox *libbalsa_mailbox_mbox_new(const gchar * path,
-                                           gboolean      create);
+LibBalsaMailbox * libbalsa_mailbox_mbox_new(const gchar * path,
+                                            gboolean create);
 
 #endif
diff --git a/libbalsa/mailbox_mh.c b/libbalsa/mailbox_mh.c
index af32ce8..e8d13c2 100644
--- a/libbalsa/mailbox_mh.c
+++ b/libbalsa/mailbox_mh.c
@@ -6,20 +6,20 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option) 
+ * the Free Software Foundation; either version 2, or (at your option)
  * any later version.
- *  
+ *
  * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of 
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *  
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H
-# include "config.h"
+#   include "config.h"
 #endif                          /* HAVE_CONFIG_H */
 
 /* to compile this on BSD/Darwin */
@@ -49,47 +49,50 @@ struct message_info {
 #define REAL_FLAGS(flags) (flags & LIBBALSA_MESSAGE_FLAGS_REAL)
 
 static void libbalsa_mailbox_mh_class_init(LibBalsaMailboxMhClass *klass);
-static void libbalsa_mailbox_mh_init(LibBalsaMailboxMh * mailbox);
-static void libbalsa_mailbox_mh_finalize(GObject * object);
-static void libbalsa_mailbox_mh_load_config(LibBalsaMailbox * mailbox,
-                                            const gchar * prefix);
+static void libbalsa_mailbox_mh_init(LibBalsaMailboxMh *mailbox);
+static void libbalsa_mailbox_mh_finalize(GObject *object);
+static void libbalsa_mailbox_mh_load_config(LibBalsaMailbox *mailbox,
+                                            const gchar     *prefix);
 
 static GMimeStream *libbalsa_mailbox_mh_get_message_stream(LibBalsaMailbox *
-                                                          mailbox,
-                                                          guint msgno,
-                                                          gboolean peek);
-static gint lbm_mh_check_files(const gchar * path, gboolean create);
-static void lbm_mh_set_path(LibBalsaMailboxLocal * mailbox,
-                            const gchar * path);
+                                                           mailbox,
+                                                           guint    msgno,
+                                                           gboolean peek);
+static gint lbm_mh_check_files(const gchar *path,
+                               gboolean     create);
+static void lbm_mh_set_path(LibBalsaMailboxLocal *mailbox,
+                            const gchar          *path);
 static void lbm_mh_remove_files(LibBalsaMailboxLocal *mailbox);
 static LibBalsaMailboxLocalMessageInfo
-    *lbm_mh_get_info(LibBalsaMailboxLocal * local, guint msgno);
+           *lbm_mh_get_info(LibBalsaMailboxLocal *local,
+                 guint                            msgno);
+
 static LibBalsaMailboxLocalAddMessageFunc lbm_mh_add_message;
 
-static gboolean libbalsa_mailbox_mh_open(LibBalsaMailbox * mailbox,
-                                        GError **err);
-static void libbalsa_mailbox_mh_close_mailbox(LibBalsaMailbox * mailbox,
-                                              gboolean expunge);
-static void libbalsa_mailbox_mh_check(LibBalsaMailbox * mailbox);
-static gboolean libbalsa_mailbox_mh_sync(LibBalsaMailbox * mailbox,
-                                         gboolean expunge);
+static gboolean             libbalsa_mailbox_mh_open(LibBalsaMailbox *mailbox,
+                                                     GError         **err);
+static void                 libbalsa_mailbox_mh_close_mailbox(LibBalsaMailbox *mailbox,
+                                                              gboolean         expunge);
+static void                 libbalsa_mailbox_mh_check(LibBalsaMailbox *mailbox);
+static gboolean             libbalsa_mailbox_mh_sync(LibBalsaMailbox *mailbox,
+                                                     gboolean         expunge);
 static struct message_info *lbm_mh_message_info_from_msgno(
-                                                 LibBalsaMailboxMh * mailbox,
-                                                 guint msgno);
+    LibBalsaMailboxMh *mailbox,
+    guint              msgno);
 static gboolean libbalsa_mailbox_mh_fetch_message_structure(LibBalsaMailbox
-                                                            * mailbox,
+                                                            *mailbox,
                                                             LibBalsaMessage
-                                                            * message,
+                                                            *message,
                                                             LibBalsaFetchFlag
                                                             flags);
-static guint libbalsa_mailbox_mh_total_messages(LibBalsaMailbox * mailbox);
+static guint libbalsa_mailbox_mh_total_messages(LibBalsaMailbox *mailbox);
 
 struct _LibBalsaMailboxMh {
     LibBalsaMailboxLocal parent;
 
-    GHashTable* messages_info;
-    GPtrArray* msgno_2_msg_info;
-    gchar* sequences_filename;
+    GHashTable *messages_info;
+    GPtrArray *msgno_2_msg_info;
+    gchar *sequences_filename;
     time_t mtime_sequences;
     guint last_fileno;
 };
@@ -103,32 +106,32 @@ G_DEFINE_TYPE(LibBalsaMailboxMh,
               LIBBALSA_TYPE_MAILBOX_LOCAL)
 
 static void
-libbalsa_mailbox_mh_class_init(LibBalsaMailboxMhClass * klass)
+libbalsa_mailbox_mh_class_init(LibBalsaMailboxMhClass *klass)
 {
     GObjectClass *object_class;
     LibBalsaMailboxClass *libbalsa_mailbox_class;
     LibBalsaMailboxLocalClass *libbalsa_mailbox_local_class;
 
-    object_class = G_OBJECT_CLASS(klass);
-    libbalsa_mailbox_class = LIBBALSA_MAILBOX_CLASS(klass);
+    object_class                 = G_OBJECT_CLASS(klass);
+    libbalsa_mailbox_class       = LIBBALSA_MAILBOX_CLASS(klass);
     libbalsa_mailbox_local_class = LIBBALSA_MAILBOX_LOCAL_CLASS(klass);
 
     object_class->finalize = libbalsa_mailbox_mh_finalize;
 
-    libbalsa_mailbox_class->load_config = libbalsa_mailbox_mh_load_config;
+    libbalsa_mailbox_class->load_config        = libbalsa_mailbox_mh_load_config;
     libbalsa_mailbox_class->get_message_stream =
-       libbalsa_mailbox_mh_get_message_stream;
+        libbalsa_mailbox_mh_get_message_stream;
 
     libbalsa_mailbox_class->open_mailbox = libbalsa_mailbox_mh_open;
-    libbalsa_mailbox_class->check = libbalsa_mailbox_mh_check;
+    libbalsa_mailbox_class->check        = libbalsa_mailbox_mh_check;
 
-    libbalsa_mailbox_class->sync = libbalsa_mailbox_mh_sync;
+    libbalsa_mailbox_class->sync          = libbalsa_mailbox_mh_sync;
     libbalsa_mailbox_class->close_mailbox =
-       libbalsa_mailbox_mh_close_mailbox;
+        libbalsa_mailbox_mh_close_mailbox;
     libbalsa_mailbox_class->fetch_message_structure =
-       libbalsa_mailbox_mh_fetch_message_structure;
+        libbalsa_mailbox_mh_fetch_message_structure;
     libbalsa_mailbox_class->total_messages =
-       libbalsa_mailbox_mh_total_messages;
+        libbalsa_mailbox_mh_total_messages;
 
     libbalsa_mailbox_local_class->check_files  = lbm_mh_check_files;
     libbalsa_mailbox_local_class->set_path     = lbm_mh_set_path;
@@ -137,14 +140,17 @@ libbalsa_mailbox_mh_class_init(LibBalsaMailboxMhClass * klass)
     libbalsa_mailbox_local_class->add_message  = lbm_mh_add_message;
 }
 
+
 static void
-libbalsa_mailbox_mh_init(LibBalsaMailboxMh * mailbox)
+libbalsa_mailbox_mh_init(LibBalsaMailboxMh *mailbox)
 {
     /* mh->sequences_file = NULL; */
 }
 
+
 static gint
-lbm_mh_check_files(const gchar * path, gboolean create)
+lbm_mh_check_files(const gchar *path,
+                   gboolean     create)
 {
     g_return_val_if_fail(path != NULL, -1);
 
@@ -169,39 +175,47 @@ lbm_mh_check_files(const gchar * path, gboolean create)
         }
 
         sequences_filename = g_build_filename(path, ".mh_sequences", NULL);
-        fd = creat(sequences_filename, S_IRWXU);
+        fd                 = creat(sequences_filename, S_IRWXU);
         g_free(sequences_filename);
 
         if (fd == -1) {
             libbalsa_information
                 (LIBBALSA_INFORMATION_WARNING,
-                 _("Could not create MH structure at %s (%s)"),
-                 path, strerror(errno));
+                _("Could not create MH structure at %s (%s)"),
+                path, strerror(errno));
             rmdir(path);
             return -1;
-        } else
+        } else {
             close(fd);
-    } else
+        }
+    } else {
         return -1;
+    }
 
     return 0;
 }
 
+
 static void
-lbm_mh_set_sequences_filename(LibBalsaMailboxMh * mh, const gchar * path)
+lbm_mh_set_sequences_filename(LibBalsaMailboxMh *mh,
+                              const gchar       *path)
 {
     g_free(mh->sequences_filename);
     mh->sequences_filename = g_build_filename(path, ".mh_sequences", NULL);
 }
 
+
 static void
-lbm_mh_set_path(LibBalsaMailboxLocal * local, const gchar * path)
+lbm_mh_set_path(LibBalsaMailboxLocal *local,
+                const gchar          *path)
 {
     lbm_mh_set_sequences_filename(LIBBALSA_MAILBOX_MH(local), path);
 }
 
+
 LibBalsaMailbox *
-libbalsa_mailbox_mh_new(const gchar * path, gboolean create)
+libbalsa_mailbox_mh_new(const gchar *path,
+                        gboolean     create)
 {
     LibBalsaMailbox *mailbox;
 
@@ -211,24 +225,26 @@ libbalsa_mailbox_mh_new(const gchar * path, gboolean create)
 
     if (libbalsa_mailbox_local_set_path(LIBBALSA_MAILBOX_LOCAL(mailbox),
                                         path, create) != 0) {
-       g_object_unref(mailbox);
-       return NULL;
+        g_object_unref(mailbox);
+        return NULL;
     }
 
     return mailbox;
 }
 
+
 static void
-libbalsa_mailbox_mh_finalize(GObject * object)
+libbalsa_mailbox_mh_finalize(GObject *object)
 {
     LibBalsaMailboxMh *mh = LIBBALSA_MAILBOX_MH(object);
     g_free(mh->sequences_filename);
     G_OBJECT_CLASS(libbalsa_mailbox_mh_parent_class)->finalize(object);
 }
 
+
 static void
-libbalsa_mailbox_mh_load_config(LibBalsaMailbox * mailbox,
-                                const gchar * prefix)
+libbalsa_mailbox_mh_load_config(LibBalsaMailbox *mailbox,
+                                const gchar     *prefix)
 {
     LibBalsaMailboxMh *mh = LIBBALSA_MAILBOX_MH(mailbox);
     gchar *path;
@@ -240,13 +256,15 @@ libbalsa_mailbox_mh_load_config(LibBalsaMailbox * mailbox,
     LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_mh_parent_class)->load_config(mailbox, prefix);
 }
 
+
 #define MH_BASENAME(msg_info) \
     g_strdup_printf((msg_info->orig_flags & LIBBALSA_MESSAGE_FLAG_DELETED) ? \
-                   ",%d" : "%d", msg_info->fileno)
+                    ",%d" : "%d", msg_info->fileno)
 
 static GMimeStream *
-libbalsa_mailbox_mh_get_message_stream(LibBalsaMailbox * mailbox,
-                                      guint msgno, gboolean peek)
+libbalsa_mailbox_mh_get_message_stream(LibBalsaMailbox *mailbox,
+                                       guint            msgno,
+                                       gboolean         peek)
 {
     GMimeStream *stream;
     struct message_info *msg_info;
@@ -255,72 +273,80 @@ libbalsa_mailbox_mh_get_message_stream(LibBalsaMailbox * mailbox,
     g_return_val_if_fail(MAILBOX_OPEN(mailbox), NULL);
 
     msg_info = lbm_mh_message_info_from_msgno(LIBBALSA_MAILBOX_MH(mailbox),
-                                             msgno);
+                                              msgno);
     base_name = MH_BASENAME(msg_info);
-    stream = libbalsa_mailbox_local_get_message_stream(mailbox, base_name, NULL);
+    stream    = libbalsa_mailbox_local_get_message_stream(mailbox, base_name, NULL);
     g_free(base_name);
 
     return stream;
 }
 
+
 static void
 lbm_mh_remove_files(LibBalsaMailboxLocal *mailbox)
 {
-    const gchar* path;
+    const gchar *path;
     g_return_if_fail(LIBBALSA_IS_MAILBOX_MH(mailbox));
     path = libbalsa_mailbox_local_get_path(mailbox);
 
     if (!libbalsa_delete_directory_contents(path)) {
-       libbalsa_information(LIBBALSA_INFORMATION_ERROR,
-                            _("Could not remove contents of %s:\n%s"),
-                            path, strerror(errno));
-       return;
+        libbalsa_information(LIBBALSA_INFORMATION_ERROR,
+                             _("Could not remove contents of %s:\n%s"),
+                             path, strerror(errno));
+        return;
     }
     if ( rmdir(path) == -1 ) {
-       libbalsa_information(LIBBALSA_INFORMATION_ERROR,
-                            _("Could not remove %s:\n%s"),
-                            path, strerror(errno));
+        libbalsa_information(LIBBALSA_INFORMATION_ERROR,
+                             _("Could not remove %s:\n%s"),
+                             path, strerror(errno));
     }
     LIBBALSA_MAILBOX_LOCAL_CLASS(libbalsa_mailbox_mh_parent_class)->remove_files(mailbox);
 }
 
 
 static LibBalsaMailboxLocalMessageInfo *
-lbm_mh_get_info(LibBalsaMailboxLocal * local, guint msgno)
+lbm_mh_get_info(LibBalsaMailboxLocal *local,
+                guint                 msgno)
 {
     struct message_info *msg_info;
 
     msg_info = lbm_mh_message_info_from_msgno(LIBBALSA_MAILBOX_MH(local),
-                                             msgno);
-    if (msg_info->local_info.flags == LIBBALSA_MESSAGE_FLAG_INVALID)
+                                              msgno);
+    if (msg_info->local_info.flags == LIBBALSA_MESSAGE_FLAG_INVALID) {
         msg_info->local_info.flags = msg_info->orig_flags;
+    }
 
     return &msg_info->local_info;
 }
 
+
 /* Ignore the garbage files.  A valid MH message consists of only
  * digits.  Deleted message get moved to a filename with a comma before
  * it.
  */
 static gboolean
-lbm_mh_check_filename(const gchar * s)
+lbm_mh_check_filename(const gchar *s)
 {
     for (; *s; s++) {
-       if (!g_ascii_isdigit(*s))
-           return FALSE;
+        if (!g_ascii_isdigit(*s)) {
+            return FALSE;
+        }
     }
     return TRUE;
 }
 
+
 static gint
-lbm_mh_compare_fileno(const struct message_info ** a,
-                     const struct message_info ** b)
+lbm_mh_compare_fileno(const struct message_info **a,
+                      const struct message_info **b)
 {
     return (*a)->fileno - (*b)->fileno;
 }
 
+
 static void
-lbm_mh_parse_mailbox(LibBalsaMailboxMh * mh, gboolean add_msg_info)
+lbm_mh_parse_mailbox(LibBalsaMailboxMh *mh,
+                     gboolean           add_msg_info)
 {
     const gchar *path;
     GDir *dir;
@@ -328,118 +354,134 @@ lbm_mh_parse_mailbox(LibBalsaMailboxMh * mh, gboolean add_msg_info)
 
     path = libbalsa_mailbox_local_get_path((LibBalsaMailboxLocal *) mh);
 
-    if ((dir = g_dir_open(path, 0, NULL)) == NULL)
-       return;
+    if ((dir = g_dir_open(path, 0, NULL)) == NULL) {
+        return;
+    }
 
     while ((filename = g_dir_read_name(dir)) != NULL) {
-       LibBalsaMessageFlag delete_flag = 0;
-       guint fileno;
+        LibBalsaMessageFlag delete_flag = 0;
+        guint fileno;
 
-       if (filename[0] == ',') {
-           filename++;
-           delete_flag = LIBBALSA_MESSAGE_FLAG_DELETED;
-       }
-       if (lbm_mh_check_filename(filename) == FALSE)
-           continue;
+        if (filename[0] == ',') {
+            filename++;
+            delete_flag = LIBBALSA_MESSAGE_FLAG_DELETED;
+        }
+        if (lbm_mh_check_filename(filename) == FALSE) {
+            continue;
+        }
 
-       if (sscanf(filename, "%10d", &fileno) != 1)
+        if (sscanf(filename, "%10d", &fileno) != 1) {
             break;     /* FIXME report error? */
-       if (fileno > mh->last_fileno)
-           mh->last_fileno = fileno;
-
-       if (add_msg_info && mh->messages_info) {
-           struct message_info *msg_info =
-               g_hash_table_lookup(mh->messages_info,
-                                   GINT_TO_POINTER(fileno));
-           if (!msg_info) {
-               msg_info = g_new0(struct message_info, 1);
-               msg_info->local_info.flags = LIBBALSA_MESSAGE_FLAG_INVALID;
-               g_hash_table_insert(mh->messages_info,
-                                   GINT_TO_POINTER(fileno), msg_info);
-               g_ptr_array_add(mh->msgno_2_msg_info, msg_info);
-               msg_info->fileno = fileno;
-           }
-           msg_info->orig_flags = delete_flag;
-       }
+        }
+        if (fileno > mh->last_fileno) {
+            mh->last_fileno = fileno;
+        }
+
+        if (add_msg_info && mh->messages_info) {
+            struct message_info *msg_info =
+                g_hash_table_lookup(mh->messages_info,
+                                    GINT_TO_POINTER(fileno));
+            if (!msg_info) {
+                msg_info                   = g_new0(struct message_info, 1);
+                msg_info->local_info.flags = LIBBALSA_MESSAGE_FLAG_INVALID;
+                g_hash_table_insert(mh->messages_info,
+                                    GINT_TO_POINTER(fileno), msg_info);
+                g_ptr_array_add(mh->msgno_2_msg_info, msg_info);
+                msg_info->fileno = fileno;
+            }
+            msg_info->orig_flags = delete_flag;
+        }
     }
     g_dir_close(dir);
 
-    if (mh->msgno_2_msg_info)
-       g_ptr_array_sort(mh->msgno_2_msg_info,
-                        (GCompareFunc) lbm_mh_compare_fileno);
+    if (mh->msgno_2_msg_info) {
+        g_ptr_array_sort(mh->msgno_2_msg_info,
+                         (GCompareFunc) lbm_mh_compare_fileno);
+    }
 }
 
-static const gchar *LibBalsaMailboxMhUnseen = "unseen:";
+
+static const gchar *LibBalsaMailboxMhUnseen  = "unseen:";
 static const gchar *LibBalsaMailboxMhFlagged = "flagged:";
 static const gchar *LibBalsaMailboxMhReplied = "replied:";
-static const gchar *LibBalsaMailboxMhRecent = "recent:";
+static const gchar *LibBalsaMailboxMhRecent  = "recent:";
 
 static void
-lbm_mh_set_flag(LibBalsaMailboxMh * mh, guint fileno, LibBalsaMessageFlag flag)
+lbm_mh_set_flag(LibBalsaMailboxMh  *mh,
+                guint               fileno,
+                LibBalsaMessageFlag flag)
 {
     struct message_info *msg_info;
 
-    if (!fileno)
-       return;
+    if (!fileno) {
+        return;
+    }
 
     msg_info = g_hash_table_lookup(mh->messages_info, GINT_TO_POINTER(fileno));
 
     if (!msg_info) {
-       g_print("MH sequence info for nonexistent message %d\n", fileno);
-       return;
+        g_print("MH sequence info for nonexistent message %d\n", fileno);
+        return;
     }
 
     msg_info->orig_flags |= flag;
 }
 
+
 static void
-lbm_mh_handle_seq_line(LibBalsaMailboxMh * mh, gchar * line)
+lbm_mh_handle_seq_line(LibBalsaMailboxMh *mh,
+                       gchar             *line)
 {
     LibBalsaMessageFlag flag;
     gchar **sequences, **seq;
 
-    if (libbalsa_str_has_prefix(line, LibBalsaMailboxMhUnseen))
-       flag = LIBBALSA_MESSAGE_FLAG_NEW;
-    else if (libbalsa_str_has_prefix(line, LibBalsaMailboxMhFlagged))
-       flag = LIBBALSA_MESSAGE_FLAG_FLAGGED;
-    else if (libbalsa_str_has_prefix(line, LibBalsaMailboxMhReplied))
-       flag = LIBBALSA_MESSAGE_FLAG_REPLIED;
-    else if (libbalsa_str_has_prefix(line, LibBalsaMailboxMhRecent))
-       flag = LIBBALSA_MESSAGE_FLAG_RECENT;
-    else                       /* unknown sequence */
-       return;
-
-    line = strchr(line, ':') + 1;
+    if (libbalsa_str_has_prefix(line, LibBalsaMailboxMhUnseen)) {
+        flag = LIBBALSA_MESSAGE_FLAG_NEW;
+    } else if (libbalsa_str_has_prefix(line, LibBalsaMailboxMhFlagged)) {
+        flag = LIBBALSA_MESSAGE_FLAG_FLAGGED;
+    } else if (libbalsa_str_has_prefix(line, LibBalsaMailboxMhReplied)) {
+        flag = LIBBALSA_MESSAGE_FLAG_REPLIED;
+    } else if (libbalsa_str_has_prefix(line, LibBalsaMailboxMhRecent)) {
+        flag = LIBBALSA_MESSAGE_FLAG_RECENT;
+    } else {                    /* unknown sequence */
+        return;
+    }
+
+    line      = strchr(line, ':') + 1;
     sequences = g_strsplit(line, " ", 0);
 
     for (seq = sequences; *seq; seq++) {
-       guint end = 0;
-       guint fileno;
+        guint end = 0;
+        guint fileno;
 
-       if (!**seq)
-           continue;
+        if (!**seq) {
+            continue;
+        }
 
-       line = strchr(*seq, '-');
-       if (line) {
-           *line++ = '\0';
-           if (sscanf(line, "%10d", &end) != 1)
+        line = strchr(*seq, '-');
+        if (line) {
+            *line++ = '\0';
+            if (sscanf(line, "%10d", &end) != 1) {
                 break; /* FIXME report error? */
-       }
-       if (sscanf(*seq, "%10d", &fileno) != 1)
+            }
+        }
+        if (sscanf(*seq, "%10d", &fileno) != 1) {
             break;     /* FIXME report error? */
-       do
-           lbm_mh_set_flag(mh, fileno, flag);
-       while (++fileno <= end);
+        }
+        do {
+            lbm_mh_set_flag(mh, fileno, flag);
+        } while (++fileno <= end);
     }
 
     g_strfreev(sequences);
 }
 
+
 static void
-lbm_mh_parse_sequences(LibBalsaMailboxMh * mailbox)
+lbm_mh_parse_sequences(LibBalsaMailboxMh *mailbox)
 {
     struct stat st;
-    const gchar* sequences_filename;
+    const gchar *sequences_filename;
     int fd;
     GMimeStream *gmime_stream;
     GMimeStream *gmime_stream_buffer;
@@ -447,89 +489,98 @@ lbm_mh_parse_sequences(LibBalsaMailboxMh * mailbox)
 
     sequences_filename = mailbox->sequences_filename;
     if (stat(sequences_filename, &st) == -1) {
-       return;
+        return;
     }
     mailbox->mtime_sequences = st.st_mtime;
 
     fd = open(sequences_filename, O_RDONLY);
-    if (fd < 0)
-       return;
-    gmime_stream = g_mime_stream_fs_new(fd);
+    if (fd < 0) {
+        return;
+    }
+    gmime_stream        = g_mime_stream_fs_new(fd);
     gmime_stream_buffer = g_mime_stream_buffer_new(gmime_stream,
-                                       GMIME_STREAM_BUFFER_BLOCK_READ);
+                                                   GMIME_STREAM_BUFFER_BLOCK_READ);
     g_object_unref(gmime_stream);
     line = g_byte_array_new();
     do {
-       guint8 zero = 0;
+        guint8 zero = 0;
 
-       g_mime_stream_buffer_readln(gmime_stream_buffer, line);
-       g_byte_array_append(line, &zero, 1);
+        g_mime_stream_buffer_readln(gmime_stream_buffer, line);
+        g_byte_array_append(line, &zero, 1);
 
-       lbm_mh_handle_seq_line(mailbox, (gchar *) line->data);
-       line->len = 0;
+        lbm_mh_handle_seq_line(mailbox, (gchar *) line->data);
+        line->len = 0;
     } while (!g_mime_stream_eos(gmime_stream_buffer));
     g_object_unref(gmime_stream_buffer);
     g_byte_array_free(line, TRUE);
 }
 
+
 static void
-lbm_mh_parse_both(LibBalsaMailboxMh * mh)
+lbm_mh_parse_both(LibBalsaMailboxMh *mh)
 {
     lbm_mh_parse_mailbox(mh, TRUE);
-    if (mh->msgno_2_msg_info)
-       lbm_mh_parse_sequences(mh);
+    if (mh->msgno_2_msg_info) {
+        lbm_mh_parse_sequences(mh);
+    }
 }
 
+
 static void
 lbm_mh_free_message_info(struct message_info *msg_info)
 {
-    if (!msg_info)
-       return;
+    if (!msg_info) {
+        return;
+    }
     if (msg_info->local_info.message) {
-       msg_info->local_info.message->mailbox = NULL;
-       msg_info->local_info.message->msgno   = 0;
-       g_object_remove_weak_pointer(G_OBJECT(msg_info->local_info.message),
-                                    (gpointer) &msg_info->local_info.message);
+        msg_info->local_info.message->mailbox = NULL;
+        msg_info->local_info.message->msgno   = 0;
+        g_object_remove_weak_pointer(G_OBJECT(msg_info->local_info.message),
+                                     (gpointer) & msg_info->local_info.message);
     }
     g_free(msg_info);
 }
 
+
 static gboolean
-libbalsa_mailbox_mh_open(LibBalsaMailbox * mailbox, GError **err)
+libbalsa_mailbox_mh_open(LibBalsaMailbox *mailbox,
+                         GError         **err)
 {
     LibBalsaMailboxMh *mh = LIBBALSA_MAILBOX_MH(mailbox);
     struct stat st;
-    const gchar* path;
-   
+    const gchar *path;
+
     path = libbalsa_mailbox_local_get_path((LibBalsaMailboxLocal *) mailbox);
 
     if (stat(path, &st) == -1) {
-       g_set_error(err, LIBBALSA_MAILBOX_ERROR, LIBBALSA_MAILBOX_OPEN_ERROR,
-                   _("Mailbox does not exist."));
-       return FALSE;
+        g_set_error(err, LIBBALSA_MAILBOX_ERROR, LIBBALSA_MAILBOX_OPEN_ERROR,
+                    _("Mailbox does not exist."));
+        return FALSE;
     }
 
     libbalsa_mailbox_set_mtime(mailbox, st.st_mtime);
 
     mh->messages_info =
-       g_hash_table_new_full(NULL, NULL, NULL,
-                             (GDestroyNotify)lbm_mh_free_message_info);
+        g_hash_table_new_full(NULL, NULL, NULL,
+                              (GDestroyNotify)lbm_mh_free_message_info);
     mh->msgno_2_msg_info = g_ptr_array_new();
-    mh->last_fileno = 0;
-    
+    mh->last_fileno      = 0;
+
     libbalsa_mailbox_set_readonly(mailbox, access(path, W_OK));
     libbalsa_mailbox_clear_unread_messages(mailbox);
     lbm_mh_parse_both(mh);
 
 #ifdef DEBUG
     g_print(_("%s: Opening %s Refcount: %d\n"),
-           "LibBalsaMailboxMh", mailbox->name, mailbox->open_ref);
+            "LibBalsaMailboxMh", mailbox->name, mailbox->open_ref);
 #endif
     return TRUE;
 }
 
+
 static gboolean
-lbm_mh_check(LibBalsaMailboxMh * mh, const gchar * path)
+lbm_mh_check(LibBalsaMailboxMh *mh,
+             const gchar       *path)
 {
     int fd;
     GMimeStream *gmime_stream;
@@ -537,52 +588,57 @@ lbm_mh_check(LibBalsaMailboxMh * mh, const gchar * path)
     GByteArray *line;
     gboolean retval = FALSE;
 
-    if ((fd = open(mh->sequences_filename, O_RDONLY)) < 0)
-       return retval;
+    if ((fd = open(mh->sequences_filename, O_RDONLY)) < 0) {
+        return retval;
+    }
 
-    gmime_stream = g_mime_stream_fs_new(fd);
+    gmime_stream        = g_mime_stream_fs_new(fd);
     gmime_stream_buffer = g_mime_stream_buffer_new(gmime_stream,
-                                       GMIME_STREAM_BUFFER_BLOCK_READ);
+                                                   GMIME_STREAM_BUFFER_BLOCK_READ);
     g_object_unref(gmime_stream);
 
     line = (GByteArray *) g_array_new(TRUE, FALSE, 1);
     do {
-       line->len = 0;
-       g_mime_stream_buffer_readln(gmime_stream_buffer, line);
-
-       if (libbalsa_str_has_prefix((gchar *) line->data,
-                                   LibBalsaMailboxMhUnseen)) {
-           /* Found the "unseen: " line... */
-           gchar *p = (gchar *) line->data + strlen(LibBalsaMailboxMhUnseen);
-           gchar **sequences, **seq;
-           
-           sequences = g_strsplit(p, " ", 0);
-           for (seq = sequences; *seq; seq++) {
-               guint end = 0;
-               guint fileno;
-
-               if (!**seq)
-                   continue;
-
-               p = strchr(*seq, '-');
-               if (p) {
-                   *p++ = '\0';
-                   if (sscanf(p, "%10d", &end) != 1)
+        line->len = 0;
+        g_mime_stream_buffer_readln(gmime_stream_buffer, line);
+
+        if (libbalsa_str_has_prefix((gchar *) line->data,
+                                    LibBalsaMailboxMhUnseen)) {
+            /* Found the "unseen: " line... */
+            gchar *p = (gchar *) line->data + strlen(LibBalsaMailboxMhUnseen);
+            gchar **sequences, **seq;
+
+            sequences = g_strsplit(p, " ", 0);
+            for (seq = sequences; *seq; seq++) {
+                guint end = 0;
+                guint fileno;
+
+                if (!**seq) {
+                    continue;
+                }
+
+                p = strchr(*seq, '-');
+                if (p) {
+                    *p++ = '\0';
+                    if (sscanf(p, "%10d", &end) != 1) {
                         break; /* FIXME report error? */
-               }
-               if (sscanf(*seq, "%10d", &fileno) != 1)
+                    }
+                }
+                if (sscanf(*seq, "%10d", &fileno) != 1) {
                     break; /* FIXME report error? */
-               do {
-                   p = g_strdup_printf("%s/%d", path, fileno);
-                   if (access(p, F_OK) == 0)
-                       retval = TRUE;
-                   g_free(p);
-                   /* One undeleted unread message is enough. */
-               } while (!retval && ++fileno <= end);
-           }
-           g_strfreev(sequences);
-           break;
-       }
+                }
+                do {
+                    p = g_strdup_printf("%s/%d", path, fileno);
+                    if (access(p, F_OK) == 0) {
+                        retval = TRUE;
+                    }
+                    g_free(p);
+                    /* One undeleted unread message is enough. */
+                } while (!retval && ++fileno <= end);
+            }
+            g_strfreev(sequences);
+            break;
+        }
     } while (!g_mime_stream_eos(gmime_stream_buffer));
 
     g_object_unref(gmime_stream_buffer);
@@ -591,93 +647,104 @@ lbm_mh_check(LibBalsaMailboxMh * mh, const gchar * path)
     return retval;
 }
 
-static int libbalsa_mailbox_mh_open_temp (const gchar *dest_path,
-                                         char **name_used);
+
+static int libbalsa_mailbox_mh_open_temp(const gchar *dest_path,
+                                         char       **name_used);
+
 /* Called with mailbox locked. */
 static void
-libbalsa_mailbox_mh_check(LibBalsaMailbox * mailbox)
+libbalsa_mailbox_mh_check(LibBalsaMailbox *mailbox)
 {
     struct stat st, st_sequences;
     LibBalsaMailboxMh *mh = LIBBALSA_MAILBOX_MH(mailbox);
-    const gchar *path =
+    const gchar *path     =
         libbalsa_mailbox_local_get_path((LibBalsaMailboxLocal *) mailbox);
     int modified = 0;
     guint renumber, msgno;
     struct message_info *msg_info;
     time_t mtime;
 
-    if (stat(path, &st) == -1)
-       return;
+    if (stat(path, &st) == -1) {
+        return;
+    }
 
     /* create .mh_sequences when there isn't one. */
     if (stat(mh->sequences_filename, &st_sequences) == -1) {
-       if (errno == ENOENT) {
-           gchar *name_used;
-           int fd = libbalsa_mailbox_mh_open_temp(path, &name_used);
-           if (fd != -1) {
-               close(fd);
-               if (libbalsa_safe_rename(name_used,
-                                        mh->sequences_filename) == -1)
-                   unlink(name_used);
-               g_free(name_used);
-           }
-           if (stat(mh->sequences_filename, &st_sequences) == -1)
-               modified = 1;
-       } else
-           modified = 1;
+        if (errno == ENOENT) {
+            gchar *name_used;
+            int fd = libbalsa_mailbox_mh_open_temp(path, &name_used);
+            if (fd != -1) {
+                close(fd);
+                if (libbalsa_safe_rename(name_used,
+                                         mh->sequences_filename) == -1) {
+                    unlink(name_used);
+                }
+                g_free(name_used);
+            }
+            if (stat(mh->sequences_filename, &st_sequences) == -1) {
+                modified = 1;
+            }
+        } else {
+            modified = 1;
+        }
     }
 
     mtime = libbalsa_mailbox_get_mtime(mailbox);
-    if (mtime == 0)
-       /* First check--just cache the mtime. */
+    if (mtime == 0) {
+        /* First check--just cache the mtime. */
         libbalsa_mailbox_set_mtime(mailbox, st.st_mtime);
-    else if (st.st_mtime > mtime)
-       modified = 1;
+    } else if (st.st_mtime > mtime) {
+        modified = 1;
+    }
 
-    if (mh->mtime_sequences == 0)
-       /* First check--just cache the mtime. */
-       mh->mtime_sequences = st_sequences.st_mtime;
-    else if (st_sequences.st_mtime > mh->mtime_sequences)
-       modified = 1;
+    if (mh->mtime_sequences == 0) {
+        /* First check--just cache the mtime. */
+        mh->mtime_sequences = st_sequences.st_mtime;
+    } else if (st_sequences.st_mtime > mh->mtime_sequences) {
+        modified = 1;
+    }
 
-    if (!modified)
-       return;
+    if (!modified) {
+        return;
+    }
 
     libbalsa_mailbox_set_mtime(mailbox, st.st_mtime);
     mh->mtime_sequences = st_sequences.st_mtime;
 
     if (!MAILBOX_OPEN(mailbox)) {
-       libbalsa_mailbox_set_unread_messages_flag(mailbox,
-                                                 lbm_mh_check(mh, path));
-       return;
+        libbalsa_mailbox_set_unread_messages_flag(mailbox,
+                                                  lbm_mh_check(mh, path));
+        return;
     }
 
     /* Was any message removed? */
     renumber = mh->msgno_2_msg_info->len + 1;
     for (msgno = 1; msgno <= mh->msgno_2_msg_info->len; ) {
-       gchar *base_name, *filename;
-
-       msg_info = lbm_mh_message_info_from_msgno(mh, msgno);
-       base_name = MH_BASENAME(msg_info);
-       filename = g_build_filename(path, base_name, NULL);
-       g_free(base_name);
-       if (access(filename, F_OK) == 0)
-           msgno++;
-       else {
-           g_ptr_array_remove(mh->msgno_2_msg_info, msg_info);
-           g_hash_table_remove(mh->messages_info, 
-                               GINT_TO_POINTER(msg_info->fileno));
-           libbalsa_mailbox_local_msgno_removed(mailbox, msgno);
-           if (renumber > msgno)
-               /* First message that needs renumbering. */
-               renumber = msgno;
-       }
-       g_free(filename);
+        gchar *base_name, *filename;
+
+        msg_info  = lbm_mh_message_info_from_msgno(mh, msgno);
+        base_name = MH_BASENAME(msg_info);
+        filename  = g_build_filename(path, base_name, NULL);
+        g_free(base_name);
+        if (access(filename, F_OK) == 0) {
+            msgno++;
+        } else {
+            g_ptr_array_remove(mh->msgno_2_msg_info, msg_info);
+            g_hash_table_remove(mh->messages_info,
+                                GINT_TO_POINTER(msg_info->fileno));
+            libbalsa_mailbox_local_msgno_removed(mailbox, msgno);
+            if (renumber > msgno) {
+                /* First message that needs renumbering. */
+                renumber = msgno;
+            }
+        }
+        g_free(filename);
     }
     for (msgno = renumber; msgno <= mh->msgno_2_msg_info->len; msgno++) {
-       msg_info = lbm_mh_message_info_from_msgno(mh, msgno);
-       if (msg_info->local_info.message)
-           msg_info->local_info.message->msgno = msgno;
+        msg_info = lbm_mh_message_info_from_msgno(mh, msgno);
+        if (msg_info->local_info.message) {
+            msg_info->local_info.message->msgno = msgno;
+        }
     }
 
     msgno = mh->msgno_2_msg_info->len;
@@ -685,88 +752,105 @@ libbalsa_mailbox_mh_check(LibBalsaMailbox * mailbox)
     libbalsa_mailbox_local_load_messages(mailbox, msgno);
 }
 
+
 static void
-libbalsa_mailbox_mh_close_mailbox(LibBalsaMailbox * mailbox,
-                                  gboolean expunge)
+libbalsa_mailbox_mh_close_mailbox(LibBalsaMailbox *mailbox,
+                                  gboolean         expunge)
 {
     LibBalsaMailboxMh *mh = LIBBALSA_MAILBOX_MH(mailbox);
     guint len;
 
     len = mh->msgno_2_msg_info->len;
     libbalsa_mailbox_mh_sync(mailbox, expunge);
-    if (mh->msgno_2_msg_info->len != len)
+    if (mh->msgno_2_msg_info->len != len) {
         libbalsa_mailbox_changed(mailbox);
+    }
 
     g_hash_table_destroy(mh->messages_info);
     mh->messages_info = NULL;
 
-    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_mh_parent_class)->close_mailbox)
+    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_mh_parent_class)->close_mailbox) {
         LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_mh_parent_class)->close_mailbox(mailbox,
-                                                            expunge);
+                                                                                expunge);
+    }
 
     /* Now it's safe to free the message info. */
     g_ptr_array_free(mh->msgno_2_msg_info, TRUE);
     mh->msgno_2_msg_info = NULL;
 }
 
+
 static int
-libbalsa_mailbox_mh_open_temp (const gchar *dest_path, char **name_used)
+libbalsa_mailbox_mh_open_temp(const gchar *dest_path,
+                              char       **name_used)
 {
     *name_used = g_build_filename(dest_path, "mh-XXXXXX", NULL);
     return g_mkstemp(*name_used);
 }
 
+
 struct line_info {
     gint first, last;
     GMimeStream *line;
 };
 
 static void
-lbm_mh_print_line(struct line_info * li)
+lbm_mh_print_line(struct line_info *li)
 {
-    if (li->last == -1)
-       return;
-    if (li->first != li->last)
-       /* interval */
-       g_mime_stream_printf(li->line, " %d-%d", li->first, li->last);
-    else
-       /* single message */
-       g_mime_stream_printf(li->line, " %d", li->last);
+    if (li->last == -1) {
+        return;
+    }
+    if (li->first != li->last) {
+        /* interval */
+        g_mime_stream_printf(li->line, " %d-%d", li->first, li->last);
+    } else {
+        /* single message */
+        g_mime_stream_printf(li->line, " %d", li->last);
+    }
 }
 
+
 static void
-lbm_mh_flag_line(struct message_info *msg_info, LibBalsaMessageFlag flag,
-                struct line_info *li)
+lbm_mh_flag_line(struct message_info *msg_info,
+                 LibBalsaMessageFlag  flag,
+                 struct line_info    *li)
 {
-    if (msg_info->local_info.flags == LIBBALSA_MESSAGE_FLAG_INVALID)
-       msg_info->local_info.flags = msg_info->orig_flags;
-    if (!(msg_info->local_info.flags & flag))
-       return;
+    if (msg_info->local_info.flags == LIBBALSA_MESSAGE_FLAG_INVALID) {
+        msg_info->local_info.flags = msg_info->orig_flags;
+    }
+    if (!(msg_info->local_info.flags & flag)) {
+        return;
+    }
 
     if (li->last < msg_info->fileno - 1) {
-       lbm_mh_print_line(li);
-       li->first = msg_info->fileno;
+        lbm_mh_print_line(li);
+        li->first = msg_info->fileno;
     }
     li->last = msg_info->fileno;
 }
 
+
 static gboolean
-lbm_mh_finish_line(struct line_info *li, GMimeStream * temp_stream,
-                  const gchar * flag_string)
+lbm_mh_finish_line(struct line_info *li,
+                   GMimeStream      *temp_stream,
+                   const gchar      *flag_string)
 {
     if (g_mime_stream_length(li->line) > 0) {
-       if (g_mime_stream_write_string(temp_stream, flag_string) == -1
-           || g_mime_stream_reset(li->line) == -1
-           || g_mime_stream_write_to_stream(li->line, temp_stream) == -1
-           || g_mime_stream_write_string(temp_stream, "\n") == -1)
-           return FALSE;
+        if ((g_mime_stream_write_string(temp_stream, flag_string) == -1)
+            || (g_mime_stream_reset(li->line) == -1)
+            || (g_mime_stream_write_to_stream(li->line, temp_stream) == -1)
+            || (g_mime_stream_write_string(temp_stream, "\n") == -1)) {
+            return FALSE;
+        }
     }
 
     return TRUE;
 }
 
+
 static gboolean
-libbalsa_mailbox_mh_sync(LibBalsaMailbox * mailbox, gboolean expunge)
+libbalsa_mailbox_mh_sync(LibBalsaMailbox *mailbox,
+                         gboolean         expunge)
 {
     LibBalsaMailboxMh *mh;
     struct line_info unseen, flagged, replied, recent;
@@ -778,7 +862,7 @@ libbalsa_mailbox_mh_sync(LibBalsaMailbox * mailbox, gboolean expunge)
     int fd;
     int sequences_fd;
     GMimeStream *temp_stream;
-    const gchar* sequences_filename;
+    const gchar *sequences_filename;
     GMimeStream *gmime_stream;
     GMimeStream *gmime_stream_buffer;
     GByteArray *line;
@@ -789,9 +873,10 @@ libbalsa_mailbox_mh_sync(LibBalsaMailbox * mailbox, gboolean expunge)
     g_return_val_if_fail( mh->messages_info != NULL, FALSE );
 
     sequences_filename = mh->sequences_filename;
-    sequences_fd = open(sequences_filename, O_RDONLY);
-    if (sequences_fd >= 0)
+    sequences_fd       = open(sequences_filename, O_RDONLY);
+    if (sequences_fd >= 0) {
         libbalsa_lock_file(sequences_filename, sequences_fd, FALSE, TRUE, 1);
+    }
 
     /* Check for new mail before flushing any changes out to disk. */
     libbalsa_mailbox_mh_check(mailbox);
@@ -810,60 +895,63 @@ libbalsa_mailbox_mh_sync(LibBalsaMailbox * mailbox, gboolean expunge)
 
     msgno = 1;
     while (msgno <= mh->msgno_2_msg_info->len) {
-       msg_info = lbm_mh_message_info_from_msgno(mh, msgno);
-       if (msg_info->local_info.flags == LIBBALSA_MESSAGE_FLAG_INVALID)
-           msg_info->local_info.flags = msg_info->orig_flags;
-       if (libbalsa_mailbox_get_state(mailbox) == LB_MAILBOX_STATE_CLOSING)
-           msg_info->local_info.flags &= ~LIBBALSA_MESSAGE_FLAG_RECENT;
+        msg_info = lbm_mh_message_info_from_msgno(mh, msgno);
+        if (msg_info->local_info.flags == LIBBALSA_MESSAGE_FLAG_INVALID) {
+            msg_info->local_info.flags = msg_info->orig_flags;
+        }
+        if (libbalsa_mailbox_get_state(mailbox) == LB_MAILBOX_STATE_CLOSING) {
+            msg_info->local_info.flags &= ~LIBBALSA_MESSAGE_FLAG_RECENT;
+        }
 
-       if (expunge && (msg_info->local_info.flags
+        if (expunge && (msg_info->local_info.flags
                         & LIBBALSA_MESSAGE_FLAG_DELETED)) {
-           /* MH just moves files out of the way when you delete them */
-           /* chbm: not quite, however this is probably a good move for
-              flag deleted */
-           char *base_name = MH_BASENAME(msg_info);
-           char *orig = g_build_filename(path, base_name, NULL);
-           g_free(base_name);
-           unlink(orig);
-           g_free(orig);
-           /* free old information */
-           g_ptr_array_remove(mh->msgno_2_msg_info, msg_info);
-           g_hash_table_remove(mh->messages_info, 
-                               GINT_TO_POINTER(msg_info->fileno));
-           libbalsa_mailbox_local_msgno_removed(mailbox, msgno);
-       } else {
-           lbm_mh_flag_line(msg_info, LIBBALSA_MESSAGE_FLAG_NEW, &unseen);
-           lbm_mh_flag_line(msg_info, LIBBALSA_MESSAGE_FLAG_FLAGGED, &flagged);
-           lbm_mh_flag_line(msg_info, LIBBALSA_MESSAGE_FLAG_REPLIED, &replied);
-           lbm_mh_flag_line(msg_info, LIBBALSA_MESSAGE_FLAG_RECENT, &recent);
-           if ((msg_info->local_info.flags ^ msg_info->orig_flags) &
-               LIBBALSA_MESSAGE_FLAG_DELETED) {
-               gchar *base_name;
-               gchar *old_file;
-               gchar *new_file;
-
-               base_name = MH_BASENAME(msg_info);
-               old_file = g_build_filename(path, base_name, NULL);
-               g_free(base_name);
+            /* MH just moves files out of the way when you delete them */
+            /* chbm: not quite, however this is probably a good move for
+               flag deleted */
+            char *base_name = MH_BASENAME(msg_info);
+            char *orig      = g_build_filename(path, base_name, NULL);
+            g_free(base_name);
+            unlink(orig);
+            g_free(orig);
+            /* free old information */
+            g_ptr_array_remove(mh->msgno_2_msg_info, msg_info);
+            g_hash_table_remove(mh->messages_info,
+                                GINT_TO_POINTER(msg_info->fileno));
+            libbalsa_mailbox_local_msgno_removed(mailbox, msgno);
+        } else {
+            lbm_mh_flag_line(msg_info, LIBBALSA_MESSAGE_FLAG_NEW, &unseen);
+            lbm_mh_flag_line(msg_info, LIBBALSA_MESSAGE_FLAG_FLAGGED, &flagged);
+            lbm_mh_flag_line(msg_info, LIBBALSA_MESSAGE_FLAG_REPLIED, &replied);
+            lbm_mh_flag_line(msg_info, LIBBALSA_MESSAGE_FLAG_RECENT, &recent);
+            if ((msg_info->local_info.flags ^ msg_info->orig_flags) &
+                LIBBALSA_MESSAGE_FLAG_DELETED) {
+                gchar *base_name;
+                gchar *old_file;
+                gchar *new_file;
+
+                base_name = MH_BASENAME(msg_info);
+                old_file  = g_build_filename(path, base_name, NULL);
+                g_free(base_name);
 
                 msg_info->orig_flags =
                     REAL_FLAGS(msg_info->local_info.flags);
 
-               base_name = MH_BASENAME(msg_info);
-               new_file = g_build_filename(path, base_name, NULL);
-               g_free(base_name);
+                base_name = MH_BASENAME(msg_info);
+                new_file  = g_build_filename(path, base_name, NULL);
+                g_free(base_name);
 
-               if (libbalsa_safe_rename(old_file, new_file) == -1) {
-                   /* FIXME: report error ... */
-               }
+                if (libbalsa_safe_rename(old_file, new_file) == -1) {
+                    /* FIXME: report error ... */
+                }
 
-               g_free(old_file);
-               g_free(new_file);
-           } else
+                g_free(old_file);
+                g_free(new_file);
+            } else {
                 msg_info->orig_flags =
                     REAL_FLAGS(msg_info->local_info.flags);
-           msgno++;
-       }
+            }
+            msgno++;
+        }
     }
     lbm_mh_print_line(&unseen);
     lbm_mh_print_line(&flagged);
@@ -872,33 +960,34 @@ libbalsa_mailbox_mh_sync(LibBalsaMailbox * mailbox, gboolean expunge)
 
     /* Renumber */
     for (msgno = 1; msgno <= mh->msgno_2_msg_info->len; msgno++) {
-       msg_info = lbm_mh_message_info_from_msgno(mh, msgno);
-       if (msg_info->local_info.message)
-           msg_info->local_info.message->msgno = msgno;
+        msg_info = lbm_mh_message_info_from_msgno(mh, msgno);
+        if (msg_info->local_info.message) {
+            msg_info->local_info.message->msgno = msgno;
+        }
     }
 
     /* open tempfile */
     path = libbalsa_mailbox_local_get_path((LibBalsaMailboxLocal *) mailbox);
-    fd = libbalsa_mailbox_mh_open_temp(path, &name_used);
-    if (fd == -1)
-    {
+    fd   = libbalsa_mailbox_mh_open_temp(path, &name_used);
+    if (fd == -1) {
         g_free(name_used);
-       g_object_unref(unseen.line);
-       g_object_unref(flagged.line);
-       g_object_unref(replied.line);
-       g_object_unref(recent.line);
-        if (sequences_fd >= 0)
+        g_object_unref(unseen.line);
+        g_object_unref(flagged.line);
+        g_object_unref(replied.line);
+        g_object_unref(recent.line);
+        if (sequences_fd >= 0) {
             libbalsa_unlock_file(sequences_filename, sequences_fd, 1);
+        }
 #ifdef DEBUG
         g_print("MH sync “%s”: cannot open temp file.\n", path);
 #endif
-       return retval;
+        return retval;
     }
     temp_stream = g_mime_stream_fs_new(fd);
 
     if (sequences_fd >= 0) {
         /* copy unknown sequences */
-        gmime_stream = g_mime_stream_fs_new(sequences_fd);
+        gmime_stream        = g_mime_stream_fs_new(sequences_fd);
         gmime_stream_buffer =
             g_mime_stream_buffer_new(gmime_stream,
                                      GMIME_STREAM_BUFFER_BLOCK_READ);
@@ -925,22 +1014,23 @@ libbalsa_mailbox_mh_sync(LibBalsaMailbox * mailbox, gboolean expunge)
 
     /* write sequences */
     if (!lbm_mh_finish_line(&unseen, temp_stream, LibBalsaMailboxMhUnseen) ||
-       !lbm_mh_finish_line(&flagged, temp_stream, LibBalsaMailboxMhFlagged) ||
-       !lbm_mh_finish_line(&replied, temp_stream, LibBalsaMailboxMhReplied) ||
-       !lbm_mh_finish_line(&recent, temp_stream, LibBalsaMailboxMhRecent)) {
-       g_object_unref(temp_stream);
-       unlink(name_used);
-       g_free(name_used);
-       g_object_unref(unseen.line);
-       g_object_unref(flagged.line);
-       g_object_unref(replied.line);
-       g_object_unref(recent.line);
-        if (sequences_fd >= 0)
+        !lbm_mh_finish_line(&flagged, temp_stream, LibBalsaMailboxMhFlagged) ||
+        !lbm_mh_finish_line(&replied, temp_stream, LibBalsaMailboxMhReplied) ||
+        !lbm_mh_finish_line(&recent, temp_stream, LibBalsaMailboxMhRecent)) {
+        g_object_unref(temp_stream);
+        unlink(name_used);
+        g_free(name_used);
+        g_object_unref(unseen.line);
+        g_object_unref(flagged.line);
+        g_object_unref(replied.line);
+        g_object_unref(recent.line);
+        if (sequences_fd >= 0) {
             libbalsa_unlock_file(sequences_filename, sequences_fd, 1);
+        }
 #ifdef DEBUG
         g_print("MH sync “%s”: error finishing sequences line.\n", path);
 #endif
-       return retval;
+        return retval;
     }
 
     /* close tempfile */
@@ -952,11 +1042,13 @@ libbalsa_mailbox_mh_sync(LibBalsaMailbox * mailbox, gboolean expunge)
     /* rename tempfile to '.mh_sequences' */
     retval = (libbalsa_safe_rename(name_used, sequences_filename) != -1);
 #ifdef DEBUG
-    if (!retval)
+    if (!retval) {
         g_print("MH sync “%s”: error renaming sequences file.\n", path);
+    }
 #endif
-    if (!retval)
-       unlink (name_used);
+    if (!retval) {
+        unlink (name_used);
+    }
 
     /* Record the mtimes; we'll just use the current time--someone else
      * might have changed something since we did, despite the file
@@ -968,13 +1060,16 @@ libbalsa_mailbox_mh_sync(LibBalsaMailbox * mailbox, gboolean expunge)
     g_object_unref(flagged.line);
     g_object_unref(replied.line);
     g_object_unref(recent.line);
-    if (sequences_fd >= 0)
+    if (sequences_fd >= 0) {
         libbalsa_unlock_file(sequences_filename, sequences_fd, 1);
+    }
     return retval;
 }
 
+
 static struct message_info *
-lbm_mh_message_info_from_msgno(LibBalsaMailboxMh * mh, guint msgno)
+lbm_mh_message_info_from_msgno(LibBalsaMailboxMh *mh,
+                               guint              msgno)
 {
     struct message_info *msg_info = NULL;
 
@@ -984,67 +1079,76 @@ lbm_mh_message_info_from_msgno(LibBalsaMailboxMh * mh, guint msgno)
     return msg_info;
 }
 
+
 static gboolean
-libbalsa_mailbox_mh_fetch_message_structure(LibBalsaMailbox * mailbox,
-                                           LibBalsaMessage * message,
-                                           LibBalsaFetchFlag flags)
+libbalsa_mailbox_mh_fetch_message_structure(LibBalsaMailbox  *mailbox,
+                                            LibBalsaMessage  *message,
+                                            LibBalsaFetchFlag flags)
 {
     if (!message->mime_msg) {
-       struct message_info *msg_info;
-       gchar *base_name;
-
-       msg_info =
-           lbm_mh_message_info_from_msgno(LIBBALSA_MAILBOX_MH(mailbox),
-                                          message->msgno);
-
-       base_name = MH_BASENAME(msg_info);
-       message->mime_msg =
-           libbalsa_mailbox_local_get_mime_message(mailbox, base_name, NULL);
-       g_free(base_name);
-
-       if (message->mime_msg) {
-           g_mime_object_remove_header(GMIME_OBJECT(message->mime_msg),
-                                       "Status");
-           g_mime_object_remove_header(GMIME_OBJECT(message->mime_msg),
-                                       "X-Status");
-       }
+        struct message_info *msg_info;
+        gchar *base_name;
+
+        msg_info =
+            lbm_mh_message_info_from_msgno(LIBBALSA_MAILBOX_MH(mailbox),
+                                           message->msgno);
+
+        base_name         = MH_BASENAME(msg_info);
+        message->mime_msg =
+            libbalsa_mailbox_local_get_mime_message(mailbox, base_name, NULL);
+        g_free(base_name);
+
+        if (message->mime_msg) {
+            g_mime_object_remove_header(GMIME_OBJECT(message->mime_msg),
+                                        "Status");
+            g_mime_object_remove_header(GMIME_OBJECT(message->mime_msg),
+                                        "X-Status");
+        }
     }
 
     return LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_mh_parent_class)->
-        fetch_message_structure(mailbox, message, flags);
+           fetch_message_structure(mailbox, message, flags);
 }
 
+
 /* Update .mh_sequences when a new message is added to the mailbox;
  * we'll just add new lines and let the next sync merge them with any
  * existing lines. */
 static void
-lbm_mh_update_sequences(LibBalsaMailboxMh * mh, gint fileno,
-                       LibBalsaMessageFlag flags)
+lbm_mh_update_sequences(LibBalsaMailboxMh  *mh,
+                        gint                fileno,
+                        LibBalsaMessageFlag flags)
 {
     FILE *fp;
 
     fp = fopen(mh->sequences_filename, "a");
 
-    if (!fp)
-       return;
-
-    if (flags & LIBBALSA_MESSAGE_FLAG_NEW)
-       fprintf(fp, "unseen: %d\n", fileno);
-    if (flags & LIBBALSA_MESSAGE_FLAG_FLAGGED)
-       fprintf(fp, "flagged: %d\n", fileno);
-    if (flags & LIBBALSA_MESSAGE_FLAG_REPLIED)
-       fprintf(fp, "replied: %d\n", fileno);
-    if (flags & LIBBALSA_MESSAGE_FLAG_RECENT)
-       fprintf(fp, "recent: %d\n", fileno);
+    if (!fp) {
+        return;
+    }
+
+    if (flags & LIBBALSA_MESSAGE_FLAG_NEW) {
+        fprintf(fp, "unseen: %d\n", fileno);
+    }
+    if (flags & LIBBALSA_MESSAGE_FLAG_FLAGGED) {
+        fprintf(fp, "flagged: %d\n", fileno);
+    }
+    if (flags & LIBBALSA_MESSAGE_FLAG_REPLIED) {
+        fprintf(fp, "replied: %d\n", fileno);
+    }
+    if (flags & LIBBALSA_MESSAGE_FLAG_RECENT) {
+        fprintf(fp, "recent: %d\n", fileno);
+    }
     fclose(fp);
 }
 
+
 /* Called with mailbox locked. */
 static gboolean
-lbm_mh_add_message(LibBalsaMailboxLocal * local,
-                   GMimeStream          * stream,
-                   LibBalsaMessageFlag    flags,
-                   GError              ** err)
+lbm_mh_add_message(LibBalsaMailboxLocal *local,
+                   GMimeStream          *stream,
+                   LibBalsaMessageFlag   flags,
+                   GError              **err)
 {
     LibBalsaMailboxMh *mh;
     const char *path;
@@ -1063,13 +1167,13 @@ lbm_mh_add_message(LibBalsaMailboxLocal * local,
 
     /* open tempfile */
     path = libbalsa_mailbox_local_get_path(local);
-    fd = libbalsa_mailbox_mh_open_temp(path, &name_used);
+    fd   = libbalsa_mailbox_mh_open_temp(path, &name_used);
     if (fd == -1) {
         g_set_error(err, LIBBALSA_MAILBOX_ERROR,
                     LIBBALSA_MAILBOX_APPEND_ERROR,
                     _("Cannot create message"));
-       g_free(name_used);
-       return FALSE;
+        g_free(name_used);
+        return FALSE;
     }
     out_stream = g_mime_stream_fs_new(fd);
 
@@ -1083,39 +1187,40 @@ lbm_mh_add_message(LibBalsaMailboxLocal * local,
     if (g_mime_stream_write_to_stream(in_stream, out_stream) == -1) {
         libbalsa_mime_stream_shared_unlock(stream);
         g_object_unref(in_stream);
-       g_object_unref(out_stream);
+        g_object_unref(out_stream);
         g_set_error(err, LIBBALSA_MAILBOX_ERROR,
                     LIBBALSA_MAILBOX_APPEND_ERROR,
                     _("Data copy error"));
-       unlink(name_used);
-       g_free(name_used);
-       return FALSE;
+        unlink(name_used);
+        g_free(name_used);
+        return FALSE;
     }
     g_object_unref(out_stream);
     libbalsa_mime_stream_shared_unlock(stream);
     g_object_unref(in_stream);
 
-    fileno = mh->last_fileno; 
+    fileno  = mh->last_fileno;
     retries = 10;
     do {
-       /* rename tempfile to message-number-name */
-       char *new_filename;
-       gint rename_status;
-
-       new_filename = g_strdup_printf("%s/%d", path, ++fileno);
-       rename_status = libbalsa_safe_rename(name_used, new_filename);
-       g_free(new_filename);
-       if (rename_status != -1)
-           break;
-       
-       if (errno != EEXIST) {
+        /* rename tempfile to message-number-name */
+        char *new_filename;
+        gint rename_status;
+
+        new_filename  = g_strdup_printf("%s/%d", path, ++fileno);
+        rename_status = libbalsa_safe_rename(name_used, new_filename);
+        g_free(new_filename);
+        if (rename_status != -1) {
+            break;
+        }
+
+        if (errno != EEXIST) {
             g_set_error(err, LIBBALSA_MAILBOX_ERROR,
                         LIBBALSA_MAILBOX_APPEND_ERROR,
                         _("Message rename error"));
-           unlink (name_used);
-           g_free(name_used);
-           return FALSE;
-       }
+            unlink (name_used);
+            g_free(name_used);
+            return FALSE;
+        }
     } while (--retries > 0);
     g_free(name_used);
 
@@ -1123,7 +1228,7 @@ lbm_mh_add_message(LibBalsaMailboxLocal * local,
         g_set_error(err, LIBBALSA_MAILBOX_ERROR,
                     LIBBALSA_MAILBOX_APPEND_ERROR,
                     "Too high activity?");
-       return FALSE;
+        return FALSE;
     }
     mh->last_fileno = fileno;
 
@@ -1133,8 +1238,9 @@ lbm_mh_add_message(LibBalsaMailboxLocal * local,
     return TRUE;
 }
 
+
 static guint
-libbalsa_mailbox_mh_total_messages(LibBalsaMailbox * mailbox)
+libbalsa_mailbox_mh_total_messages(LibBalsaMailbox *mailbox)
 {
     LibBalsaMailboxMh *mh = (LibBalsaMailboxMh *) mailbox;
 
diff --git a/libbalsa/mailbox_mh.h b/libbalsa/mailbox_mh.h
index 1d9bdf6..dd37be0 100644
--- a/libbalsa/mailbox_mh.h
+++ b/libbalsa/mailbox_mh.h
@@ -6,14 +6,14 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option) 
+ * the Free Software Foundation; either version 2, or (at your option)
  * any later version.
- *  
+ *
  * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of 
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *  
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
@@ -29,8 +29,7 @@ G_DECLARE_FINAL_TYPE(LibBalsaMailboxMh,
                      MAILBOX_MH,
                      LibBalsaMailboxLocal)
 
-LibBalsaMailbox *libbalsa_mailbox_mh_new(const gchar * path,
-                                         gboolean      create);
+LibBalsaMailbox * libbalsa_mailbox_mh_new(const gchar * path,
+                                          gboolean create);
 
 #endif
-
diff --git a/libbalsa/mailbox_pop3.c b/libbalsa/mailbox_pop3.c
index d61cec7..9c0ee6a 100644
--- a/libbalsa/mailbox_pop3.c
+++ b/libbalsa/mailbox_pop3.c
@@ -6,20 +6,20 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option) 
+ * the Free Software Foundation; either version 2, or (at your option)
  * any later version.
- *  
+ *
  * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of 
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *  
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H
-# include "config.h"
+#   include "config.h"
 #endif                          /* HAVE_CONFIG_H */
 
 
@@ -44,7 +44,7 @@ enum {
 struct _LibBalsaMailboxPop3Class {
     LibBalsaMailboxRemoteClass klass;
 
-    void (*config_changed) (LibBalsaMailboxPop3* mailbox_pop3);
+    void (*config_changed) (LibBalsaMailboxPop3 *mailbox_pop3);
 };
 
 struct _LibBalsaMailboxPop3 {
@@ -57,67 +57,69 @@ struct _LibBalsaMailboxPop3 {
     gint msg_size_limit;
     gboolean filter; /* filter through procmail/filter_cmd? */
     gboolean disable_apop; /* Some servers claim to support it but
-                              * they do not. */
+                            * they do not. */
     gboolean enable_pipe;  /* ditto */
 };
 
-static void libbalsa_mailbox_pop3_class_init(LibBalsaMailboxPop3Class *
-                                            klass);
-static void libbalsa_mailbox_pop3_init(LibBalsaMailboxPop3 * mailbox_pop3);
+static void     libbalsa_mailbox_pop3_class_init(LibBalsaMailboxPop3Class *
+                                                 klass);
+static void     libbalsa_mailbox_pop3_init(LibBalsaMailboxPop3 *mailbox_pop3);
 
-static gboolean libbalsa_mailbox_pop3_open(LibBalsaMailbox * mailbox,
-                                          GError **err);
-static void libbalsa_mailbox_pop3_check(LibBalsaMailbox * mailbox);
+static gboolean libbalsa_mailbox_pop3_open(LibBalsaMailbox *mailbox,
+                                           GError         **err);
+static void     libbalsa_mailbox_pop3_check(LibBalsaMailbox *mailbox);
 
-static void libbalsa_mailbox_pop3_save_config(LibBalsaMailbox * mailbox,
-                                             const gchar * prefix);
-static void libbalsa_mailbox_pop3_load_config(LibBalsaMailbox * mailbox,
-                                             const gchar * prefix);
-static void libbalsa_mailbox_pop3_finalize(GObject *object);
+static void     libbalsa_mailbox_pop3_save_config(LibBalsaMailbox *mailbox,
+                                                  const gchar     *prefix);
+static void     libbalsa_mailbox_pop3_load_config(LibBalsaMailbox *mailbox,
+                                                  const gchar     *prefix);
+static void     libbalsa_mailbox_pop3_finalize(GObject *object);
 
 
-#define MBOX_POP3_ERROR        (g_quark_from_static_string("mailbox-pop3"))
+#define MBOX_POP3_ERROR         (g_quark_from_static_string("mailbox-pop3"))
 
 G_DEFINE_TYPE(LibBalsaMailboxPop3,
               libbalsa_mailbox_pop3,
               LIBBALSA_TYPE_MAILBOX_REMOTE)
 
 static void
-libbalsa_mailbox_pop3_class_init(LibBalsaMailboxPop3Class * klass)
+libbalsa_mailbox_pop3_class_init(LibBalsaMailboxPop3Class *klass)
 {
     GObjectClass *object_class;
     LibBalsaMailboxClass *libbalsa_mailbox_class;
 
-    object_class = G_OBJECT_CLASS(klass);
+    object_class           = G_OBJECT_CLASS(klass);
     libbalsa_mailbox_class = LIBBALSA_MAILBOX_CLASS(klass);
 
     object_class->finalize = libbalsa_mailbox_pop3_finalize;
 
     libbalsa_mailbox_class->open_mailbox = libbalsa_mailbox_pop3_open;
-    libbalsa_mailbox_class->check = libbalsa_mailbox_pop3_check;
+    libbalsa_mailbox_class->check        = libbalsa_mailbox_pop3_check;
 
     libbalsa_mailbox_class->save_config =
-       libbalsa_mailbox_pop3_save_config;
+        libbalsa_mailbox_pop3_save_config;
     libbalsa_mailbox_class->load_config =
-       libbalsa_mailbox_pop3_load_config;
+        libbalsa_mailbox_pop3_load_config;
 
 }
 
+
 static void
-libbalsa_mailbox_pop3_init(LibBalsaMailboxPop3 * mailbox_pop3)
+libbalsa_mailbox_pop3_init(LibBalsaMailboxPop3 *mailbox_pop3)
 {
     LibBalsaMailboxRemote *remote;
-    mailbox_pop3->check = FALSE;
+    mailbox_pop3->check              = FALSE;
     mailbox_pop3->delete_from_server = FALSE;
-    mailbox_pop3->inbox = NULL;
-    mailbox_pop3->msg_size_limit = -1;
+    mailbox_pop3->inbox              = NULL;
+    mailbox_pop3->msg_size_limit     = -1;
 
-    mailbox_pop3->filter = FALSE;
+    mailbox_pop3->filter     = FALSE;
     mailbox_pop3->filter_cmd = NULL;
-    remote = LIBBALSA_MAILBOX_REMOTE(mailbox_pop3);
+    remote                   = LIBBALSA_MAILBOX_REMOTE(mailbox_pop3);
     libbalsa_mailbox_remote_set_server(remote, libbalsa_server_new());
 }
 
+
 static void
 libbalsa_mailbox_pop3_finalize(GObject *object)
 {
@@ -128,7 +130,8 @@ libbalsa_mailbox_pop3_finalize(GObject *object)
     G_OBJECT_CLASS(libbalsa_mailbox_pop3_parent_class)->finalize(object);
 }
 
-LibBalsaMailboxPop3*
+
+LibBalsaMailboxPop3 *
 libbalsa_mailbox_pop3_new(void)
 {
     LibBalsaMailboxPop3 *mailbox_pop3;
@@ -140,7 +143,8 @@ libbalsa_mailbox_pop3_new(void)
 
 
 static gboolean
-libbalsa_mailbox_pop3_open(LibBalsaMailbox * mailbox, GError **err)
+libbalsa_mailbox_pop3_open(LibBalsaMailbox *mailbox,
+                           GError         **err)
 {
     g_return_val_if_fail(LIBBALSA_IS_MAILBOX_POP3(mailbox), FALSE);
 
@@ -152,202 +156,223 @@ libbalsa_mailbox_pop3_open(LibBalsaMailbox * mailbox, GError **err)
 }
 
 
-#define POP_UID_FILE   "/.balsa/pop-uids"
+#define POP_UID_FILE    "/.balsa/pop-uids"
 static GMutex uid_mutex;
 
 
 static GHashTable *
 mp_load_uids(const gchar *prefix)
 {
-       GHashTable *res;
-       gboolean read_res;
-       gchar *fname;
-       gchar *contents;
-
-       res = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
-
-       fname = g_strconcat(g_get_home_dir(), POP_UID_FILE, NULL);
-       g_mutex_lock(&uid_mutex);
-       read_res = g_file_get_contents(fname, &contents, NULL, NULL);
-       g_mutex_unlock(&uid_mutex);
-       g_free(fname);
-
-       if (read_res) {
-               gchar **lines;
-               size_t prefix_len;
-               guint n;
-
-               lines = g_strsplit(contents, "\n", -1);
-               g_free(contents);
-               prefix_len = strlen(prefix);
-               for (n = 0; lines[n] != NULL; n++) {
-                       if (strncmp(lines[n], prefix, prefix_len) == 0) {
-                               g_hash_table_insert(res, g_strdup(lines[n]), GINT_TO_POINTER(1));
-                       }
-               }
-
-               g_strfreev(lines);
-       }
+    GHashTable *res;
+    gboolean read_res;
+    gchar *fname;
+    gchar *contents;
+
+    res = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+
+    fname = g_strconcat(g_get_home_dir(), POP_UID_FILE, NULL);
+    g_mutex_lock(&uid_mutex);
+    read_res = g_file_get_contents(fname, &contents, NULL, NULL);
+    g_mutex_unlock(&uid_mutex);
+    g_free(fname);
+
+    if (read_res) {
+        gchar **lines;
+        size_t prefix_len;
+        guint n;
+
+        lines = g_strsplit(contents, "\n", -1);
+        g_free(contents);
+        prefix_len = strlen(prefix);
+        for (n = 0; lines[n] != NULL; n++) {
+            if (strncmp(lines[n], prefix, prefix_len) == 0) {
+                g_hash_table_insert(res, g_strdup(lines[n]), GINT_TO_POINTER(1));
+            }
+        }
+
+        g_strfreev(lines);
+    }
 
-       return res;
+    return res;
 }
 
 
 static void
-mp_save_uid(gpointer key, gpointer G_GNUC_UNUSED value, gpointer user_data)
+mp_save_uid(gpointer               key,
+            gpointer G_GNUC_UNUSED value,
+            gpointer               user_data)
 {
-       FILE *out = (FILE *) user_data;
+    FILE *out = (FILE *) user_data;
 
-       fputs((const gchar *) key, out);
-       fputc('\n', out);
+    fputs((const gchar *) key, out);
+    fputc('\n', out);
 }
 
 
 static gboolean
-mp_save_uids(GHashTable *uids, const gchar *prefix, GError **error)
-{
-       gchar *fname;
-       gboolean read_res;
-       gchar *contents = NULL;
-       FILE *out;
-       gboolean result;
-
-       fname = g_strconcat(g_get_home_dir(), POP_UID_FILE, NULL);
-
-       g_mutex_lock(&uid_mutex);
-       read_res = g_file_get_contents(fname, &contents, NULL, NULL);
-       out = fopen(fname, "w");
-       g_free(fname);
-       if (out != NULL) {
-               if (read_res) {
-                       gchar **lines;
-                       size_t prefix_len;
-                       guint n;
-
-                       lines = g_strsplit(contents, "\n", -1);
-                       g_free(contents);
-                       prefix_len = strlen(prefix);
-                       for (n = 0; lines[n] != NULL; n++) {
-                               if ((lines[n][0] != '\0') && (strncmp(lines[n], prefix, prefix_len) != 0)) {
-                                       fputs(lines[n], out);
-                                       fputc('\n', out);
-                               }
-                       }
-
-                       g_strfreev(lines);
-               }
-
-               if (uids != NULL) {
-                       g_hash_table_foreach(uids, mp_save_uid, out);
-               }
-               fclose(out);
-               result = TRUE;
-       } else {
-               g_set_error(error, MBOX_POP3_ERROR, errno, _("Saving the POP3 message UID list failed: %s"), 
g_strerror(errno));
-               result = FALSE;
-       }
-
-       g_mutex_unlock(&uid_mutex);
-       return result;
+mp_save_uids(GHashTable  *uids,
+             const gchar *prefix,
+             GError     **error)
+{
+    gchar *fname;
+    gboolean read_res;
+    gchar *contents = NULL;
+    FILE *out;
+    gboolean result;
+
+    fname = g_strconcat(g_get_home_dir(), POP_UID_FILE, NULL);
+
+    g_mutex_lock(&uid_mutex);
+    read_res = g_file_get_contents(fname, &contents, NULL, NULL);
+    out      = fopen(fname, "w");
+    g_free(fname);
+    if (out != NULL) {
+        if (read_res) {
+            gchar **lines;
+            size_t prefix_len;
+            guint n;
+
+            lines = g_strsplit(contents, "\n", -1);
+            g_free(contents);
+            prefix_len = strlen(prefix);
+            for (n = 0; lines[n] != NULL; n++) {
+                if ((lines[n][0] != '\0') && (strncmp(lines[n], prefix, prefix_len) != 0)) {
+                    fputs(lines[n], out);
+                    fputc('\n', out);
+                }
+            }
+
+            g_strfreev(lines);
+        }
+
+        if (uids != NULL) {
+            g_hash_table_foreach(uids, mp_save_uid, out);
+        }
+        fclose(out);
+        result = TRUE;
+    } else {
+        g_set_error(error, MBOX_POP3_ERROR, errno,
+                    _("Saving the POP3 message UID list failed: %s"), g_strerror(errno));
+        result = FALSE;
+    }
+
+    g_mutex_unlock(&uid_mutex);
+    return result;
 }
 
 
 #ifdef POP_SYNC
 static int
-dump_cb(unsigned len, char *buf, void *arg)
+dump_cb(unsigned len,
+        char    *buf,
+        void    *arg)
 {
     /* FIXME: Bad things happen in the mh driver when messages are empty. */
-    return fwrite(buf, 1, len, (FILE*)arg) == len;
+    return fwrite(buf, 1, len, (FILE *)arg) == len;
 }
+
+
 #endif /* POP_SYNC */
 
 
 typedef struct {
-       gboolean filter;
-       GMimeStream *mbx_stream;        /* used if we store directly to a mailbox only */
-       FILE *filter_pipe;                      /* used of we write to a filter pipe only */
-       gchar *path;                            /* needed for error reporting only */
+    gboolean filter;
+    GMimeStream *mbx_stream;            /* used if we store directly to a mailbox only */
+    FILE *filter_pipe;                          /* used of we write to a filter pipe only */
+    gchar *path;                                /* needed for error reporting only */
 } pop_handler_t;
 
 
 static pop_handler_t *
 pop_handler_new(const gchar *filter_path,
-                               GError     **error)
-{
-       pop_handler_t *res;
-
-       res = g_new0(pop_handler_t, 1U);
-       if (filter_path != NULL) {
-               res->filter = TRUE;
-               res->filter_pipe = popen(filter_path, "w");
-               if (res->filter_pipe == NULL) {
-                       g_set_error(error, MBOX_POP3_ERROR, errno, _("Passing POP message to %s failed: %s"), 
filter_path, g_strerror(errno));
-                       g_free(res);
-                       res = NULL;
-               } else {
-                       res->path = g_strdup(filter_path);
-               }
-       } else {
-               res->mbx_stream = g_mime_stream_mem_new();
-       }
+                GError     **error)
+{
+    pop_handler_t *res;
+
+    res = g_new0(pop_handler_t, 1U);
+    if (filter_path != NULL) {
+        res->filter      = TRUE;
+        res->filter_pipe = popen(filter_path, "w");
+        if (res->filter_pipe == NULL) {
+            g_set_error(error,
+                        MBOX_POP3_ERROR,
+                        errno,
+                        _("Passing POP message to %s failed: %s"),
+                        filter_path,
+                        g_strerror(errno));
+            g_free(res);
+            res = NULL;
+        } else {
+            res->path = g_strdup(filter_path);
+        }
+    } else {
+        res->mbx_stream = g_mime_stream_mem_new();
+    }
 
-       return res;
+    return res;
 }
 
 
 static gboolean
 pop_handler_write(pop_handler_t *handler,
-                                 const gchar   *buffer,
-                                 gsize          count,
-                                 GError       **error)
-{
-       gboolean result = TRUE;
-
-       if (handler->filter) {
-               if (fwrite(buffer, 1U, count, handler->filter_pipe) != count) {
-                       g_set_error(error, MBOX_POP3_ERROR, errno, _("Passing POP message to %s failed: %s"), 
handler->path, g_strerror(errno));
-                       result = FALSE;
-               }
-       } else {
-               if (g_mime_stream_write(handler->mbx_stream, buffer, count) != (ssize_t) count) {
-                       g_set_error(error, MBOX_POP3_ERROR, -1, _("Saving POP message failed"));
-                       result = FALSE;
-               }
-       }
-       return result;
+                  const gchar   *buffer,
+                  gsize          count,
+                  GError       **error)
+{
+    gboolean result = TRUE;
+
+    if (handler->filter) {
+        if (fwrite(buffer, 1U, count, handler->filter_pipe) != count) {
+            g_set_error(error,
+                        MBOX_POP3_ERROR,
+                        errno,
+                        _("Passing POP message to %s failed: %s"),
+                        handler->path,
+                        g_strerror(errno));
+            result = FALSE;
+        }
+    } else {
+        if (g_mime_stream_write(handler->mbx_stream, buffer, count) != (ssize_t) count) {
+            g_set_error(error, MBOX_POP3_ERROR, -1, _("Saving POP message failed"));
+            result = FALSE;
+        }
+    }
+    return result;
 }
 
 
 static gboolean
 pop_handler_close(pop_handler_t *handler,
-                                 GError       **error)
-{
-       gboolean result = TRUE;
-
-       if (handler->filter) {
-               int res;
-
-               res = pclose(handler->filter_pipe);
-               if (res != 0) {
-                       g_set_error(error, MBOX_POP3_ERROR, errno, _("Transferring POP message to %s failed: 
%s"), handler->path,
-                               g_strerror(errno));
-                       result = FALSE;
-               }
-       } else {
-               g_object_unref(G_OBJECT(handler->mbx_stream));
-       }
-       g_free(handler->path);
-       g_free(handler);
-       return result;
+                  GError       **error)
+{
+    gboolean result = TRUE;
+
+    if (handler->filter) {
+        int res;
+
+        res = pclose(handler->filter_pipe);
+        if (res != 0) {
+            g_set_error(error, MBOX_POP3_ERROR, errno,
+                        _("Transferring POP message to %s failed: %s"), handler->path,
+                        g_strerror(errno));
+            result = FALSE;
+        }
+    } else {
+        g_object_unref(G_OBJECT(handler->mbx_stream));
+    }
+    g_free(handler->path);
+    g_free(handler);
+    return result;
 }
 
 
 /* ===================================================================
    Functions supporting asynchronous retrieval of messages.
-*/
+ */
 struct fetch_data {
     LibBalsaMailbox *mailbox;
-    const gchar *filter_path;                          /* filter path, NULL for storing the message without 
filtering */
+    const gchar *filter_path;                           /* filter path, NULL for storing the
+                                                           message without filtering */
     gsize total_messages;
     gsize total_size;
     gchar *total_size_msg;
@@ -361,96 +386,113 @@ static void
 notify_progress(const struct fetch_data *fd)
 {
     gdouble fraction;
-       gchar *recvbuf;
+    gchar *recvbuf;
 
-       fraction = (gdouble) fd->received / (gdouble) fd->total_size;
-       recvbuf = libbalsa_size_to_gchar(fd->received);
-       libbalsa_mailbox_progress_notify(fd->mailbox, LIBBALSA_NTFY_UPDATE, fraction, _("Message %lu of %lu 
(%s of %s)"),
-               (unsigned long) fd->msgno, (unsigned long) fd->total_messages, recvbuf, fd->total_size_msg);
-       g_free(recvbuf);
+    fraction = (gdouble) fd->received / (gdouble) fd->total_size;
+    recvbuf  = libbalsa_size_to_gchar(fd->received);
+    libbalsa_mailbox_progress_notify(fd->mailbox,
+                                     LIBBALSA_NTFY_UPDATE,
+                                     fraction,
+                                     _("Message %lu of %lu (%s of %s)"),
+                                     (unsigned long) fd->msgno,
+                                     (unsigned long) fd->total_messages,
+                                     recvbuf,
+                                     fd->total_size_msg);
+    g_free(recvbuf);
 }
 
+
 static gboolean
-message_cb(const gchar                    *buffer,
-                  gssize                          count,
-                  gsize                           lines,
-                  const NetClientPopMessageInfo  *info,
-                  gpointer                        user_data,
-                  GError                        **error)
-{
-       struct fetch_data *fd = (struct fetch_data *) user_data;
-       gboolean result = TRUE;
-
-       if (count > 0) {
-               /* message data chunk - initialise for a new message if the output does not exist */
-               if (fd->handler == NULL) {
-                       fd->handler = pop_handler_new(fd->filter_path, error);
-
-                       if (fd->handler == NULL) {
-                               result = FALSE;
-                       } else {
-                               fd->msgno++;
-                               fd->next_notify = g_get_monotonic_time();               /* force immediate 
update of the progress dialogue */
-                       }
-               }
-
-               /* add data if we were successful so far */
-               if (result) {
-                       result = pop_handler_write(fd->handler, buffer, count, error);
-                       if (result) {
-                               gint64 current_time;
-
-                               current_time = g_get_monotonic_time();
-                               /* as the cr is removed from line endings, we have to compensate for it - see 
RFC 1939, sect. 11 */
-                               fd->received += (gsize) count + lines;
-                               if (current_time >= fd->next_notify) {
-                                       notify_progress(fd);
-                                       fd->next_notify = current_time + 500000;
-                               }
-                       }
-               }
-       } else if (count == 0) {
-               gboolean close_res;
-
-               notify_progress(fd);
-               if (fd->filter_path == NULL) {
-                    GError *add_err = NULL;
-                    LibBalsaMailbox *mailbox;
-                    LibBalsaMailbox *inbox;
-
-                    mailbox = fd->mailbox;
-                    inbox = LIBBALSA_MAILBOX_POP3(mailbox)->inbox;
-
-                   g_mime_stream_reset(fd->handler->mbx_stream);
-                   result =
-                        libbalsa_mailbox_add_message(inbox, fd->handler->mbx_stream,
-                                                     LIBBALSA_MESSAGE_FLAG_NEW |
-                                                     LIBBALSA_MESSAGE_FLAG_RECENT,
-                                                     &add_err);
-                   if (!result) {
-                       libbalsa_information(LIBBALSA_INFORMATION_WARNING, _("Error appending message %d from 
%s to %s: %s"),
-                               info->id,
-                                libbalsa_mailbox_get_name(mailbox),
-                                libbalsa_mailbox_get_name(inbox),
-                                add_err != NULL ? add_err->message : "?");
-                       g_clear_error(&add_err);
-                   }
-               }
-
-               /* current message done */
-               close_res = pop_handler_close(fd->handler, error);
-               fd->handler = NULL;
-               result = close_res & result;
-       } else {
-               /* count < 0: error; note that the handler may already be NULL if the error occurred for 
count == 0 */
-               if (fd->handler != NULL) {
-                       (void) pop_handler_close(fd->handler, NULL);
-                       fd->handler = NULL;
-               }
-               result = FALSE;
-       }
-
-       return result;
+message_cb(const gchar                   *buffer,
+           gssize                         count,
+           gsize                          lines,
+           const NetClientPopMessageInfo *info,
+           gpointer                       user_data,
+           GError                       **error)
+{
+    struct fetch_data *fd = (struct fetch_data *) user_data;
+    gboolean result       = TRUE;
+
+    if (count > 0) {
+        /* message data chunk - initialise for a new message if the output does not exist */
+        if (fd->handler == NULL) {
+            fd->handler = pop_handler_new(fd->filter_path, error);
+
+            if (fd->handler == NULL) {
+                result = FALSE;
+            } else {
+                fd->msgno++;
+                fd->next_notify = g_get_monotonic_time();                               /* force
+                                                                                           immediate
+                                                                                           update
+                                                                                           of
+                                                                                           the
+                                                                                           progress
+                                                                                           dialogue
+                                                                                         */
+            }
+        }
+
+        /* add data if we were successful so far */
+        if (result) {
+            result = pop_handler_write(fd->handler, buffer, count, error);
+            if (result) {
+                gint64 current_time;
+
+                current_time = g_get_monotonic_time();
+                /* as the cr is removed from line endings, we have to compensate for it - see
+                   RFC 1939, sect. 11 */
+                fd->received += (gsize) count + lines;
+                if (current_time >= fd->next_notify) {
+                    notify_progress(fd);
+                    fd->next_notify = current_time + 500000;
+                }
+            }
+        }
+    } else if (count == 0) {
+        gboolean close_res;
+
+        notify_progress(fd);
+        if (fd->filter_path == NULL) {
+            GError *add_err = NULL;
+            LibBalsaMailbox *mailbox;
+            LibBalsaMailbox *inbox;
+
+            mailbox = fd->mailbox;
+            inbox   = LIBBALSA_MAILBOX_POP3(mailbox)->inbox;
+
+            g_mime_stream_reset(fd->handler->mbx_stream);
+            result =
+                libbalsa_mailbox_add_message(inbox, fd->handler->mbx_stream,
+                                             LIBBALSA_MESSAGE_FLAG_NEW |
+                                             LIBBALSA_MESSAGE_FLAG_RECENT,
+                                             &add_err);
+            if (!result) {
+                libbalsa_information(LIBBALSA_INFORMATION_WARNING,
+                                     _("Error appending message %d from %s to %s: %s"),
+                                     info->id,
+                                     libbalsa_mailbox_get_name(mailbox),
+                                     libbalsa_mailbox_get_name(inbox),
+                                     add_err != NULL ? add_err->message : "?");
+                g_clear_error(&add_err);
+            }
+        }
+
+        /* current message done */
+        close_res   = pop_handler_close(fd->handler, error);
+        fd->handler = NULL;
+        result      = close_res & result;
+    } else {
+        /* count < 0: error; note that the handler may already be NULL if the error occurred for
+           count == 0 */
+        if (fd->handler != NULL) {
+            (void) pop_handler_close(fd->handler, NULL);
+            fd->handler = NULL;
+        }
+        result = FALSE;
+    }
+
+    return result;
 }
 
 
@@ -460,69 +502,96 @@ libbalsa_mailbox_pop3_startup(LibBalsaServer      *server,
                               const gchar         *name,
                               GList              **msg_list)
 {
-        LibBalsaMailbox *mailbox = (LibBalsaMailbox *) mailbox_pop3;
-       NetClientPop *pop;
-       GError *error = NULL;
-       guint allow_auth;
-
-       /* create the mailbox connection */
-       if (libbalsa_server_get_security(server) == NET_CLIENT_CRYPT_ENCRYPTED) {
-               pop = net_client_pop_new(libbalsa_server_get_host(server), 995U, 
libbalsa_server_get_security(server), mailbox_pop3->enable_pipe);
-       } else {
-               pop = net_client_pop_new(libbalsa_server_get_host(server), 110U, 
libbalsa_server_get_security(server), mailbox_pop3->enable_pipe);
-       }
-       if (pop == NULL) {
-               return NULL;
-       }
-
-       /* configure the mailbox connection; allow all (including plain text) auth methods even for 
unencrypted connections so using
-        * e.g. popfile on localhost is possible, i.e. the user is responsible for choosing a proper security 
mode */
-       allow_auth = NET_CLIENT_POP_AUTH_ALL;
-       if (mailbox_pop3->disable_apop) {
-               allow_auth &= ~NET_CLIENT_POP_AUTH_APOP;
-       }
-       net_client_pop_allow_auth(pop, TRUE, allow_auth);
-       net_client_pop_allow_auth(pop, FALSE, allow_auth);
-       net_client_set_timeout(NET_CLIENT(pop), 60U);
-
-       /* load client certificate if configured */
-       if (libbalsa_server_get_client_cert(server)) {
-               g_signal_connect(G_OBJECT(pop), "cert-pass", G_CALLBACK(libbalsa_server_get_cert_pass), 
server);
-               if (!net_client_set_cert_from_file(NET_CLIENT(pop), libbalsa_server_get_cert_file(server), 
&error)) {
-                       libbalsa_information(LIBBALSA_INFORMATION_ERROR, _("Cannot load certificate file %s: 
%s"), libbalsa_server_get_cert_file(server),
-                               error->message);
-                       g_error_free(error);
-                       g_object_unref(G_OBJECT(pop));
-                       return NULL;
-               }
-       }
-
-       /* connect signals */
-       g_signal_connect(G_OBJECT(pop), "cert-check", G_CALLBACK(libbalsa_server_check_cert), pop);
-       g_signal_connect(G_OBJECT(pop), "auth", G_CALLBACK(libbalsa_server_get_auth), server);
-
-       /* connect server */
-       libbalsa_mailbox_progress_notify(mailbox, LIBBALSA_NTFY_INIT, INFINITY, _("Connecting %s…"), 
libbalsa_server_get_host(server));
-       if (!net_client_pop_connect(pop, NULL, &error)) {
-               libbalsa_information(LIBBALSA_INFORMATION_ERROR, _("POP3 mailbox %s: cannot connect %s: %s"), 
name, libbalsa_server_get_host(server),
-                       error->message);
-               g_error_free(error);
-               net_client_shutdown(NET_CLIENT(pop));
-               g_object_unref(G_OBJECT(pop));
-               return NULL;
-       }
-
-       /* load message list */
-       libbalsa_mailbox_progress_notify(mailbox, LIBBALSA_NTFY_UPDATE, INFINITY, _("List messages…"));
-       if (!net_client_pop_list(pop, msg_list, !mailbox_pop3->delete_from_server, &error)) {
-               libbalsa_information(LIBBALSA_INFORMATION_ERROR, _("POP3 mailbox %s error: %s"), name, 
error->message);
-               g_error_free(error);
-               net_client_shutdown(NET_CLIENT(pop));
-               g_object_unref(G_OBJECT(pop));
-               pop = NULL;
-       }
-
-       return pop;
+    LibBalsaMailbox *mailbox = (LibBalsaMailbox *) mailbox_pop3;
+    NetClientPop *pop;
+    GError *error = NULL;
+    guint allow_auth;
+
+    /* create the mailbox connection */
+    if (libbalsa_server_get_security(server) == NET_CLIENT_CRYPT_ENCRYPTED) {
+        pop = net_client_pop_new(libbalsa_server_get_host(server),
+                                 995U,
+                                 libbalsa_server_get_security(server),
+                                 mailbox_pop3->enable_pipe);
+    } else {
+        pop = net_client_pop_new(libbalsa_server_get_host(server),
+                                 110U,
+                                 libbalsa_server_get_security(server),
+                                 mailbox_pop3->enable_pipe);
+    }
+    if (pop == NULL) {
+        return NULL;
+    }
+
+    /* configure the mailbox connection; allow all (including plain text) auth methods even for
+       unencrypted connections so using
+     * e.g. popfile on localhost is possible, i.e. the user is responsible for choosing a proper
+     * security mode */
+    allow_auth = NET_CLIENT_POP_AUTH_ALL;
+    if (mailbox_pop3->disable_apop) {
+        allow_auth &= ~NET_CLIENT_POP_AUTH_APOP;
+    }
+    net_client_pop_allow_auth(pop, TRUE, allow_auth);
+    net_client_pop_allow_auth(pop, FALSE, allow_auth);
+    net_client_set_timeout(NET_CLIENT(pop), 60U);
+
+    /* load client certificate if configured */
+    if (libbalsa_server_get_client_cert(server)) {
+        g_signal_connect(G_OBJECT(pop),
+                         "cert-pass",
+                         G_CALLBACK(libbalsa_server_get_cert_pass),
+                         server);
+        if (!net_client_set_cert_from_file(NET_CLIENT(pop),
+                                           libbalsa_server_get_cert_file(server), &error)) {
+            libbalsa_information(LIBBALSA_INFORMATION_ERROR,
+                                 _("Cannot load certificate file %s: %s"),
+                                 libbalsa_server_get_cert_file(server),
+                                 error->message);
+            g_error_free(error);
+            g_object_unref(G_OBJECT(pop));
+            return NULL;
+        }
+    }
+
+    /* connect signals */
+    g_signal_connect(G_OBJECT(pop), "cert-check", G_CALLBACK(libbalsa_server_check_cert), pop);
+    g_signal_connect(G_OBJECT(pop), "auth", G_CALLBACK(libbalsa_server_get_auth), server);
+
+    /* connect server */
+    libbalsa_mailbox_progress_notify(mailbox,
+                                     LIBBALSA_NTFY_INIT,
+                                     INFINITY,
+                                     _("Connecting %s…"),
+                                     libbalsa_server_get_host(server));
+    if (!net_client_pop_connect(pop, NULL, &error)) {
+        libbalsa_information(LIBBALSA_INFORMATION_ERROR,
+                             _("POP3 mailbox %s: cannot connect %s: %s"),
+                             name,
+                             libbalsa_server_get_host(server),
+                             error->message);
+        g_error_free(error);
+        net_client_shutdown(NET_CLIENT(pop));
+        g_object_unref(G_OBJECT(pop));
+        return NULL;
+    }
+
+    /* load message list */
+    libbalsa_mailbox_progress_notify(mailbox,
+                                     LIBBALSA_NTFY_UPDATE,
+                                     INFINITY,
+                                     _("List messages…"));
+    if (!net_client_pop_list(pop, msg_list, !mailbox_pop3->delete_from_server, &error)) {
+        libbalsa_information(LIBBALSA_INFORMATION_ERROR,
+                             _("POP3 mailbox %s error: %s"),
+                             name,
+                             error->message);
+        g_error_free(error);
+        net_client_shutdown(NET_CLIENT(pop));
+        g_object_unref(G_OBJECT(pop));
+        pop = NULL;
+    }
+
+    return pop;
 }
 
 
@@ -533,177 +602,193 @@ update_msg_list(struct fetch_data         *fd,
                 LibBalsaServer            *server,
                 GList                     *msg_list)
 {
-       GHashTable *uids = NULL;
-       gchar *uid_prefix = NULL;
-       size_t prefix_len = 0U;
-       GList *p;
-
-       /* load uid's if messages shall be left on the server */
-       if (!mailbox_pop3->delete_from_server) {
-               uid_prefix = g_strconcat(libbalsa_server_get_username(server), "@", 
libbalsa_server_get_host(server), NULL);
-               prefix_len = strlen(uid_prefix);
-               uids = mp_load_uids(uid_prefix);
-               *current_uids = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
-       }
-
-       /* calculate totals, remove oversized messages, remember in the hash if required */
-       fd->total_messages = 0U;
-       fd->total_size = 0U;
-       p = msg_list;
-       while (p != NULL) {
-               NetClientPopMessageInfo *msg_info = (NetClientPopMessageInfo*) p->data;
-               gboolean skip = FALSE;
-               GList* next = p->next;
-
-               /* check for oversized message */
-               if ((mailbox_pop3->msg_size_limit > 0) &&
-                        (msg_info->size >= (gsize) mailbox_pop3->msg_size_limit)) {
-                       gchar *size_str;
-
-                       size_str = libbalsa_size_to_gchar(msg_info->size);
-                       libbalsa_information(LIBBALSA_INFORMATION_WARNING, _("POP3 message %d oversized: %s — 
skipped."), msg_info->id,
-                               size_str);
-                       g_free(size_str);
-                       skip = TRUE;
-               }
-
-               /* check if we already know this message */
-               if (!skip && !mailbox_pop3->delete_from_server) {
-                       gchar *full_uid = g_strconcat(uid_prefix, " ", msg_info->uid, NULL);
-
-                       g_hash_table_insert(*current_uids, full_uid, GINT_TO_POINTER(1));
-                       if (g_hash_table_lookup(uids, full_uid) != NULL) {
-                               skip = TRUE;
-                       }
-               }
-
-               /* delete from list if we want to skip the message, update totals otherwise */
-               if (skip) {
-                       net_client_pop_msg_info_free(msg_info);
-                       msg_list = g_list_delete_link(msg_list, p);
-               } else {
-                       fd->total_messages++;
-                       fd->total_size += msg_info->size;
-               }
-               p = next;
-       }
-
-       /* copy all keys /not/ starting with the prefix from the old to the current hash table, and drop the 
old table */
-       if (!mailbox_pop3->delete_from_server && (msg_list != NULL)) {
-               GHashTableIter iter;
-               gpointer key;
-
-               g_hash_table_iter_init(&iter, uids);
-               while (g_hash_table_iter_next(&iter, &key, NULL)) {
-                       if (strncmp((const char *) key, uid_prefix, prefix_len) != 0) {
-                               g_hash_table_insert(*current_uids, key, GINT_TO_POINTER(1));
-                       }
-               }
-       }
-
-       g_free(uid_prefix);
-       if (uids != NULL) {
-               g_hash_table_destroy(uids);
-       }
-
-       return msg_list;
+    GHashTable *uids  = NULL;
+    gchar *uid_prefix = NULL;
+    size_t prefix_len = 0U;
+    GList *p;
+
+    /* load uid's if messages shall be left on the server */
+    if (!mailbox_pop3->delete_from_server) {
+        uid_prefix = g_strconcat(libbalsa_server_get_username(server),
+                                 "@",
+                                 libbalsa_server_get_host(server),
+                                 NULL);
+        prefix_len    = strlen(uid_prefix);
+        uids          = mp_load_uids(uid_prefix);
+        *current_uids = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+    }
+
+    /* calculate totals, remove oversized messages, remember in the hash if required */
+    fd->total_messages = 0U;
+    fd->total_size     = 0U;
+    p                  = msg_list;
+    while (p != NULL) {
+        NetClientPopMessageInfo *msg_info = (NetClientPopMessageInfo *) p->data;
+        gboolean skip                     = FALSE;
+        GList *next                       = p->next;
+
+        /* check for oversized message */
+        if ((mailbox_pop3->msg_size_limit > 0) &&
+            (msg_info->size >= (gsize) mailbox_pop3->msg_size_limit)) {
+            gchar *size_str;
+
+            size_str = libbalsa_size_to_gchar(msg_info->size);
+            libbalsa_information(LIBBALSA_INFORMATION_WARNING,
+                                 _("POP3 message %d oversized: %s — skipped."), msg_info->id,
+                                 size_str);
+            g_free(size_str);
+            skip = TRUE;
+        }
+
+        /* check if we already know this message */
+        if (!skip && !mailbox_pop3->delete_from_server) {
+            gchar *full_uid = g_strconcat(uid_prefix, " ", msg_info->uid, NULL);
+
+            g_hash_table_insert(*current_uids, full_uid, GINT_TO_POINTER(1));
+            if (g_hash_table_lookup(uids, full_uid) != NULL) {
+                skip = TRUE;
+            }
+        }
+
+        /* delete from list if we want to skip the message, update totals otherwise */
+        if (skip) {
+            net_client_pop_msg_info_free(msg_info);
+            msg_list = g_list_delete_link(msg_list, p);
+        } else {
+            fd->total_messages++;
+            fd->total_size += msg_info->size;
+        }
+        p = next;
+    }
+
+    /* copy all keys /not/ starting with the prefix from the old to the current hash table, and
+       drop the old table */
+    if (!mailbox_pop3->delete_from_server && (msg_list != NULL)) {
+        GHashTableIter iter;
+        gpointer key;
+
+        g_hash_table_iter_init(&iter, uids);
+        while (g_hash_table_iter_next(&iter, &key, NULL)) {
+            if (strncmp((const char *) key, uid_prefix, prefix_len) != 0) {
+                g_hash_table_insert(*current_uids, key, GINT_TO_POINTER(1));
+            }
+        }
+    }
+
+    g_free(uid_prefix);
+    if (uids != NULL) {
+        g_hash_table_destroy(uids);
+    }
+
+    return msg_list;
 }
 
 
 static void
-libbalsa_mailbox_pop3_check(LibBalsaMailbox * mailbox)
-{
-       LibBalsaMailboxPop3 *mailbox_pop3 = LIBBALSA_MAILBOX_POP3(mailbox);
-       LibBalsaServer *server;
-       NetClientPop *pop;
-       GList *msg_list;
-
-       if (!mailbox_pop3->check || (mailbox_pop3->inbox == NULL)) {
-               return;
-       }
-
-       server = LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mailbox_pop3);
-
-       /* open the mailbox connection and get the messages list (note: initiates the progress dialogue) */
-       pop = libbalsa_mailbox_pop3_startup(server, mailbox_pop3,
-                                            libbalsa_mailbox_get_name(mailbox),
-                                            &msg_list);
-
-       /* proceed on success only */
-       if (pop != NULL) {
-               struct fetch_data fd;
-               GHashTable *current_uids = NULL;
-               gboolean result = TRUE;
-               GError *err = NULL;
-
-               libbalsa_mailbox_progress_notify(mailbox, LIBBALSA_NTFY_UPDATE, INFINITY,
-                       _("Connected to %s"), net_client_get_host(NET_CLIENT(pop)));
-               memset(&fd, 0, sizeof(fd));
-
-               /* nothing to do if no messages are on the server */
-               if (msg_list != NULL) {
-                       /* load uid's if messages shall be left on the server */
-                       msg_list = update_msg_list(&fd, mailbox_pop3, &current_uids,
-                                                   server, msg_list);
-               }
-
-               /* download messages unless the list is empty */
-               if (fd.total_messages > 0U) {
-                       fd.mailbox = mailbox;
-                       fd.total_size_msg = libbalsa_size_to_gchar(fd.total_size);
-
-                       libbalsa_mailbox_progress_notify(mailbox, LIBBALSA_NTFY_UPDATE, 0.0,
-                               ngettext("%lu new message (%s)", "%lu new messages (%s)", fd.total_messages),
-                               (unsigned long) fd.total_messages, fd.total_size_msg);
-
-                       if (mailbox_pop3->filter) {
-                               fd.filter_path = mailbox_pop3->filter_cmd;
-                       }
-
-                       if (result) {
-                               result = net_client_pop_retr(pop, msg_list, message_cb, &fd, &err);
-                               if (result && mailbox_pop3->delete_from_server) {
-                                       libbalsa_mailbox_progress_notify(mailbox, LIBBALSA_NTFY_UPDATE, 
INFINITY,
-                                               _("Deleting messages on server…"));
-                                       result = net_client_pop_dele(pop, msg_list, &err);
-                               }
-                       }
-
-                       /* clean up */
-                       g_free(fd.total_size_msg);
-                       g_list_free_full(msg_list, (GDestroyNotify) net_client_pop_msg_info_free);
-               }
-
-               /* store uid list */
-               if (result && !mailbox_pop3->delete_from_server) {
-                       gchar *uid_prefix = g_strconcat(libbalsa_server_get_username(server), "@", 
libbalsa_server_get_host(server), NULL);
-
-                       mp_save_uids(current_uids, uid_prefix, &err);
-                       g_free(uid_prefix);
-                       if (current_uids != NULL) {
-                               g_hash_table_destroy(current_uids);
-                       }
-               }
-
-               if (!result) {
-                       net_client_shutdown(NET_CLIENT(pop));
-                       libbalsa_information(LIBBALSA_INFORMATION_ERROR, _("POP3 error: %s"),
-                                             err != NULL ? err->message : "?");
-                       if (err != NULL)
-                               g_error_free(err);
-               }
-
-               /* done - clean up */
-               g_object_unref(G_OBJECT(pop));
-       }
-
-       libbalsa_mailbox_progress_notify(mailbox, LIBBALSA_NTFY_FINISHED, 1.0, _("Finished"));
+libbalsa_mailbox_pop3_check(LibBalsaMailbox *mailbox)
+{
+    LibBalsaMailboxPop3 *mailbox_pop3 = LIBBALSA_MAILBOX_POP3(mailbox);
+    LibBalsaServer *server;
+    NetClientPop *pop;
+    GList *msg_list;
+
+    if (!mailbox_pop3->check || (mailbox_pop3->inbox == NULL)) {
+        return;
+    }
+
+    server = LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mailbox_pop3);
+
+    /* open the mailbox connection and get the messages list (note: initiates the progress
+       dialogue) */
+    pop = libbalsa_mailbox_pop3_startup(server, mailbox_pop3,
+                                        libbalsa_mailbox_get_name(mailbox),
+                                        &msg_list);
+
+    /* proceed on success only */
+    if (pop != NULL) {
+        struct fetch_data fd;
+        GHashTable *current_uids = NULL;
+        gboolean result          = TRUE;
+        GError *err              = NULL;
+
+        libbalsa_mailbox_progress_notify(mailbox, LIBBALSA_NTFY_UPDATE, INFINITY,
+                                         _("Connected to %s"),
+                                         net_client_get_host(NET_CLIENT(pop)));
+        memset(&fd, 0, sizeof(fd));
+
+        /* nothing to do if no messages are on the server */
+        if (msg_list != NULL) {
+            /* load uid's if messages shall be left on the server */
+            msg_list = update_msg_list(&fd, mailbox_pop3, &current_uids,
+                                       server, msg_list);
+        }
+
+        /* download messages unless the list is empty */
+        if (fd.total_messages > 0U) {
+            fd.mailbox        = mailbox;
+            fd.total_size_msg = libbalsa_size_to_gchar(fd.total_size);
+
+            libbalsa_mailbox_progress_notify(mailbox,
+                                             LIBBALSA_NTFY_UPDATE,
+                                             0.0,
+                                             ngettext("%lu new message (%s)",
+                                                      "%lu new messages (%s)",
+                                                      fd.total_messages),
+                                             (unsigned long) fd.total_messages,
+                                             fd.total_size_msg);
+
+            if (mailbox_pop3->filter) {
+                fd.filter_path = mailbox_pop3->filter_cmd;
+            }
+
+            if (result) {
+                result = net_client_pop_retr(pop, msg_list, message_cb, &fd, &err);
+                if (result && mailbox_pop3->delete_from_server) {
+                    libbalsa_mailbox_progress_notify(mailbox, LIBBALSA_NTFY_UPDATE, INFINITY,
+                                                     _("Deleting messages on server…"));
+                    result = net_client_pop_dele(pop, msg_list, &err);
+                }
+            }
+
+            /* clean up */
+            g_free(fd.total_size_msg);
+            g_list_free_full(msg_list, (GDestroyNotify) net_client_pop_msg_info_free);
+        }
+
+        /* store uid list */
+        if (result && !mailbox_pop3->delete_from_server) {
+            gchar *uid_prefix = g_strconcat(libbalsa_server_get_username(server),
+                                            "@",
+                                            libbalsa_server_get_host(server),
+                                            NULL);
+
+            mp_save_uids(current_uids, uid_prefix, &err);
+            g_free(uid_prefix);
+            if (current_uids != NULL) {
+                g_hash_table_destroy(current_uids);
+            }
+        }
+
+        if (!result) {
+            net_client_shutdown(NET_CLIENT(pop));
+            libbalsa_information(LIBBALSA_INFORMATION_ERROR, _("POP3 error: %s"),
+                                 err != NULL ? err->message : "?");
+            if (err != NULL) {
+                g_error_free(err);
+            }
+        }
+
+        /* done - clean up */
+        g_object_unref(G_OBJECT(pop));
+    }
+
+    libbalsa_mailbox_progress_notify(mailbox, LIBBALSA_NTFY_FINISHED, 1.0, _("Finished"));
 }
 
 
 static void
-libbalsa_mailbox_pop3_save_config(LibBalsaMailbox * mailbox,
-                                 const gchar * prefix)
+libbalsa_mailbox_pop3_save_config(LibBalsaMailbox *mailbox,
+                                  const gchar     *prefix)
 {
     LibBalsaMailboxPop3 *mailbox_pop3;
 
@@ -718,18 +803,21 @@ libbalsa_mailbox_pop3_save_config(LibBalsaMailbox * mailbox,
     libbalsa_conf_set_bool("DisableApop", mailbox_pop3->disable_apop);
     libbalsa_conf_set_bool("EnablePipe", mailbox_pop3->enable_pipe);
     libbalsa_conf_set_bool("Filter", mailbox_pop3->filter);
-    if(mailbox_pop3->filter_cmd)
+    if (mailbox_pop3->filter_cmd) {
         libbalsa_conf_set_string("FilterCmd", mailbox_pop3->filter_cmd);
+    }
 
-    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_pop3_parent_class)->save_config)
-       LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_pop3_parent_class)->
-            save_config(mailbox, prefix);
+    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_pop3_parent_class)->save_config) {
+        LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_pop3_parent_class)->
+        save_config(mailbox, prefix);
+    }
 
 }
 
+
 static void
-libbalsa_mailbox_pop3_load_config(LibBalsaMailbox * mailbox,
-                                 const gchar * prefix)
+libbalsa_mailbox_pop3_load_config(LibBalsaMailbox *mailbox,
+                                  const gchar     *prefix)
 {
     LibBalsaMailboxPop3 *mailbox_pop3;
 
@@ -739,21 +827,25 @@ libbalsa_mailbox_pop3_load_config(LibBalsaMailbox * mailbox,
 
     libbalsa_server_load_config(LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mailbox));
 
-    mailbox_pop3->check = libbalsa_conf_get_bool("Check=false");
+    mailbox_pop3->check              = libbalsa_conf_get_bool("Check=false");
     mailbox_pop3->delete_from_server = libbalsa_conf_get_bool("Delete=false");
-    mailbox_pop3->disable_apop = libbalsa_conf_get_bool("DisableApop=false");
-    mailbox_pop3->enable_pipe = libbalsa_conf_get_bool("EnablePipe=false");
-    mailbox_pop3->filter = libbalsa_conf_get_bool("Filter=false");
-    mailbox_pop3->filter_cmd = libbalsa_conf_get_string("FilterCmd");
-    if (mailbox_pop3->filter_cmd != NULL && mailbox_pop3->filter_cmd[0] == '\0') {
-       g_free(mailbox_pop3->filter_cmd); mailbox_pop3->filter_cmd = NULL;
+    mailbox_pop3->disable_apop       = libbalsa_conf_get_bool("DisableApop=false");
+    mailbox_pop3->enable_pipe        = libbalsa_conf_get_bool("EnablePipe=false");
+    mailbox_pop3->filter             = libbalsa_conf_get_bool("Filter=false");
+    mailbox_pop3->filter_cmd         = libbalsa_conf_get_string("FilterCmd");
+    if ((mailbox_pop3->filter_cmd != NULL) && (mailbox_pop3->filter_cmd[0] == '\0')) {
+        g_free(mailbox_pop3->filter_cmd);
+        mailbox_pop3->filter_cmd = NULL;
     }
 
-    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_pop3_parent_class)->load_config)
-       LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_pop3_parent_class)->
-            load_config(mailbox, prefix);
+    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_pop3_parent_class)->load_config) {
+        LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_pop3_parent_class)->
+        load_config(mailbox, prefix);
+    }
 
 }
+
+
 void
 libbalsa_mailbox_pop3_set_inbox(LibBalsaMailbox *mailbox,
                                 LibBalsaMailbox *inbox)
@@ -764,9 +856,10 @@ libbalsa_mailbox_pop3_set_inbox(LibBalsaMailbox *mailbox,
 
     mailbox_pop3 = LIBBALSA_MAILBOX_POP3(mailbox);
 
-    mailbox_pop3->inbox=inbox;
+    mailbox_pop3->inbox = inbox;
 }
 
+
 /*
  * Getters
  */
@@ -777,86 +870,98 @@ libbalsa_mailbox_pop3_get_delete_from_server(LibBalsaMailboxPop3 *mailbox_pop3)
     return mailbox_pop3->delete_from_server;
 }
 
+
 gboolean
 libbalsa_mailbox_pop3_get_check(LibBalsaMailboxPop3 *mailbox_pop3)
 {
     return mailbox_pop3->check;
 }
 
+
 gboolean
 libbalsa_mailbox_pop3_get_filter(LibBalsaMailboxPop3 *mailbox_pop3)
 {
     return mailbox_pop3->filter;
 }
 
+
 const gchar *
 libbalsa_mailbox_pop3_get_filter_cmd(LibBalsaMailboxPop3 *mailbox_pop3)
 {
     return mailbox_pop3->filter_cmd;
 }
 
+
 gboolean
 libbalsa_mailbox_pop3_get_disable_apop(LibBalsaMailboxPop3 *mailbox_pop3)
 {
     return mailbox_pop3->disable_apop;
 }
 
+
 gboolean
 libbalsa_mailbox_pop3_get_enable_pipe(LibBalsaMailboxPop3 *mailbox_pop3)
 {
     return mailbox_pop3->enable_pipe;
 }
 
+
 /*
  * Setters
  */
 
 void
 libbalsa_mailbox_pop3_set_msg_size_limit(LibBalsaMailboxPop3 *mailbox_pop3,
-                                         gint sz_limit)
+                                         gint                 sz_limit)
 {
     mailbox_pop3->msg_size_limit = sz_limit;
 }
 
+
 void
 libbalsa_mailbox_pop3_set_check(LibBalsaMailboxPop3 *mailbox_pop3,
-                                gboolean check)
+                                gboolean             check)
 {
     mailbox_pop3->check = check;
 }
 
+
 void
 libbalsa_mailbox_pop3_set_disable_apop(LibBalsaMailboxPop3 *mailbox_pop3,
-                                       gboolean disable_apop)
+                                       gboolean             disable_apop)
 {
     mailbox_pop3->disable_apop = disable_apop;
 }
 
+
 void
 libbalsa_mailbox_pop3_set_delete_from_server(LibBalsaMailboxPop3 *mailbox_pop3,
-                                             gboolean delete_from_server)
+                                             gboolean             delete_from_server)
 {
     mailbox_pop3->delete_from_server = delete_from_server;
 }
 
+
 void
 libbalsa_mailbox_pop3_set_filter(LibBalsaMailboxPop3 *mailbox_pop3,
-                                 gboolean filter)
+                                 gboolean             filter)
 {
     mailbox_pop3->filter = filter;
 }
 
+
 void
 libbalsa_mailbox_pop3_set_filter_cmd(LibBalsaMailboxPop3 *mailbox_pop3,
-                                     const gchar * filter_cmd)
+                                     const gchar         *filter_cmd)
 {
     g_free(mailbox_pop3->filter_cmd);
     mailbox_pop3->filter_cmd = g_strdup(filter_cmd);
 }
 
+
 void
 libbalsa_mailbox_pop3_set_enable_pipe(LibBalsaMailboxPop3 *mailbox_pop3,
-                                             gboolean enable_pipe)
+                                      gboolean             enable_pipe)
 {
     mailbox_pop3->enable_pipe = enable_pipe;
 }
diff --git a/libbalsa/mailbox_pop3.h b/libbalsa/mailbox_pop3.h
index adb8604..7dc6ca3 100644
--- a/libbalsa/mailbox_pop3.h
+++ b/libbalsa/mailbox_pop3.h
@@ -6,14 +6,14 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option) 
+ * the Free Software Foundation; either version 2, or (at your option)
  * any later version.
- *  
+ *
  * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of 
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *  
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
@@ -29,36 +29,36 @@ G_DECLARE_FINAL_TYPE(LibBalsaMailboxPop3,
                      MAILBOX_POP3,
                      LibBalsaMailboxRemote)
 
-LibBalsaMailboxPop3 *libbalsa_mailbox_pop3_new(void);
+LibBalsaMailboxPop3 * libbalsa_mailbox_pop3_new(void);
 void libbalsa_mailbox_pop3_set_inbox(LibBalsaMailbox *mailbox,
                                      LibBalsaMailbox *inbox);
 
 /*
  * Getters
  */
-gboolean libbalsa_mailbox_pop3_get_delete_from_server(LibBalsaMailboxPop3 *mailbox_pop3);
-gboolean libbalsa_mailbox_pop3_get_check(LibBalsaMailboxPop3 *mailbox_pop3);
-gboolean libbalsa_mailbox_pop3_get_filter(LibBalsaMailboxPop3 *mailbox_pop3);
-const gchar * libbalsa_mailbox_pop3_get_filter_cmd(LibBalsaMailboxPop3 *mailbox_pop3);
-gboolean libbalsa_mailbox_pop3_get_disable_apop(LibBalsaMailboxPop3 *mailbox_pop3);
-gboolean libbalsa_mailbox_pop3_get_enable_pipe(LibBalsaMailboxPop3 *mailbox_pop3);
+gboolean     libbalsa_mailbox_pop3_get_delete_from_server(LibBalsaMailboxPop3 *mailbox_pop3);
+gboolean     libbalsa_mailbox_pop3_get_check(LibBalsaMailboxPop3 *mailbox_pop3);
+gboolean     libbalsa_mailbox_pop3_get_filter(LibBalsaMailboxPop3 *mailbox_pop3);
+const gchar *libbalsa_mailbox_pop3_get_filter_cmd(LibBalsaMailboxPop3 *mailbox_pop3);
+gboolean     libbalsa_mailbox_pop3_get_disable_apop(LibBalsaMailboxPop3 *mailbox_pop3);
+gboolean     libbalsa_mailbox_pop3_get_enable_pipe(LibBalsaMailboxPop3 *mailbox_pop3);
 
 /*
  * Setters
  */
 void libbalsa_mailbox_pop3_set_msg_size_limit(LibBalsaMailboxPop3 *mailbox,
-                                              gint sz_limit);
+                                              gint                 sz_limit);
 void libbalsa_mailbox_pop3_set_check(LibBalsaMailboxPop3 *mailbox_pop3,
-                                     gboolean check);
+                                     gboolean             check);
 void libbalsa_mailbox_pop3_set_disable_apop(LibBalsaMailboxPop3 *mailbox_pop3,
-                                            gboolean disable_apop);
+                                            gboolean             disable_apop);
 void libbalsa_mailbox_pop3_set_delete_from_server(LibBalsaMailboxPop3 *mailbox_pop3,
-                                             gboolean delete_from_server);
+                                                  gboolean             delete_from_server);
 void libbalsa_mailbox_pop3_set_filter(LibBalsaMailboxPop3 *mailbox_pop3,
-                                 gboolean filter);
+                                      gboolean             filter);
 void libbalsa_mailbox_pop3_set_filter_cmd(LibBalsaMailboxPop3 *mailbox_pop3,
-                                     const gchar * filter_cmd);
+                                          const gchar         *filter_cmd);
 void libbalsa_mailbox_pop3_set_enable_pipe(LibBalsaMailboxPop3 *mailbox_pop3,
-                                             gboolean enable_pipe);
+                                           gboolean             enable_pipe);
 
-#endif                         /* __LIBBALSA_MAILBOX_POP3_H__ */
+#endif                          /* __LIBBALSA_MAILBOX_POP3_H__ */
diff --git a/libbalsa/mailbox_remote.c b/libbalsa/mailbox_remote.c
index 8dbdd3f..6674738 100644
--- a/libbalsa/mailbox_remote.c
+++ b/libbalsa/mailbox_remote.c
@@ -6,32 +6,32 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option) 
+ * the Free Software Foundation; either version 2, or (at your option)
  * any later version.
- *  
+ *
  * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of 
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *  
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H
-# include "config.h"
+#   include "config.h"
 #endif                          /* HAVE_CONFIG_H */
 
 #include "libbalsa.h"
 #include "server.h"
 
 static void libbalsa_mailbox_remote_class_init(LibBalsaMailboxRemoteClass *
-                                              klass);
-static void libbalsa_mailbox_remote_init(LibBalsaMailboxRemote * mailbox);
-static void libbalsa_mailbox_remote_dispose(GObject * object);
-static void libbalsa_mailbox_remote_test_can_reach(LibBalsaMailbox          * mailbox,
-                                                   LibBalsaCanReachCallback * cb,
-                                                   gpointer                   cb_data);
+                                               klass);
+static void libbalsa_mailbox_remote_init(LibBalsaMailboxRemote *mailbox);
+static void libbalsa_mailbox_remote_dispose(GObject *object);
+static void libbalsa_mailbox_remote_test_can_reach(LibBalsaMailbox          *mailbox,
+                                                   LibBalsaCanReachCallback *cb,
+                                                   gpointer                  cb_data);
 
 typedef struct _LibBalsaMailboxRemotePrivate LibBalsaMailboxRemotePrivate;
 struct _LibBalsaMailboxRemotePrivate {
@@ -43,12 +43,12 @@ G_DEFINE_TYPE_WITH_PRIVATE(LibBalsaMailboxRemote,
                            LIBBALSA_TYPE_MAILBOX)
 
 static void
-libbalsa_mailbox_remote_class_init(LibBalsaMailboxRemoteClass * klass)
+libbalsa_mailbox_remote_class_init(LibBalsaMailboxRemoteClass *klass)
 {
     GObjectClass *object_class;
     LibBalsaMailboxClass *libbalsa_mailbox_class;
 
-    object_class = G_OBJECT_CLASS(klass);
+    object_class           = G_OBJECT_CLASS(klass);
     libbalsa_mailbox_class = LIBBALSA_MAILBOX_CLASS(klass);
 
     object_class->dispose = libbalsa_mailbox_remote_dispose;
@@ -57,8 +57,9 @@ libbalsa_mailbox_remote_class_init(LibBalsaMailboxRemoteClass * klass)
         libbalsa_mailbox_remote_test_can_reach;
 }
 
+
 static void
-libbalsa_mailbox_remote_init(LibBalsaMailboxRemote * remote)
+libbalsa_mailbox_remote_init(LibBalsaMailboxRemote *remote)
 {
     LibBalsaMailboxRemotePrivate *priv =
         libbalsa_mailbox_remote_get_instance_private(remote);
@@ -66,24 +67,26 @@ libbalsa_mailbox_remote_init(LibBalsaMailboxRemote * remote)
     priv->server = NULL;
 }
 
+
 static void
-libbalsa_mailbox_remote_dispose(GObject * object)
+libbalsa_mailbox_remote_dispose(GObject *object)
 {
-    LibBalsaMailboxRemote *remote = (LibBalsaMailboxRemote *) object;
+    LibBalsaMailboxRemote *remote      = (LibBalsaMailboxRemote *) object;
     LibBalsaMailboxRemotePrivate *priv =
         libbalsa_mailbox_remote_get_instance_private(remote);
 
     g_clear_object(&priv->server);
 }
 
+
 /* Test whether a mailbox is reachable */
 
 static void
-libbalsa_mailbox_remote_test_can_reach(LibBalsaMailbox          * mailbox,
-                                       LibBalsaCanReachCallback * cb,
-                                       gpointer                   cb_data)
+libbalsa_mailbox_remote_test_can_reach(LibBalsaMailbox          *mailbox,
+                                       LibBalsaCanReachCallback *cb,
+                                       gpointer                  cb_data)
 {
-    LibBalsaMailboxRemote *remote = (LibBalsaMailboxRemote *) mailbox;
+    LibBalsaMailboxRemote *remote      = (LibBalsaMailboxRemote *) mailbox;
     LibBalsaMailboxRemotePrivate *priv =
         libbalsa_mailbox_remote_get_instance_private(remote);
 
@@ -91,6 +94,7 @@ libbalsa_mailbox_remote_test_can_reach(LibBalsaMailbox          * mailbox,
                                         cb, cb_data, (GObject *) mailbox);
 }
 
+
 /* Public methods */
 
 LibBalsaServer *
@@ -102,6 +106,7 @@ libbalsa_mailbox_remote_get_server(LibBalsaMailboxRemote *remote)
     return priv->server;
 }
 
+
 void
 libbalsa_mailbox_remote_set_server(LibBalsaMailboxRemote *remote,
                                    LibBalsaServer        *server)
diff --git a/libbalsa/mailbox_remote.h b/libbalsa/mailbox_remote.h
index a165d50..85f7b85 100644
--- a/libbalsa/mailbox_remote.h
+++ b/libbalsa/mailbox_remote.h
@@ -6,14 +6,14 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option) 
+ * the Free Software Foundation; either version 2, or (at your option)
  * any later version.
- *  
+ *
  * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of 
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *  
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
@@ -24,8 +24,8 @@
 
 #include "libbalsa.h"
 
-/* Imap and Pop3 are remote mailboxes 
-   
+/* Imap and Pop3 are remote mailboxes
+
    this object doesn't do any real work.  it is abstract
 
      this mini-struct greatly helps in getting the server
@@ -46,11 +46,12 @@ struct _LibBalsaMailboxRemoteClass {
 };
 
 LibBalsaServer *libbalsa_mailbox_remote_get_server(LibBalsaMailboxRemote *remote);
+
 /* Macro to avoid casts: */
 #define LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mailbox) \
     libbalsa_mailbox_remote_get_server(LIBBALSA_MAILBOX_REMOTE(mailbox))
 
 void libbalsa_mailbox_remote_set_server(LibBalsaMailboxRemote *remote,
-                                       LibBalsaServer        *server);
+                                        LibBalsaServer        *server);
 
-#endif                         /* __LIBBALSA_MAILBOX_REMOTE_H__ */
+#endif                          /* __LIBBALSA_MAILBOX_REMOTE_H__ */



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