aboutsummaryrefslogtreecommitdiffstats
path: root/perl/Rspamd/Object.xs
blob: cf5fffb1152c4ead14da7c3c1525123a4f74d431 (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
MODULE = Mail::Rspamd PACKAGE = Mail::Rspamd::Object PREFIX = rspamd_object_

void
rspamd_object_set_content_type (mime_object, content_type)
		Mail::Rspamd::Object	mime_object
		Mail::Rspamd::ContentType	content_type
	CODE:
		g_mime_object_set_content_type (mime_object, content_type);
		plist = g_list_remove (plist, content_type);

Mail::Rspamd::ContentType
rspamd_object_get_content_type (mime_object)
		Mail::Rspamd::Object	mime_object
	PREINIT:
		char *			textdata;
		GMimeContentType	*ct;
	CODE:
		ct = g_mime_object_get_content_type (mime_object);
		textdata = g_mime_content_type_to_string (ct);
		RETVAL = g_mime_content_type_new_from_string (textdata);
		plist = g_list_prepend (plist, RETVAL);
		g_free (textdata);
	OUTPUT:
		RETVAL

void
rspamd_object_set_content_type_parameter (mime_object, name, value)
		Mail::Rspamd::Object	mime_object
		const char *		name
		const char *		value
	CODE:
		gmime_object_set_content_type_parameter (mime_object, name, value);

const char *
rspamd_object_get_content_type_parameter (mime_object, name)
		Mail::Rspamd::Object	mime_object
		const char *		name
	CODE:
		RETVAL = g_mime_object_get_content_type_parameter (mime_object, name);
	OUTPUT:
		RETVAL

void
rspamd_object_set_content_id (mime_object, content_id)
		Mail::Rspamd::Object	mime_object
		const char *		content_id
	CODE:
		g_mime_object_set_content_id (mime_object, content_id);

const char *
rspamd_object_get_content_id(mime_object)
		Mail::Rspamd::Object	mime_object
	CODE:
		RETVAL = g_mime_object_get_content_id (mime_object);
	OUTPUT:
		RETVAL


void
rspamd_object_add_header (mime_object, field, value)
		Mail::Rspamd::Object	mime_object
		const char *	field
		const char *	value
	CODE:
		g_mime_object_add_header (mime_object, field, value);

void
rspamd_object_set_header (mime_object, field, value)
		Mail::Rspamd::Object	mime_object
		const char *	field
		const char *	value
	CODE:
		g_mime_object_set_header (mime_object, field, value);

const char *
rspamd_object_get_header (mime_object, field)
		Mail::Rspamd::Object	mime_object
		const char *	field
	CODE:
		RETVAL = g_mime_object_get_header (mime_object, field);
	OUTPUT:
		RETVAL

void
rspamd_object_remove_header (mime_object, field)
		Mail::Rspamd::Object	mime_object
		const char *	field
	CODE:
		g_mime_object_remove_header (mime_object, field);

SV *
rspamd_object_get_headers(mime_object)
		Mail::Rspamd::Object	mime_object
	PREINIT:
		char *		textdata;
	CODE:
		textdata = g_mime_object_get_headers(mime_object);
		if (textdata == NULL) {
			XSRETURN_UNDEF;
		}
		RETVAL = newSVpv (textdata, 0);
		g_free (textdata);
	OUTPUT:
		RETVAL

SV *
rspamd_object_to_string(mime_object)
		Mail::Rspamd::Object	mime_object
	PREINIT:
		char *	textdata;
	CODE:
		textdata = g_mime_object_to_string (mime_object);
		if (textdata) {
	  		RETVAL = newSVpv (textdata, 0);
	  		g_free (textdata);
		} else {
	  		XSRETURN_UNDEF;
		}
	OUTPUT:
		RETVAL

guint
rspamd_object_get_content_length(mime_object)
		Mail::Rspamd::Object	mime_object
	PREINIT:
		guint			lsize = 0;
		GMimePart *		mime_part;
	CODE:
		if (mime_object) {
			if (GMIME_IS_PART(mime_object)) { // also MESSAGE_PARTIAL
				mime_part = GMIME_PART(mime_object);
				lsize = (mime_part->content && mime_part->content->stream) ?
							g_mime_stream_length (mime_part->content->stream) : 0; 
				if (lsize) {
#ifdef GMIME24
					GMimeContentEncoding enc;

					enc = _mime_part_get_encoding (mime_part);
					switch (enc) {
				  		case GMIME_CONTENT_ENCODING_BASE64:
							lsize = BASE64_ENCODE_LEN (lsize);
							break;
				  		case GMIME_CONTENT_ENCODING_QUOTEDPRINTABLE:
							lsize = QP_ENCODE_LEN (lsize);
							break;
					}
#else
					GMimePartEncodingType	enc;

					enc = g_mime_part_get_encoding (mime_part);
					switch (enc) {
				  		case GMIME_PART_ENCODING_BASE64:
							lsize = BASE64_ENCODE_LEN (lsize);
							break;
				  		case GMIME_PART_ENCODING_QUOTEDPRINTABLE:
							lsize = QP_ENCODE_LEN (lsize);
							break;
					}
#endif				
				}
			}
		}
		RETVAL = lsize;
	OUTPUT:
		RETVAL