* script to move messages according to tags
@ 2019-12-11 7:44 Alan Schmitt
2019-12-11 12:58 ` Örjan Ekeberg
0 siblings, 1 reply; 6+ messages in thread
From: Alan Schmitt @ 2019-12-11 7:44 UTC (permalink / raw)
To: notmuch
[-- Attachment #1: Type: text/plain, Size: 742 bytes --]
Hello,
I'm considering switching to notmuch, but there are two use cases
for
which I need to move messages around between folders. After
reading
https://notmuchmail.org/excluding/, it seems the recommended
approach is
to use a tag to flag such messages, then to use a script to move
the
messages. Has someone written such a script that I could copy and
adapt?
My use cases are:
- find files with a deleted flag not in the Trash and move them to
the
Trash
- find files with an archive flag in my active mail store and move
them
to my local mail store
I think this should not be too complicated, but I'm worried about
searches returning related messages that should not be moved
(especially
when deleting messages).
Best,
Alan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: script to move messages according to tags
2019-12-11 7:44 script to move messages according to tags Alan Schmitt
@ 2019-12-11 12:58 ` Örjan Ekeberg
2019-12-11 15:28 ` Alan Schmitt
0 siblings, 1 reply; 6+ messages in thread
From: Örjan Ekeberg @ 2019-12-11 12:58 UTC (permalink / raw)
To: Alan Schmitt, notmuch
Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> Has someone written such a script that I could copy and
> adapt?
>
> My use cases are:
> - find files with a deleted flag not in the Trash and move them to
> the
> Trash
> - find files with an archive flag in my active mail store and move
> them
> to my local mail store
Hi Alan,
Below is the script that I use which does more-or-less what you are
asking for.
The only "magic" here is the function safeMove which strips the
identifier number and flags from the filename when a file is moved.
These identifier numbers are added by mbsync which is the program I use
to synchronise my folders with our webmail server, and keeping the
numbers when moving the files proved to interfere with its
synchronisation logic.
Cheers,
Örjan
=== 8< ===
#!/bin/bash
MAILDIR=$HOME/MyMail
# Move a message file while removing its UID-part
function safeMove { s=${1##*/}; s=${s%%,*}; mv -f $1 $2/$s; }
# Move all deleted messages to the Trash folder
echo Moving $(notmuch count --output=files --exclude=false tag:deleted AND NOT folder:Trash) \
deleted messages to the Trash folder
for i in $(notmuch search --exclude=false --output=files tag:deleted AND NOT folder:Trash); do
safeMove $i ${MAILDIR}/Trash/cur
done
# Move all spam messages to the Spam folder
echo Moving $(notmuch count --output=files tag:spam AND NOT folder:Spam) \
spam-marked messages to the Spam folder
for i in $(notmuch search --output=files tag:spam AND NOT folder:Spam); do
safeMove $i ${MAILDIR}/Spam/cur
done
# Move all archived messages from Inbox to Archive folder
echo Moving $(notmuch count --output=files folder:Inbox AND NOT tag:inbox) \
archived messages from Inbox to Archive folder
for i in $(notmuch search --output=files folder:Inbox AND NOT tag:inbox); do
safeMove $i ${MAILDIR}/Arkiv/cur
done
echo Syncing with Webmail
mbsync twoway
echo Updating notmuch database
notmuch new --no-hooks
=== 8< ===
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: script to move messages according to tags
2019-12-11 12:58 ` Örjan Ekeberg
@ 2019-12-11 15:28 ` Alan Schmitt
2019-12-11 15:33 ` David Edmondson
0 siblings, 1 reply; 6+ messages in thread
From: Alan Schmitt @ 2019-12-11 15:28 UTC (permalink / raw)
To: Örjan Ekeberg; +Cc: notmuch
[-- Attachment #1: Type: text/plain, Size: 674 bytes --]
Hello Örjan,
On 2019-12-11 13:58, Örjan Ekeberg <ekeberg@kth.se> writes:
> Below is the script that I use which does more-or-less what you
> are
> asking for.
Thank you very much, this is most helpful.
I do have one small question: how do you deal with mails that have
duplicates? For instance, when I send a mail to a mailing list, I
end up
with both the sent email and the one I later receive from the
list. If I
tag the send one with deleted (no need to keep it), won't I run
the risk
to delete both mails?
(Maybe I'm dealing with sent mails in a wrong way… I don't know
what
notmuch best practice is in that case.)
Thanks,
Alan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 483 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: script to move messages according to tags
2019-12-11 15:28 ` Alan Schmitt
@ 2019-12-11 15:33 ` David Edmondson
2019-12-11 15:42 ` Alan Schmitt
0 siblings, 1 reply; 6+ messages in thread
From: David Edmondson @ 2019-12-11 15:33 UTC (permalink / raw)
To: Alan Schmitt, Örjan Ekeberg; +Cc: notmuch
On Wednesday, 2019-12-11 at 16:28:20 +01, Alan Schmitt wrote:
> I do have one small question: how do you deal with mails that have
> duplicates? For instance, when I send a mail to a mailing list, I end
> up with both the sent email and the one I later receive from the
> list. If I tag the send one with deleted (no need to keep it), won't I
> run the risk to delete both mails?
If you have the id of a message you can get a list of all of the
corresponding files with:
notmuch search --exclude=false --output=files $id
How you decide to deal with multiple results is really up to you - in my
case I move/delete all of them (except that I don't actually delete
anything).
dme.
--
Our President's crazy, did you hear what he said?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: script to move messages according to tags
2019-12-11 15:33 ` David Edmondson
@ 2019-12-11 15:42 ` Alan Schmitt
2019-12-11 17:46 ` Carl Worth
0 siblings, 1 reply; 6+ messages in thread
From: Alan Schmitt @ 2019-12-11 15:42 UTC (permalink / raw)
To: David Edmondson; +Cc: Örjan Ekeberg, notmuch
[-- Attachment #1: Type: text/plain, Size: 460 bytes --]
On 2019-12-11 16:33, David Edmondson <dme@dme.org> writes:
> How you decide to deal with multiple results is really up to you
> - in my
> case I move/delete all of them (except that I don't actually
> delete
> anything).
This is probably the key: I'm used to file-based MUA that will
show me
duplicates. If notmuch hides them from me, I could just ignore
that they
exist (it's not like it's taking too much space anyway…)
Best,
Alan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: script to move messages according to tags
2019-12-11 15:42 ` Alan Schmitt
@ 2019-12-11 17:46 ` Carl Worth
0 siblings, 0 replies; 6+ messages in thread
From: Carl Worth @ 2019-12-11 17:46 UTC (permalink / raw)
To: Alan Schmitt, David Edmondson; +Cc: notmuch
[-- Attachment #1: Type: text/plain, Size: 1075 bytes --]
Yes,
Notmuch considers any email files with the same message-id header as
being the same message so won't show you multiple versions of the same
email, (unless you're specifically asking for it to with something like
--output=files).
In normal usage I never worry about the duplicates I get from mailing
lists, etc.
I hope you'll find notmuch very useful.
Have fun!
-Carl
On Wed, Dec 11 2019, Alan Schmitt wrote:
> On 2019-12-11 16:33, David Edmondson <dme@dme.org> writes:
>
>> How you decide to deal with multiple results is really up to you
>> - in my
>> case I move/delete all of them (except that I don't actually
>> delete
>> anything).
>
> This is probably the key: I'm used to file-based MUA that will
> show me
> duplicates. If notmuch hides them from me, I could just ignore
> that they
> exist (it's not like it's taking too much space anyway…)
>
> Best,
>
> Alan
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-12-11 17:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-11 7:44 script to move messages according to tags Alan Schmitt
2019-12-11 12:58 ` Örjan Ekeberg
2019-12-11 15:28 ` Alan Schmitt
2019-12-11 15:33 ` David Edmondson
2019-12-11 15:42 ` Alan Schmitt
2019-12-11 17:46 ` Carl Worth
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).