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 Py_TYPE(self
)->tp_free((PyObject
*)self
);
47 static PyObject
* Mailbox_str(clawsmail_MailboxObject
*self
)
49 if(self
->folder
&& self
->folder
->name
)
50 return PyUnicode_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 PyUnicode_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 PyVarObject_HEAD_INIT(NULL
, 0)
70 "clawsmail.Mailbox", /* tp_name*/
71 sizeof(clawsmail_MailboxObject
), /* tp_basicsize*/
73 (destructor
)Mailbox_dealloc
, /* tp_dealloc*/
80 0, /* tp_as_sequence*/
84 (reprfunc
)Mailbox_str
, /* tp_str*/
88 Py_TPFLAGS_DEFAULT
, /* tp_flags*/
89 "Mailbox objects.\n\n" /* tp_doc */
90 "Do not construct objects of this type yourself.",
93 0, /* tp_richcompare */
94 0, /* tp_weaklistoffset */
99 Mailbox_getset
, /* tp_getset */
102 0, /* tp_descr_get */
103 0, /* tp_descr_set */
104 0, /* tp_dictoffset */
105 (initproc
)Mailbox_init
, /* tp_init */
113 0, /* tp_subclasses */
116 #if ((PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 6) || \
117 (PY_MAJOR_VERSION == 3))
118 0, /* tp_version_tag */
120 #if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 4)
125 gboolean
cmpy_add_mailbox(PyObject
*module
)
127 clawsmail_MailboxType
.tp_new
= PyType_GenericNew
;
128 if(PyType_Ready(&clawsmail_MailboxType
) < 0)
131 Py_INCREF(&clawsmail_MailboxType
);
132 return (PyModule_AddObject(module
, "Mailbox", (PyObject
*)&clawsmail_MailboxType
) == 0);
135 PyObject
* clawsmail_mailbox_new(Folder
*folder
)
137 clawsmail_MailboxObject
*ff
;
142 ff
= (clawsmail_MailboxObject
*) PyObject_CallObject((PyObject
*) &clawsmail_MailboxType
, NULL
);
147 return (PyObject
*)ff
;
150 Folder
* clawsmail_mailbox_get_folder(PyObject
*self
)
152 return ((clawsmail_MailboxObject
*)self
)->folder
;
155 PyTypeObject
* clawsmail_mailbox_get_type_object()
157 return &clawsmail_MailboxType
;
160 gboolean
clawsmail_mailbox_check(PyObject
*self
)
162 return (PyObject_TypeCheck(self
, &clawsmail_MailboxType
) != 0);