[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: nnimap-split-download-body removed?
From: |
Eric Abrahamsen |
Subject: |
Re: nnimap-split-download-body removed? |
Date: |
Wed, 02 Dec 2020 12:34:04 -0800 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Bodertz <bodertz@gmail.com> writes:
>> I'm not sure how big of a rewrite this would require. First fetching
>> headers only wouldn't be hard, but then we'd need to somehow partially
>> fake a run of the splitting process in order to know which messages
>> needed more. How do you indicate in your splits that the body should
>> be examined?
>
> I guess an additional splitting character could be introduced (maybe @).
> And instead of splitting then and there it would push the article number
> onto some list, and then after all the normal non-body-splitting
> happens, if that list is non-nil, `nnimap-fetch-inbox' would download
> the bodies for those messages and run the split again. But I don't
> really know.
>
> Going back to what I said earlier about just having the function in the
> `(: function)' split download the body, it seems like that is possible.
> Because it's in the split rule, it only deals with one message at a
> time, so it is inefficient in that sense. In my case, I expect
> on-demand downloading of the occasional message body to be more
> efficient than downloading the body of every message and not using most
> of them, but maybe I'm mistaken.
TBH I don't think it's very likely we'll do a major rewrite to
accommodate this case. Particularly if body-scanning is only likely to
happen for a smaller subset of messages, I'd just do it the way you're
doing it below.
> Anyway, the code is messy, and not quite right (it doesn't clean up the
> `^M's for example), but it does seem to work in the sense that I can
> search for strings in the body and split based on that. I don't know
> which if any of these save-(excursion|restriction|match-data) forms are
> required.
>
>
> (setq nnimap-split-download-body-default nil)
>
> (defun scratch/test-split ()
> (current-buffer) ;; => " *nntpd*"
> (save-excursion
> (save-restriction
> (save-match-data
> (goto-char (point-min))
> (re-search-forward (rx "X-nnimap-article: "
> (group (+ digit))))
> (let* ((article (match-string 1))
> (command (format "UID FETCH %s (UID BODY.PEEK[])" article))
> (full-message
> (with-current-buffer (nnimap-buffer)
> (let ((message-start (point-max)))
> (nnimap-send-command command)
> (buffer-substring message-start (point))))))
> ;; Clear the original message (with only headers)
> (delete-region (point-min)
> (point-max))
> ;; Insert the full message
> (insert full-message)
> ;; Finally split based on message body
> (goto-char (point-min))
> (if (search-forward "Test Gnus Splitting" nil t)
> "mail.bodertz.test"
> "mail.bodertz"))))))
You might try putting the `full-message' text in a temp buffer and
running `nnimap-transform-split-mail' on it first, that might clear up
some of the oddities of the body text itself. I would keep both the
`save-restriction' and `save-match-data'. Otherwise looks like this will
do what you want!