summaryrefslogtreecommitdiffstats
path: root/perl/Rspamd/Part.xs
blob: 5401a1e08d5c7a4fa23d8f1595c24e5101d14c1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
MODULE = Mail::Rspamd PACKAGE = Mail::Rspamd::Part PREFIX = rspamd_part

Mail::Rspamd::Part
g_mime_part_new (Class = "Mail::Rspamd::Part", type = "text", subtype = "plain")
		char *		Class;
		const char *		type;
		const char *		subtype;
	CODE:
		RETVAL = g_mime_part_new_with_type (type, subtype);
		plist = g_list_prepend (plist, RETVAL);
	OUTPUT:
		RETVAL

void
DESTROY (mime_part)
		Mail::Rspamd::Part	mime_part
	CODE:
		if (g_list_find (plist,mime_part)) {
			g_object_unref (G_OBJECT (mime_part));
			plist = g_list_remove (plist, mime_part);
		}

void
interface_p_set(mime_part, value)
	Mail::Rspamd::Part	mime_part
	char *				value
	INTERFACE_MACRO:
	XSINTERFACE_FUNC
	XSINTERFACE_FUNC_RSPAMD_PART_SET
	INTERFACE:
	set_content_description
	set_content_md5
	set_content_location
	set_filename


const char *
interface_p_get(mime_part)
	Mail::Rspamd::Part	mime_part
	INTERFACE_MACRO:
	XSINTERFACE_FUNC
	XSINTERFACE_FUNC_RSPAMD_PART_SET
	INTERFACE:
	get_content_description
	get_content_md5
	get_content_location
	get_filename

#if !defined(GMIME24)

void
rspamd_part_set_content_header (mime_part, field, value)
		Mail::Rspamd::Part	mime_part
		const char *		field
		const char *		value
	CODE:
		g_mime_part_set_content_header (mime_part, field, value);

const char *
rspamd_part_get_content_header (mime_part, field)
		Mail::Rspamd::Part	mime_part
		const char *		field
	CODE:
		RETVAL = g_mime_part_get_content_header (mime_part, field);
	OUTPUT:
		RETVAL

#endif

void
rspamd_part_set_content_type (mime_part, content_type)
		Mail::Rspamd::Part		mime_part
		Mail::Rspamd::ContentType	content_type
	CODE:
		g_mime_part_set_content_type (mime_part, content_type);
		plist = g_list_remove (plist, content_type);


void
rspamd_part_set_encoding (mime_part, encoding)
		Mail::Rspamd::Part			mime_part
		Mail::Rspamd::PartEncodingType		encoding
	CODE:
		g_mime_part_set_encoding (mime_part, encoding);

Mail::Rspamd::PartEncodingType
rspamd_part_get_encoding (mime_part)
		Mail::Rspamd::Part	mime_part
	CODE:
		RETVAL = g_mime_part_get_encoding (mime_part);
	OUTPUT:
		RETVAL

const char *
rspamd_part_encoding_to_string (encoding)
		Mail::Rspamd::PartEncodingType		encoding
	PREINIT:
	CODE:
#ifdef GMIME24
		RETVAL = g_mime_content_encoding_to_string (encoding);
#else
		RETVAL = g_mime_part_encoding_to_string (encoding);
#endif
	OUTPUT:
		RETVAL

Mail::Rspamd::PartEncodingType
rspamd_part_encoding_from_string (encoding)
		const char *		encoding
	CODE:
#ifdef GMIME24
		RETVAL = g_mime_content_encoding_from_string (encoding);
#else
		RETVAL = g_mime_part_encoding_from_string (encoding);
#endif
	OUTPUT:
		RETVAL

void
rspamd_part_add_content_disposition_parameter (mime_part, name, value)
		Mail::Rspamd::Part	mime_part
		const char *		name
		const char *		value
	CODE:
#ifdef GMIME24
		g_mime_object_add_content_disposition_parameter (GMIME_OBJECT (mime_part), name, value);
#else
		g_mime_part_add_content_disposition_parameter (mime_part, name, value);
#endif

const char *
rspamd_part_get_content_disposition_parameter (mime_part, name)
		Mail::Rspamd::Part	mime_part
		const char *		name
	CODE:
#ifdef GMIME24
		RETVAL = g_mime_object_get_content_disposition_parameter (GMIME_OBJECT (mime_part), name);
#else
		RETVAL = g_mime_part_get_content_disposition_parameter (mime_part, name);
#endif
	OUTPUT:
		RETVAL


void
rspamd_part_set_pre_encoded_content(mime_part, content, encoding)
		Mail::Rspamd::Part	mime_part
		SV *		content
		Mail::Rspamd::PartEncodingType	encoding
	PREINIT:
		char *	data;
		STRLEN	len;
	CODE:
		data = SvPV (content, len);
		g_mime_part_set_pre_encoded_content (mime_part, data, len, encoding);


SV *
rspamd_part_get_content(mime_part)
		Mail::Rspamd::Part	mime_part
	PREINIT:
#ifdef GMIME24
		GMimeDataWrapper *wrapper;
        GMimeStream *part_stream;
        GByteArray *part_content;
#else
		guint len;
		const char * content_char;
#endif
		SV * content;
	CODE:
		ST(0) = &PL_sv_undef;
#ifdef GMIME24
		if (!(mime_part->content) || !(mime_part->content->stream) ||
			 (wrapper = g_mime_part_get_content_object (mime_part)) == NULL) {
#else
		if (!(mime_part->content) || !(mime_part->content->stream) ||
			 (content_char = g_mime_part_get_content (mime_part, &len)) == NULL) {
#endif
			return;
		}
		content = sv_newmortal ();
		SvUPGRADE (content, SVt_PV);
		SvREADONLY_on (content);
#ifdef GMIME24
		part_stream = g_mime_stream_mem_new ();
		g_mime_data_wrapper_write_to_stream (wrapper, part_stream);
		part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (part_stream));
		SvPVX(content) = (char *) (part_content->data);
		SvCUR_set (content, part_content->len);
#else
		SvPVX(content) = (char *) (content_char);
		SvCUR_set (content, len);
#endif
		SvLEN_set (content, 0);
		SvPOK_only (content);
		ST(0) = content;