aboutsummaryrefslogtreecommitdiff
path: root/services/docker/mail-server/aws-sendmail/main.ts
blob: 3a73a6fcf365b43b8234ec998c5685c0df674064 (plain)
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
import { MailTrafficDeliverer } from "./delivers/traffic.ts";
import { Logger } from "./logger.ts";

class BugError extends Error {
}

function warn(message: string) {
}

class MailProcessor {
  appendHeaders(
    rawMail: string,
    headers: [key: string, value: string][],
  ): string {
    const separatorMatch = rawMail.match(/(\r\n|\n)(\r\n|\n)/);
    if (separatorMatch == null) {
      throw new Error(
        "No header/body separator (2 successive EOLs) found. Cannot append headers.",
      );
    }

    if (separatorMatch[1] !== separatorMatch[2]) {
      warn("Different EOLs (\\r\\n and \\n) found in mail!");
    }

    const headerStr = headers.map(([k, v]) => `${k}: ${v}${separatorMatch[1]}`)
      .join("");
    const endOfHeadersIndex = separatorMatch.index! + separatorMatch[1].length;
    return rawMail.slice(0, endOfHeadersIndex) + headerStr +
      rawMail.slice(endOfHeadersIndex);
  }
}

class App {
  readonly logger = new Logger("log");
  readonly mailTrafficDeliverer = new MailTrafficDeliverer(this.logger);

  constructor() {
  }
}

if (import.meta.main) {
  const app = new App();
}