]> xn--ix-yja.es Git - alex.git/commitdiff
Refactor mbsync stuff
authoralex <alex@pdp7.net>
Thu, 19 Oct 2023 20:09:54 +0000 (22:09 +0200)
committeralex <alex@pdp7.net>
Thu, 19 Oct 2023 20:09:54 +0000 (22:09 +0200)
scripts/p7s/mail/__init__.py [new file with mode: 0644]
scripts/p7s/mail/mbsync.py [new file with mode: 0644]
scripts/p7s/mbsync.py [deleted file]
scripts/pyproject.toml

diff --git a/scripts/p7s/mail/__init__.py b/scripts/p7s/mail/__init__.py
new file mode 100644 (file)
index 0000000..f5db2d8
--- /dev/null
@@ -0,0 +1,14 @@
+import pathlib
+
+from p7s import bitwarden
+from p7s.mail import mbsync
+
+
+def generate_config():
+    gmail = bitwarden.get_item("https://bitwarden.pdp7.net", "alex@corcoles.net", "cad137b0-cfd5-4d5c-b167-98a9e792f4cc")["login"]
+    yahoo = bitwarden.get_item("https://bitwarden.pdp7.net", "alex@corcoles.net", "e24727e7-c0ef-4c97-afd0-8497d547304c")["login"]
+    (pathlib.Path.home() / (".mbsyncrc")).write_text(
+        mbsync.mbsync_gmail(gmail["username"], gmail["password"], "~/Mail") +
+        "\n" +
+        mbsync.mbsync_yahoo(yahoo["username"], yahoo["password"], "~/Mail")
+    )
diff --git a/scripts/p7s/mail/mbsync.py b/scripts/p7s/mail/mbsync.py
new file mode 100644 (file)
index 0000000..0aabeea
--- /dev/null
@@ -0,0 +1,54 @@
+import textwrap
+
+
+def mbsync_gmail(login, password, store_path):
+    return textwrap.dedent(f"""
+        IMAPAccount {login}
+        Host imap.gmail.com
+        SSLType IMAPS
+        User {login}
+        Pass {password}
+
+        IMAPStore {login}-remote
+        Account {login}
+
+        MaildirStore {login}-local
+        SubFolders Verbatim
+        Path {store_path}/{login}/
+        Inbox {store_path}/{login}/Inbox
+
+        Channel {login}
+        Far :{login}-remote:
+        Near :{login}-local:
+        Patterns *
+        Create Both
+        Expunge Both
+        SyncState *
+    """).lstrip()
+
+
+def mbsync_yahoo(login, password, store_path):
+    return textwrap.dedent(f"""
+        IMAPAccount {login}
+        Host imap.mail.yahoo.com
+        SSLType IMAPS
+        User {login}
+        Pass {password}
+        PipelineDepth 5
+
+        IMAPStore {login}-remote
+        Account {login}
+
+        MaildirStore {login}-local
+        SubFolders Verbatim
+        Path {store_path}/{login}/
+        Inbox {store_path}/{login}/Inbox
+
+        Channel {login}
+        Far :{login}-remote:
+        Near :{login}-local:
+        Patterns *
+        Create Both
+        Expunge Both
+        SyncState *
+    """).lstrip()
diff --git a/scripts/p7s/mbsync.py b/scripts/p7s/mbsync.py
deleted file mode 100644 (file)
index 8c4194e..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-import pathlib
-import textwrap
-
-from p7s import bitwarden
-
-
-def generate_config():
-    gmail_password = bitwarden.get_item("https://bitwarden.pdp7.net", "alex@corcoles.net", "cad137b0-cfd5-4d5c-b167-98a9e792f4cc")["login"]["password"]
-    (pathlib.Path.home() / (".mbsyncrc")).write_text(textwrap.dedent(f"""
-        IMAPStore gmail-remote
-        Host imap.gmail.com
-        SSLType IMAPS
-        AuthMechs LOGIN
-        User koalillo@gmail.com
-        Pass "{gmail_password}"
-
-        MaildirStore gmail-local
-        Path ~/Mail/koalillo@gmail.com/
-        Inbox ~/Mail/koalillo@gmail.com/INBOX
-        Subfolders Verbatim
-
-        Channel gmail
-        Far :gmail-remote:
-        Near :gmail-local:
-        Create Both
-        Expunge Both
-        Patterns *
-        SyncState *
-    """))
index 2df3f45549b6ff82e6b5666e5e8b940af6bf904e..b797e68b597daffec248de01176b5b1b9967e2b8 100644 (file)
@@ -17,6 +17,6 @@ build-backend = "poetry.core.masonry.api"
 
 [tool.poetry.scripts]
 ruscreen = 'p7s.ruscreen:main'
-mbsync_config = 'p7s.mbsync:generate_config'
+mbsync_config = 'p7s.mail:generate_config'
 db-create = 'p7s.distrobox:create'
 db-enter = 'p7s.distrobox:enter'