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
//! 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>>>;
}
);