#include "nodetype.h"
#include "composewindowtype.h"
+#include "folderpropertiestype.h"
#include "foldertype.h"
#include "messageinfotype.h"
+#include "accounttype.h"
+#include "mailboxtype.h"
#include <pygobject.h>
#include <pygtk/pygtk.h>
#include "toolbar.h"
#include "prefs_common.h"
#include "common/tags.h"
+#include "account.h"
#include <glib.h>
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;
return tags_tuple;
}
+static PyObject* get_accounts(PyObject *self, PyObject *args)
+{
+ PyObject *accounts_tuple;
+ GList *accounts_list;
+ GList *walk;
+
+ accounts_list = account_get_list();
+
+ accounts_tuple = PyTuple_New(g_list_length(accounts_list));
+ if(accounts_tuple) {
+ PyObject *account_object;
+ Py_ssize_t iAccount;
+
+ iAccount = 0;
+ for(walk = accounts_list; walk; walk = walk->next) {
+ account_object = clawsmail_account_new(walk->data);
+ if(account_object == NULL) {
+ Py_DECREF(accounts_tuple);
+ return NULL;
+ }
+ PyTuple_SET_ITEM(accounts_tuple, iAccount++, account_object);
+ }
+ }
+
+ 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;
return move_or_copy_messages(self, args, FALSE);
}
+static PyObject* get_current_account(PyObject *self, PyObject *args)
+{
+ PrefsAccount *account;
+ account = account_get_cur_account();
+ if(account) {
+ return clawsmail_account_new(account);
+ }
+ else
+ Py_RETURN_NONE;
+}
+
+static PyObject* get_default_account(PyObject *self, PyObject *args)
+{
+ PrefsAccount *account;
+ account = account_get_default();
+ if(account) {
+ return clawsmail_account_new(account);
+ }
+ else
+ Py_RETURN_NONE;
+}
+
+
static PyMethodDef ClawsMailMethods[] = {
/* public */
{"get_mainwindow_action_group", get_mainwindow_action_group, METH_NOARGS,
{"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"
"Raises a KeyError exception if the tag does not exist.\n"
"Raises a ValueError exception if the old or new tag name is a reserved name."},
+ {"get_accounts", get_accounts, METH_NOARGS,
+ "get_accounts() - get a tuple of all accounts that Claws Mail knows about\n"
+ "\n"
+ "Get a tuple of Account objects representing all accounts that are defined in Claws Mail."},
+
+ {"get_current_account", get_current_account, METH_NOARGS,
+ "get_current_account() - get the current account\n"
+ "\n"
+ "Return the object representing the currently selected account."},
+
+ {"get_default_account", get_default_account, METH_NOARGS,
+ "get_default_account() - get the default account\n"
+ "\n"
+ "Return the object representing the default account."},
+
+ {"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"
/* add module member "compose_window" set to None */
Py_INCREF(Py_None);
- PyModule_AddObject(cm_module, "compose window", Py_None);
+ PyModule_AddObject(cm_module, "compose_window", Py_None);
/* initialize classes */
ok = ok && cmpy_add_node(cm_module);
ok = ok && cmpy_add_composewindow(cm_module);
ok = ok && cmpy_add_folder(cm_module);
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)