/
syncnotmuchtag.py
executable file
·89 lines (71 loc) · 1.82 KB
/
syncnotmuchtag.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
import os
from notmuch import Database, Query
db = Database(
"/home/fbence/.mail/.notmuch", create=False, mode=Database.MODE.READ_WRITE
)
def move_maildir(msg, folder):
print(msg, folder)
path = msg.get_filename().replace("/.notmuch", "")
account = "/".join(path.split("/")[:5])
account = account.replace("/.notmuch", "")
filename = path.split("/")[-1]
print(filename)
try:
name, _, flags = filename.split(",")
except ValueError:
name, flags = filename.split(",")
os.rename(path, f"{account}/{folder}/cur/{name}:2,{flags}")
# move folders
foldernames = [
"1_megválaszolni",
"2_rám_vár",
"3_másra_vár",
"4_olvasni",
"5_információ",
"6_visszaigazolások",
"7_hivatalos+pénzügyek",
"Archive",
]
msgs = Query(
db,
"tag:aerc",
).search_messages()
for msg in msgs:
for t in msg.get_tags():
if t in foldernames:
move_maildir(msg, t)
break
for f in foldernames:
msg.remove_tag(f)
msg.remove_tag("aerc")
del msgs
# sync inbox
path1 = "elte/Inbox/**"
path2 = "priestoferis/Inbox/**"
path4 = "pharmahungary/Inbox/**"
path5 = "bence/Inbox/**"
msgs = Query(
db,
f"tag:inbox and not (path:{path1} or path:{path2} or path:{path4} or path:{path5})",
).search_messages()
for msg in msgs:
msg.remove_tag("inbox")
del msgs
msgs = Query(
db,
f"(path:{path1} or path:{path2} or path:{path4} or path:{path5}) and not tag:inbox",
).search_messages()
for msg in msgs:
msg.add_tag("inbox")
del msgs
# # sync unread
# msgs = Query(
# db,
# f"tag:unread and not (path:{path1} or path:{path2} or path:{path3} or path:{path4})",
# ).search_messages()
# for msg in msgs:
# msg.remove_tag("unread", sync_maildir_flags=True)
# del msgs
db.close()
del db