all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Danny YUE <sheepduke@gmail.com>
To: Joost Kremers <joostkremers@fastmail.fm>
Cc: help-gnu-emacs@gnu.org, Danny YUE <sheepduke@gmail.com>
Subject: Re: How do you automatically refile mails with mu4e?
Date: Mon, 20 Mar 2017 21:14:22 +0800	[thread overview]
Message-ID: <87zigg3xap.fsf@gmail.com> (raw)
In-Reply-To: <878to0z6rx.fsf@fastmail.fm>

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 <joostkremers@fastmail.fm> 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	other threads:[~2017-03-20 13:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-20  7:36 How do you automatically refile mails with mu4e? Danny YUE
2017-03-20  8:33 ` Joost Kremers
2017-03-20 13:14   ` Danny YUE [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zigg3xap.fsf@gmail.com \
    --to=sheepduke@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=joostkremers@fastmail.fm \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.