| 1 |
Move Mode |
| 2 |
========= |
| 3 |
|
| 4 |
Configuration Section |
| 5 |
--------------------- |
| 6 |
|
| 7 |
Here is a full sample configuration for move mode: |
| 8 |
|
| 9 |
.. code-block:: ini |
| 10 |
|
| 11 |
[MailMover] |
| 12 |
folders = INBOX Junk |
| 13 |
rename = False |
| 14 |
max_age = 15 |
| 15 |
|
| 16 |
# rules |
| 17 |
INBOX = 'tag:spam':Junk 'NOT tag:inbox':Archive |
| 18 |
Junk = 'NOT tag:spam AND tag:inbox':INBOX 'NOT tag:spam':Archive |
| 19 |
|
| 20 |
Below we explain what each bit of this means. |
| 21 |
|
| 22 |
Rules |
| 23 |
----- |
| 24 |
|
| 25 |
First you need to specify which folders should be checked for mails |
| 26 |
that are to be moved (as a whitespace separated list). Folder names |
| 27 |
containing whitespace need to be quoted: |
| 28 |
|
| 29 |
.. code-block:: ini |
| 30 |
|
| 31 |
folders = INBOX Junk "Sent Mail" |
| 32 |
|
| 33 |
Then you have to specify rules that define move actions of the form |
| 34 |
|
| 35 |
.. code-block:: ini |
| 36 |
|
| 37 |
<src> = ['<qry>':<dst>]+ |
| 38 |
|
| 39 |
Every mail in the `<src>` folder that matches a `<qry>` will be moved into the |
| 40 |
`<dst>` folder associated with that query. A message that matches |
| 41 |
multiple queries will be copied to multiple destinations. |
| 42 |
|
| 43 |
You can bind as many rules to a maildir folder as you deem necessary. Just add |
| 44 |
them as elements of a (whitespace separated) list. |
| 45 |
|
| 46 |
Please note, though, that you need to specify at least one rule for every folder |
| 47 |
given by the `folders` option and at least one folder to check in order to use |
| 48 |
the move mode. |
| 49 |
|
| 50 |
.. code-block:: ini |
| 51 |
|
| 52 |
INBOX = 'tag:spam':Junk |
| 53 |
|
| 54 |
will bind one rule to the maildir folder `INBOX` that states that all mails in |
| 55 |
said folder that carry (potentially among others) the tag **spam** are to be moved |
| 56 |
into the folder `Junk`. |
| 57 |
|
| 58 |
With `<qry>` being an arbitrary notmuch query, you have the power to construct |
| 59 |
arbitrarily flexible rules. You can check for the absence of tags and look out |
| 60 |
for combinations of attributes: |
| 61 |
|
| 62 |
.. code-block:: ini |
| 63 |
|
| 64 |
Junk = 'NOT tag:spam AND tag:inbox':INBOX 'NOT tag:spam':Archive |
| 65 |
|
| 66 |
The above rules will move all mails in `Junk` that don't have the **spam** tag |
| 67 |
but do have an **inbox** tag into the directory `INBOX`. All other mails not |
| 68 |
tagged with **spam** will be moved into `Archive`. |
| 69 |
|
| 70 |
Max Age |
| 71 |
------- |
| 72 |
|
| 73 |
You can limit the age of mails you want to move by setting the `max_age` option |
| 74 |
in the configuration section. By providing |
| 75 |
|
| 76 |
.. code-block:: ini |
| 77 |
|
| 78 |
max_age = 15 |
| 79 |
|
| 80 |
afew will only check mails at most 15 days old. |
| 81 |
|
| 82 |
Rename |
| 83 |
------ |
| 84 |
|
| 85 |
Set this option if you are using the `mbsync` IMAP syncing tool. |
| 86 |
`mbsync` adds a unique identifier to files' names when it syncs them. |
| 87 |
If the `rename` option is not set, moving files can cause UID conflicts |
| 88 |
and prevent `mbsync` from syncing with error messages such as |
| 89 |
"Maildir error: duplicate UID 1234" or "UID 567 is beyond highest assigned UID 89". |
| 90 |
|
| 91 |
When the option is set, afew will rename files while moving them, |
| 92 |
removing the UID but preserving other `mbsync` information. |
| 93 |
This allows `mbsync` to assign a new UID to the file and avoid UID conflicts. |
| 94 |
|
| 95 |
If you are using `offlineimap`, you can safely ignore this option. |
| 96 |
|
| 97 |
.. code-block:: ini |
| 98 |
|
| 99 |
rename = True |
| 100 |
|
| 101 |
|
| 102 |
Limitations |
| 103 |
----------- |
| 104 |
|
| 105 |
**(1)** Rules don't manipulate tags. |
| 106 |
|
| 107 |
.. code-block:: ini |
| 108 |
|
| 109 |
INBOX = 'NOT tag:inbox':Archive |
| 110 |
Junk = 'NOT tag:spam':INBOX |
| 111 |
|
| 112 |
The above combination of rules might prove tricky, since you might expect |
| 113 |
de-spammed mails to end up in `INBOX`. But since the `Junk` rule will *not* add |
| 114 |
an **inbox** tag, the next run in move mode might very well move the matching |
| 115 |
mails into `Archive`. |
| 116 |
|
| 117 |
Then again, if you remove the **spam** tag and do not set an **inbox** tag, how |
| 118 |
would you come to expect the mail would end up in your INBOX folder after |
| 119 |
moving it? ;) |
| 120 |
|
| 121 |
**(2)** There is no 1:1 mapping between folders and tags. And that's a |
| 122 |
feature. If you tag a mail with two tags and there is a rule for each |
| 123 |
of them, both rules will apply. Your mail will be copied into two |
| 124 |
destination folders, then removed from its original location. |