mirror of
https://github.com/flectar/mail.git
synced 2026-11-12 10:15:19 +00:00
feat: report received mail links on stderr
This commit is contained in:
1 parent
ac84d732f8
commit
915743accc
4 files changed
+35
-11
No files matched your search
+27
-7
@@ -105,23 +105,43 @@ pub(super) fn receive_from_macos(app: &AppWindow) {
|
||||
return;
|
||||
};
|
||||
window_controller::activate(&app, None);
|
||||
open(&app, [url]);
|
||||
open(&app, "apple-event", [url]);
|
||||
});
|
||||
}
|
||||
|
||||
/// Open mailto links in the composer as soon as it can take them.
|
||||
pub(super) fn open<S: AsRef<str>>(app: &AppWindow, uris: impl IntoIterator<Item = S>) {
|
||||
let mut unreadable = false;
|
||||
/// Open mailto links in the composer as soon as it can take them. `source`
|
||||
/// says how they arrived ("message", "launch", "forwarded" or
|
||||
/// "apple-event") for the diagnostic line.
|
||||
pub(super) fn open<S: AsRef<str>>(
|
||||
app: &AppWindow,
|
||||
source: &'static str,
|
||||
uris: impl IntoIterator<Item = S>,
|
||||
) {
|
||||
let (mut received, mut unreadable) = (0_usize, 0_usize);
|
||||
LINKS.with(|links| {
|
||||
let mut links = links.borrow_mut();
|
||||
for uri in uris {
|
||||
match mailto::parse(uri.as_ref()) {
|
||||
Some(message) => links.pending.push_back(message),
|
||||
None => unreadable = true,
|
||||
Some(message) => {
|
||||
links.pending.push_back(message);
|
||||
received += 1;
|
||||
}
|
||||
None => unreadable += 1,
|
||||
}
|
||||
}
|
||||
});
|
||||
if unreadable {
|
||||
if received + unreadable > 0 {
|
||||
// Whether a link reached the application, without any of its
|
||||
// content, like the FLECTAR_RENDERER lines.
|
||||
eprintln!(
|
||||
"FLECTAR_MAIL_LINKS {}",
|
||||
serde_json::json!({
|
||||
"event": "received", "source": source,
|
||||
"links": received, "unreadable": unreadable,
|
||||
})
|
||||
);
|
||||
}
|
||||
if unreadable > 0 {
|
||||
app.set_render_status(UiMessage::plain("This email link is too long to open."));
|
||||
}
|
||||
open_pending_soon(app);
|
||||
|
||||
+2
-2
@@ -1806,13 +1806,13 @@ pub fn run(platform: PlatformContext) -> Result<(), Box<dyn std::error::Error>>
|
||||
instance.serve(&runtime, move |activation| {
|
||||
let _ = app.upgrade_in_event_loop(move |app| {
|
||||
window_controller::activate(&app, activation.activation_token);
|
||||
mailto_links::open(&app, activation.links);
|
||||
mailto_links::open(&app, "forwarded", activation.links);
|
||||
});
|
||||
});
|
||||
}
|
||||
// They open once the mail store is ready and the composer connected.
|
||||
#[cfg(desktop)]
|
||||
mailto_links::open(&app, launch_links.unwrap_or_default());
|
||||
mailto_links::open(&app, "launch", launch_links.unwrap_or_default());
|
||||
// The launcher's token was meant for this window: it lets the desktop
|
||||
// focus it (Wayland) and ends the launch feedback (X11).
|
||||
#[cfg(desktop)]
|
||||
|
||||
@@ -842,7 +842,11 @@ fn mailto_links_open_without_losing_the_draft(
|
||||
app.set_compose_subject("My own subject".into());
|
||||
// The reader's link handler was replaced by a recorder above; open the
|
||||
// link the way it does.
|
||||
mailto_links::open(app, ["mailto:second@example.com?attach=/etc/passwd"]);
|
||||
mailto_links::open(
|
||||
app,
|
||||
"message",
|
||||
["mailto:second@example.com?attach=/etc/passwd"],
|
||||
);
|
||||
frame();
|
||||
assert_eq!(
|
||||
*saved.borrow(),
|
||||
|
||||
@@ -116,7 +116,7 @@ pub(super) fn register_renderer_input_callbacks(
|
||||
return;
|
||||
}
|
||||
if flectar_mail_core::mailto::is_mailto(&url) {
|
||||
crate::mailto_links::open(&app, [url.as_str()]);
|
||||
crate::mailto_links::open(&app, "message", [url.as_str()]);
|
||||
return;
|
||||
}
|
||||
if let Err(error) = open_email_link(&opener, &url) {
|
||||
|
||||
Reference in new issue
Block a user