#include "claws-features.h"
#endif
-#include <glib.h>
#include <glib/gi18n.h>
#include "messageinfotype.h"
#include "common/tags.h"
+#include "common/defs.h"
#include "mainwindow.h"
#include "summaryview.h"
+#include "procheader.h"
#include <structmember.h>
+#include <string.h>
+
+#define HEADER_CONTENT_SIZE BUFFSIZE
typedef struct {
PyObject_HEAD
PyObject *from;
PyObject *to;
+ PyObject *cc;
PyObject *subject;
PyObject *msgid;
PyObject *filepath;
{
Py_XDECREF(self->from);
Py_XDECREF(self->to);
+ Py_XDECREF(self->cc);
Py_XDECREF(self->subject);
Py_XDECREF(self->msgid);
self->ob_type->tp_free((PyObject*)self);
Py_INCREF(Py_None);
self->to = Py_None;
+ Py_INCREF(Py_None);
+ self->cc = Py_None;
+
Py_INCREF(Py_None);
self->subject = Py_None;
return add_or_remove_tag(self, args, FALSE);
}
+static PyObject* get_header(PyObject *self, PyObject *args)
+{
+ int retval;
+ const char *header_str;
+ char *header_str_dup;
+ MsgInfo *msginfo;
+ gchar header_content[HEADER_CONTENT_SIZE];
+
+ retval = PyArg_ParseTuple(args, "s", &header_str);
+ if(!retval)
+ return NULL;
+
+ msginfo = ((clawsmail_MessageInfoObject*)self)->msginfo;
+
+ header_str_dup = g_strdup(header_str);
+ retval = procheader_get_header_from_msginfo(msginfo, header_content, HEADER_CONTENT_SIZE, header_str);
+ g_free(header_str_dup);
+ if(retval == 0) {
+ PyObject *header_content_object;
+ gchar *content_start;
+
+ /* the string is now Header: Value. Strip the Header: part */
+ content_start = strstr(header_content, ":");
+ if(content_start == NULL)
+ content_start = header_content;
+ else
+ content_start++;
+ /* strip leading spaces */
+ while(*content_start == ' ')
+ content_start++;
+ header_content_object = Py_BuildValue("s", content_start);
+ return header_content_object;
+ }
+ else {
+ Py_RETURN_NONE;
+ }
+}
+
static PyMethodDef MessageInfo_methods[] = {
{"is_new", is_new, METH_NOARGS,
"\n"
"Returns True if the new flag of the message is set."},
- {"is_unread", is_unread, METH_NOARGS,
+ {"is_unread", is_unread, METH_NOARGS,
"is_unread() - checks if the message is unread\n"
"\n"
"Returns True if the unread flag of the message is set."},
"Remove a tag from this message. If the tag is not set, a KeyError exception is raised.\n"
"If the tag does not exist, a ValueError exception is raised."},
+ {"get_header", get_header, METH_VARARGS,
+ "get_header(name) - get a message header with a given name\n"
+ "\n"
+ "Get a message header content with a given name. If the header does not exist,\n"
+ "the value 'None' is returned. If multiple headers with the same name exist,\n"
+ "the first one is returned."},
+
{NULL}
};
static PyMemberDef MessageInfo_members[] = {
- {"From", T_OBJECT_EX, offsetof(clawsmail_MessageInfoObject, from), 0,
- "From - the From header of the message"},
+ { "From", T_OBJECT_EX, offsetof(clawsmail_MessageInfoObject, from), 0,
+ "From - the From header of the message" },
+
+ { "To", T_OBJECT_EX, offsetof(clawsmail_MessageInfoObject, to), 0,
+ "To - the To header of the message" },
- {"To", T_OBJECT_EX, offsetof(clawsmail_MessageInfoObject, to), 0,
- "To - the To header of the message"},
+ { "Cc", T_OBJECT_EX, offsetof(clawsmail_MessageInfoObject, cc), 0,
+ "Cc - the Cc header of the message" },
{"Subject", T_OBJECT_EX, offsetof(clawsmail_MessageInfoObject, subject), 0,
"Subject - the subject header of the message"},
0, /* tp_new */
};
-PyMODINIT_FUNC initmessageinfo(PyObject *module)
+gboolean cmpy_add_messageinfo(PyObject *module)
{
- clawsmail_MessageInfoType.tp_new = PyType_GenericNew;
- if(PyType_Ready(&clawsmail_MessageInfoType) < 0)
- return;
+ clawsmail_MessageInfoType.tp_new = PyType_GenericNew;
+ if(PyType_Ready(&clawsmail_MessageInfoType) < 0)
+ return FALSE;
- Py_INCREF(&clawsmail_MessageInfoType);
- PyModule_AddObject(module, "MessageInfo", (PyObject*)&clawsmail_MessageInfoType);
+ Py_INCREF(&clawsmail_MessageInfoType);
+ return (PyModule_AddObject(module, "MessageInfo", (PyObject*)&clawsmail_MessageInfoType) == 0);
}
#define MSGINFO_STRING_TO_PYTHON_MESSAGEINFO_MEMBER(fis, pms) \
MSGINFO_STRING_TO_PYTHON_MESSAGEINFO_MEMBER(msginfo->from, "From");
MSGINFO_STRING_TO_PYTHON_MESSAGEINFO_MEMBER(msginfo->to, "To");
+ MSGINFO_STRING_TO_PYTHON_MESSAGEINFO_MEMBER(msginfo->cc, "Cc");
MSGINFO_STRING_TO_PYTHON_MESSAGEINFO_MEMBER(msginfo->subject, "Subject");
MSGINFO_STRING_TO_PYTHON_MESSAGEINFO_MEMBER(msginfo->msgid, "MessageID");