Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shutdown-hook does not execute sync-mailbox (possible bug) #4184

Open
rafaelrc7 opened this issue Feb 9, 2024 · 7 comments
Open

shutdown-hook does not execute sync-mailbox (possible bug) #4184

rafaelrc7 opened this issue Feb 9, 2024 · 7 comments
Labels

Comments

@rafaelrc7
Copy link

rafaelrc7 commented Feb 9, 2024

Hello, I'm trying to run multiple commands with a single hook. This sounds simple enough, but I was not able to do it nor find any information about online.

My ideia is to use shutdown-hook to first save changes with <sync-mailbox> and then run a shell script that synchronises the maildir itself. I am able to easily do each alone, writing either shutdown-hook 'exec sync-mailbox' or shutdown-hook 'echo `sync-script.sh`'. However, I was not able to run both, first sync-mailbox and then the script.

Is there a way that I could do that? Thanks.

@rafaelrc7 rafaelrc7 added the type:question Question label Feb 9, 2024
@rafaelrc7
Copy link
Author

Ok. I think I did manage to run both commands, by either doing:

shutdown-hook 'exec sync-mailbox `sync-script.sh`'

or

shutdown-hook 'exec sync-mailbox ; echo `sync-script.sh`'

However it still seems to not be working as expected... The sync-script (that is just a call to mbsync) detects no changes, so read emails are not updated, as if sync-mailbox had not been executed. However, if I run the hook two times, by closing, opening and closing it works, so the command is working but the mailbox is only being saved after the program exits.

How could I fix it?

@dorsiflexion
Copy link

dorsiflexion commented Feb 18, 2024

In fact it seems that shutdown-hook 'exec sync-mailbox' is doing exactly nothing.

I'm trying to do something very similar. It doesn't even seem to be a race condition, because when doing

shutdown-hook 'exec sync-mailbox; echo `sleep 5`; echo `script.sh`'

it is still not updated when the script runs.

Btw. neomutt updates mailboxes when it quits. So if you are closing, opening, closing and it works, that is no indication that the hook actually did something.

I'd also greatly appreciate some advice on what's wrong here.

@rafaelrc7
Copy link
Author

In fact it seems that shutdown-hook 'exec sync-mailbox' is doing exactly nothing.

I'm trying to do something very similar. It doesn't even seem to be a race condition, because when doing

shutdown-hook 'exec sync-mailbox; echo `sleep 5`; echo `script.sh`'

it is still not updated when the script runs.

Btw. neomutt updates mailboxes when it quits. So if you are closing, opening, closing and it works, that is no indication that the hook actually did something.

I'd also greatly appreciate some advice on what's wrong here.

Yes, I also tried using sleep in my hook to test if it was some race condition, and had the same results.

I ended up rebinding the exit key (q) to run the sync commands and then quit. It works. But it still seems to be something wrong with the shutdown-hook.

@rafaelrc7 rafaelrc7 changed the title Run multiple commands with single hook [Run multiple commands with single hook (possible bug) Feb 20, 2024
@rafaelrc7 rafaelrc7 changed the title [Run multiple commands with single hook (possible bug) shutdown-hook does not execute sync-mailbox (possible bug) Feb 20, 2024
@roccoblues
Copy link
Member

Hi,

to clarify: the shutdown-hook is executed right? The problem is that sync-mailbox doesn't work as expected in it?

My wild guess is that sync-mailbox works on the current mailbox and by the time the shutdown-hook is executed there's no "current mailbox" anymore. But we need @flatcap expertise here.

@dorsiflexion
Copy link

to clarify: the shutdown-hook is executed right? The problem is that sync-mailbox doesn't work as expected in it?

Exactly. If I do something like:

shutdown-hook 'exec sync-mailbox; echo `notify-send test`'

I'm getting the notification. It's just that sync-mailbox doesn't seem to have an effect.

@roccoblues
Copy link
Member

roccoblues commented Mar 18, 2024

I had a deeper look and the problem doesn't seem to be related to sync-mailbox. It looks like no exec command gets executed. With the following shutdown-hook

shutdown-hook "echo 'before'; exec sync-mailbox; echo 'after'"

and some additional logging I get:

[2024-03-18 08:44:11]<1> dlg_index() Got op OP_QUIT (198)
[2024-03-18 08:44:11]<5> mutt_startup_shutdown_hook() shutdown
[2024-03-18 08:44:11]<5> mutt_startup_shutdown_hook() hook: echo 'before'; exec sync-mailbox; echo 'after'
[2024-03-18 08:44:11]<5> parse_rc_buffer() buffer:
[2024-03-18 08:44:11]<1> parse_rc_buffer() NT_COMMAND: echo
[2024-03-18 08:44:11]<M> parse_echo() before
[2024-03-18 08:44:11]<5> msgwin_set_text() MW SET: 6, before
[2024-03-18 08:44:11]<5> msgwin_calc_rows() msgwin_calc_rows() => 1
[2024-03-18 08:44:11]<5> msgwin_recalc() recalc done, request WA_REPAINT
[2024-03-18 08:44:11]<5> msgwin_repaint() msgwin repaint done
[2024-03-18 08:44:11]<5> parse_rc_buffer() rc: 0
[2024-03-18 08:44:11]<N> notify_send() sending: NT_COMMAND/13
[2024-03-18 08:44:11]<N> send() send: 7, 0x12001f800
[2024-03-18 08:44:11]<1> parse_rc_buffer() NT_COMMAND: exec
[2024-03-18 08:44:11]<5> mutt_parse_exec() exec: echo 'before'; exec sync-mailbox; echo 'after'
[2024-03-18 08:44:11]<5> mutt_parse_exec() function: sync-mailbox
[2024-03-18 08:44:11]<5> mutt_push_macro_event() ch: 0 op: 174
[2024-03-18 08:44:11]<5> parse_rc_buffer() rc: 0
[2024-03-18 08:44:11]<N> notify_send() sending: NT_COMMAND/14
[2024-03-18 08:44:11]<N> send() send: 7, 0x12001f800
[2024-03-18 08:44:11]<1> parse_rc_buffer() NT_COMMAND: echo
[2024-03-18 08:44:11]<M> parse_echo() after
[2024-03-18 08:44:11]<5> msgwin_set_text() MW SET: 5, after

Notice how the exec sync-mailbox gets parsed correct but never executed. It's gets pushed as an "event" in mutt_push_macro_event() but that's it. I think that is because NeoMutt is no longer in the main loop and nothing is actually handling those events.

I'll see if I can find some changes related to that next.

@roccoblues
Copy link
Member

Quick update here: we have a, not to ugly, PR that fixes the issue that exec functions aren't triggered in the hook.

However the behavior is confusing because the command queue is only triggered after the complete hook is parsed. Fixing this would be a way bigger change.

I suggest something like alias nm='neomutt && sync-script.sh' as a temporary workaround for the original issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants