maildir形式のファイルをgmailに移す

IMAPのAPPENDコマンドでmaildir形式のファイルをGmailに送る

#!/usr/bin/env node
"use strict";

const simpleParser = require("mailparser").simpleParser;
const { ImapFlow } = require("imapflow");
const client = new ImapFlow({
  host: "imap.gmail.com",
  port: 993,
  secure: true,
  auth: {
    user: "hoge@gmail.com",
    pass: "password",
  },
});
const fs = require("fs");

(async () => {
  const mail = fs.readFileSync(
    process.argv[2],
    "utf8"
  );
  const parsed = await simpleParser(mail);
  await client.connect();
  await client.append("INBOX", mail, ["\\Seen"], parsed.date);
  await client.logout();
})().catch((e) => {
  console.log(e);
  process.exit(1);
});