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
// 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 ParamList;
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 data structure representing a Content-Disposition.
    ///
    /// # Implements
    ///
    /// [`ContentDispositionExt`](trait.ContentDispositionExt.html)
    pub struct ContentDisposition(Object<ffi::GMimeContentDisposition, ffi::GMimeContentDispositionClass>);

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

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

    /// Parses the input string into a `ContentDisposition` object.
    /// ## `options`
    /// a `ParserOptions` or `None`
    /// ## `str`
    /// Content-Disposition field value
    ///
    /// # Returns
    ///
    /// a new `ContentDisposition` object.
    pub fn parse<'a, P: Into<Option<&'a ParserOptions>>>(options: P, str: &str) -> Option<ContentDisposition> {
        let options = options.into();
        unsafe {
            from_glib_full(ffi::g_mime_content_disposition_parse(mut_override(options.to_glib_none().0), str.to_glib_none().0))
        }
    }
}

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

/// Trait containing all `ContentDisposition` methods.
///
/// # Implementors
///
/// [`ContentDisposition`](struct.ContentDisposition.html)
pub trait ContentDispositionExt {
    /// Encodes the Content-Disposition header.
    /// ## `options`
    /// a `FormatOptions` or `None`
    ///
    /// # Returns
    ///
    /// a new string containing the encoded header value.
    fn encode<'a, P: Into<Option<&'a FormatOptions>>>(&self, options: P) -> Option<String>;

    /// Gets the disposition or `None` on fail.
    ///
    /// # Returns
    ///
    /// the disposition string which is probably one of
    /// `GMIME_DISPOSITION_ATTACHMENT` or `GMIME_DISPOSITION_INLINE`.
    fn get_disposition(&self) -> Option<String>;

    /// Gets the parameter value specified by `name` if it's available.
    /// ## `name`
    /// parameter name
    ///
    /// # Returns
    ///
    /// the value of the requested parameter or `None` if the
    /// parameter is not set. If the parameter is set, the returned string
    /// will be in UTF-8.
    fn get_parameter(&self, name: &str) -> Option<String>;

    /// Gets the Content-Disposition parameter list.
    ///
    /// # Returns
    ///
    /// the Content-Disposition's parameter list.
    fn get_parameters(&self) -> Option<ParamList>;

    /// Determines if a Content-Disposition has a value of "attachment".
    ///
    /// # Returns
    ///
    /// `true` if the value matches "attachment", otherwise `false`.
    fn is_attachment(&self) -> bool;

    /// Sets the disposition to `value` 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.
    /// ## `value`
    /// disposition value
    fn set_disposition(&self, value: &str);

    /// Sets a parameter on the Content-Disposition.
    ///
    /// Note: The `name` should be in US-ASCII while the `value` should be in
    /// UTF-8.
    /// ## `name`
    /// parameter name
    /// ## `value`
    /// parameter value
    fn set_parameter(&self, name: &str, value: &str);
}

impl<O: IsA<ContentDisposition>> ContentDispositionExt for O {
    fn encode<'a, P: Into<Option<&'a FormatOptions>>>(&self, options: P) -> Option<String> {
        let options = options.into();
        unsafe {
            from_glib_full(ffi::g_mime_content_disposition_encode(self.to_glib_none().0, mut_override(options.to_glib_none().0)))
        }
    }

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

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

    fn get_parameters(&self) -> Option<ParamList> {
        unsafe {
            from_glib_none(ffi::g_mime_content_disposition_get_parameters(self.to_glib_none().0))
        }
    }

    fn is_attachment(&self) -> bool {
        unsafe {
            from_glib(ffi::g_mime_content_disposition_is_attachment(self.to_glib_none().0))
        }
    }

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

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