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
// 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 AutocryptPreferEncrypt;
use InternetAddressMailbox;
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! {
    /// An object containing Autocrypt information about a given e-mail
    /// address, as derived from a message header.
    ///
    /// See https://autocrypt.org/ for details and motivation.
    ///
    /// # Implements
    ///
    /// [`AutocryptHeaderExt`](trait.AutocryptHeaderExt.html)
    pub struct AutocryptHeader(Object<ffi::GMimeAutocryptHeader, ffi::GMimeAutocryptHeaderClass>);

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

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

    /// Creates a new `AutocryptHeader` object based on the value of an
    /// Autocrypt: header.
    ///
    /// Note that this will not have an `effective_date` set, since the
    /// `effective_date` is derived from the Date: line in the same block of
    /// e-mail headers, but cannot be extracted from the raw Autocrypt:
    /// header itself.
    /// ## `string`
    /// The raw string value of an Autocrypt header
    ///
    /// # Returns
    ///
    /// a new `AutocryptHeader` object, or
    /// `None` on error.
    pub fn new_from_string(string: &str) -> AutocryptHeader {
        unsafe {
            from_glib_full(ffi::g_mime_autocrypt_header_new_from_string(string.to_glib_none().0))
        }
    }
}

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

/// Trait containing all `AutocryptHeader` methods.
///
/// # Implementors
///
/// [`AutocryptHeader`](struct.AutocryptHeader.html)
pub trait AutocryptHeaderExt {
    /// If address and type already match between `src` and `self`, copy
    /// keydata, prefer_encrypt, effective_date from `src` to `self`.
    /// ## `src`
    /// a `AutocryptHeader` object
    fn clone(&self, src: &AutocryptHeader);

    /// Gets the internal address of the Autocrypt header, or `None` if not set.
    ///
    /// # Returns
    ///
    /// the address associated with the Autocrypt header
    fn get_address(&self) -> Option<InternetAddressMailbox>;

    /// Gets the internal address of the Autocrypt header as a C string, or `None` if not set.
    ///
    /// # Returns
    ///
    /// the address associated with the Autocrypt header
    fn get_address_as_string(&self) -> Option<String>;

    /// Gets the effective date of the Autocrypt header, or `None` if not set.
    ///
    /// # Returns
    ///
    /// the effective date associated with the Autocrypt header
    fn get_effective_date(&self) -> Option<glib::DateTime>;

    /// Gets the raw keydata of the Autocrypt header, or `None` if not set.
    ///
    /// # Returns
    ///
    /// the raw key data associated with the Autocrypt header
    fn get_keydata(&self) -> Option<glib::Bytes>;

    /// Gets the encryption preference stated by the Autocrypt header.
    ///
    /// # Returns
    ///
    /// the encryption preference associated with the Autocrypt header
    fn get_prefer_encrypt(&self) -> AutocryptPreferEncrypt;

    /// When dealing with Autocrypt headers derived from a message, some
    /// sender addresses will not have a legitimate/complete header
    /// associated with them. When a given sender address has no complete
    /// header of a specific type, it should "reset" the state of the
    /// associated address.
    ///
    /// # Returns
    ///
    /// `true` if the header is complete, or `false` if it is incomplete.
    fn is_complete(&self) -> bool;

    /// Set the address associated with the autocrypt_header.
    /// ## `address`
    /// a `InternetAddressMailbox` value
    fn set_address(&self, address: &InternetAddressMailbox);

    /// Set the address associated with the autocrypt_header.
    /// ## `address`
    /// a `None`-terminated string that is a raw e-mail address
    fn set_address_from_string(&self, address: &str);

    /// Set the effective date associated with the Autocrypt header.
    /// ## `effective_date`
    /// a `glib::DateTime` object
    fn set_effective_date(&self, effective_date: &glib::DateTime);

    /// Set the raw key data associated with the Autocrypt header.
    fn set_keydata(&self, data: &glib::Bytes);

    /// Set the encryption preference associated with the Autocrypt header.
    /// ## `pref`
    /// a `AutocryptPreferEncrypt` value
    fn set_prefer_encrypt(&self, pref: AutocryptPreferEncrypt);

    /// Gets the string representation of the Autocrypt header, or `None` on
    /// error. For example, it might return:
    ///
    ///  prefer-encrypt=mutual; addr=bob\@example.com; keydata=AAAB15BE...
    ///
    /// If you are using this object to populate an Autocrypt-Gossip
    /// header, you should set `gossip` to `true` (this will suppress
    /// inclusion of prefer-encrypt).
    /// ## `gossip`
    /// a `gboolean`, indicating whether this header is for use with gossip
    ///
    /// # Returns
    ///
    /// the string representation of the
    /// Autocrypt header.
    fn to_string(&self, gossip: bool) -> String;
}

impl<O: IsA<AutocryptHeader>> AutocryptHeaderExt for O {
    fn clone(&self, src: &AutocryptHeader) {
        unsafe {
            ffi::g_mime_autocrypt_header_clone(self.to_glib_none().0, src.to_glib_none().0);
        }
    }

    fn get_address(&self) -> Option<InternetAddressMailbox> {
        unsafe {
            from_glib_none(ffi::g_mime_autocrypt_header_get_address(self.to_glib_none().0))
        }
    }

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

    fn get_effective_date(&self) -> Option<glib::DateTime> {
        unsafe {
            from_glib_none(ffi::g_mime_autocrypt_header_get_effective_date(self.to_glib_none().0))
        }
    }

    fn get_keydata(&self) -> Option<glib::Bytes> {
        unsafe {
            from_glib_none(ffi::g_mime_autocrypt_header_get_keydata(self.to_glib_none().0))
        }
    }

    fn get_prefer_encrypt(&self) -> AutocryptPreferEncrypt {
        unsafe {
            from_glib(ffi::g_mime_autocrypt_header_get_prefer_encrypt(self.to_glib_none().0))
        }
    }

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

    fn set_address(&self, address: &InternetAddressMailbox) {
        unsafe {
            ffi::g_mime_autocrypt_header_set_address(self.to_glib_none().0, address.to_glib_none().0);
        }
    }

    fn set_address_from_string(&self, address: &str) {
        unsafe {
            ffi::g_mime_autocrypt_header_set_address_from_string(self.to_glib_none().0, address.to_glib_none().0);
        }
    }

    fn set_effective_date(&self, effective_date: &glib::DateTime) {
        unsafe {
            ffi::g_mime_autocrypt_header_set_effective_date(self.to_glib_none().0, effective_date.to_glib_none().0);
        }
    }

    fn set_keydata(&self, data: &glib::Bytes) {
        unsafe {
            ffi::g_mime_autocrypt_header_set_keydata(self.to_glib_none().0, data.to_glib_none().0);
        }
    }

    fn set_prefer_encrypt(&self, pref: AutocryptPreferEncrypt) {
        unsafe {
            ffi::g_mime_autocrypt_header_set_prefer_encrypt(self.to_glib_none().0, pref.to_glib());
        }
    }

    fn to_string(&self, gossip: bool) -> String {
        unsafe {
            from_glib_full(ffi::g_mime_autocrypt_header_to_string(self.to_glib_none().0, gossip.to_glib()))
        }
    }
}