1 /* Python plugin for Claws-Mail
2 * Copyright (C) 2013 Holger Berndt <hb@claws-mail.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # include "claws-features.h"
23 #include "mailboxtype.h"
26 #include <glib/gi18n.h>
28 #include <structmember.h>
33 } clawsmail_MailboxObject;
35 static int Mailbox_init(clawsmail_MailboxObject *self, PyObject *args, PyObject *kwds)
41 static void Mailbox_dealloc(clawsmail_MailboxObject* self)
44 self->ob_type->tp_free((PyObject*)self);
47 static PyObject* Mailbox_str(clawsmail_MailboxObject *self)
49 if(self->folder && self->folder->name)
50 return PyString_FromFormat("Mailbox: %s", self->folder->name);
54 static PyObject* get_name(clawsmail_MailboxObject *self, void *closure)
56 if(self->folder && self->folder->name)
57 return PyString_FromString(self->folder->name);
61 static PyGetSetDef Mailbox_getset[] = {
62 {"name", (getter)get_name, (setter)NULL,
63 "name - name of the mailbox", NULL},
68 static PyTypeObject clawsmail_MailboxType = {
69 PyObject_HEAD_INIT(NULL)
71 "clawsmail.Mailbox", /* tp_name*/
72 sizeof(clawsmail_MailboxObject), /* tp_basicsize*/
74 (destructor)Mailbox_dealloc, /* tp_dealloc*/
81 0, /* tp_as_sequence*/
85 (reprfunc)Mailbox_str, /* tp_str*/
89 Py_TPFLAGS_DEFAULT, /* tp_flags*/
90 "Mailbox objects.\n\n" /* tp_doc */
91 "Do not construct objects of this type yourself.",
94 0, /* tp_richcompare */
95 0, /* tp_weaklistoffset */
100 Mailbox_getset, /* tp_getset */
103 0, /* tp_descr_get */
104 0, /* tp_descr_set */
105 0, /* tp_dictoffset */
106 (initproc)Mailbox_init, /* tp_init */
112 gboolean cmpy_add_mailbox(PyObject *module)
114 clawsmail_MailboxType.tp_new = PyType_GenericNew;
115 if(PyType_Ready(&clawsmail_MailboxType) < 0)
118 Py_INCREF(&clawsmail_MailboxType);
119 return (PyModule_AddObject(module, "Mailbox", (PyObject*)&clawsmail_MailboxType) == 0);
122 PyObject* clawsmail_mailbox_new(Folder *folder)
124 clawsmail_MailboxObject *ff;
129 ff = (clawsmail_MailboxObject*) PyObject_CallObject((PyObject*) &clawsmail_MailboxType, NULL);
134 return (PyObject*)ff;
137 Folder* clawsmail_mailbox_get_folder(PyObject *self)
139 return ((clawsmail_MailboxObject*)self)->folder;
142 PyTypeObject* clawsmail_mailbox_get_type_object()
144 return &clawsmail_MailboxType;
147 gboolean clawsmail_mailbox_check(PyObject *self)
149 return (PyObject_TypeCheck(self, &clawsmail_MailboxType) != 0);