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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
// This file was generated by gir (https://github.com/gtk-rs/gir @ fe7a6ff+)
// from gir-files (https://github.com/gtk-rs/gir-files @ b215ee8)
// DO NOT EDIT

use FormatOptions;
use InternetAddress;
use ParserOptions;
use ffi;
use glib::object::IsA;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use std::mem;
use std::ptr;

glib_wrapper! {
    /// A collection of `InternetAddress` objects.
    ///
    /// # Implements
    ///
    /// [`InternetAddressListExt`](trait.InternetAddressListExt.html)
    pub struct InternetAddressList(Object<ffi::InternetAddressList, ffi::InternetAddressListClass>);

    match fn {
        get_type => || ffi::internet_address_list_get_type(),
    }
}

impl InternetAddressList {
    /// Creates a new `InternetAddressList`.
    ///
    /// # Returns
    ///
    /// a new `InternetAddressList`.
    pub fn new() -> InternetAddressList {
        unsafe {
            from_glib_full(ffi::internet_address_list_new())
        }
    }

    /// Construct a list of internet addresses from the given string.
    /// ## `options`
    /// a `ParserOptions` or `None`
    /// ## `str`
    /// a string containing internet addresses
    ///
    /// # Returns
    ///
    /// a `InternetAddressList` or `None` if the
    /// input string does not contain any addresses.
    pub fn parse<'a, P: Into<Option<&'a ParserOptions>>>(options: P, str: &str) -> Option<InternetAddressList> {
        let options = options.into();
        unsafe {
            from_glib_full(ffi::internet_address_list_parse(mut_override(options.to_glib_none().0), str.to_glib_none().0))
        }
    }
}

impl Default for InternetAddressList {
    fn default() -> Self {
        Self::new()
    }
}

/// Trait containing all `InternetAddressList` methods.
///
/// # Implementors
///
/// [`InternetAddressList`](struct.InternetAddressList.html)
pub trait InternetAddressListExt {
    /// Adds an `InternetAddress` to the `InternetAddressList`.
    /// ## `ia`
    /// a `InternetAddress`
    ///
    /// # Returns
    ///
    /// the index of the added `InternetAddress`.
    fn add<P: IsA<InternetAddress>>(&self, ia: &P) -> i32;

    /// Adds all of the addresses in `append` to `self`.
    /// ## `append`
    /// a `InternetAddressList`
    fn append(&self, append: &InternetAddressList);

    /// Clears the list of addresses.
    fn clear(&self);

    /// Checks whether or not the specified `InternetAddress` is contained
    /// within the `InternetAddressList`.
    /// ## `ia`
    /// a `InternetAddress`
    ///
    /// # Returns
    ///
    /// `true` if the specified `InternetAddress` is contained
    /// within the specified `InternetAddressList` or `false` otherwise.
    fn contains<P: IsA<InternetAddress>>(&self, ia: &P) -> bool;

    //fn encode<'a, P: Into<Option<&'a FormatOptions>>>(&self, options: P, str: /*Ignored*/&mut glib::String);

    /// Gets the `InternetAddress` at the specified index.
    /// ## `index`
    /// index of `InternetAddress` to get
    ///
    /// # Returns
    ///
    /// the `InternetAddress` at the specified
    /// index or `None` if the index is out of range.
    fn get_address(&self, index: i32) -> Option<InternetAddress>;

    /// Gets the index of the specified `InternetAddress` inside the
    /// `InternetAddressList`.
    /// ## `ia`
    /// a `InternetAddress`
    ///
    /// # Returns
    ///
    /// the index of the requested `InternetAddress` within the
    /// `InternetAddressList` or %-1 if it is not contained within the
    /// `InternetAddressList`.
    fn index_of<P: IsA<InternetAddress>>(&self, ia: &P) -> i32;

    /// Inserts an `InternetAddress` into the `InternetAddressList` at the
    /// specified index.
    /// ## `index`
    /// index to insert at
    /// ## `ia`
    /// a `InternetAddress`
    fn insert<P: IsA<InternetAddress>>(&self, index: i32, ia: &P);

    /// Gets the length of the list.
    ///
    /// # Returns
    ///
    /// the number of `InternetAddress` objects in the list.
    fn length(&self) -> i32;

    /// Inserts all of the addresses in `prepend` to the beginning of `self`.
    /// ## `prepend`
    /// a `InternetAddressList`
    fn prepend(&self, prepend: &InternetAddressList);

    /// Removes an `InternetAddress` from the `InternetAddressList`.
    /// ## `ia`
    /// a `InternetAddress`
    ///
    /// # Returns
    ///
    /// `true` if the specified `InternetAddress` was removed or
    /// `false` otherwise.
    fn remove<P: IsA<InternetAddress>>(&self, ia: &P) -> bool;

    /// Removes an `InternetAddress` from the `InternetAddressList` at the
    /// specified index.
    /// ## `index`
    /// index to remove
    ///
    /// # Returns
    ///
    /// `true` if an `InternetAddress` was removed or `false`
    /// otherwise.
    fn remove_at(&self, index: i32) -> bool;

    /// Sets the `InternetAddress` at the specified index to `ia`.
    /// ## `index`
    /// index of `InternetAddress` to set
    /// ## `ia`
    /// a `InternetAddress`
    fn set_address<P: IsA<InternetAddress>>(&self, index: i32, ia: &P);

    /// Allocates a string buffer containing the rfc822 formatted addresses
    /// in `self`.
    /// ## `options`
    /// a `FormatOptions` or `None`
    /// ## `encode`
    /// `true` if the address should be rfc2047 encoded
    ///
    /// # Returns
    ///
    /// a string containing the list of addresses in rfc822
    /// format or `None` if no addresses are contained in the list.
    fn to_string<'a, P: Into<Option<&'a FormatOptions>>>(&self, options: P, encode: bool) -> String;
}

impl<O: IsA<InternetAddressList>> InternetAddressListExt for O {
    fn add<P: IsA<InternetAddress>>(&self, ia: &P) -> i32 {
        unsafe {
            ffi::internet_address_list_add(self.to_glib_none().0, ia.to_glib_none().0)
        }
    }

    fn append(&self, append: &InternetAddressList) {
        unsafe {
            ffi::internet_address_list_append(self.to_glib_none().0, append.to_glib_none().0);
        }
    }

    fn clear(&self) {
        unsafe {
            ffi::internet_address_list_clear(self.to_glib_none().0);
        }
    }

    fn contains<P: IsA<InternetAddress>>(&self, ia: &P) -> bool {
        unsafe {
            from_glib(ffi::internet_address_list_contains(self.to_glib_none().0, ia.to_glib_none().0))
        }
    }

    //fn encode<'a, P: Into<Option<&'a FormatOptions>>>(&self, options: P, str: /*Ignored*/&mut glib::String) {
    //    unsafe { TODO: call ffi::internet_address_list_encode() }
    //}

    fn get_address(&self, index: i32) -> Option<InternetAddress> {
        unsafe {
            from_glib_none(ffi::internet_address_list_get_address(self.to_glib_none().0, index))
        }
    }

    fn index_of<P: IsA<InternetAddress>>(&self, ia: &P) -> i32 {
        unsafe {
            ffi::internet_address_list_index_of(self.to_glib_none().0, ia.to_glib_none().0)
        }
    }

    fn insert<P: IsA<InternetAddress>>(&self, index: i32, ia: &P) {
        unsafe {
            ffi::internet_address_list_insert(self.to_glib_none().0, index, ia.to_glib_none().0);
        }
    }

    fn length(&self) -> i32 {
        unsafe {
            ffi::internet_address_list_length(self.to_glib_none().0)
        }
    }

    fn prepend(&self, prepend: &InternetAddressList) {
        unsafe {
            ffi::internet_address_list_prepend(self.to_glib_none().0, prepend.to_glib_none().0);
        }
    }

    fn remove<P: IsA<InternetAddress>>(&self, ia: &P) -> bool {
        unsafe {
            from_glib(ffi::internet_address_list_remove(self.to_glib_none().0, ia.to_glib_none().0))
        }
    }

    fn remove_at(&self, index: i32) -> bool {
        unsafe {
            from_glib(ffi::internet_address_list_remove_at(self.to_glib_none().0, index))
        }
    }

    fn set_address<P: IsA<InternetAddress>>(&self, index: i32, ia: &P) {
        unsafe {
            ffi::internet_address_list_set_address(self.to_glib_none().0, index, ia.to_glib_none().0);
        }
    }

    fn to_string<'a, P: Into<Option<&'a FormatOptions>>>(&self, options: P, encode: bool) -> String {
        let options = options.into();
        unsafe {
            from_glib_full(ffi::internet_address_list_to_string(self.to_glib_none().0, mut_override(options.to_glib_none().0), encode.to_glib()))
        }
    }
}