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
// 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 Filter;
use NewLineFormat;
use ParamEncodingMethod;
use ffi;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use std::mem;
use std::ptr;

glib_wrapper! {
    /// Format options for serializing various GMime objects.
    pub struct FormatOptions(Boxed<ffi::GMimeFormatOptions>);

    match fn {
        copy => |ptr| gobject_ffi::g_boxed_copy(ffi::g_mime_format_options_get_type(), ptr as *mut _) as *mut ffi::GMimeFormatOptions,
        free => |ptr| gobject_ffi::g_boxed_free(ffi::g_mime_format_options_get_type(), ptr as *mut _),
        get_type => || ffi::g_mime_format_options_get_type(),
    }
}

impl FormatOptions {
    /// Creates a new set of `FormatOptions`.
    ///
    /// # Returns
    ///
    /// a newly allocated set of `FormatOptions` with the default values.
    pub fn new() -> FormatOptions {
        unsafe {
            from_glib_full(ffi::g_mime_format_options_new())
        }
    }

    /// Adds the given header to the list of headers that should be hidden.
    /// ## `header`
    /// a header name
    pub fn add_hidden_header(&mut self, header: &str) {
        unsafe {
            ffi::g_mime_format_options_add_hidden_header(self.to_glib_none_mut().0, header.to_glib_none().0);
        }
    }

    /// Clears the list of headers that should be hidden.
    pub fn clear_hidden_headers(&mut self) {
        unsafe {
            ffi::g_mime_format_options_clear_hidden_headers(self.to_glib_none_mut().0);
        }
    }

    /// Clones a `FormatOptions`.
    ///
    /// # Returns
    ///
    /// a newly allocated `FormatOptions`.
    pub fn clone(&mut self) -> Option<FormatOptions> {
        unsafe {
            from_glib_full(ffi::g_mime_format_options_clone(self.to_glib_none_mut().0))
        }
    }

    /// Creates a `Filter` suitable for converting line-endings to the
    /// currently set new-line format.
    /// ## `ensure_newline`
    /// `true` if the output must *always* end with a new line
    ///
    /// # Returns
    ///
    /// a `Filter` to convert to the specified new-line format.
    pub fn create_newline_filter(&mut self, ensure_newline: bool) -> Option<Filter> {
        unsafe {
            from_glib_full(ffi::g_mime_format_options_create_newline_filter(self.to_glib_none_mut().0, ensure_newline.to_glib()))
        }
    }

    /// Gets a string representing the currently set new-line format.
    ///
    /// # Returns
    ///
    /// a new-line character sequence.
    pub fn get_newline(&mut self) -> Option<String> {
        unsafe {
            from_glib_none(ffi::g_mime_format_options_get_newline(self.to_glib_none_mut().0))
        }
    }

    /// Gets the new-line format to use when writing out messages and headers.
    ///
    /// # Returns
    ///
    /// the new-line format that is currently set.
    pub fn get_newline_format(&mut self) -> NewLineFormat {
        unsafe {
            from_glib(ffi::g_mime_format_options_get_newline_format(self.to_glib_none_mut().0))
        }
    }

    /// Gets the parameter encoding method to use for `Param` parameters that do not
    /// already have an encoding method specified.
    ///
    /// # Returns
    ///
    /// the encoding method that is currently set.
    pub fn get_param_encoding_method(&mut self) -> ParamEncodingMethod {
        unsafe {
            from_glib(ffi::g_mime_format_options_get_param_encoding_method(self.to_glib_none_mut().0))
        }
    }

    /// Gets whether or not the specified header should be hidden.
    /// ## `header`
    /// the name of a header
    ///
    /// # Returns
    ///
    /// `true` if the header should be hidden or `false` otherwise.
    pub fn is_hidden_header(&mut self, header: &str) -> bool {
        unsafe {
            from_glib(ffi::g_mime_format_options_is_hidden_header(self.to_glib_none_mut().0, header.to_glib_none().0))
        }
    }

    /// Removes the given header from the list of headers that should be hidden.
    /// ## `header`
    /// a header name
    pub fn remove_hidden_header(&mut self, header: &str) {
        unsafe {
            ffi::g_mime_format_options_remove_hidden_header(self.to_glib_none_mut().0, header.to_glib_none().0);
        }
    }

    /// Sets the new-line format that should be used when writing headers and messages.
    /// ## `newline`
    /// a `NewLineFormat`
    pub fn set_newline_format(&mut self, newline: NewLineFormat) {
        unsafe {
            ffi::g_mime_format_options_set_newline_format(self.to_glib_none_mut().0, newline.to_glib());
        }
    }

    /// Sets the parameter encoding method to use when encoding parameters which
    /// do not have an encoding method specified.
    ///
    /// Note: `ParamEncodingMethod::Default` is not allowed.
    /// ## `method`
    /// a `ParamEncodingMethod`
    pub fn set_param_encoding_method(&mut self, method: ParamEncodingMethod) {
        unsafe {
            ffi::g_mime_format_options_set_param_encoding_method(self.to_glib_none_mut().0, method.to_glib());
        }
    }

    /// Gets the default format options.
    ///
    /// # Returns
    ///
    /// the default format options.
    pub fn get_default() -> Option<FormatOptions> {
        unsafe {
            from_glib_full(ffi::g_mime_format_options_get_default())
        }
    }
}

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