Karta.Scan.ClamAV (Karta v1.0.0)

Virus scanning of a received message through clamd's INSTREAM command, before the final reply to DATA.

The spool file is streamed to clamd in chunks of 64 KiB, each with its length in front as the protocol wants, and the file is never read into memory: a message costs one chunk here whatever its size. One connection is made per scan, and nothing is retried inside the SMTP session: a scanner that cannot answer is the caller's fail-closed decision, not a silent second attempt.

scan/2 returns

  • {:ok, :clean} - clamd answered stream: OK;
  • {:ok, {:infected, name}} - clamd answered stream: <name> FOUND; the name is cut to 64 characters and to letters, digits, _, - and .;
  • {:error, reason} - clamd could not answer (:timeout, :econnrefused, :answer_too_large, {:clamd, "..."}, ...), or the message is larger than :max_size (:too_large).

Options: :host and :port (a TCP connection, the default port 3310), or :socket (a Unix socket path), :timeout (milliseconds for the connection and each read), :max_size (bytes; a larger message is not sent) and :chunk (bytes per chunk, for tests). The caller sets the budget: without :timeout and :max_size nothing is bounded here (Karta.Scan gives both).

Summary

Functions

Scans the message at path. See the module doc.

Functions

scan(path, opts)

@spec scan(Path.t(), keyword()) ::
  {:ok, :clean | {:infected, String.t()}} | {:error, term()}

Scans the message at path. See the module doc.