djcb / mu

maildir indexer/searcher + emacs mail client + guile bindings
http://www.djcbsoftware.nl/code/mu
GNU General Public License v3.0
1.62k stars 391 forks source link

[mu4e bug] Wrong timestamp for drafts with discarded edits #2763

Closed 88-percent closed 1 month ago

88-percent commented 2 months ago

Describe the bug

Date field for draft messages doesn't reliably update for a very specific use case: where a draft message has discarded edits.

This causes these messages to display an incorrect date upon send - including to recipient.

How to Reproduce

  1. create a new message (M-x mu4e-compose-new)
  2. draft new message
  3. save message as draft (M-x message-dont-send)

-- practically some time would elapse here --

  1. locate draft message
  2. edit message (M-x mu4e-compose-edit)
  3. choose account
  4. make edits
  5. discard edit (M-x message-kill-buffer)
  6. message modified; kill anyway? (y or n) - y
  7. remove the backup file too? (y or n) - y

-- practically some time would elapse here --

  1. locate draft message again
  2. edit message (M-x mu4e-compose-edit)
  3. choose account

Expected behavior: the message is opened in compose mode with all info the same as when it was saved except the date field which should be populated with the current time & date.

Actual behavior: the message is opened in compose mode with all info the same as when it was last saved - including the date field which is the time and date the message was last saved.

Environment

Emacs: 29.4 Spacemacs: 0.999 mu: 1.12.5 OS: Pop!OS 22.04

Checklist

I'm running Spacemacs so I'm unfortunately unable to disable Evil for testing. I've tried to run the above without using evil commands.

bderembl commented 2 months ago

Acutally, for me, do step 1->5 then 6b. send mail

the mail is sent with the timestamp of the creation of the email (step 1)

edit: this might be a feature or a bug, I don't know...

88-percent commented 2 months ago

Acutally, for me, do step 1->5 then 6b. send mail

the mail is sent with the timestamp of the creation of the email (step 1)

edit: this might be a feature or a bug, I don't know...

What version are you on? I ask because I experienced this exact issue when I was using the version of mu included with my distro. After upgrading to 1.12 I now get the correct timestamp for drafts. Even drafts edited multiple times present with the updated timestamp.

It's now only after calling M-x message-kill-buffer while editing a draft message that the timestamp fails to update on my system.

djcb commented 2 months ago

I pushed a change that hopefully address this... does it work for you?

bderembl commented 2 months ago

What version are you on?

I must admit I reverted back to 1.10.8 (shame on me)... I actually find this version slightly more friendly. (no encoding errors, reply to all, attachments work more smoothly)

88-percent commented 1 month ago

sorry for my ignorance, but can I just drop the lisp from your commit in mu4e-draft.el or should I pull and recompile mu to try this out?

djcb commented 1 month ago

@88-percent: either should work, thanks!

88-percent commented 1 month ago

I tried adding the lisp to my mu4e-draft.el but this doesn't seem to have solved the issue for me: if edits are discarded using M-x message-kill-buffer the timestamp still doesn't seem to update on next edit.

I've noticed the function is different from the most recent version. If you think this could be caused by the fact that I'm a version behind (I'm on 1.12.5) I could try and upgrade to master. Just let me know and I'll do my best to help out. I also tried dropping the entire mu4e-draft.el in place but it seems that it doesn't want to play nicely with the rest of my version.

Here's how the function looks in my edited version of mu4e-draft.el

(defun mu4e--compose-before-send ()
  "Function called just before sending a message."
  ;; Remove References: if In-Reply-To: is missing.
  ;; This allows the user to effectively start a new message-thread by
  ;; removing the In-Reply-To header.
  (when (eq mu4e-compose-type 'reply)
    (unless (message-field-value "In-Reply-To")
      (message-remove-header "References")))
  (when use-hard-newlines
    (mu4e--send-harden-newlines))
  ;; TEST new draft fix from https://github.com/djcb/mu/commit/413c03ea1cc9e1f1139a826f357d26f7bb6b6d33
  ;; in any case, make sure to save the message; this will also trigger
  ;; before/after save hooks, which fixes up various fields.
  (set-buffer-modified-p t)
  (save-buffer)
  ;; now handle what happens _after_ sending; typically, draft is gone and
  ;; the sent message appears in sent. Update flags for related messages,
  ;; i.e. for Forwarded ('Passed') and Replied messages, try to set the
  ;; appropriate flag at the message forwarded or replied-to.
  (add-hook 'message-sent-hook
            (lambda ()
              (when-let ((fcc-path (message-field-value "Fcc")))
                (mu4e--set-parent-flags fcc-path)
                ;; we end up with a ((buried) buffer here, visiting the
                ;; fcc-path; not quite sure why. But let's get rid of it (#2681)
                (when-let ((buf (find-buffer-visiting fcc-path)))
                  (kill-buffer buf))
                ;; remove draft
                (when-let ((draft (buffer-file-name)))
                  (mu4e--server-remove draft))))
            nil t))
88-percent commented 1 month ago

I take it back. It seems like the change is working. Thanks!

The timestamp displayed after calling M-x mu4e-compose-edit is still the incorrect (old) timestamp, which is what was confusing me.

But the timestamp now seems to be updated correctly upon send. This is all I really need.

I've only had a brief amount of time to test this, but wanted to report it as soon as I noticed it. I'll keep an eye open to see if the behavior is consistent and report back.

djcb commented 1 month ago

Okay, thank you! Closing as fixed.