objc2-mail-kit 0.3.2

Bindings to the MailKit framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

extern_class!(
    /// An instance of this class is associated with the lifecycle of a single mail compose window. This object associates the actions performed by the user in a mail compose window to a unique session. An instance of this class is passed to the methods in
    /// `MEComposeSessionHandler.`
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/mailkit/mecomposesession?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct MEComposeSession;
);

extern_conformance!(
    unsafe impl NSCoding for MEComposeSession {}
);

extern_conformance!(
    unsafe impl NSObjectProtocol for MEComposeSession {}
);

extern_conformance!(
    unsafe impl NSSecureCoding for MEComposeSession {}
);

impl MEComposeSession {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        /// A unique identifier for the session.
        #[unsafe(method(sessionID))]
        #[unsafe(method_family = none)]
        pub unsafe fn sessionID(&self) -> Retained<NSUUID>;

        #[cfg(feature = "MEMessage")]
        /// An instance of
        /// `MEMessage`that represents properties of the mail message that author is composing in this
        /// `MEComposeSession`
        #[unsafe(method(mailMessage))]
        #[unsafe(method_family = none)]
        pub unsafe fn mailMessage(&self) -> Retained<MEMessage>;

        #[cfg(feature = "MEComposeContext")]
        /// An instance of
        /// `MEComposeContext`that provides additional information about the compose session.
        #[unsafe(method(composeContext))]
        #[unsafe(method_family = none)]
        pub unsafe fn composeContext(&self) -> Retained<MEComposeContext>;

        /// Requests Mail to refresh compose session with new information that the extension has.
        ///
        /// Extensions can use this call this method to regenerate
        /// `MEAddressAnnotation`instances to replace those that were previously generated for this session. This will result in invocations to
        /// `-[MEComposeSessionHandler``session:annotateAddressesWithCompletionHandler:].`
        #[unsafe(method(reloadSession))]
        #[unsafe(method_family = none)]
        pub unsafe fn reloadSession(&self);
    );
}

extern "C" {
    /// Error domain and codes for extensions to report errors before message is delivered.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/mailkit/mecomposesessionerrordomain?language=objc)
    pub static MEComposeSessionErrorDomain: &'static NSErrorDomain;
}

/// [Apple's documentation](https://developer.apple.com/documentation/mailkit/mecomposesessionerrorcode?language=objc)
// NS_ERROR_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MEComposeSessionErrorCode(pub NSInteger);
impl MEComposeSessionErrorCode {
    #[doc(alias = "MEComposeSessionErrorCodeInvalidRecipients")]
    pub const InvalidRecipients: Self = Self(0);
    #[doc(alias = "MEComposeSessionErrorCodeInvalidHeaders")]
    pub const InvalidHeaders: Self = Self(1);
    #[doc(alias = "MEComposeSessionErrorCodeInvalidBody")]
    pub const InvalidBody: Self = Self(2);
}

unsafe impl Encode for MEComposeSessionErrorCode {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for MEComposeSessionErrorCode {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_protocol!(
    /// Methods in this protocol can be used by a mail app extension to keep track of new messages composed by the user and to make changes to the recipeint email address tokens.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/mailkit/mecomposesessionhandler?language=objc)
    pub unsafe trait MEComposeSessionHandler: NSObjectProtocol + MainThreadOnly {
        /// This is invoked when a new message compose window is created.
        ///
        /// Parameter `session`: -
        /// `MEComposeSession`instance that is tied to the compose window that is opened.
        #[unsafe(method(mailComposeSessionDidBegin:))]
        #[unsafe(method_family = none)]
        unsafe fn mailComposeSessionDidBegin(&self, session: &MEComposeSession);

        /// This is invoked when a message compose window is closed.
        ///
        /// Parameter `session`: -
        /// `MEComposeSession`instance that is tied to the compose window that was closed.
        #[unsafe(method(mailComposeSessionDidEnd:))]
        #[unsafe(method_family = none)]
        unsafe fn mailComposeSessionDidEnd(&self, session: &MEComposeSession);

        #[cfg(all(feature = "MEExtensionViewController", feature = "objc2-app-kit"))]
        /// A view controller to be presented in Mail compose window.
        ///
        /// Mail will call this method when user clicks on the extension's button.
        #[unsafe(method(viewControllerForSession:))]
        #[unsafe(method_family = none)]
        unsafe fn viewControllerForSession(
            &self,
            session: &MEComposeSession,
        ) -> Retained<MEExtensionViewController>;

        #[cfg(all(
            feature = "MEAddressAnnotation",
            feature = "MEEmailAddress",
            feature = "block2"
        ))]
        /// Delegate method to annotate mail addresses.
        ///
        /// Mail will call this method based on user's input in To, Cc or Bcc fields.
        #[optional]
        #[unsafe(method(session:annotateAddressesWithCompletionHandler:))]
        #[unsafe(method_family = none)]
        unsafe fn session_annotateAddressesWithCompletionHandler(
            &self,
            session: &MEComposeSession,
            completion_handler: &block2::DynBlock<
                dyn Fn(NonNull<NSDictionary<MEEmailAddress, MEAddressAnnotation>>),
            >,
        );

        #[cfg(feature = "block2")]
        /// Validate if the message is ready to be delivered to recipients.
        ///
        /// Mail will call this method when user clicks on the send message button. Extensions can provide an error from the
        /// `MEComposeSessionErrorDomain`error domain to indicate why message validation has failed.
        #[optional]
        #[unsafe(method(session:canSendMessageWithCompletionHandler:))]
        #[unsafe(method_family = none)]
        unsafe fn session_canSendMessageWithCompletionHandler(
            &self,
            session: &MEComposeSession,
            completion: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        /// Set Additional headers on outgoing mail message.
        ///
        /// Mail will call this method to request additional headers to be set on the
        /// `MEMessage`that user is composing as part of this
        /// `MEComposeSession.`Keys in this dictionary will be normalized to lowercase before they are set on the message.
        #[optional]
        #[unsafe(method(additionalHeadersForSession:))]
        #[unsafe(method_family = none)]
        unsafe fn additionalHeadersForSession(
            &self,
            session: &MEComposeSession,
        ) -> Retained<NSDictionary<NSString, NSArray<NSString>>>;
    }
);