[Commits] [SCM] claws branch, master, updated. 3.9.2-79-gbac58ac

holger at claws-mail.org holger at claws-mail.org
Tue Aug 20 00:16:44 CEST 2013


The branch master of project "claws" (Claws Mail) has been updated
       via  bac58acf0fe34e6801f040822af7414eb56e397f (commit)
       via  3674dea3cd04371151b555b2ed785ece13456853 (commit)
       via  b641d571e82c5f86c340954ee384d636586b96a3 (commit)
       via  aee1db32a7f22c77011ecfae0765c9c0b27bb7f3 (commit)
       via  4c26c8fa24f1947c4ce73bbee3696bc1cb301a59 (commit)
       via  784a101b7c2a898f893c656de01f08da00d19c1e (commit)
       via  a193b41e8f120d4f742b8f81bec58ca34a79b805 (commit)
       via  fa0e1e653303caad97d63eedfa777316e412b579 (commit)
      from  78573edb833f03b831dc9acc46b49a2b7e2540d5 (commit)


- Log -----------------------------------------------------------------
commit bac58acf0fe34e6801f040822af7414eb56e397f
Author: Holger Berndt <hb at claws-mail.org>
Date:   Tue Aug 20 00:13:20 2013 +0200

    Python plugin: Example: Make recursive-mark-as-read also work on mailbox

diff --git a/src/plugins/python/examples/main/Recusively-mark-messages-as-read b/src/plugins/python/examples/main/Recusively-mark-messages-as-read
index 85c108e..bcb3cb5 100644
--- a/src/plugins/python/examples/main/Recusively-mark-messages-as-read
+++ b/src/plugins/python/examples/main/Recusively-mark-messages-as-read
@@ -2,34 +2,38 @@
 
 # Define the function to deal with each folder
 def deal_with_folder(folder):
-    # Get actions for selecting all messages, and marking the selection as read
-    action_group = clawsmail.get_mainwindow_action_group();
-    select_all_action = action_group.get_action("Edit/SelectAll")
-    mark_read_action = action_group.get_action("Message/Mark/MarkRead")
-    
-    # Select given folder
-    clawsmail.folderview_select_folder(folder)
-    
-    # Search for messages with age greater than 28 days
-    clawsmail.quicksearch_search("ag 28", clawsmail.QUICK_SEARCH_EXTENDED)
-    
-    # Mark all messages in the search result as read
-    select_all_action.activate()
-    mark_read_action.activate()
+    if folder.num_unread_messages > 0:
+        # Get actions for selecting all messages, and marking the selection as read
+        action_group = clawsmail.get_mainwindow_action_group();
+        select_all_action = action_group.get_action("Edit/SelectAll")
+        mark_read_action = action_group.get_action("Message/Mark/MarkRead")
+        
+        # Select given folder
+        clawsmail.folderview_select_folder(folder)
+        
+        # Search for messages with age greater than 28 days
+        clawsmail.quicksearch_search("ag 28", clawsmail.QUICK_SEARCH_EXTENDED)
+        
+        # Mark all messages in the search result as read
+        select_all_action.activate()
+        mark_read_action.activate()
 
 
 # Get selected folder
 root = clawsmail.get_folderview_selected_folder()
+if root is None:
+    root = clawsmail.get_folderview_selected_mailbox()
 
-# Get a tree of subfolders. The argument could also be a string of a mailbox name,
-# or left out for a list of mailbox trees.
-tree = clawsmail.get_folder_tree(root)
-
-# Call above function for all folders.
-tree.traverse(deal_with_folder)
-
-# Clear the quicksearch widget again
-clawsmail.quicksearch_clear()
-
-# Change back to original folder
-clawsmail.folderview_select_folder(root)
+if root is not None:
+    # Get a tree of subfolders. The argument could also be a string of a mailbox name,
+    # or left out for a list of mailbox trees.
+    tree = clawsmail.get_folder_tree(root)
+    
+    # Call above function for all folders.
+    tree.traverse(deal_with_folder)
+    
+    # Clear the quicksearch widget again
+    clawsmail.quicksearch_clear()
+    
+    # Change back to original folder
+    clawsmail.folderview_select(root)

commit 3674dea3cd04371151b555b2ed785ece13456853
Author: Holger Berndt <hb at claws-mail.org>
Date:   Tue Aug 20 00:08:13 2013 +0200

    Python plugin: Folder: Add message counts as read-only properties

diff --git a/src/plugins/python/foldertype.c b/src/plugins/python/foldertype.c
index 7873b0c..2a8c2e4 100644
--- a/src/plugins/python/foldertype.c
+++ b/src/plugins/python/foldertype.c
@@ -176,6 +176,76 @@ static PyObject* get_properties(clawsmail_FolderObject *self, void *closure)
   return self->properties;
 }
 
+static PyObject* get_num_messages(clawsmail_FolderObject *self, void *closure)
+{
+  if(self && self->folderitem)
+    return PyInt_FromLong(self->folderitem->total_msgs);
+  Py_RETURN_NONE;
+}
+
+static PyObject* get_num_new_messages(clawsmail_FolderObject *self, void *closure)
+{
+  if(self && self->folderitem)
+    return PyInt_FromLong(self->folderitem->new_msgs);
+  Py_RETURN_NONE;
+}
+
+static PyObject* get_num_unread_messages(clawsmail_FolderObject *self, void *closure)
+{
+  if(self && self->folderitem)
+    return PyInt_FromLong(self->folderitem->unread_msgs);
+  Py_RETURN_NONE;
+}
+
+static PyObject* get_num_marked_messages(clawsmail_FolderObject *self, void *closure)
+{
+  if(self && self->folderitem)
+    return PyInt_FromLong(self->folderitem->marked_msgs);
+  Py_RETURN_NONE;
+}
+
+static PyObject* get_num_locked_messages(clawsmail_FolderObject *self, void *closure)
+{
+  if(self && self->folderitem)
+    return PyInt_FromLong(self->folderitem->locked_msgs);
+  Py_RETURN_NONE;
+}
+
+static PyObject* get_num_unread_marked_messages(clawsmail_FolderObject *self, void *closure)
+{
+  if(self && self->folderitem)
+    return PyInt_FromLong(self->folderitem->unreadmarked_msgs);
+  Py_RETURN_NONE;
+}
+
+static PyObject* get_num_ignored_messages(clawsmail_FolderObject *self, void *closure)
+{
+  if(self && self->folderitem)
+    return PyInt_FromLong(self->folderitem->ignored_msgs);
+  Py_RETURN_NONE;
+}
+
+static PyObject* get_num_watched_messages(clawsmail_FolderObject *self, void *closure)
+{
+  if(self && self->folderitem)
+    return PyInt_FromLong(self->folderitem->watched_msgs);
+  Py_RETURN_NONE;
+}
+
+static PyObject* get_num_replied_messages(clawsmail_FolderObject *self, void *closure)
+{
+  if(self && self->folderitem)
+    return PyInt_FromLong(self->folderitem->replied_msgs);
+  Py_RETURN_NONE;
+}
+
+static PyObject* get_num_forwarded_messages(clawsmail_FolderObject *self, void *closure)
+{
+  if(self && self->folderitem)
+    return PyInt_FromLong(self->folderitem->forwarded_msgs);
+  Py_RETURN_NONE;
+}
+
 static PyMethodDef Folder_methods[] = {
     {"get_identifier", (PyCFunction)Folder_get_identifier, METH_NOARGS,
      "get_identifier() - get identifier\n"
@@ -184,8 +254,10 @@ static PyMethodDef Folder_methods[] = {
     {"get_messages", (PyCFunction)Folder_get_messages, METH_NOARGS,
      "get_messages() - get a tuple of messages in folder\n"
      "\n"
-     "Get a tuple of MessageInfos for the folder."},
-    {NULL}
+     "Get a tuple of MessageInfos for the folder.\n\n"
+     "DEPRECATED: Use identifier property instead."},
+
+     {NULL}
 };
 
 static PyGetSetDef Folder_getset[] = {
@@ -208,6 +280,36 @@ static PyGetSetDef Folder_getset[] = {
     {"properties", (getter)get_properties, (setter)NULL,
      "properties - folder properties object", NULL},
 
+    {"num_messages", (getter)get_num_messages, (setter)NULL,
+     "num_messages - total number of messages in folder", NULL},
+
+    {"num_new_messages", (getter)get_num_new_messages, (setter)NULL,
+     "num_new_messages - number of new messages in folder", NULL},
+
+    {"num_unread_messages", (getter)get_num_unread_messages, (setter)NULL,
+     "num_unread_messages - number of unread messages in folder", NULL},
+
+    {"num_marked_messages", (getter)get_num_marked_messages, (setter)NULL,
+     "num_marked_messages - number of marked messages in folder", NULL},
+
+    {"num_locked_messages", (getter)get_num_locked_messages, (setter)NULL,
+     "num_locked_messages - number of locked messages in folder", NULL},
+
+    {"num_unread_marked_messages", (getter)get_num_unread_marked_messages, (setter)NULL,
+     "num_unread_marked_messages - number of unread marked messages in folder", NULL},
+
+    {"num_ignored_messages", (getter)get_num_ignored_messages, (setter)NULL,
+     "num_ignored_messages - number of ignored messages in folder", NULL},
+
+    {"num_watched_messages", (getter)get_num_watched_messages, (setter)NULL,
+     "num_watched_messages - number of watched messages in folder", NULL},
+
+    {"num_replied_messages", (getter)get_num_replied_messages, (setter)NULL,
+     "num_replied_messages - number of replied messages in folder", NULL},
+
+    {"num_forwarded_messages", (getter)get_num_forwarded_messages, (setter)NULL,
+     "num_forwarded_messages - number of forwarded messages in folder", NULL},
+
     {NULL}
 };
 

commit b641d571e82c5f86c340954ee384d636586b96a3
Author: Holger Berndt <hb at claws-mail.org>
Date:   Mon Aug 19 00:52:39 2013 +0200

    Python plugin: Make it possible to select a mailbox in folderview

diff --git a/src/plugins/python/clawsmailmodule.c b/src/plugins/python/clawsmailmodule.c
index 53e3b36..c573aaf 100644
--- a/src/plugins/python/clawsmailmodule.c
+++ b/src/plugins/python/clawsmailmodule.c
@@ -133,26 +133,44 @@ static PyObject *get_folderview_selected_mailbox(PyObject *self, PyObject *args)
   Py_RETURN_NONE;
 }
 
-
-static PyObject *folderview_select_folder(PyObject *self, PyObject *args)
+static PyObject *folderview_select_row(PyObject *self, PyObject *args)
 {
   MainWindow *mainwin;
+  gboolean ok;
 
+  ok = TRUE;
   mainwin =  mainwindow_get_mainwindow();
   if(mainwin && mainwin->folderview) {
-    FolderItem *item;
-    PyObject *folder;
-    folder = PyTuple_GetItem(args, 0);
-    if(!folder)
+    PyObject *arg;
+    arg = PyTuple_GetItem(args, 0);
+    if(!arg)
       return NULL;
-    Py_INCREF(folder);
-    item = clawsmail_folder_get_item(folder);
-    Py_DECREF(folder);
-    if(item)
-      folderview_select(mainwin->folderview, item);
+    Py_INCREF(arg);
+
+    if(clawsmail_folder_check(arg)) {
+      FolderItem *item;
+      item = clawsmail_folder_get_item(arg);
+      if(item)
+        folderview_select(mainwin->folderview, item);
+    }
+    else if(clawsmail_mailbox_check(arg)) {
+      Folder *folder;
+      folder = clawsmail_mailbox_get_folder(arg);
+      if(folder && folder->node) {
+        folderview_select(mainwin->folderview, folder->node->data);
+      }
+    }
+    else {
+      PyErr_SetString(PyExc_TypeError, "Bad argument type");
+      ok = FALSE;
+    }
+
+    Py_DECREF(arg);
   }
-  Py_INCREF(Py_None);
-  return Py_None;
+  if(ok)
+    Py_RETURN_NONE;
+  else
+    return NULL;
 }
 
 static gboolean setup_folderitem_node(GNode *item_node, GNode *item_parent, PyObject **pyparent)
@@ -316,7 +334,7 @@ static PyObject* get_folder_tree(PyObject *self, PyObject *args)
   else if(PyObject_TypeCheck(arg, clawsmail_folder_get_type_object())) {
     result = get_folder_tree_from_folderitem(clawsmail_folder_get_item(arg));
   }
-  else if(PyObject_TypeCheck(arg, clawsmail_mailbox_get_type_object())) {
+  else if(clawsmail_mailbox_check(arg)) {
     result = get_folder_tree_from_folder(clawsmail_mailbox_get_folder(arg));
   }
   else {
@@ -749,16 +767,24 @@ static PyMethodDef ClawsMailMethods[] = {
      "get_folderview_selected_folder() - get selected folder in folderview\n"
      "\n"
      "Returns the currently selected folder as a clawsmail.Folder or None if no folder is selected."},
-    {"folderview_select_folder",  folderview_select_folder, METH_VARARGS,
+    {"folderview_select_folder",  folderview_select_row, METH_VARARGS,
      "folderview_select_folder(folder) - select folder in folderview\n"
      "\n"
-     "Takes an argument of type clawsmail.Folder, and selects the corresponding folder."},
+     "Takes an argument of type clawsmail.Folder, and selects the corresponding folder.\n"
+     "\n"
+     "DEPRECATED: Use folderview_select() instead."},
 
     {"get_folderview_selected_mailbox",  get_folderview_selected_mailbox, METH_NOARGS,
      "get_folderview_selected_mailbox() - get selected mailbox in folderview\n"
      "\n"
      "Returns the currently selected mailbox as a clawsmail.Mailbox or None if no mailbox is selected."},
 
+     {"folderview_select",  folderview_select_row, METH_VARARGS,
+      "folderview_select(arg) - select folder or a mailbox in folderview\n"
+      "\n"
+      "Takes an argument of type clawsmail.Folder or clawsmail.Mailbox, and selects the corresponding\n"
+      "row in the folder view."},
+
     {"quicksearch_search", quicksearch_search, METH_VARARGS,
      "quicksearch_search(string [, type]) - perform a quicksearch\n"
      "\n"

commit aee1db32a7f22c77011ecfae0765c9c0b27bb7f3
Author: Holger Berndt <hb at claws-mail.org>
Date:   Sun Aug 18 23:49:20 2013 +0200

    Python plugin: Mailbox: Add type checking function

diff --git a/src/plugins/python/mailboxtype.c b/src/plugins/python/mailboxtype.c
index 3cc6c26..f0fa4f0 100644
--- a/src/plugins/python/mailboxtype.c
+++ b/src/plugins/python/mailboxtype.c
@@ -143,3 +143,8 @@ PyTypeObject* clawsmail_mailbox_get_type_object()
 {
   return &clawsmail_MailboxType;
 }
+
+gboolean clawsmail_mailbox_check(PyObject *self)
+{
+  return (PyObject_TypeCheck(self, &clawsmail_MailboxType) != 0);
+}
diff --git a/src/plugins/python/mailboxtype.h b/src/plugins/python/mailboxtype.h
index 5aeb9a9..4640a60 100644
--- a/src/plugins/python/mailboxtype.h
+++ b/src/plugins/python/mailboxtype.h
@@ -30,4 +30,6 @@ PyObject* clawsmail_mailbox_new(Folder *folder);
 Folder* clawsmail_mailbox_get_folder(PyObject *self);
 PyTypeObject* clawsmail_mailbox_get_type_object();
 
+gboolean clawsmail_mailbox_check(PyObject *self);
+
 #endif /* MAILBOXTYPE_H */

commit 4c26c8fa24f1947c4ce73bbee3696bc1cb301a59
Author: Holger Berndt <hb at claws-mail.org>
Date:   Mon Aug 12 01:00:44 2013 +0200

    Python plugin: Make it possible to get folder tree from a Mailbox

diff --git a/src/plugins/python/clawsmailmodule.c b/src/plugins/python/clawsmailmodule.c
index 6323e25..53e3b36 100644
--- a/src/plugins/python/clawsmailmodule.c
+++ b/src/plugins/python/clawsmailmodule.c
@@ -204,6 +204,29 @@ static gboolean setup_folderitem_node(GNode *item_node, GNode *item_parent, PyOb
   return TRUE;
 }
 
+static PyObject* get_folder_tree_from_folder(Folder *folder)
+{
+  if(folder->node) {
+    PyObject *root;
+    int n_children, i_child;
+
+    /* create root nodes */
+    root = clawsmail_node_new(cm_module);
+    if(!root)
+      return NULL;
+
+    n_children = g_node_n_children(folder->node);
+    for(i_child = 0; i_child < n_children; i_child++) {
+      if(!setup_folderitem_node(g_node_nth_child(folder->node, i_child), folder->node, &root)) {
+        Py_DECREF(root);
+        return NULL;
+      }
+    }
+    return root;
+  }
+  return NULL;
+}
+
 static PyObject* get_folder_tree_from_account_name(const char *str)
 {
   PyObject *result;
@@ -215,28 +238,19 @@ static PyObject* get_folder_tree_from_account_name(const char *str)
 
   for(walk = folder_get_list(); walk; walk = walk->next) {
     Folder *folder = walk->data;
-    if((!str || !g_strcmp0(str, folder->name)) && folder->node) {
-      PyObject *root;
-      int n_children, i_child, retval;
-
-      /* create root nodes */
-      root = clawsmail_node_new(cm_module);
-      if(!root) {
-        Py_DECREF(result);
-        return NULL;
-      }
-
-      n_children = g_node_n_children(folder->node);
-      for(i_child = 0; i_child < n_children; i_child++) {
-        if(!setup_folderitem_node(g_node_nth_child(folder->node, i_child), folder->node, &root)) {
-          Py_DECREF(root);
+    if(!str || !g_strcmp0(str, folder->name)) {
+      PyObject *tree_from_folder;
+      tree_from_folder = get_folder_tree_from_folder(folder);
+      if(tree_from_folder) {
+        int retval;
+        retval = PyList_Append(result, tree_from_folder);
+        Py_DECREF(tree_from_folder);
+        if(retval == -1) {
           Py_DECREF(result);
           return NULL;
         }
       }
-      retval = PyList_Append(result, root);
-      Py_DECREF(root);
-      if(retval == -1) {
+      else {
         Py_DECREF(result);
         return NULL;
       }
@@ -302,8 +316,11 @@ static PyObject* get_folder_tree(PyObject *self, PyObject *args)
   else if(PyObject_TypeCheck(arg, clawsmail_folder_get_type_object())) {
     result = get_folder_tree_from_folderitem(clawsmail_folder_get_item(arg));
   }
+  else if(PyObject_TypeCheck(arg, clawsmail_mailbox_get_type_object())) {
+    result = get_folder_tree_from_folder(clawsmail_mailbox_get_folder(arg));
+  }
   else {
-    PyErr_SetString(PyExc_TypeError, "Parameter must be nothing, a mailbox string or a Folder object.");
+    PyErr_SetString(PyExc_TypeError, "Parameter must be nothing, a Folder object, a Mailbox object, or a mailbox name string.");
     return NULL;
   }
 
@@ -717,12 +734,15 @@ static PyMethodDef ClawsMailMethods[] = {
      "\n"
      "Without arguments, get a list of folder trees for all mailboxes.\n"
      "\n"
-     "If the optional root argument is a string, it is supposed to be a\n"
-     "mailbox name. The function then returns a tree of folders of that mailbox.\n"
-     "\n"
      "If the optional root argument is a clawsmail.Folder, the function\n"
      "returns a tree of subfolders with the given folder as root element.\n"
      "\n"
+     "If the optional root argument is a clawsmail.Mailbox, the function\n"
+     "returns a tree of folders with the given mailbox as root element.\n"
+     "\n"
+     "If the optional root argument is a string, it is supposed to be a\n"
+     "mailbox name. The function then returns a tree of folders of that mailbox.\n"
+     "\n"
      "In any case, a tree consists of elements of the type clawsmail.Node."},
 
     {"get_folderview_selected_folder",  get_folderview_selected_folder, METH_NOARGS,
diff --git a/src/plugins/python/mailboxtype.c b/src/plugins/python/mailboxtype.c
index ffb42f0..3cc6c26 100644
--- a/src/plugins/python/mailboxtype.c
+++ b/src/plugins/python/mailboxtype.c
@@ -133,3 +133,13 @@ PyObject* clawsmail_mailbox_new(Folder *folder)
   ff->folder = folder;
   return (PyObject*)ff;
 }
+
+Folder* clawsmail_mailbox_get_folder(PyObject *self)
+{
+  return ((clawsmail_MailboxObject*)self)->folder;
+}
+
+PyTypeObject* clawsmail_mailbox_get_type_object()
+{
+  return &clawsmail_MailboxType;
+}
diff --git a/src/plugins/python/mailboxtype.h b/src/plugins/python/mailboxtype.h
index 61337f1..5aeb9a9 100644
--- a/src/plugins/python/mailboxtype.h
+++ b/src/plugins/python/mailboxtype.h
@@ -27,4 +27,7 @@ gboolean cmpy_add_mailbox(PyObject *module);
 
 PyObject* clawsmail_mailbox_new(Folder *folder);
 
+Folder* clawsmail_mailbox_get_folder(PyObject *self);
+PyTypeObject* clawsmail_mailbox_get_type_object();
+
 #endif /* MAILBOXTYPE_H */

commit 784a101b7c2a898f893c656de01f08da00d19c1e
Author: Holger Berndt <hb at claws-mail.org>
Date:   Sat Aug 10 15:09:19 2013 +0200

    Python pluging: Folder: Add accessor to Mailbox object

diff --git a/src/plugins/python/foldertype.c b/src/plugins/python/foldertype.c
index 9080787..7873b0c 100644
--- a/src/plugins/python/foldertype.c
+++ b/src/plugins/python/foldertype.c
@@ -25,6 +25,7 @@
 #include "foldertype.h"
 #include "folderpropertiestype.h"
 #include "messageinfotype.h"
+#include "mailboxtype.h"
 
 #include <structmember.h>
 
@@ -145,6 +146,14 @@ static PyObject* get_mailbox_name(clawsmail_FolderObject *self, void *closure)
   Py_RETURN_NONE;
 }
 
+static PyObject* get_mailbox(clawsmail_FolderObject *self, void *closure)
+{
+  if(self->folderitem && self->folderitem->folder)
+    return clawsmail_mailbox_new(self->folderitem->folder);
+  Py_RETURN_NONE;
+}
+
+
 static PyObject* get_identifier(clawsmail_FolderObject *self, void *closure)
 {
   if(self->folderitem) {
@@ -189,8 +198,12 @@ static PyGetSetDef Folder_getset[] = {
     {"identifier", (getter)get_identifier, (setter)NULL,
      "identifier - identifier of folder", NULL},
 
+    {"mailbox", (getter)get_mailbox, (setter)NULL,
+     "mailbox - corresponding mailbox", NULL},
+
     {"mailbox_name", (getter)get_mailbox_name, (setter)NULL,
-     "mailbox_name - name of the corresponding mailbox", NULL},
+     "mailbox_name - name of the corresponding mailbox\n\n"
+     "DEPRECATED: Use folder.mailbox.name instead", NULL},
 
     {"properties", (getter)get_properties, (setter)NULL,
      "properties - folder properties object", NULL},

commit a193b41e8f120d4f742b8f81bec58ca34a79b805
Author: Holger Berndt <hb at claws-mail.org>
Date:   Sat Aug 10 14:56:28 2013 +0200

    Python plugin: Add Mailbox type

diff --git a/src/plugins/python/Makefile.am b/src/plugins/python/Makefile.am
index 4f72a91..dcade0b 100644
--- a/src/plugins/python/Makefile.am
+++ b/src/plugins/python/Makefile.am
@@ -17,6 +17,8 @@ python_la_SOURCES = \
 	folderpropertiestype.h \
 	foldertype.c \
 	foldertype.h \
+	mailboxtype.c \
+	mailboxtype.h \
 	messageinfotype.c \
 	messageinfotype.h \
 	nodetype.c \
diff --git a/src/plugins/python/clawsmailmodule.c b/src/plugins/python/clawsmailmodule.c
index ec1f223..6323e25 100644
--- a/src/plugins/python/clawsmailmodule.c
+++ b/src/plugins/python/clawsmailmodule.c
@@ -31,6 +31,7 @@
 #include "foldertype.h"
 #include "messageinfotype.h"
 #include "accounttype.h"
+#include "mailboxtype.h"
 
 #include <pygobject.h>
 #include <pygtk/pygtk.h>
@@ -106,10 +107,33 @@ static PyObject *get_folderview_selected_folder(PyObject *self, PyObject *args)
     if(item)
       return clawsmail_folder_new(item);
   }
-  Py_INCREF(Py_None);
-  return Py_None;
+  Py_RETURN_NONE;
+}
+
+static PyObject *get_folderview_selected_mailbox(PyObject *self, PyObject *args)
+{
+  MainWindow *mainwin;
+
+  mainwin =  mainwindow_get_mainwindow();
+  if(mainwin && mainwin->folderview) {
+    FolderItem *item;
+    item = folderview_get_selected_item(mainwin->folderview);
+    if(item) {
+      gchar *id;
+      id = folder_item_get_identifier(item);
+      /* If there is an id, it's a folder, not a mailbox */
+      if(id) {
+        g_free(id);
+        Py_RETURN_NONE;
+      }
+      else
+        return clawsmail_mailbox_new(item->folder);
+    }
+  }
+  Py_RETURN_NONE;
 }
 
+
 static PyObject *folderview_select_folder(PyObject *self, PyObject *args)
 {
   MainWindow *mainwin;
@@ -464,6 +488,34 @@ static PyObject* get_accounts(PyObject *self, PyObject *args)
   return accounts_tuple;
 }
 
+static PyObject* get_mailboxes(PyObject *self, PyObject *args)
+{
+  PyObject *mailboxes_tuple;
+  GList *mailboxes_list;
+  GList *walk;
+
+  mailboxes_list = folder_get_list();
+
+  mailboxes_tuple = PyTuple_New(g_list_length(mailboxes_list));
+  if(mailboxes_tuple) {
+    PyObject *mailbox_object;
+    Py_ssize_t iMailbox;
+
+    iMailbox = 0;
+    for(walk = mailboxes_list; walk; walk = walk->next) {
+      mailbox_object = clawsmail_mailbox_new(walk->data);
+      if(mailbox_object == NULL) {
+        Py_DECREF(mailboxes_tuple);
+        return NULL;
+      }
+      PyTuple_SET_ITEM(mailboxes_tuple, iMailbox++, mailbox_object);
+    }
+  }
+
+  return mailboxes_tuple;
+}
+
+
 static PyObject* make_sure_tag_exists(PyObject *self, PyObject *args)
 {
   int retval;
@@ -676,12 +728,17 @@ static PyMethodDef ClawsMailMethods[] = {
     {"get_folderview_selected_folder",  get_folderview_selected_folder, METH_NOARGS,
      "get_folderview_selected_folder() - get selected folder in folderview\n"
      "\n"
-     "Returns the currently selected folder as a clawsmail.Folder."},
+     "Returns the currently selected folder as a clawsmail.Folder or None if no folder is selected."},
     {"folderview_select_folder",  folderview_select_folder, METH_VARARGS,
      "folderview_select_folder(folder) - select folder in folderview\n"
      "\n"
      "Takes an argument of type clawsmail.Folder, and selects the corresponding folder."},
 
+    {"get_folderview_selected_mailbox",  get_folderview_selected_mailbox, METH_NOARGS,
+     "get_folderview_selected_mailbox() - get selected mailbox in folderview\n"
+     "\n"
+     "Returns the currently selected mailbox as a clawsmail.Mailbox or None if no mailbox is selected."},
+
     {"quicksearch_search", quicksearch_search, METH_VARARGS,
      "quicksearch_search(string [, type]) - perform a quicksearch\n"
      "\n"
@@ -764,7 +821,12 @@ static PyMethodDef ClawsMailMethods[] = {
       "\n"
       "Return the object representing the default account."},
 
-      /* private */
+     {"get_mailboxes", get_mailboxes, METH_NOARGS,
+      "get_mailboxes() - get a tuple of all mailboxes that Claws Mail knows about\n"
+      "\n"
+      "Get a tuple of Mailbox objects representing all mailboxes that are defined in Claws Mail."},
+
+     /* private */
     {"__gobj", private_wrap_gobj, METH_VARARGS,
      "__gobj(ptr) - transforms a C GObject pointer into a PyGObject\n"
      "\n"
@@ -821,6 +883,7 @@ PyMODINIT_FUNC initclawsmail(void)
   ok = ok && cmpy_add_messageinfo(cm_module);
   ok = ok && cmpy_add_account(cm_module);
   ok = ok && cmpy_add_folderproperties(cm_module);
+  ok = ok && cmpy_add_mailbox(cm_module);
 
   /* initialize misc things */
   if(ok)
diff --git a/src/plugins/python/mailboxtype.c b/src/plugins/python/mailboxtype.c
new file mode 100644
index 0000000..ffb42f0
--- /dev/null
+++ b/src/plugins/python/mailboxtype.c
@@ -0,0 +1,135 @@
+/* Python plugin for Claws-Mail
+ * Copyright (C) 2013 Holger Berndt <hb at claws-mail.org>
+ *
+ * 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 3 of the License, 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
+ * 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/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#  include "claws-features.h"
+#endif
+
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include "mailboxtype.h"
+
+#include <structmember.h>
+
+typedef struct {
+    PyObject_HEAD
+    Folder *folder;
+} clawsmail_MailboxObject;
+
+static int Mailbox_init(clawsmail_MailboxObject *self, PyObject *args, PyObject *kwds)
+{
+  self->folder = NULL;
+  return 0;
+}
+
+static void Mailbox_dealloc(clawsmail_MailboxObject* self)
+{
+  self->folder = NULL;
+  self->ob_type->tp_free((PyObject*)self);
+}
+
+static PyObject* Mailbox_str(clawsmail_MailboxObject *self)
+{
+  if(self->folder && self->folder->name)
+    return PyString_FromFormat("Mailbox: %s", self->folder->name);
+  Py_RETURN_NONE;
+}
+
+static PyObject* get_name(clawsmail_MailboxObject *self, void *closure)
+{
+  if(self->folder && self->folder->name)
+    return PyString_FromString(self->folder->name);
+  Py_RETURN_NONE;
+}
+
+static PyGetSetDef Mailbox_getset[] = {
+   {"name", (getter)get_name, (setter)NULL,
+    "name - name of the mailbox", NULL},
+
+   {NULL}
+};
+
+static PyTypeObject clawsmail_MailboxType = {
+    PyObject_HEAD_INIT(NULL)
+    0,                         /* ob_size*/
+    "clawsmail.Mailbox",       /* tp_name*/
+    sizeof(clawsmail_MailboxObject), /* tp_basicsize*/
+    0,                         /* tp_itemsize*/
+    (destructor)Mailbox_dealloc, /* tp_dealloc*/
+    0,                         /* tp_print*/
+    0,                         /* tp_getattr*/
+    0,                         /* tp_setattr*/
+    0,                         /* tp_compare*/
+    0,                         /* tp_repr*/
+    0,                         /* tp_as_number*/
+    0,                         /* tp_as_sequence*/
+    0,                         /* tp_as_mapping*/
+    0,                         /* tp_hash */
+    0,                         /* tp_call*/
+    (reprfunc)Mailbox_str,     /* tp_str*/
+    0,                         /* tp_getattro*/
+    0,                         /* tp_setattro*/
+    0,                         /* tp_as_buffer*/
+    Py_TPFLAGS_DEFAULT,        /* tp_flags*/
+    "Mailbox objects.\n\n"     /* tp_doc */
+    "Do not construct objects of this type yourself.",
+    0,                         /* tp_traverse */
+    0,                         /* tp_clear */
+    0,                         /* tp_richcompare */
+    0,                         /* tp_weaklistoffset */
+    0,                         /* tp_iter */
+    0,                         /* tp_iternext */
+    0,                         /* tp_methods */
+    0,                         /* tp_members */
+    Mailbox_getset,            /* tp_getset */
+    0,                         /* tp_base */
+    0,                         /* tp_dict */
+    0,                         /* tp_descr_get */
+    0,                         /* tp_descr_set */
+    0,                         /* tp_dictoffset */
+    (initproc)Mailbox_init,    /* tp_init */
+    0,                         /* tp_alloc */
+    0,                         /* tp_new */
+};
+
+
+gboolean cmpy_add_mailbox(PyObject *module)
+{
+  clawsmail_MailboxType.tp_new = PyType_GenericNew;
+  if(PyType_Ready(&clawsmail_MailboxType) < 0)
+    return FALSE;
+
+  Py_INCREF(&clawsmail_MailboxType);
+  return (PyModule_AddObject(module, "Mailbox", (PyObject*)&clawsmail_MailboxType) == 0);
+}
+
+PyObject* clawsmail_mailbox_new(Folder *folder)
+{
+  clawsmail_MailboxObject *ff;
+
+  if(!folder)
+    return NULL;
+
+  ff = (clawsmail_MailboxObject*) PyObject_CallObject((PyObject*) &clawsmail_MailboxType, NULL);
+  if(!ff)
+    return NULL;
+
+  ff->folder = folder;
+  return (PyObject*)ff;
+}
diff --git a/src/plugins/python/mailboxtype.h b/src/plugins/python/mailboxtype.h
new file mode 100644
index 0000000..61337f1
--- /dev/null
+++ b/src/plugins/python/mailboxtype.h
@@ -0,0 +1,30 @@
+/* Python plugin for Claws-Mail
+ * Copyright (C) 2013 Holger Berndt <hb at claws-mail.org>
+ *
+ * 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 3 of the License, 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
+ * 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/>.
+ */
+
+#ifndef MAILBOXTYPE_H
+#define MAILBOXTYPE_H
+
+#include <glib.h>
+#include <Python.h>
+
+#include "folder.h"
+
+gboolean cmpy_add_mailbox(PyObject *module);
+
+PyObject* clawsmail_mailbox_new(Folder *folder);
+
+#endif /* MAILBOXTYPE_H */

commit fa0e1e653303caad97d63eedfa777316e412b579
Author: Holger Berndt <hb at claws-mail.org>
Date:   Sat Aug 10 14:28:01 2013 +0200

    Python plugin: Folder: Return None for folders without an id

diff --git a/src/plugins/python/foldertype.c b/src/plugins/python/foldertype.c
index 3afd0cc..9080787 100644
--- a/src/plugins/python/foldertype.c
+++ b/src/plugins/python/foldertype.c
@@ -265,11 +265,14 @@ PyObject* clawsmail_folder_new(FolderItem *folderitem)
     return NULL;
 
   id = folder_item_get_identifier(folderitem);
-  arglist = Py_BuildValue("(s)", id);
-  g_free(id);
-  ff = (clawsmail_FolderObject*) PyObject_CallObject((PyObject*) &clawsmail_FolderType, arglist);
-  Py_DECREF(arglist);
-  return (PyObject*)ff;
+  if(id) {
+    arglist = Py_BuildValue("(s)", id);
+    g_free(id);
+    ff = (clawsmail_FolderObject*) PyObject_CallObject((PyObject*) &clawsmail_FolderType, arglist);
+    Py_DECREF(arglist);
+    return (PyObject*)ff;
+  }
+  Py_RETURN_NONE;
 }
 
 FolderItem* clawsmail_folder_get_item(PyObject *self)

-----------------------------------------------------------------------

Summary of changes:
 src/plugins/python/Makefile.am                     |    2 +
 src/plugins/python/clawsmailmodule.c               |  187 ++++++++++++++++----
 .../examples/main/Recusively-mark-messages-as-read |   56 +++---
 src/plugins/python/foldertype.c                    |  134 +++++++++++++-
 .../{folderpropertiestype.c => mailboxtype.c}      |  106 ++++++-----
 .../{folderpropertiestype.h => mailboxtype.h}      |   15 +-
 6 files changed, 373 insertions(+), 127 deletions(-)
 copy src/plugins/python/{folderpropertiestype.c => mailboxtype.c} (54%)
 copy src/plugins/python/{folderpropertiestype.h => mailboxtype.h} (69%)


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list