unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* Editing the raw mail file?
@ 2024-07-09 21:50 Morten Kjeldgaard
  2024-07-09 23:28 ` David Bremner
  0 siblings, 1 reply; 4+ messages in thread
From: Morten Kjeldgaard @ 2024-07-09 21:50 UTC (permalink / raw)
  To: notmuch

Hi, I have ported all om my mail since 1991 into notmuch and I am
thrilled that I can now organize and easily see everything I have been
doing for the last 30+ years.

However, some of the mail messages have wrong information in the RFC822
header, probably because of bad mail delivery agents that were used at
the time.

Especially, I have a whole bunch of mails that are assigned the date
1970-01-01, and when I look in the file itself, it turns out it has the
year 100, which of course was year 2000.

Other messages have a faulty Content-Type: text header, which means the
content is wrapped in [ application/octet-stream ] which is annoying
because the message isn't immediately visible.

It's tedious to use the notmuch CLI client to search for the mail and
then copy/paste the filename, and edit it to correct the date. It would
be so much easier if it were possible to edit the raw file directly in
Emacs. I can use 'V' to view the raw file, and then 'E' to be allowed to
edit it, but Emacs has no idea of what file it is editing.

Is there a way to solve this problem? Notmuch of course already knows
the original filename.

Cheers,
Morten

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Editing the raw mail file?
  2024-07-09 21:50 Editing the raw mail file? Morten Kjeldgaard
@ 2024-07-09 23:28 ` David Bremner
  2024-07-10  8:45   ` Morten Kjeldgaard
  0 siblings, 1 reply; 4+ messages in thread
From: David Bremner @ 2024-07-09 23:28 UTC (permalink / raw)
  To: Morten Kjeldgaard, notmuch

Morten Kjeldgaard <mortenkjeldgaard@gmail.com> writes:

>
> It's tedious to use the notmuch CLI client to search for the mail and
> then copy/paste the filename, and edit it to correct the date. It would
> be so much easier if it were possible to edit the raw file directly in
> Emacs. I can use 'V' to view the raw file, and then 'E' to be allowed to
> edit it, but Emacs has no idea of what file it is editing.
>
> Is there a way to solve this problem? Notmuch of course already knows
> the original filename.

you can use "c F" to copy the file name of the current message into the
the kill ring, then just yank wherever useful (e.g. to visit the file in
emacs).

After editing you will need to reindex that file. One way would be
to use "c i" to copy the message id into the kill ring, then yank it
into a shell command like

     notmuch reindex id:<whatever>

If that seems to do what you want, then the steps can be automated
within emacs.

d

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Editing the raw mail file?
  2024-07-09 23:28 ` David Bremner
@ 2024-07-10  8:45   ` Morten Kjeldgaard
  2024-07-11  3:02     ` David Bremner
  0 siblings, 1 reply; 4+ messages in thread
From: Morten Kjeldgaard @ 2024-07-10  8:45 UTC (permalink / raw)
  To: David Bremner, notmuch

David Bremner <david@tethera.net> wrote:

> you can use "c F" to copy the file name of the current message into the
> the kill ring, then just yank wherever useful (e.g. to visit the file in
> emacs).
>
> After editing you will need to reindex that file. One way would be
> to use "c i" to copy the message id into the kill ring, then yank it
> into a shell command like
>
>      notmuch reindex id:<whatever>
>
> If that seems to do what you want, then the steps can be automated
> within emacs.

It works! But as you suggested I made two functions to make it easier, I
enclose them below in case others could benefit. One function opens the
mbox file in an edit buffer, the other runs the reindexing, both need to
be run in the context of the message.

I would love to have just one function that carries out both tasks,
opening the file in a temporary buffer, and after you finish with C-c
C-c, it automatically does the reindexing for you. Unfortunately it's
above my current Elisp skills to write this.

Thanks for your help!
Cheers,
Morten

-------8<----- snip -------
(defun mok/notmuch-edit-raw-mail ()
  "Within the context of a mail message, open the raw mbox file in a buffer."
  (interactive)
  (let ((mbox-file-name (notmuch-show-get-filename)))
    (message "edit %s" mbox-file-name)
    (find-file mbox-file-name)))

(defun mok/notmuch-reindex-id ()
  "Within the context of a mail message, reindex the message to update header information"
  (interactive)
  (let ((id (notmuch-show-get-message-id)))
    (message "reindex %s" id)
    (notmuch--call-process notmuch-command nil t nil "reindex" id)))
-------8<----- snip -------

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Editing the raw mail file?
  2024-07-10  8:45   ` Morten Kjeldgaard
@ 2024-07-11  3:02     ` David Bremner
  0 siblings, 0 replies; 4+ messages in thread
From: David Bremner @ 2024-07-11  3:02 UTC (permalink / raw)
  To: Morten Kjeldgaard, notmuch

Morten Kjeldgaard <mortenkjeldgaard@gmail.com> writes:
> I would love to have just one function that carries out both tasks,
> opening the file in a temporary buffer, and after you finish with C-c
> C-c, it automatically does the reindexing for you. Unfortunately it's
> above my current Elisp skills to write this.
>

Maybe something like the re-edit draft as new interface (e), although
allowing arbitrary edits is a bit of a footgun, so we'd probably want to
make people confirm "are you sure, this could destroy your message" or
similar. I'm too far behind to do this myself, but I'll (eventually)
look at patches if someone wants to work something up.

d

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-07-11  3:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-09 21:50 Editing the raw mail file? Morten Kjeldgaard
2024-07-09 23:28 ` David Bremner
2024-07-10  8:45   ` Morten Kjeldgaard
2024-07-11  3:02     ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).