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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
// 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 AutocryptHeaderList;
use ContentDisposition;
use ContentType;
use EncodingConstraint;
use FormatOptions;
use HeaderList;
use InternetAddressList;
use ParserOptions;
use Stream;
use ffi;
use glib;
use glib::object::IsA;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use std::mem;
use std::ptr;

glib_wrapper! {
    /// Base class for all MIME parts.
    ///
    /// # Implements
    ///
    /// [`ObjectExt`](trait.ObjectExt.html)
    pub struct Object(Object<ffi::GMimeObject, ffi::GMimeObjectClass>);

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

impl Object {
    /// Performs a lookup of registered `Object` subclasses, registered
    /// using `Object::register_type`, to find an appropriate class
    /// capable of handling MIME parts of the specified Content-Type. If no
    /// class has been registered to handle that type, it looks for a
    /// registered class that can handle `content_type`'s media type. If
    /// that also fails, then it will use the generic part class,
    /// `Part`.
    /// ## `options`
    /// a `ParserOptions` or `None`
    /// ## `content_type`
    /// a `ContentType` object
    ///
    /// # Returns
    ///
    /// an appropriate `Object` registered to handle MIME
    /// parts appropriate for `content_type`.
    pub fn new<'a, P: Into<Option<&'a ParserOptions>>>(options: P, content_type: &ContentType) -> Object {
        let options = options.into();
        unsafe {
            from_glib_full(ffi::g_mime_object_new(mut_override(options.to_glib_none().0), content_type.to_glib_none().0))
        }
    }

    /// Performs a lookup of registered `Object` subclasses, registered
    /// using `Object::register_type`, to find an appropriate class
    /// capable of handling MIME parts of type `type_`/`subtype`. If no class
    /// has been registered to handle that type, it looks for a registered
    /// class that can handle `type_`. If that also fails, then it will use
    /// the generic part class, `Part`.
    /// ## `options`
    /// a `ParserOptions` or `None`
    /// ## `type_`
    /// mime type
    /// ## `subtype`
    /// mime subtype
    ///
    /// # Returns
    ///
    /// an appropriate `Object` registered to handle mime-types
    /// of `type_`/`subtype`.
    pub fn new_type<'a, P: Into<Option<&'a ParserOptions>>>(options: P, type_: &str, subtype: &str) -> Object {
        let options = options.into();
        unsafe {
            from_glib_full(ffi::g_mime_object_new_type(mut_override(options.to_glib_none().0), type_.to_glib_none().0, subtype.to_glib_none().0))
        }
    }

    /// Registers the object type `object_type` for use with the
    /// `Object::new_type` convenience function.
    ///
    /// Note: You may use the wildcard "*" to match any type and/or
    /// subtype.
    /// ## `type_`
    /// mime type
    /// ## `subtype`
    /// mime subtype
    /// ## `object_type`
    /// object type
    pub fn register_type(type_: &str, subtype: &str, object_type: glib::types::Type) {
        unsafe {
            ffi::g_mime_object_register_type(type_.to_glib_none().0, subtype.to_glib_none().0, object_type.to_glib());
        }
    }

    pub fn type_registry_init() {
        unsafe {
            ffi::g_mime_object_type_registry_init();
        }
    }

    pub fn type_registry_shutdown() {
        unsafe {
            ffi::g_mime_object_type_registry_shutdown();
        }
    }
}

/// Trait containing all `Object` methods.
///
/// # Implementors
///
/// [`MessagePart`](struct.MessagePart.html), [`Message`](struct.Message.html), [`Multipart`](struct.Multipart.html), [`Object`](struct.Object.html), [`Part`](struct.Part.html)
pub trait ObjectExt {
    /// Appends a new header to the header list.
    /// ## `header`
    /// header name
    /// ## `value`
    /// header value
    /// ## `charset`
    /// a charset
    fn append_header(&self, header: &str, value: &str, charset: &str);

    /// Calculates and sets the most efficient Content-Transfer-Encoding
    /// for this `Object` and all child parts based on the `constraint`
    /// provided.
    /// ## `constraint`
    /// a `EncodingConstraint`
    fn encode(&self, constraint: EncodingConstraint);

    fn get_autocrypt_headers(&self, effective_date: &glib::DateTime, matchheader: &str, addresses: &InternetAddressList, keep_incomplete: bool) -> Option<AutocryptHeaderList>;

    /// Gets the `ContentDisposition` for the specified MIME object.
    ///
    /// # Returns
    ///
    /// the `ContentDisposition` set on the
    /// MIME object.
    fn get_content_disposition(&self) -> Option<ContentDisposition>;

    /// Gets the value of the Content-Disposition parameter specified by
    /// `name`, or `None` if the parameter does not exist.
    /// ## `name`
    /// parameter name
    ///
    /// # Returns
    ///
    /// the value of the requested content-disposition param or
    /// `None` if the param doesn't exist. If the param is set, the returned
    /// string will be in UTF-8.
    fn get_content_disposition_parameter(&self, name: &str) -> Option<String>;

    /// Gets the Content-Id of the MIME object or NULL if one is not set.
    ///
    /// # Returns
    ///
    /// a const pointer to the Content-Id header.
    fn get_content_id(&self) -> Option<String>;

    /// Gets the `ContentType` object for the given MIME object or
    /// `None` on fail.
    ///
    /// # Returns
    ///
    /// the content-type object for the specified
    /// MIME object.
    fn get_content_type(&self) -> Option<ContentType>;

    /// Gets the value of the content-type param `name` set on the MIME part
    /// `self`.
    /// ## `name`
    /// param name
    ///
    /// # Returns
    ///
    /// the value of the requested content-type param or `None` if
    /// the param doesn't exist. If the param is set, the returned string
    /// will be in UTF-8.
    fn get_content_type_parameter(&self, name: &str) -> Option<String>;

    /// Gets the MIME object's disposition if set or `None` otherwise.
    ///
    /// # Returns
    ///
    /// the disposition string which is probably one of
    /// `GMIME_DISPOSITION_ATTACHMENT` or `GMIME_DISPOSITION_INLINE`.
    fn get_disposition(&self) -> Option<String>;

    /// Gets the value of the first header with the specified name.
    /// ## `header`
    /// header name
    ///
    /// # Returns
    ///
    /// the value of the requested header if it
    /// exists or `None` otherwise.
    fn get_header(&self, header: &str) -> Option<String>;

    /// Get the header list for `self`.
    ///
    /// # Returns
    ///
    /// the `HeaderList` for `self`. Do not
    /// free this pointer when you are done with it.
    fn get_header_list(&self) -> Option<HeaderList>;

    /// Allocates a string buffer containing all of the MIME object's raw
    /// headers.
    /// ## `options`
    /// a `FormatOptions` or `None`
    ///
    /// # Returns
    ///
    /// an allocated string containing all of the raw MIME headers.
    ///
    /// Note: The returned string will not be suitable for display.
    fn get_headers<'a, P: Into<Option<&'a FormatOptions>>>(&self, options: P) -> Option<String>;

    /// Prepends a new header to the header list.
    /// ## `header`
    /// header name
    /// ## `value`
    /// header value
    /// ## `charset`
    /// a charset
    fn prepend_header(&self, header: &str, value: &str, charset: &str);

    /// Removed the specified header if it exists.
    /// ## `header`
    /// header name
    ///
    /// # Returns
    ///
    /// `true` if the header was removed or `false` if it could not
    /// be found.
    fn remove_header(&self, header: &str) -> bool;

    /// Set the content disposition for the specified mime part and then
    /// serializes it to the Content-Disposition header field.
    /// ## `disposition`
    /// a `ContentDisposition` object
    fn set_content_disposition(&self, disposition: &ContentDisposition);

    /// Add a content-disposition parameter to the specified mime part.
    ///
    /// Note: The `name` string should be in US-ASCII while the `value`
    /// string should be in UTF-8.
    /// ## `name`
    /// parameter name
    /// ## `value`
    /// parameter value
    fn set_content_disposition_parameter(&self, name: &str, value: &str);

    /// Sets the Content-Id of the MIME object.
    /// ## `content_id`
    /// content-id (addr-spec portion)
    fn set_content_id(&self, content_id: &str);

    /// Sets the content-type for the specified MIME object and then
    /// serializes it to the Content-Type header field.
    /// ## `content_type`
    /// a `ContentType` object
    fn set_content_type(&self, content_type: &ContentType);

    /// Sets the content-type param `name` to the value `value`.
    ///
    /// Note: The `name` string should be in US-ASCII while the `value`
    /// string should be in UTF-8.
    /// ## `name`
    /// param name
    /// ## `value`
    /// param value
    fn set_content_type_parameter(&self, name: &str, value: &str);

    /// Sets the disposition to `disposition` which may be one of
    /// `GMIME_DISPOSITION_ATTACHMENT` or `GMIME_DISPOSITION_INLINE` or, by
    /// your choice, any other string which would indicate how the MIME
    /// part should be displayed by the MUA.
    /// ## `disposition`
    /// disposition ("attachment" or "inline")
    fn set_disposition(&self, disposition: &str);

    /// Sets a header to the specified value.
    /// ## `header`
    /// header name
    /// ## `value`
    /// header value
    /// ## `charset`
    /// a charset
    fn set_header(&self, header: &str, value: &str, charset: &str);

    /// Allocates a string buffer containing the contents of `self`.
    /// ## `options`
    /// a `FormatOptions` or `None`
    ///
    /// # Returns
    ///
    /// an allocated string containing the contents of the mime
    /// object.
    fn to_string<'a, P: Into<Option<&'a FormatOptions>>>(&self, options: P) -> String;

    /// Write the contents of the MIME object to `stream`.
    /// ## `options`
    /// a `FormatOptions` or `None`
    /// ## `stream`
    /// stream
    ///
    /// # Returns
    ///
    /// the number of bytes written or %-1 on fail.
    fn write_to_stream<'a, P: Into<Option<&'a FormatOptions>>, Q: IsA<Stream>>(&self, options: P, stream: &Q) -> isize;
}

impl<O: IsA<Object>> ObjectExt for O {
    fn append_header(&self, header: &str, value: &str, charset: &str) {
        unsafe {
            ffi::g_mime_object_append_header(self.to_glib_none().0, header.to_glib_none().0, value.to_glib_none().0, charset.to_glib_none().0);
        }
    }

    fn encode(&self, constraint: EncodingConstraint) {
        unsafe {
            ffi::g_mime_object_encode(self.to_glib_none().0, constraint.to_glib());
        }
    }

    fn get_autocrypt_headers(&self, effective_date: &glib::DateTime, matchheader: &str, addresses: &InternetAddressList, keep_incomplete: bool) -> Option<AutocryptHeaderList> {
        unsafe {
            from_glib_none(ffi::g_mime_object_get_autocrypt_headers(self.to_glib_none().0, effective_date.to_glib_none().0, matchheader.to_glib_none().0, addresses.to_glib_none().0, keep_incomplete.to_glib()))
        }
    }

    fn get_content_disposition(&self) -> Option<ContentDisposition> {
        unsafe {
            from_glib_none(ffi::g_mime_object_get_content_disposition(self.to_glib_none().0))
        }
    }

    fn get_content_disposition_parameter(&self, name: &str) -> Option<String> {
        unsafe {
            from_glib_none(ffi::g_mime_object_get_content_disposition_parameter(self.to_glib_none().0, name.to_glib_none().0))
        }
    }

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

    fn get_content_type(&self) -> Option<ContentType> {
        unsafe {
            from_glib_none(ffi::g_mime_object_get_content_type(self.to_glib_none().0))
        }
    }

    fn get_content_type_parameter(&self, name: &str) -> Option<String> {
        unsafe {
            from_glib_none(ffi::g_mime_object_get_content_type_parameter(self.to_glib_none().0, name.to_glib_none().0))
        }
    }

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

    fn get_header(&self, header: &str) -> Option<String> {
        unsafe {
            from_glib_none(ffi::g_mime_object_get_header(self.to_glib_none().0, header.to_glib_none().0))
        }
    }

    fn get_header_list(&self) -> Option<HeaderList> {
        unsafe {
            from_glib_none(ffi::g_mime_object_get_header_list(self.to_glib_none().0))
        }
    }

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

    fn prepend_header(&self, header: &str, value: &str, charset: &str) {
        unsafe {
            ffi::g_mime_object_prepend_header(self.to_glib_none().0, header.to_glib_none().0, value.to_glib_none().0, charset.to_glib_none().0);
        }
    }

    fn remove_header(&self, header: &str) -> bool {
        unsafe {
            from_glib(ffi::g_mime_object_remove_header(self.to_glib_none().0, header.to_glib_none().0))
        }
    }

    fn set_content_disposition(&self, disposition: &ContentDisposition) {
        unsafe {
            ffi::g_mime_object_set_content_disposition(self.to_glib_none().0, disposition.to_glib_none().0);
        }
    }

    fn set_content_disposition_parameter(&self, name: &str, value: &str) {
        unsafe {
            ffi::g_mime_object_set_content_disposition_parameter(self.to_glib_none().0, name.to_glib_none().0, value.to_glib_none().0);
        }
    }

    fn set_content_id(&self, content_id: &str) {
        unsafe {
            ffi::g_mime_object_set_content_id(self.to_glib_none().0, content_id.to_glib_none().0);
        }
    }

    fn set_content_type(&self, content_type: &ContentType) {
        unsafe {
            ffi::g_mime_object_set_content_type(self.to_glib_none().0, content_type.to_glib_none().0);
        }
    }

    fn set_content_type_parameter(&self, name: &str, value: &str) {
        unsafe {
            ffi::g_mime_object_set_content_type_parameter(self.to_glib_none().0, name.to_glib_none().0, value.to_glib_none().0);
        }
    }

    fn set_disposition(&self, disposition: &str) {
        unsafe {
            ffi::g_mime_object_set_disposition(self.to_glib_none().0, disposition.to_glib_none().0);
        }
    }

    fn set_header(&self, header: &str, value: &str, charset: &str) {
        unsafe {
            ffi::g_mime_object_set_header(self.to_glib_none().0, header.to_glib_none().0, value.to_glib_none().0, charset.to_glib_none().0);
        }
    }

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

    fn write_to_stream<'a, P: Into<Option<&'a FormatOptions>>, Q: IsA<Stream>>(&self, options: P, stream: &Q) -> isize {
        let options = options.into();
        unsafe {
            ffi::g_mime_object_write_to_stream(self.to_glib_none().0, mut_override(options.to_glib_none().0), stream.to_glib_none().0)
        }
    }
}