aboutsummaryrefslogtreecommitdiffstats
path: root/perl/Rspamd/InternetAddress.xs
blob: 6ccf30ce33e3d60caf83aa618382bb55c6b565b6 (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
MODULE = Mail::Rspamd PACKAGE = Mail::Rspamd::InternetAddress PREFIX = rspamd_internet_address_

Mail::Rspamd::InternetAddress
rspamd_internet_address_new (Class, name, address)
	CASE: items <= 1
		char *		Class
	CODE:
#ifdef GMIME24
		XSRETURN_UNDEF;
#else
		RETVAL = internet_address_new ();
		plist = g_list_prepend (plist, RETVAL);
#endif
	OUTPUT:
		RETVAL
	CASE: items == 2
		char *		Class
		char *		name
	CODE:
#ifdef GMIME24
		RETVAL = internet_address_group_new (name);
#else
		RETVAL = internet_address_new_group (name);
#endif
		plist = g_list_prepend (plist, RETVAL);
	OUTPUT:
		RETVAL
	CASE: items == 3
		char *		Class
		char *		name
		char *		address
	CODE:
#ifdef GMIME24
		RETVAL = internet_address_mailbox_new (name, address);
#else
		RETVAL = internet_address_new_name (name, address);
#endif
		plist = g_list_prepend (plist, RETVAL);
	OUTPUT:
		RETVAL

void
DESTROY(ia)
		Mail::Rspamd::InternetAddress	ia
	CODE:
		if (g_list_find (plist,ia)) {
			internet_address_unref (ia);
			plist = g_list_remove (plist, ia);
		}

AV *
rspamd_internet_address_parse_string (str)
		const char *		str
	PREINIT:
		InternetAddressList *		addrlist;
		AV * 		retav;
		int i;
	CODE:
#ifdef GMIME24
		addrlist = internet_address_list_parse_string (str);
#else
		addrlist = internet_address_parse_string (str);
#endif
		retav = newAV ();
#ifdef GMIME24
		i = internet_address_list_length (addrlist);
		while (i > 0) {
			SV * address = newSViv(0);
			sv_setref_pv (address, "Mail::Rspamd::InternetAddress", (Mail__Rspamd__InternetAddress)internet_address_list_get_address (addrlist, i));
			av_push (retav, address);
			-- i;
		}
#else
		while (addrlist) {
		  SV * address = newSViv (0);
		  sv_setref_pv (address, "Mail::Rspamd::InternetAddress", (Mail__Rspamd__InternetAddress)(addrlist->address));
		  av_push (retav, address);
		  addrlist = addrlist->next;
		}
#endif
		RETVAL = retav;
	OUTPUT:
		RETVAL

#ifdef GMIME24

void
interface_ia_set (ia, value)
		Mail::Rspamd::InternetAddress	ia
	char *				value
	INTERFACE_MACRO:
	XSINTERFACE_FUNC
	XSINTERFACE_FUNC_RSPAMD_IA_SET
	INTERFACE:
	set_name

#else

void
interface_ia_set (ia, value)
		Mail::Rspamd::InternetAddress	ia
	char *				value
	INTERFACE_MACRO:
	XSINTERFACE_FUNC
	XSINTERFACE_FUNC_RSPAMD_IA_SET
	INTERFACE:
	set_name
	set_addr

#endif

SV *
rspamd_internet_address_to_string (ia, encode = TRUE)
		Mail::Rspamd::InternetAddress	ia
		gboolean		encode
	PREINIT:
		char *		textdata;
	CODE:
		textdata = internet_address_to_string (ia, encode);
		if (textdata == NULL) {
			XSRETURN_UNDEF;
		}
		RETVAL = newSVpv (textdata, 0);
	OUTPUT:
		RETVAL

void
rspamd_internet_address_set_group (ia, ...)
		Mail::Rspamd::InternetAddress	ia
	PREINIT:
		Mail__Rspamd__InternetAddress	addr;
		InternetAddressList *		addrlist = NULL;
		int			i;
	CODE:
		if (items < 2) {
	  		XSRETURN_UNDEF;
		}
		for (i = items - 1; i > 0; --i) {
			/* retrieve each address from the perl array */
			if (sv_derived_from (ST (items - i), "Mail::Rspamd::InternetAddress")) {
				IV tmp = SvIV ((SV*)SvRV (ST (items - i)));
				addr = INT2PTR (Mail__Rspamd__InternetAddress, tmp);
			}
			if (addr) {
#ifdef GMIME24
				internet_address_list_add (addrlist, addr);
#else
				internet_address_list_append (addrlist, addr);
#endif
			}
		}
		if (addrlist) {
			internet_address_set_group (ia, addrlist);
		}

void
rspamd_internet_address_add_member (ia, member)
		Mail::Rspamd::InternetAddress	ia
		Mail::Rspamd::InternetAddress	member
	CODE:
		internet_address_add_memeber (ia, member);

Mail::Rspamd::InternetAddressType
rspamd_internet_address_type (ia)
		Mail::Rspamd::InternetAddress	ia
	CODE:
#ifndef GMIME24
		RETVAL = ia->type;
#else
		XSRETURN_UNDEF;
#endif
	OUTPUT:
		RETVAL