imap2mbox - backup utility into mbox file

About

A utility to export email folders from an IMAP server to local mbox files with YAML configuration and optional gzip compression.

Free for personal and non-commercial use. Contact me if you’d like to use it in your business.

Features:

Installation

Binary file

Ubuntu

Add my repo https://deb.blindage.org/#ubuntudebian and install imap2mbox.

Docker

With this image you can use it inside docker or kubernetes cronjob:

ghcr.io/21h/imap2mbox:1.0

Helm

Requres volume. Download helm chart package imap2mbox-cronjob with CronJob.

Create pvc.yaml for your backup volume and save:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: imap2mbox
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: csi-s3-cold
  resources:
    requests:
      storage: 1Gi

Now create all resources:

namespace="mail"
# create secret with config file
kubectl create secret generic imap2mbox-credentials --namespace ${namespace} \
    --from-file=./config.yaml --dry-run -o yaml > mbox-secret.yaml
kubectl apply -n ${namespace} -f mbox-secret.yaml

# create pvc with your backup storage
kubectl apply -n ${namespace} -f pvc.yaml

helm upgrade imap2mbox-backup -n ${namespace} --install imap2mbox-cronjob-1.0.0.tgz

Configuration

Create a config.yaml file in the same directory as the script:

imap:
  host: "imap.example.com"
  port: 993
  username: "user@example.com"
  password: "secret"
  tls: true           # implicit TLS, port 993
  starttls: false     # STARTTLS upgrade, port 143 (mutually exclusive with tls)

folders:
  - INBOX
  - Sent
  - Drafts
  - Archive
  - Spam

output:
  dir: "./backup"          # one .mbox file per folder will be created here
  gzip: false              # set true to write .mbox.gz instead
  max_message_size: 0      # bytes, 0 = no limit (e.g. 10485760 = 10 MB)

Usage

By default program search config.yaml in current directory or use:

imap2mbox -config config_for_mail.ru.yaml
imap2mbox -config config_for_gmail.com.yaml

Command-line Options

Option Description
-config PATH Path to YAML configuration file (default: config.yaml)
-dry-run Scan and report without writing anything

Importing into Claws Mail

Unpack mbox file before import into Claws Mail.

  1. In Claws Mail, go to File β†’ Import mbox file…
  2. Select the mbox file
  3. Claws Mail will automatically import all messages
claws mail import mbox

Security Notes

Author

Copyright by Vladimir Smagin, 2026.

Contacts: