From c085ef2b0b989ade9bd61aa57fd2342e3d6e913f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20F=C3=B6rtsch?= Date: Tue, 10 Mar 2026 11:24:27 +0100 Subject: [PATCH] add mbsync config generator Co-Authored-By: Claude Opus 4.6 --- backend/src/services/sync.test.ts | 29 +++++++++++++++++++++++++ backend/src/services/sync.ts | 36 +++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 backend/src/services/sync.test.ts create mode 100644 backend/src/services/sync.ts diff --git a/backend/src/services/sync.test.ts b/backend/src/services/sync.test.ts new file mode 100644 index 0000000..0fa4457 --- /dev/null +++ b/backend/src/services/sync.test.ts @@ -0,0 +1,29 @@ +import { describe, expect, test } from "bun:test"; +import { generateMbsyncConfig } from "./sync"; + +describe("generateMbsyncConfig", () => { + test("generates valid mbsyncrc for a single IMAP account", () => { + const config = generateMbsyncConfig({ + id: "personal", + host: "mail.example.com", + user: "user@example.com", + passCmd: "cat ~/.mail-pass", + sslType: "IMAPS", + mailDir: "/home/user/Mail/personal", + }); + + expect(config).toContain("IMAPAccount personal"); + expect(config).toContain("Host mail.example.com"); + expect(config).toContain("User user@example.com"); + expect(config).toContain('PassCmd "cat ~/.mail-pass"'); + expect(config).toContain("SSLType IMAPS"); + expect(config).toContain("Path /home/user/Mail/personal/"); + expect(config).toContain("Inbox /home/user/Mail/personal/Inbox"); + expect(config).toContain("Channel personal"); + expect(config).toContain("Far :personal-remote:"); + expect(config).toContain("Near :personal-local:"); + expect(config).toContain("Patterns *"); + expect(config).toContain("Create Both"); + expect(config).toContain("SyncState *"); + }); +}); diff --git a/backend/src/services/sync.ts b/backend/src/services/sync.ts new file mode 100644 index 0000000..b324237 --- /dev/null +++ b/backend/src/services/sync.ts @@ -0,0 +1,36 @@ +export interface ImapAccount { + id: string; + host: string; + user: string; + passCmd: string; + sslType: "IMAPS" | "STARTTLS"; + mailDir: string; +} + +export function generateMbsyncConfig(account: ImapAccount): string { + const { id, host, user, passCmd, sslType, mailDir } = account; + const trailingSlashDir = mailDir.endsWith("/") ? mailDir : `${mailDir}/`; + + return `IMAPAccount ${id} +Host ${host} +User ${user} +PassCmd "${passCmd}" +SSLType ${sslType} + +IMAPStore ${id}-remote +Account ${id} + +MaildirStore ${id}-local +Subfolders Verbatim +Path ${trailingSlashDir} +Inbox ${trailingSlashDir}Inbox + +Channel ${id} +Far :${id}-remote: +Near :${id}-local: +Patterns * +Create Both +Expunge None +SyncState * +`; +}