objc2_mail_kit/generated/
MEComposeSession.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10extern_class!(
11    /// 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
12    /// `MEComposeSessionHandler.`
13    ///
14    /// See also [Apple's documentation](https://developer.apple.com/documentation/mailkit/mecomposesession?language=objc)
15    #[unsafe(super(NSObject))]
16    #[derive(Debug, PartialEq, Eq, Hash)]
17    pub struct MEComposeSession;
18);
19
20extern_conformance!(
21    unsafe impl NSCoding for MEComposeSession {}
22);
23
24extern_conformance!(
25    unsafe impl NSObjectProtocol for MEComposeSession {}
26);
27
28extern_conformance!(
29    unsafe impl NSSecureCoding for MEComposeSession {}
30);
31
32impl MEComposeSession {
33    extern_methods!(
34        #[unsafe(method(new))]
35        #[unsafe(method_family = new)]
36        pub unsafe fn new() -> Retained<Self>;
37
38        #[unsafe(method(init))]
39        #[unsafe(method_family = init)]
40        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
41
42        /// A unique identifier for the session.
43        #[unsafe(method(sessionID))]
44        #[unsafe(method_family = none)]
45        pub unsafe fn sessionID(&self) -> Retained<NSUUID>;
46
47        #[cfg(feature = "MEMessage")]
48        /// An instance of
49        /// `MEMessage`that represents properties of the mail message that author is composing in this
50        /// `MEComposeSession`
51        #[unsafe(method(mailMessage))]
52        #[unsafe(method_family = none)]
53        pub unsafe fn mailMessage(&self) -> Retained<MEMessage>;
54
55        #[cfg(feature = "MEComposeContext")]
56        /// An instance of
57        /// `MEComposeContext`that provides additional information about the compose session.
58        #[unsafe(method(composeContext))]
59        #[unsafe(method_family = none)]
60        pub unsafe fn composeContext(&self) -> Retained<MEComposeContext>;
61
62        /// Requests Mail to refresh compose session with new information that the extension has.
63        ///
64        /// Extensions can use this call this method to regenerate
65        /// `MEAddressAnnotation`instances to replace those that were previously generated for this session. This will result in invocations to
66        /// `-[MEComposeSessionHandler``session:annotateAddressesWithCompletionHandler:].`
67        #[unsafe(method(reloadSession))]
68        #[unsafe(method_family = none)]
69        pub unsafe fn reloadSession(&self);
70    );
71}
72
73extern "C" {
74    /// Error domain and codes for extensions to report errors before message is delivered.
75    ///
76    /// See also [Apple's documentation](https://developer.apple.com/documentation/mailkit/mecomposesessionerrordomain?language=objc)
77    pub static MEComposeSessionErrorDomain: &'static NSErrorDomain;
78}
79
80/// [Apple's documentation](https://developer.apple.com/documentation/mailkit/mecomposesessionerrorcode?language=objc)
81// NS_ERROR_ENUM
82#[repr(transparent)]
83#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
84pub struct MEComposeSessionErrorCode(pub NSInteger);
85impl MEComposeSessionErrorCode {
86    #[doc(alias = "MEComposeSessionErrorCodeInvalidRecipients")]
87    pub const InvalidRecipients: Self = Self(0);
88    #[doc(alias = "MEComposeSessionErrorCodeInvalidHeaders")]
89    pub const InvalidHeaders: Self = Self(1);
90    #[doc(alias = "MEComposeSessionErrorCodeInvalidBody")]
91    pub const InvalidBody: Self = Self(2);
92}
93
94unsafe impl Encode for MEComposeSessionErrorCode {
95    const ENCODING: Encoding = NSInteger::ENCODING;
96}
97
98unsafe impl RefEncode for MEComposeSessionErrorCode {
99    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
100}
101
102extern_protocol!(
103    /// 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.
104    ///
105    /// See also [Apple's documentation](https://developer.apple.com/documentation/mailkit/mecomposesessionhandler?language=objc)
106    pub unsafe trait MEComposeSessionHandler: NSObjectProtocol + MainThreadOnly {
107        /// This is invoked when a new message compose window is created.
108        ///
109        /// Parameter `session`: -
110        /// `MEComposeSession`instance that is tied to the compose window that is opened.
111        #[unsafe(method(mailComposeSessionDidBegin:))]
112        #[unsafe(method_family = none)]
113        unsafe fn mailComposeSessionDidBegin(&self, session: &MEComposeSession);
114
115        /// This is invoked when a message compose window is closed.
116        ///
117        /// Parameter `session`: -
118        /// `MEComposeSession`instance that is tied to the compose window that was closed.
119        #[unsafe(method(mailComposeSessionDidEnd:))]
120        #[unsafe(method_family = none)]
121        unsafe fn mailComposeSessionDidEnd(&self, session: &MEComposeSession);
122
123        #[cfg(all(feature = "MEExtensionViewController", feature = "objc2-app-kit"))]
124        /// A view controller to be presented in Mail compose window.
125        ///
126        /// Mail will call this method when user clicks on the extension's button.
127        #[unsafe(method(viewControllerForSession:))]
128        #[unsafe(method_family = none)]
129        unsafe fn viewControllerForSession(
130            &self,
131            session: &MEComposeSession,
132        ) -> Retained<MEExtensionViewController>;
133
134        #[cfg(all(
135            feature = "MEAddressAnnotation",
136            feature = "MEEmailAddress",
137            feature = "block2"
138        ))]
139        /// Delegate method to annotate mail addresses.
140        ///
141        /// Mail will call this method based on user's input in To, Cc or Bcc fields.
142        #[optional]
143        #[unsafe(method(session:annotateAddressesWithCompletionHandler:))]
144        #[unsafe(method_family = none)]
145        unsafe fn session_annotateAddressesWithCompletionHandler(
146            &self,
147            session: &MEComposeSession,
148            completion_handler: &block2::DynBlock<
149                dyn Fn(NonNull<NSDictionary<MEEmailAddress, MEAddressAnnotation>>),
150            >,
151        );
152
153        #[cfg(feature = "block2")]
154        /// Validate if the message is ready to be delivered to recipients.
155        ///
156        /// Mail will call this method when user clicks on the send message button. Extensions can provide an error from the
157        /// `MEComposeSessionErrorDomain`error domain to indicate why message validation has failed.
158        #[optional]
159        #[unsafe(method(session:canSendMessageWithCompletionHandler:))]
160        #[unsafe(method_family = none)]
161        unsafe fn session_canSendMessageWithCompletionHandler(
162            &self,
163            session: &MEComposeSession,
164            completion: &block2::DynBlock<dyn Fn(*mut NSError)>,
165        );
166
167        /// Set Additional headers on outgoing mail message.
168        ///
169        /// Mail will call this method to request additional headers to be set on the
170        /// `MEMessage`that user is composing as part of this
171        /// `MEComposeSession.`Keys in this dictionary will be normalized to lowercase before they are set on the message.
172        #[optional]
173        #[unsafe(method(additionalHeadersForSession:))]
174        #[unsafe(method_family = none)]
175        unsafe fn additionalHeadersForSession(
176            &self,
177            session: &MEComposeSession,
178        ) -> Retained<NSDictionary<NSString, NSArray<NSString>>>;
179    }
180);