add mbsync config generator
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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 *");
|
||||
});
|
||||
});
|
||||
@@ -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 *
|
||||
`;
|
||||
}
|
||||
Reference in New Issue
Block a user