From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Danny YUE Newsgroups: gmane.emacs.help Subject: Re: How do you automatically refile mails with mu4e? Date: Mon, 20 Mar 2017 21:14:22 +0800 Message-ID: <87zigg3xap.fsf@gmail.com> References: <87r31siemr.fsf@gmail.com> <878to0z6rx.fsf@fastmail.fm> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1490015875 25837 195.159.176.226 (20 Mar 2017 13:17:55 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 20 Mar 2017 13:17:55 +0000 (UTC) User-Agent: mu4e 0.9.18; emacs 25.2.1 Cc: help-gnu-emacs@gnu.org, Danny YUE To: Joost Kremers Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Mar 20 14:17:47 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cpxBw-0005ci-4D for geh-help-gnu-emacs@m.gmane.org; Mon, 20 Mar 2017 14:17:44 +0100 Original-Received: from localhost ([::1]:32964 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpxC2-0007kx-09 for geh-help-gnu-emacs@m.gmane.org; Mon, 20 Mar 2017 09:17:50 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50503) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpx9l-0006dq-Fj for help-gnu-emacs@gnu.org; Mon, 20 Mar 2017 09:15:31 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cpx9i-0003bB-7V for help-gnu-emacs@gnu.org; Mon, 20 Mar 2017 09:15:29 -0400 Original-Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:35600) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cpx9i-0003aY-1x for help-gnu-emacs@gnu.org; Mon, 20 Mar 2017 09:15:26 -0400 Original-Received: by mail-pf0-x243.google.com with SMTP id n11so5975433pfg.2 for ; Mon, 20 Mar 2017 06:15:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version; bh=mSJyZYo3MKsr3ubLDWgog/yYgR6fNTNSjMgw1qf9AUk=; b=Z+UHYT2mkfbagjCmwOhOKfi82qaeCH6HtqlSNPFNE9tVGRgKe+5A+9RbTRcePNa57e Dv6EJ7NUWqRtWSPHKZfQJay3lstL7iglDPpMZn7XNK/lI6vBjuMbuANMh/St6NezPaRl quwUH9kBaoMK+5hvMI9q4ugp2LxOWTYwIMm3e0Lr2+nn22tZWo1+InsA4t7B6JoHgq8S nKRbxF3Kaq6ST5kTRBSKE9mkMgS+CqQbYrWuzdiE0Yv1wf2kty5XxN0z+31zJyxEMt/e iFIJVynDrjDdpnJAhATQz9VSag/B+RvF28W8IZW4zuDhP8NPXlUV8evd81YpyeVXsGAA O0og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version; bh=mSJyZYo3MKsr3ubLDWgog/yYgR6fNTNSjMgw1qf9AUk=; b=YhwZtv42H9GFzxaCJ3zpWMb+p3GyFsaPJ9rr8Wug5TIHcASMAoS5flh6OFJKsS3Wb1 ABVpPB8EDGDJtrJdkC9zI09MDbeasmz2rOaXKh/C6C3NZizP1Sev2uEWLCJ7iV3TamOQ jNKNvEXXwbkOOagzVzto8Fcg/GTyjucX8yJ26e5G+pDU6PC/YeXixJ14V5UNG2DN8vIK EdQi6UwtcDkvgm4hKCNA1tuAimBnh4BNCRqvAUKpyj6ZNEPgO0L+WYAQJtlnicLKh+U9 tXStqtmXruK/tzFbcwioZVpEyfFWhu+0Q/w1+tifWUTnGpArUG3SOXUzc9E0bwdGt5Hu 4pCg== X-Gm-Message-State: AFeK/H0AImtdZ6QgjgYrJk/8PBVCJN+ywtdHZAEVCDiwDHC07MGHOPVBGk+alNAzX5RNQQ== X-Received: by 10.98.218.76 with SMTP id w12mr32710009pfl.162.1490015725112; Mon, 20 Mar 2017 06:15:25 -0700 (PDT) Original-Received: from localhost (23.83.238.120.16clouds.com. [23.83.238.120]) by smtp.gmail.com with ESMTPSA id i3sm33424302pfk.47.2017.03.20.06.15.23 (version=TLS1_2 cipher=AES128-GCM-SHA256 bits=128/128); Mon, 20 Mar 2017 06:15:23 -0700 (PDT) In-reply-to: <878to0z6rx.fsf@fastmail.fm> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::243 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:112611 Archived-At: 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 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