Revision 8d7dcace lib/filters/textcontent-filter.c

View differences:

lib/filters/textcontent-filter.c
1 1
#include <glib.h>
2
#include <stdio.h>
2 3
#include <string.h>
3 4

  
4 5
#include "filter.h"
5 6
#include "textcontent-filter.h"
6 7

  
8
#include "libsylph/procheader.h"
9
#include "libsylph/procmsg.h"
10
#include "libsylph/procmime.h"
11
#include "libsylph/utils.h"
7 12

  
13

  
14
static XMessageData *xfilter_rfc822_to_text(const XMessageData *data)
15
{
16
	const char *file;
17
	MsgInfo *msginfo;
18
	MsgFlags flags = {0};
19
	XMessageData *newdata;
20
	FILE *fp;
21
	char *text;
22

  
23
	file = xfilter_message_data_get_file(data);
24
	if (!file)
25
		return NULL;
26

  
27
	msginfo = procheader_parse_file(file, flags, TRUE);
28
	if (!msginfo)
29
		return NULL;
30
	msginfo->file_path = g_strdup(file);
31

  
32
	fp = procmime_get_first_text_content(msginfo, NULL);
33
	if (!fp) {
34
		procmsg_msginfo_free(msginfo);
35
		return NULL;
36
	}
37
	text = file_read_stream_to_str(fp);
38
	if (!text) {
39
		fclose(fp);
40
		procmsg_msginfo_free(msginfo);
41
		return NULL;
42
	}
43

  
44
	newdata = xfilter_message_data_new(text, "text/plain");
45
	if (msginfo->from)
46
		xfilter_message_data_set_attribute(newdata, XM_FROM, msginfo->from, FALSE);
47
	if (msginfo->to)
48
		xfilter_message_data_set_attribute(newdata, XM_TO, msginfo->to, FALSE);
49
	if (msginfo->cc)
50
		xfilter_message_data_set_attribute(newdata, XM_CC, msginfo->cc, FALSE);
51
	if (msginfo->subject)
52
		xfilter_message_data_set_attribute(newdata, XM_SUBJECT, msginfo->subject, FALSE);
53

  
54
	procmsg_msginfo_free(msginfo);
55
	return newdata;
56
}
57

  
58
#if 0
8 59
static XMessageData *xfilter_rfc822_to_text(const XMessageData *data)
9 60
{
10 61
	const char *rfc822content;
......
100 151

  
101 152
	return newdata;
102 153
}
154
#endif
103 155

  
104 156
static XFilterStatus xfilter_content_func(XFilter *filter, const XMessageData *data, XFilterResult *result)
105 157
{
......
119 171
		xfilter_result_set_message_data(result, newdata);
120 172
	} else if (!g_strcasecmp(mime_type, "message/rfc822")) {
121 173
		newdata = xfilter_rfc822_to_text(data);
174
		if (!newdata)
175
			return XF_ERROR;
122 176
		xfilter_result_set_message_data(result, newdata);
123 177
		g_print("from:%s\n", xfilter_message_data_get_attribute(newdata, XM_FROM));
124 178
		g_print("to:%s\n", xfilter_message_data_get_attribute(newdata, XM_TO));

Also available in: Unified diff