Getting tags synced back to IMAP using mbsync

85 views
Skip to first unread message

Stephen Eglen

unread,
Jan 6, 2017, 12:41:53 PM1/6/17
to mu-discuss
hi Dirk,

mu4e contains to be the email reader of choice in 2017!  Wonderful.

I have a query.  I'd like to add "tags" to my mail, e.g. using
mu4e-action-retag-message.  As I use mbsync for retrieving mail, if I
add a tag, but do not move the message, the tag is nor propagated back
to the imap server.  So what I think I need to do is to move the message
(but keep it in the same maildir) after tagging it.  So, how best should
I do this?

1. add code to the end of mu4e-action-retag-message to move the message
within the maildir?

2. make a note somewhere (e.g. in a buffer/file/variable,
mu4e-messages-to-move) that the message file has been edited.  Then, add
a function mu4e-update-pre-hook which will move all the files noted in
mu4e-messages-to-move.  In this way if several messages are tagged
between updates, they will all be moved at once.

I presume the function mu4e~proc-move could be used to actually move
each file.  (ALthough I note that this an internal function.)

Which workflow do you tihnk would make more sense?  I think I can write this,
but just wanted your feedback first!

Stephen

Dirk-Jan C. Binnema

unread,
Jan 14, 2017, 6:22:10 AM1/14/17
to mu-di...@googlegroups.com
Hi Stephen,
Hmmm, there have been some similar questions before; my preferred
solution would be for mbsync to check the file mtime, or md5-hash or
whatever, to decide whether a file needs re-syncing - that seems to be
the 'right' solution.

In any case, that if we want to do something for this on the mu side, I
wouldn't want to add extra magic to mu4e to trick mbsync to do what's
expected -- this might give unexpected results elsewhere
(e.g. offlineimap, ...), and hard to understand bug reports[*].

So, what I'd propose instead that we don't add any more magic for that
in mu4e, but add a mu command, say, 'tickle', that does the renaming;
after you've done some retagging, you could trigger a script, something
like:

--8<---------------cut here---------------start------------->8---
kill mu server
mu find "" --after `cat ~/.last_update_time` --exec 'mu tickle'
mbsync <mbsync-options>
date +%s > ~/.last_update_time
--8<---------------cut here---------------end--------------->8---

This would work for any message that changed (not just re-tagged) as
other people have asked for; and it makes it obvious that it's a
hack. I've added a 'mu tickle' command to make this a bit easier.

Kind regards,
Dirk.

[*] there's `mu4e-change-filenames-when-moving' already, but in
hindsight I think it's a bit problematic.

--
Dirk-Jan C. Binnema Helsinki, Finland
e:dj...@djcbsoftware.nl w:www.djcbsoftware.nl
pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C

Stephen Eglen

unread,
Jan 17, 2017, 4:26:12 AM1/17/17
to mu-discuss
Thank you very much Dirk, I will experiment.

Where do you think the best place is for running the script?  Immediately after tagging?  If so, I'm wondering whether the "mbsync" command should be executed at that time, as that can sometimes be slow (a few seconds).

But I really like the tickle idea, as that may be more useful for other operations I have occasionally thought of (e.g. stripping large attachments from a message).

Reply all
Reply to author
Forward
0 new messages