Skip to content

Conversation

@mjg
Copy link
Contributor

@mjg mjg commented Jun 12, 2018

In move mode, afew calls notmuch new after moving mails around. This
prevents afew -m from being used in a pre-new hook in notmuch.

Allow to specify args, so that afew -m --notmuch-args=--no-hooks can
live happily in a pre-new hook.

@flokli
Copy link
Member

flokli commented Jun 12, 2018

Can you use #187 for that?

@mjg
Copy link
Contributor Author

mjg commented Jun 12, 2018

Can you use #187 for that?

First of all, sorry for not searching the issues before... #187 is not quite it but #188 looks promising since it updates the notmuch db (even more effectively) but avoids hooks. It implies a change in behaviour for those users which use hooks (in my case, welcome change). I'll try #188 and report back.

@mjg
Copy link
Contributor Author

mjg commented Jun 14, 2018

So, that approach (use notmuch bindings, not the binary) works and looks better all together, but the implementation is lacking (ignores rename setting). Cleaning up that patch over there seems to be worthwhile if you decide that the change in behaviour is OK (no more hooks being fired - fine for me :)).

@GuillaumeSeren
Copy link
Collaborator

Hey,
first thank you for the patch 🍺

I agree on the feature as a heavy user of the MailMover myself,
it is close / same as the #187 and could trigger the same db non atomic operation,
but if we assume that a user can manage that issue on its own,
we could merge that before the rework of the MailMover.

I will check the patch, but i think if it can solve both your issue (#200) and (#187),
it could be a good thing.

@vanicat Can you have a look and check if it solve your issue ?

@rpuntaie
Copy link

#200 is for notmuch pre-new hook. I call afew in post-new hook. There it does not lead to a second afew run. It seems like notmuch sees its DB in use and so does not call post-new.

I consider using it in the post-new hook is the right way,

@mjg
Copy link
Contributor Author

mjg commented Aug 21, 2019

#200 is for notmuch pre-new hook. I call afew in post-new hook. There it does not lead to a second afew run. It seems like notmuch sees its DB in use and so does not call post-new.

I consider using it in the post-new hook is the right way,

This depends on your use of MUA and synchronisers. For me, the MUA only changes tags in the notmuch db or adds messages (sending), i.e. it operates through the nm library and the db is in sync locally.

afew/notmuch does the remote sync, which encompasses fetching/pushing of e-mail including necessary moves by tag and tagging by folder. This has to be done in a specific order to make sense. My ordering ist:

  1. nm.pre-new: afew -m --notmuch-args=--no-hooks makes sure any new tags lead to apropriate foldering
  2. nm.pre-new: mbsync pushes the local state to the remote, fetches remote updates
  3. notmuch syncs the local file system state (changed by mbsync) to the db
  4. nm.post-new: afew -t -n tags new messages in the db

I could not come up with any other ordering that makes sure that db and local state and remote state are in sync and that requires only one run of notmuch, mbsync and the two afew modules. But I'd be happy to learn alternatives.

@rpuntaie
Copy link

I'm currently moving from Thunderbird to a more open mail store.
So I'm just figuring things out step-by-step and happy to learn from others.

I have set up a mail sync script, that basically does

  1. mbsync

  2. notmuch new

    in $MAILDIR/.notmuch/post-new I have

    # create missing folders based on afew config, then
    afew -mn
    afew -tn
    

My [MailMover] does not use tags, but rather something like:

gmail/INBOX = 'from:someone AND subject:something':somefolder

-tn then tags based on the new folders using FolderNameFilter.

remote is synched only the next time my sync script is called.
It will then

  • update the local storage with new mails from remote
  • update remote with the mails I have removed locally (i.e. moved to non-synced local mailboxes)

I mean, remote and local will get out of sync anyway.
There is no need to leave the script with both at sync.

mjg added 5 commits August 26, 2019 11:20
In move mode, afew calls `notmuch new` after moving mails around. This
prevents `afew -m` from being used in a pre-new hook in `notmuch`.

Allow to specify args, so that `afew -m --notmuch-args=--no-hooks` can
live happily in a pre-new hook.
`:flags` need to be preserved when renaming files, but UIDs of the form
`U=[0-9]+` should be removed. The current code fails to do that when a mail
file has a UID but no flags.

Change the code to nuke the non-flag part in any case.
Refactor so that the name generation becomes clearer, and before
changing the dir generation.

Change in behavour: returns a full path instead of a dir now in the
rename==False case.
Currently, MailMover moves all mail to `/cur`. But everyone moving mail
from `/new` to `/cur` is required to set up the maildir flags field in
the name.

Rather than setting up that field, preserve the maildir subdir part and
let other clients change subdirs as necessary. After all, "moving" does
not constitute "reading".
@GuillaumeSeren
Copy link
Collaborator

Ok let's merge this thank you for the patch @mjg

@GuillaumeSeren GuillaumeSeren merged commit 6b321b8 into afewmail:master Sep 18, 2019
to_delete_fnames = []
moved = False
for query in rules.keys():
destination = '{}/{}/cur/'.format(self.db_path, rules[query])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did that cur here go?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparantly, #200 and #201 got merged together when they were both merged (or I rebased one PR branch too early, or github computes the diff relative to the original merge base).
In any case, this is reflected in the change to new_name(): In short, afew used to move mail from new to cur but failed to update flags (everyone moving to cur should update flags), so #201 made afew leave mail in the respective subdir rather than chopping off new/cur/.. and appending cur..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but this still doesn't feel quite readable to me.

I could guess submaildir is cur or new, but just taking [1] out of os.path.split()'s tail sounds scary - what happens to the other path components?

Could this maybe be made slightly more readable way, maybe by adding some comments?

We could also probably use pathlib paths around instead of strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants