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
// 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 Header;
use ParserOptions;
use Stream;
use ffi;
use glib::object::IsA;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use std::mem;
use std::ptr;

glib_wrapper! {
    /// A list of message or mime-part headers.
    ///
    /// # Implements
    ///
    /// [`HeaderListExt`](trait.HeaderListExt.html)
    pub struct HeaderList(Object<ffi::GMimeHeaderList, ffi::GMimeHeaderListClass>);

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

impl HeaderList {
    /// Creates a new `HeaderList` object.
    /// ## `options`
    /// a `ParserOptions` or `None`
    ///
    /// # Returns
    ///
    /// a new header list object.
    pub fn new<'a, P: Into<Option<&'a ParserOptions>>>(options: P) -> HeaderList {
        let options = options.into();
        unsafe {
            from_glib_full(ffi::g_mime_header_list_new(mut_override(options.to_glib_none().0)))
        }
    }
}

/// Trait containing all `HeaderList` methods.
///
/// # Implementors
///
/// [`HeaderList`](struct.HeaderList.html)
pub trait HeaderListExt {
    /// Appends a header. If `value` is `None`, a space will be set aside for it
    /// (useful for setting the order of headers before values can be
    /// obtained for them) otherwise the header will be unset.
    /// ## `name`
    /// header name
    /// ## `value`
    /// header value
    /// ## `charset`
    /// a charset
    fn append(&self, name: &str, value: &str, charset: &str);

    /// Removes all of the headers from the `HeaderList`.
    fn clear(&self);

    /// Checks whether or not a header exists.
    /// ## `name`
    /// header name
    ///
    /// # Returns
    ///
    /// `true` if the specified header exists or `false` otherwise.
    fn contains(&self, name: &str) -> bool;

    /// Gets the number of headers contained within the header list.
    ///
    /// # Returns
    ///
    /// the number of headers in the header list.
    fn get_count(&self) -> i32;

    /// Gets the first header with the specified name.
    /// ## `name`
    /// header name
    ///
    /// # Returns
    ///
    /// a `Header` for the specified `name`.
    fn get_header(&self, name: &str) -> Option<Header>;

    /// Gets the header at the specified `index` within the list.
    /// ## `index`
    /// the 0-based index of the header
    ///
    /// # Returns
    ///
    /// the header at position `index`.
    fn get_header_at(&self, index: i32) -> Option<Header>;

    /// Prepends a header. If `value` is `None`, a space will be set aside
    /// for it (useful for setting the order of headers before values can
    /// be obtained for them) otherwise the header will be unset.
    /// ## `name`
    /// header name
    /// ## `value`
    /// header value
    /// ## `charset`
    /// a charset
    fn prepend(&self, name: &str, value: &str, charset: &str);

    /// Remove the first instance of the specified header.
    /// ## `name`
    /// header name
    ///
    /// # Returns
    ///
    /// `true` if the header was successfully removed or `false` if
    /// the specified header could not be found.
    fn remove(&self, name: &str) -> bool;

    /// Removes the header at the specified `index` from `self`.
    /// ## `index`
    /// the 0-based index of the header to remove
    fn remove_at(&self, index: i32);

    /// Set the value of the specified header. If `value` is `None` and the
    /// header, `name`, had not been previously set, a space will be set
    /// aside for it (useful for setting the order of headers before values
    /// can be obtained for them) otherwise the header will be unset.
    ///
    /// Note: If there are multiple headers with the specified field name,
    /// the first instance of the header will be replaced and further
    /// instances will be removed.
    /// ## `name`
    /// header name
    /// ## `value`
    /// header value
    /// ## `charset`
    /// a charset
    fn set(&self, name: &str, value: &str, charset: &str);

    /// Allocates a string buffer containing the raw rfc822 headers
    /// contained in `self`.
    /// ## `options`
    /// a `FormatOptions` or `None`
    ///
    /// # Returns
    ///
    /// a string containing the header block.
    fn to_string<'a, P: Into<Option<&'a FormatOptions>>>(&self, options: P) -> String;

    /// Write the headers to a stream.
    /// ## `options`
    /// a `FormatOptions` or `None`
    /// ## `stream`
    /// output 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<HeaderList>> HeaderListExt for O {
    fn append(&self, name: &str, value: &str, charset: &str) {
        unsafe {
            ffi::g_mime_header_list_append(self.to_glib_none().0, name.to_glib_none().0, value.to_glib_none().0, charset.to_glib_none().0);
        }
    }

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

    fn contains(&self, name: &str) -> bool {
        unsafe {
            from_glib(ffi::g_mime_header_list_contains(self.to_glib_none().0, name.to_glib_none().0))
        }
    }

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

    fn get_header(&self, name: &str) -> Option<Header> {
        unsafe {
            from_glib_none(ffi::g_mime_header_list_get_header(self.to_glib_none().0, name.to_glib_none().0))
        }
    }

    fn get_header_at(&self, index: i32) -> Option<Header> {
        unsafe {
            from_glib_none(ffi::g_mime_header_list_get_header_at(self.to_glib_none().0, index))
        }
    }

    fn prepend(&self, name: &str, value: &str, charset: &str) {
        unsafe {
            ffi::g_mime_header_list_prepend(self.to_glib_none().0, name.to_glib_none().0, value.to_glib_none().0, charset.to_glib_none().0);
        }
    }

    fn remove(&self, name: &str) -> bool {
        unsafe {
            from_glib(ffi::g_mime_header_list_remove(self.to_glib_none().0, name.to_glib_none().0))
        }
    }

    fn remove_at(&self, index: i32) {
        unsafe {
            ffi::g_mime_header_list_remove_at(self.to_glib_none().0, index);
        }
    }

    fn set(&self, name: &str, value: &str, charset: &str) {
        unsafe {
            ffi::g_mime_header_list_set(self.to_glib_none().0, name.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_header_list_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_header_list_write_to_stream(self.to_glib_none().0, mut_override(options.to_glib_none().0), stream.to_glib_none().0)
        }
    }
}