{"id":38020097,"url":"https://github.com/ansemjo/imapfetch","last_synced_at":"2026-01-16T19:28:17.310Z","repository":{"id":40413773,"uuid":"154547149","full_name":"ansemjo/imapfetch","owner":"ansemjo","description":"python script to download all emails from a mailserver and store them in a maildir format","archived":false,"fork":false,"pushed_at":"2025-11-10T21:05:33.000Z","size":327,"stargazers_count":28,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-11-10T23:16:24.513Z","etag":null,"topics":["backup","imap","mailboxes","maildir"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ansemjo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2018-10-24T18:13:11.000Z","updated_at":"2025-11-10T21:05:30.000Z","dependencies_parsed_at":"2024-03-03T20:27:29.052Z","dependency_job_id":"aaf061a7-dca9-447e-95c9-ae6dd4394773","html_url":"https://github.com/ansemjo/imapfetch","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/ansemjo/imapfetch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ansemjo%2Fimapfetch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ansemjo%2Fimapfetch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ansemjo%2Fimapfetch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ansemjo%2Fimapfetch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ansemjo","download_url":"https://codeload.github.com/ansemjo/imapfetch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ansemjo%2Fimapfetch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28481726,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backup","imap","mailboxes","maildir"],"created_at":"2026-01-16T19:28:17.074Z","updated_at":"2026-01-16T19:28:17.271Z","avatar_url":"https://github.com/ansemjo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# imapfetch\n\n`imapfetch.py` is a relatively straighforward Python script to download all emails from an IMAP4 mailserver and store them locally in a simple, plaintext maildir format, e.g. for backup purposes.\n\n### New Version v1.0.0\n\nThe new development branch was finally merged into `main`. Unfortunately, it has a few incompatible changes, so I bumped the major version. **You cannot use v1 with old archives created with v0**, the new version will not know about the previously archived mails.\n\nThat being said, I think the changes are well worth the switch:\n\n* uses `IMAPClient` library for safer communication to the server\n* SHA224 header digests used in filename, as a sort of content-addressing scheme\n* completely rewritten logging, silent by default\n* switched index to a simple SQLite file\n\n## INSTALL\n\nYou can quickly install directly from GitHub with `pip`:\n\n    pip install git+https://github.com/ansemjo/imapfetch.git\n\nFor other options, see [packaging](#packaging) below.\n\n## USAGE\n\nConfigure your accounts using the provided [configuration sample](assets/settings.cfg) and run:\n\n    imapfetch settings.cfg\n\nUse `--help` to see a list of possible options:\n\n    imapfetch [-h] [--full] [--list] [--verbose] [--start-date START_DATE] [--end-date END_DATE] config [section ...]\n\nThe configuration file is passed as the first and only required positional argument. Any further positional arguments are section names from the configuration file, which will be run exclusively; for example if you want to archive only a single account at a time.\n\n+ `--list`: Only show a list of folders for every account and exit. Useful to get an overview of your accounts before writing exclusion patterns or just checking connectivity.\n\n* `--full`: Perform a full backup by starting with UID 1 in every folder; only useful if the server returns inconsistent or not strictly monotonically increasing UIDs. Duplicate mails which are already in the index will not be downloaded either way.\n\n- `--verbose`: Show more verbose logging. Can be passed multiple times.\n\n+ `--start-date START_DATE`: Start date for filtering messages (YYYY-MM-DD)\n\n* `--end-date END_DATE`: End date for filtering messages (YYYY-MM-DD)\n\n## CONFIGURATION\n\nThe available configuration options are mostly explained in the provided sample.\n\n- you add one `[section]` per account\n- `archive` points to the directory where you want to store the mails\n- `server`, `username` and `password` are the IMAP4 connection details\n\n- `exclude` is a multi-line string of UNIX-style globbing patterns to exclude folders from the\n  backup; one pattern per line\n- `quoting` enables urlencoding of folder names before writing to disk; some systems will not handle all allowed inbox characters otherwise\n\nMinimal required sample:\n\n    [myarchive]\n    archive     = ~/mailarchive\n    server      = imap.strato.de\n    username    = max@mustermann.de\n    password    = verySecurePassword\n\n### RUNNING\n\nDuring execution the `archive` directory is created if it does not exist and a simple `index.db` is created, which is an SQLite file.\n\nFor every backed up folder a subdirectory is created with the same name. Those subdirectories are [maildir](http://www.qmail.org/man/man5/maildir.html) mailboxes and can be viewed with most email clients; for example `mutt`.\n\nFor every E-Mail in that folder, the header is downloaded and hashed. If the resulting digest is not present in the index, the rest of the email is downloaded and stored in the local maildir. This is done to detect duplicates and avoid storing a mail twice if it is moved between folders.\n\n    $ tree archive/ -L 2\n    archive/\n    ├── INBOX\n    │   ├── cur\n    │   ├── new\n    │   └── tmp\n    ├── index.db\n    ├── muttrc\n    ...\n\n### BACKUP\n\nOnce `imapfetch` is done you have a local copy of all your emails. This is a **one-way operation**, no emails that are deleted online are ever deleted in your archive. You can then backup that entire directory as-is with tools like [borg](https://www.borgbackup.org/) or [restic](https://restic.net/). Both do a fantastic job at deduplicating existing data, so you don't waste much space even if you take daily or even hourly snapshots.\n\nIf you are sufficiently sure that you will never have an inbox folder called `backup` on your mailserver you might do something like this:\n\n    borg init --encryption repokey-blake2 ./backup\n    borg create --stats --progress --compression zstd \\\n      ./backup::$(date --utc +%F-%H%M%S%Z) INBOX*/ index\n\n### VIEWING\n\nGenerally all applications that handle maildir mailboxes should be able to browse your archive. `mutt` is a nice terminal application that is able to handle these archives with an absolute minimum configuration. A sample is [provided](assets/muttrc) with this project: just copy the `muttrc` to your `archive` directory and run:\n\n    cd path/to/my/archive\n    mutt -F ./muttrc\n\nUse \u003ckbd\u003ec\u003c/kbd\u003e to change directories.\n\nGenerally, since maildir is a plaintext format, most commandline tools should work. `grep` is decently fast at finding specific emails, for example.\n\n## PACKAGING\n\nMake sure you run a decently modern version of Python 3; anything newer than `3.5` _should_ work but development was done on `3.10`.\n\n### PIP\n\nSince this project only uses a PEP 517 style `pyproject.toml`, you might have to update your `pip`. Install the package directly from GitHub as shown above or use a specific version archive:\n\n    pip install [--user] https://github.com/ansemjo/imapfetch/archive/v1.0.0.tar.gz\n\n### AUR\n\nOn Arch Linux install `imapfetch-git` with an AUR helper:\n\n    paru -S imapfetch-git\n\n### RPM, DEB, APK\n\nOther packages can be built with [ansemjo/fpm](https://hub.docker.com/r/ansemjo/fpm/) using `assets/Makefile`:\n\n    make -f assets/Makefile packages\n\nThese can then be installed locally with `yum` / `dnf` / `dpkg` etc.\n\n### CONTAINER\n\nAutomatic GitHub workflows regularly [build a container image](https://github.com/ansemjo/imapfetch/pkgs/container/imapfetch) using `assets/Dockerfile`, which includes `crond` to run the script on a specific schedule easily. Run the container with `docker` or `podman` like this:\n\n    docker run -d \\\n      -v ~/.config/imapfetch.cfg:/imapfetch.cfg \\\n      -v ~/mailarchive:/archive \\\n      -e SCHEDULE=\"*/15 * * * *\" \\\n      ghcr.io/ansemjo/imapfetch\n\nMake sure the `archive` key in your configuration points to the directory *as mounted inside the container*.\n\n## LICENSE\n\nThe script is licensed under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fansemjo%2Fimapfetch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fansemjo%2Fimapfetch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fansemjo%2Fimapfetch/lists"}