Skip to main content

imapbackup

Download all emails from an IMAP server and save these emails to .eml files, and allow you to restore these emails to a new imap server.

Install

pip install imapbackup

Usage

main

test@test emailbackup % imapbackup
Usage: imapbackup [OPTIONS] COMMAND [ARGS]...

Options:
  --username TEXT                 IMAP account username.  [required]
  --password TEXT                 IMAP account password.  [required]
  --host TEXT                     IMAP server host.  [required]
  --port INTEGER                  IMAP server port, default to 993 if SSL is
                                  enabled and default to 143 if SSL is not
                                  enabled.
  --ssl / --no-ssl                Enable ssl.
  --ssl-ciphers TEXT              SSL ciphers used to make SSL connection.
  --connection-timeout INTEGER    Connection timeout.
  --loglevel [DEBUG|INFO|WARN|ERROR]
  --logfmt [default|simple|message_only]
  --help                          Show this message and exit.

Commands:
  backup   Backup folders from IMAP server.
  list     List all folders of the IMAP server.
  restore  Restore all backup email files to IMAP server.
  upload   Upload eml to IMAP server.

backup

test@test emailbackup % imapbackup --host <imap.server.address> --ssl --username <username> --password <password> backup --help
Usage: imapbackup backup [OPTIONS] [FOLDER]...

  Backup folders from IMAP server. If no folder given, then backup all
  folders.

  Data save structure:

  ----------------------------------------------------------

  <Dest>

      <MailFolder 1>

          <mail_uid>-<mail_date>-<subject>-<mail_code>.eml

      <MailFolder ...>

          <mail_uid>-<mail_date>-<subject>-<mail_code>.eml

  ----------------------------------------------------------

  <Dest>: is your data storage root. Given by option -d.

  <MailFolder>: is the folder name from the IMAP server.

  <mail_uid>: is the mail's UID from the IMAP server.

  <mail_date>: is the mail's INTERNALDATE from the IMAP server.

  <subject>: is the mail's Subject. We replace slash “/” sign to underline "_"
  sign.

  <mail_code>: is the sha1 hash code of the mail's BODY.

  ----------------------------------------------------------

Options:
  -l, --limit INTEGER  Fetch limit.
  -d, --dest TEXT      Dest folder. Data storage root. Default to ./data/.
  --help               Show this message and exit.

list

test@test emailbackup % imapbackup --host <imap.server.address> --ssl --username <username> --password <password> list --help  
Usage: imapbackup list [OPTIONS]

  List all folders of the IMAP server.

Options:
  --folder-name-max-length INTEGER
  --folder-name-mask TEXT
  --help                          Show this message and exit.

restore

test@test emailbackup % imapbackup --host <imap.server.adddress> --ssl --username <username> --password <password> restore --help
Usage: imapbackup restore [OPTIONS] BACKUP_ROOT

  Restore all backup email files to IMAP server.

Options:
  --help  Show this message and exit.

upload

test@test emailbackup % imapbackup --host <imap.server.adddress> --ssl --username <username> --password <password> upload --help 
Usage: imapbackup upload [OPTIONS] DATA...

  Upload eml to IMAP server.

Options:
  -f, --folder TEXT  Upload eml to this folder. The folder MUST be created
                     already. Default to INBOX.
  --help             Show this message and exit.

Example

  1. backup imap server.
imapbackup --host <imap.server.address> --ssl --username username01@example.com --password 'Password!' --loglevel=DEBUG backup --dest 'username01@example.com'
  1. Your IMAP server address is <imap.server.address>, and using ssl connection, so that the imap server port is 993.

  2. Your email adddress is username01@example.com and your password is Password!.

  3. Write process log to logs/app.log, and set the log level to DEBUG.

  4. Save the backup emails under folder username01@example.com, group by IMAP folder, e.g. INBOX, 已发送.

  5. restore the backup data.

imapbackup --host <imap.server.address> --ssl --username username02@example.com --password 'Password!' --loglevel=DEBUG restore 'username01@example.com'
  1. Upload all emails under folder username01@example.com to the username02@example.com IMAP server.
  2. Mostly the emails are created by imapbackup command.

Release

v0.1.0

  • First release.

v0.1.1

  • Fix python 3.8 and below, imaplib.IMAP4 and imaplib.IMAP4_SSL doesn't support timeout parameter problem.

v0.1.2

  • Try to use Date from email body while doing upload.

Release files for imapbackup 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for imapbackup 0.1.2
File Size Uploaded
imapbackup-0.1.2.tar.gz 11.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for imapbackup 0.1.2
File Interpreter ABI Platform
imapbackup-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 23.3 kB

Release files / imapbackup-0.1.2.tar.gz

Download URL imapbackup-0.1.2.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
26c02786721dca2d5e7f044195e6526acc199e6dab67b95226219b8a1e40b494
BLAKE2b-256 checksum
How to use checksums
94c758e108345ebccc3bb2e911729f7c5028d6d4bf676099a6a9bd6f71cd167c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Release files / imapbackup-0.1.2-py3-none-any.whl

Download URL imapbackup-0.1.2-py3-none-any.whl
Size 11.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
281cb72c2db92d3648ab0e318cd823735a8df903c5078e40193381f579925105
BLAKE2b-256 checksum
How to use checksums
352d3c8a5f7c9c5bdb6af2a6df047933a0d4221096d86b364ea70154ab63eaab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page