No description
Find a file
Clément BREISCH 82986081a6
All checks were successful
Build and Push Mail2NC / Load Configuration (push) Successful in 2s
Build and Push Mail2NC / Build (push) Successful in 41s
Build and Push Mail2NC / Functional Tests (push) Successful in 7s
Build and Push Mail2NC / Compliance Scan (push) Successful in 47s
Build and Push Mail2NC / Security Scan (push) Successful in 1m0s
Build and Push Mail2NC / Push to Production (push) Successful in 7s
Build and Push Mail2NC / Cleanup (push) Successful in 1s
use BODY.PEEK to prevent auto-seen on fetch failure, poll every 30s
2026-02-11 13:12:45 +00:00
.github/workflows pass security thresholds from metadata to scan action 2026-02-11 12:25:19 +00:00
examples add docker secrets support, security hardening, and example compose 2026-02-11 11:20:55 +00:00
.dockerignore initial commit: imap to nextcloud attachment forwarder 2026-02-11 11:13:45 +00:00
.gitignore initial commit: imap to nextcloud attachment forwarder 2026-02-11 11:13:45 +00:00
.metadata.json adjust security scan thresholds for distroless base image 2026-02-11 11:39:33 +00:00
Dockerfile use BODY.PEEK to prevent auto-seen on fetch failure, poll every 30s 2026-02-11 13:12:45 +00:00
main.py use BODY.PEEK to prevent auto-seen on fetch failure, poll every 30s 2026-02-11 13:12:45 +00:00
README.md use BODY.PEEK to prevent auto-seen on fetch failure, poll every 30s 2026-02-11 13:12:45 +00:00

Mail2NC

Polls an IMAP mailbox and uploads attachments to Nextcloud via WebDAV.

Quick Start

services:
  mail2nc:
    image: git.breis.ch/clement/mail2nc:latest
    environment:
      IMAP_HOST: mail.example.com
      IMAP_USER: scanner@example.com
      IMAP_PASS: secret
      NEXTCLOUD_URL: https://cloud.example.com
      NEXTCLOUD_USER: admin
      NEXTCLOUD_PASS: secret
    volumes:
      - mail2nc-data:/data

volumes:
  mail2nc-data:

For a production setup with Docker secrets and full security hardening, see examples/docker-compose.yml.

Environment Variables

Required

Variable Description
IMAP_HOST IMAP server hostname
IMAP_USER IMAP login username
IMAP_PASS IMAP login password
NEXTCLOUD_URL Nextcloud base URL (e.g. https://cloud.example.com)
NEXTCLOUD_USER Nextcloud username for WebDAV uploads
NEXTCLOUD_PASS Nextcloud password or app token

Optional

Variable Default Description
IMAP_PORT 993 IMAP SSL port
IMAP_FOLDER INBOX IMAP folder to monitor
NEXTCLOUD_FOLDER /Scans Nextcloud destination folder
POLL_INTERVAL 30 Seconds between mailbox checks

Docker Secrets

All variables support the _FILE suffix for Docker secrets. When set, the value is read from the file path provided.

secrets:
  imap_password:
    file: ./secrets/imap_password.txt

services:
  mail2nc:
    environment:
      IMAP_PASS_FILE: /run/secrets/imap_password
    secrets:
      - imap_password

How It Works

  1. Connects to the IMAP server over SSL
  2. Searches for new/unseen emails
  3. Extracts attachments from each email
  4. Uploads them to Nextcloud via WebDAV with sanitized filenames
  5. Marks successfully processed emails as read
  6. Persists state to /data/state.json to survive restarts

Filenames follow the pattern: YYYYMMDD_HHMMSS_uid<N>_<original_name>

If an upload fails, the email is not marked as read and will be retried on the next poll.

Persistence

Mount a volume at /data to persist the processing state across container restarts. Without it, previously processed emails may be re-uploaded.