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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
// 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 Object;
use ffi;
use glib::object::IsA;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use std::mem;
use std::ptr;

glib_wrapper! {
    /// A base MIME multipart object.
    ///
    /// # Implements
    ///
    /// [`MultipartExt`](trait.MultipartExt.html), [`ObjectExt`](trait.ObjectExt.html)
    pub struct Multipart(Object<ffi::GMimeMultipart, ffi::GMimeMultipartClass>): Object;

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

impl Multipart {
    /// Creates a new MIME multipart object with a default content-type of
    /// multipart/mixed.
    ///
    /// # Returns
    ///
    /// an empty MIME multipart object with a default content-type of
    /// multipart/mixed.
    pub fn new() -> Multipart {
        unsafe {
            from_glib_full(ffi::g_mime_multipart_new())
        }
    }

    /// Creates a new MIME multipart object with a content-type of
    /// multipart/`subtype`.
    /// ## `subtype`
    /// content-type subtype
    ///
    /// # Returns
    ///
    /// an empty MIME multipart object with a content-type of
    /// multipart/`subtype`.
    pub fn new_with_subtype(subtype: &str) -> Multipart {
        unsafe {
            from_glib_full(ffi::g_mime_multipart_new_with_subtype(subtype.to_glib_none().0))
        }
    }
}

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

/// Trait containing all `Multipart` methods.
///
/// # Implementors
///
/// [`MultipartEncrypted`](struct.MultipartEncrypted.html), [`MultipartSigned`](struct.MultipartSigned.html), [`Multipart`](struct.Multipart.html)
pub trait MultipartExt {
    /// Appends a mime part to `self`.
    /// ## `part`
    /// a `Object`
    fn add<P: IsA<Object>>(&self, part: &P);

    /// Removes all subparts from `self`.
    fn clear(&self);

    /// Checks if `part` is contained within `self`.
    /// ## `part`
    /// a `Object`
    ///
    /// # Returns
    ///
    /// `true` if `part` is a subpart of `self` or `false`
    /// otherwise.
    fn contains<P: IsA<Object>>(&self, part: &P) -> bool;

    //fn foreach<P: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(&self, callback: /*Unknown conversion*//*Unimplemented*/ObjectForeachFunc, user_data: P);

    /// Gets the boundary on the multipart. If the internal boundary is
    /// `None`, then an auto-generated boundary will be set on the multipart
    /// and returned.
    ///
    /// # Returns
    ///
    /// the boundary on the multipart.
    fn get_boundary(&self) -> Option<String>;

    /// Gets the number of parts contained within `self`.
    ///
    /// # Returns
    ///
    /// the number of parts contained within `self`.
    fn get_count(&self) -> i32;

    /// Gets the epilogue on the multipart.
    ///
    /// # Returns
    ///
    /// a pointer to the epilogue string on the multipart.
    fn get_epilogue(&self) -> Option<String>;

    /// Gets the part at the specified `index` within the multipart.
    /// ## `index`
    /// the 0-based index of the part
    ///
    /// # Returns
    ///
    /// the part at position `index`.
    fn get_part(&self, index: i32) -> Option<Object>;

    /// Gets the prologue on the multipart.
    ///
    /// # Returns
    ///
    /// a pointer to the prologue string on the multipart.
    fn get_prologue(&self) -> Option<String>;

    /// Gets the mime part with the content-id `content_id` from the
    /// multipart `self`.
    /// ## `content_id`
    /// the content id of the part to look for
    ///
    /// # Returns
    ///
    /// the `Object` whose content-id matches
    /// the search string, or `None` if a match cannot be found.
    fn get_subpart_from_content_id(&self, content_id: &str) -> Option<Object>;

    /// Gets the 0-based index of `part` within `self`.
    /// ## `part`
    /// a `Object`
    ///
    /// # Returns
    ///
    /// the 0-based index of `part` within `self` or %-1 if not found.
    fn index_of<P: IsA<Object>>(&self, part: &P) -> i32;

    /// Inserts `part` into `self` at the specified `index`.
    /// ## `index`
    /// the 0-based index to insert the part
    /// ## `part`
    /// a `Object`
    fn insert<P: IsA<Object>>(&self, index: i32, part: &P);

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

    /// Removes the part at the specified `index` from `self`.
    /// ## `index`
    /// the 0-based index of the part to remove
    ///
    /// # Returns
    ///
    /// the mime part that was removed or `None`
    /// if the part was not contained within the multipart.
    fn remove_at(&self, index: i32) -> Option<Object>;

    /// Replaces the part at the specified `index` within `self` with
    /// `replacement`.
    /// ## `index`
    /// the 0-based index of the part to replace
    /// ## `replacement`
    /// a `Object` to use as the replacement
    ///
    /// # Returns
    ///
    /// the part that was replaced or `None`
    /// if the part was not contained within the multipart.
    fn replace<P: IsA<Object>>(&self, index: i32, replacement: &P) -> Option<Object>;

    /// Sets `boundary` as the boundary on the multipart. If `boundary` is
    /// `None`, then a boundary will be auto-generated for you.
    /// ## `boundary`
    /// boundary or `None` to autogenerate one
    fn set_boundary(&self, boundary: &str);

    /// Sets the epilogue on the multipart.
    /// ## `epilogue`
    /// epilogue
    fn set_epilogue(&self, epilogue: &str);

    /// Sets the prologue on the multipart.
    /// ## `prologue`
    /// prologue
    fn set_prologue(&self, prologue: &str);
}

impl<O: IsA<Multipart>> MultipartExt for O {
    fn add<P: IsA<Object>>(&self, part: &P) {
        unsafe {
            ffi::g_mime_multipart_add(self.to_glib_none().0, part.to_glib_none().0);
        }
    }

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

    fn contains<P: IsA<Object>>(&self, part: &P) -> bool {
        unsafe {
            from_glib(ffi::g_mime_multipart_contains(self.to_glib_none().0, part.to_glib_none().0))
        }
    }

    //fn foreach<P: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(&self, callback: /*Unknown conversion*//*Unimplemented*/ObjectForeachFunc, user_data: P) {
    //    unsafe { TODO: call ffi::g_mime_multipart_foreach() }
    //}

    fn get_boundary(&self) -> Option<String> {
        unsafe {
            from_glib_none(ffi::g_mime_multipart_get_boundary(self.to_glib_none().0))
        }
    }

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

    fn get_epilogue(&self) -> Option<String> {
        unsafe {
            from_glib_none(ffi::g_mime_multipart_get_epilogue(self.to_glib_none().0))
        }
    }

    fn get_part(&self, index: i32) -> Option<Object> {
        unsafe {
            from_glib_none(ffi::g_mime_multipart_get_part(self.to_glib_none().0, index))
        }
    }

    fn get_prologue(&self) -> Option<String> {
        unsafe {
            from_glib_none(ffi::g_mime_multipart_get_prologue(self.to_glib_none().0))
        }
    }

    fn get_subpart_from_content_id(&self, content_id: &str) -> Option<Object> {
        unsafe {
            from_glib_none(ffi::g_mime_multipart_get_subpart_from_content_id(self.to_glib_none().0, content_id.to_glib_none().0))
        }
    }

    fn index_of<P: IsA<Object>>(&self, part: &P) -> i32 {
        unsafe {
            ffi::g_mime_multipart_index_of(self.to_glib_none().0, part.to_glib_none().0)
        }
    }

    fn insert<P: IsA<Object>>(&self, index: i32, part: &P) {
        unsafe {
            ffi::g_mime_multipart_insert(self.to_glib_none().0, index, part.to_glib_none().0);
        }
    }

    fn remove<P: IsA<Object>>(&self, part: &P) -> bool {
        unsafe {
            from_glib(ffi::g_mime_multipart_remove(self.to_glib_none().0, part.to_glib_none().0))
        }
    }

    fn remove_at(&self, index: i32) -> Option<Object> {
        unsafe {
            from_glib_full(ffi::g_mime_multipart_remove_at(self.to_glib_none().0, index))
        }
    }

    fn replace<P: IsA<Object>>(&self, index: i32, replacement: &P) -> Option<Object> {
        unsafe {
            from_glib_full(ffi::g_mime_multipart_replace(self.to_glib_none().0, index, replacement.to_glib_none().0))
        }
    }

    fn set_boundary(&self, boundary: &str) {
        unsafe {
            ffi::g_mime_multipart_set_boundary(self.to_glib_none().0, boundary.to_glib_none().0);
        }
    }

    fn set_epilogue(&self, epilogue: &str) {
        unsafe {
            ffi::g_mime_multipart_set_epilogue(self.to_glib_none().0, epilogue.to_glib_none().0);
        }
    }

    fn set_prologue(&self, prologue: &str) {
        unsafe {
            ffi::g_mime_multipart_set_prologue(self.to_glib_none().0, prologue.to_glib_none().0);
        }
    }
}