help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do you automatically refile mails with mu4e?


From: Danny YUE
Subject: Re: How do you automatically refile mails with mu4e?
Date: Mon, 20 Mar 2017 21:14:22 +0800
User-agent: mu4e 0.9.18; emacs 25.2.1

Hi,

Thanks for your advice.

Well, I finally managed to accomplish it myself.

For those who might be interested, I post a snippet here to prove that
it does work:

(defun mu4e-refile-search-and-refile (&optional query)
  "Search by QUERY and refile them. If QUERY is not given, ask for it."
  (interactive)
  (save-window-excursion
        (while (not query)
          (setq query (read-string "[mu4e] Search and refile for: ")))

        (let (mu4e-active-p)
          ;; If there is any buffer currently opened, save it.
          (when (or (get-buffer mu4e-refile-header-buffer-name)
                                (get-buffer "*mu4e-main*"))
                (setq mu4e-active-p t)
                (mu4e-refile-save-header-buffer))

          ;; Search the message and refile.
          ;; We have to wait until mu4e has finished its job.
          (mu4e~headers-search-execute query t)
          (while (not (mu4e-refile-finished-p))
                (sleep-for 0.1))

          (mu4e-refile-current-buffer)
          (kill-buffer)
          ;; If mu4e is active, kill current buffer and restore mu4e
          session.
          (when mu4e-active-p
                (mu4e-refile-restore-header-buffer)))))

Then I added this line to my config file:
(add-hook 'mu4e-index-updated-hook 'mu4e-refile-unread)

After that every time I get a new mail, mu4e will automatically refile
incoming files according to mu4e-refile-folder function.

For a complete version please see:
https://github.com/sheepduke/mu4e-refile


Thanks anyway.
Danny


On 2017-03-20 08:33, Joost Kremers <address@hidden> wrote:
> On Mon, Mar 20 2017, Danny YUE wrote:
>> How can you refile the mails without opening any mu4e buffers?
>>
>> I read the manual and I know that it is possible to define a
>> function to
>> refile based on something.
>> But every time I have to mark-and-execute manually, and it
>> sometimes
>> annoys me.
>>
>> I would like it to be automatically done: every time the index
>> is
>> updated, the incoming unread mails are refiled automatically.
>>
>> My idea is to add something to the mu4e-update-pre-hook.
>> But I did not found any clue how I can refile mails in the
>> background, without opening any buffer.
>> Looking into the code did not really help.
>>
>> Can anyone help? Thanks in advance.
>
> I'm not sure if what you want is possible at all with mu4e
> (personally I use my mail provider's file & filtering options,
> other people do it locally using something like procmail).
>
> However, mu4e has its own mailing list. I think your best bet
> would be to ask your question there.
>
> HTH



reply via email to

[Prev in Thread] Current Thread [Next in Thread]