← All procedures

mail.headers

Give the headers of the recent messages of an IMAP mailbox, read only (no message becomes read)

CLI
Package
@procedures/mail · README
Path
["mail","headers"]
CLI
mark mail headers --host <string> --user <string>
As data
{"$proc":["mail","headers"],"input":{}}

Use it

In TypeScript

import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/mail/register"; // registers its procedures

const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const result = await client.exec(["mail","headers"], { host: "<host>", user: "<user>" });
console.log(JSON.stringify(result));

From the command line

$ mark mail headers --host <string> --user <string>

As data, in a program

{
  "$proc": ["mail", "headers"],
  "input": { "host": "<host>", "user": "<user>" }
}

Input

FieldTypeRequiredDefaultDescription
hoststringyesThe IMAP server, for example imap.gmail.com
portintegerno993The port (default: 993)
securebooleannotrueUse TLS from the start (default: true)
userstringyesThe user name of the mailbox
passwordEnvstringno"IMAP_PASSWORD"The name of the environment variable that holds the password: IMAP_ or MAIL_ and more (default: IMAP_PASSWORD). The password is never an input, so no log records it.
mailboxstringno"INBOX"The mailbox (default: INBOX)
sinceDaysintegerno1The messages of this number of days (default: 1)
limitintegerno200The maximum number of messages, the newest first (default: 200)
timeoutMsintegerno60000The time limit, in milliseconds (default: 60000)

Output

FieldTypeRequiredDefaultDescription
messagesobject[]yes
JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "host": {
        "type": "string",
        "minLength": 1,
        "description": "The IMAP server, for example imap.gmail.com"
      },
      "port": {
        "default": 993,
        "description": "The port (default: 993)",
        "type": "integer",
        "minimum": 1,
        "maximum": 65535
      },
      "secure": {
        "default": true,
        "description": "Use TLS from the start (default: true)",
        "type": "boolean"
      },
      "user": {
        "type": "string",
        "minLength": 1,
        "description": "The user name of the mailbox"
      },
      "passwordEnv": {
        "default": "IMAP_PASSWORD",
        "description": "The name of the environment variable that holds the password: IMAP_ or MAIL_ and more (default: IMAP_PASSWORD). The password is never an input, so no log records it.",
        "type": "string",
        "pattern": "^(?:IMAP|MAIL)_[A-Za-z0-9_]+$"
      },
      "mailbox": {
        "default": "INBOX",
        "description": "The mailbox (default: INBOX)",
        "type": "string",
        "minLength": 1
      },
      "sinceDays": {
        "default": 1,
        "description": "The messages of this number of days (default: 1)",
        "type": "integer",
        "minimum": 1,
        "maximum": 365
      },
      "limit": {
        "default": 200,
        "description": "The maximum number of messages, the newest first (default: 200)",
        "type": "integer",
        "minimum": 1,
        "maximum": 5000
      },
      "timeoutMs": {
        "default": 60000,
        "description": "The time limit, in milliseconds (default: 60000)",
        "type": "integer",
        "exclusiveMinimum": 0,
        "maximum": 600000
      }
    },
    "required": [
      "host",
      "user"
    ]
  },
  "output": {
    "type": "object",
    "properties": {
      "messages": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "uid": {
              "type": "number"
            },
            "subject": {
              "type": "string"
            },
            "from": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "address": {
                    "type": "string"
                  }
                },
                "required": [
                  "address"
                ],
                "additionalProperties": false
              }
            },
            "to": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "address": {
                    "type": "string"
                  }
                },
                "required": [
                  "address"
                ],
                "additionalProperties": false
              }
            },
            "date": {
              "type": "string"
            },
            "seen": {
              "type": "boolean"
            }
          },
          "required": [
            "uid",
            "subject",
            "from",
            "to",
            "seen"
          ],
          "additionalProperties": false
        }
      }
    },
    "required": [
      "messages"
    ],
    "additionalProperties": false
  }
}