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
use Message;
use Object;
use Part;
use ffi;
use glib::object::IsA;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use std::mem;
use std::ptr;

glib_wrapper! {
    /// A message/partial MIME part.
    ///
    /// # Implements
    ///
    /// [`MessagePartialExt`](trait.MessagePartialExt.html), [`PartExt`](trait.PartExt.html), [`ObjectExt`](trait.ObjectExt.html)
    pub struct MessagePartial(Object<ffi::GMimeMessagePartial, ffi::GMimeMessagePartialClass>): Part, Object;

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

impl MessagePartial {
    /// Creates a new MIME message/partial object.
    /// ## `id`
    /// message/partial part id
    /// ## `number`
    /// message/partial part number
    /// ## `total`
    /// total number of message/partial parts
    ///
    /// # Returns
    ///
    /// an empty MIME message/partial object.
    pub fn new(id: &str, number: i32, total: i32) -> MessagePartial {
        unsafe {
            from_glib_full(ffi::g_mime_message_partial_new(id.to_glib_none().0, number, total))
        }
    }

    /// Reconstructs the GMimeMessage from the given message/partial parts
    /// in `partials`.
    /// ## `partials`
    /// an array of message/partial mime parts
    /// ## `num`
    /// the number of elements in `partials`
    ///
    /// # Returns
    ///
    /// a GMimeMessage object on success or `None`
    /// on fail.
    pub fn reconstruct_message(partials: &Vec<MessagePartial>) -> Option<Message> {
        unsafe {
            from_glib_full(ffi::g_mime_message_partial_reconstruct_message(partials.to_glib_none().0, partials.len()))
        }
    }
}

/// Trait containing all `MessagePartial` methods.
///
/// # Implementors
///
/// [`MessagePartial`](struct.MessagePartial.html)
pub trait MessagePartialExt {
    /// Gets the message/partial id parameter value.
    ///
    /// # Returns
    ///
    /// the message/partial id or `None` on fail.
    fn get_id(&self) -> Option<String>;

    /// Gets the message/partial part number.
    ///
    /// # Returns
    ///
    /// the message/partial part number or %-1 on fail.
    fn get_number(&self) -> i32;

    /// Gets the total number of message/partial parts needed to
    /// reconstruct the original message.
    ///
    /// # Returns
    ///
    /// the total number of message/partial parts needed to
    /// reconstruct the original message or -1 on fail.
    fn get_total(&self) -> i32;
}

impl<O: IsA<MessagePartial>> MessagePartialExt for O {
    fn get_id(&self) -> Option<String> {
        unsafe {
            from_glib_none(ffi::g_mime_message_partial_get_id(self.to_glib_none().0))
        }
    }

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

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