feat: add calendar event normalization and sanitization functions with tests

This commit is contained in:
Linus Rath
2026-03-27 18:46:20 +01:00
parent 42734f16c3
commit b868ad591d
17 changed files with 424 additions and 47 deletions
+39
View File
@@ -171,4 +171,43 @@ describe('sieve generator', () => {
expect(script).toContain('"Line with \\"quotes\\" and \\\\backslash"');
});
});
describe('Stalwart vacation-only script detection (parseScript)', () => {
it('should detect a plain Stalwart vacation-only script as non-opaque', () => {
const script = `require ["vacation"];\n\nvacation :subject "OOO" "I am away.";\n`;
const result = parseScript(script);
expect(result.isOpaque).toBe(false);
expect(result.vacation?.isEnabled).toBe(true);
expect(result.vacation?.subject).toBe('OOO');
expect(result.rules).toHaveLength(0);
});
it('should detect vacation script when body contains "if" keyword', () => {
const script = `require ["vacation"];\n\nvacation :subject "Away" "if you need help contact support.";\n`;
const result = parseScript(script);
expect(result.isOpaque).toBe(false);
expect(result.vacation?.isEnabled).toBe(true);
});
it('should detect vacation script when body contains "else" keyword', () => {
const script = `require ["vacation"];\n\nvacation "Otherwise I will respond when I return.";\n`;
const result = parseScript(script);
expect(result.isOpaque).toBe(false);
expect(result.vacation?.isEnabled).toBe(true);
});
it('should mark as opaque when real filter rules exist alongside vacation', () => {
const script = `require ["vacation", "fileinto"];\n\nvacation "Away";\n\nif header :contains "From" "boss@example.com" {\n fileinto "Important";\n}\n`;
const result = parseScript(script);
expect(result.isOpaque).toBe(true);
});
it('should handle Stalwart :mime format vacation script', () => {
const script = `require ["vacation", "relational", "date"];\n\nvacation :mime :subject "Test" "Content-Type: text/plain; charset=\\"utf-8\\"\nContent-Transfer-Encoding: 7bit\n\ntest";\n`;
const result = parseScript(script);
expect(result.isOpaque).toBe(false);
expect(result.vacation?.isEnabled).toBe(true);
expect(result.vacation?.subject).toBe('Test');
});
});
});