Revision 8d7dcace lib/filter.c

View differences:

lib/filter.c
72 72
	g_return_val_if_fail(mime_type != NULL, NULL);
73 73

  
74 74
	data = g_new0(XMessageData, 1);
75
	data->file = NULL;
75 76
	data->content = g_strdup(src);
76 77
	data->mime_type = g_strdup(mime_type);
77 78
	return data;
......
80 81
XMessageData *xfilter_message_data_read_file(const char *file, const char *mime_type)
81 82
{
82 83
	XMessageData *data;
83
	char *content;
84 84

  
85 85
	g_return_val_if_fail(file != NULL, NULL);
86 86
	g_return_val_if_fail(mime_type != NULL, NULL);
87 87

  
88
	content = xfilter_utils_get_file_contents(file);
89
	if (!content)
90
		return NULL;
91

  
92 88
	data = g_new0(XMessageData, 1);
93
	data->content = content;
89
	data->file = g_strdup(file);
90
	data->content = NULL;
94 91
	data->mime_type = g_strdup(mime_type);
95 92
	return data;
96 93
}
......
101 98
		return;
102 99

  
103 100
	g_free(msgdata->mime_type);
101
	g_free(msgdata->file);
104 102
	g_free(msgdata->content);
105 103
	g_free(msgdata->from);
106 104
	g_free(msgdata->to);
......
110 108
	g_free(msgdata);
111 109
}
112 110

  
111
void xfilter_message_data_set_file(XMessageData *msgdata, const char *file)
112
{
113
	xfilter_message_data_set_content(msgdata, NULL);
114
	g_free(msgdata->file);
115
	msgdata->file = g_strdup(file);
116
}
117

  
113 118
void xfilter_message_data_set_content(XMessageData *msgdata, char *content)
114 119
{
115 120
	if (msgdata->content)
......
185 190

  
186 191
const char *xfilter_message_data_get_attribute(const XMessageData *msgdata, XMessageAttr attr)
187 192
{
193
	g_return_val_if_fail(msgdata != NULL, NULL);
194

  
188 195
	switch (attr) {
189 196
	case XM_FROM:
190 197
		return msgdata->from;
......
208 215
	return msgdata->mime_type;
209 216
}
210 217

  
218
const char *xfilter_message_data_get_file(const XMessageData *msgdata)
219
{
220
	g_return_val_if_fail(msgdata != NULL, NULL);
221

  
222
	return msgdata->file;
223
}
224

  
211 225
const char *xfilter_message_data_get_content(const XMessageData *msgdata)
212 226
{
213 227
	g_return_val_if_fail(msgdata != NULL, NULL);
214 228

  
215
	return msgdata->content;
229
	if (msgdata->content)
230
		return msgdata->content;
231

  
232
	if (msgdata->file) {
233
		char *content;
234

  
235
		g_print("xfilter_message_data_get_content: getting file content: %s\n", msgdata->file);
236
		content = xfilter_utils_get_file_contents(msgdata->file);
237
		if (content)
238
			((XMessageData *)msgdata)->content = content;
239

  
240
		return content;
241
	}
242

  
243
	return NULL;
216 244
}
217 245

  
218 246
void xfilter_set_content_filter_func(XContentFilter *filter, XContentFilterFunc func)

Also available in: Unified diff