Skip to content

A python script to backup any IMAP capable email account to a HTML archive, nicely browsable, instead of weird folders (Maildir), one huge file (mbox), only needing a web browser to view (thunderbird) and no propritary code, so you can make sure I don't steal your password.

License

Notifications You must be signed in to change notification settings

xtsimpouris/imap-to-local-html

Repository files navigation

IMAP mailbox to local HTML files, email backup script

This is a python script to backup any IMAP capable email account to a bowsable HTML archive and a Maildir folder. Not one huge file (mbox), only needing a web browser to view and no proprietary code, so you can make sure I won't steal your password.

Screenshots

Running the program

Execution

Index page

Home page

Folder Overview page

Folder view

Email itself

Email view

Features

  • Python 3
  • Jinja2 template for HTML export
  • Bootstrap v4.4.1
  • Datatables to support sorting and searching in all columns within a folder
  • python-slugify so it doesn't matter any more what filenames attachments have. They will be always saved locally in whatever OS as invalid characters are slugified
  • Works with any IMAP/IMAPS account
  • Supports "Reply-to" header and shows threads for easy navigation Thread support
  • Supports multiple IMAP folders
  • Tries its best to handle many encodings. chardet is also comes into play to try and identify missing cases
  • Supports text, HTML and multipart email
  • Saves attachments
  • Mail are saved in HTML format only once, even if exists across different folders (like Google "labels" approach)
  • Backups to HTML files for easy browsing
  • Small HTML files can be backed up to external medium more easily, and can be sent over the internet more easily.
  • Backs up to Maildir for easy restoring

Changelog

New in version 8: (20-12-2021)

  • Python 3 support
  • Tries its best to handle many encodings

New in version 7: (18-12-2021)

  • Refactored to extract mails in different folders per account
  • Support bootstrap view

New in version 6 (up to fork from RaymiiOrg/NoPriv): (18-11-2013)

  • Add support to download all folders without typing them all out. Using "NoPriv_All" as foldername now downloads all available folders.
  • Fix quite a few HTML errors
  • Converted layout from HTML Kickstart to Twitter Bootstrap
  • Add offline mode (only converts the Maildir to HTML, does not try to download new email)

New in version 5:
(13-11-2013)

  • Fix issue #22, NoPriv does not crash on empty IMAP folders anymore
  • Fix issue #23, NoPriv now tries a few times when the IMAP connection is reset. This happens with Google Mail sometimes.

New in version 4:

New in version 3.1:

  • Added a sample muttrc file to view NoPriv with the Mutt mail client.

New in version 3:

  • Supports incremental backups
  • If you stop the backup while running, it will now continue were it left off
  • Unread mails stay unread, but are backed up (before they were marked as read)
  • Restoring possible because it also creates a Maildir
  • Better unicode support
  • Attachment page is now also styled

New in version 2:

  • Support for multiple IMAP folders
  • Index page is generated
  • Pages have menu now.
  • On running it shows all available IMAP folders.

Usage

  1. Clone the repository:

    git clone https://github.com/xtsimpouris/imap-to-local-html

  2. Set up your login details, imap server and ssl:

Clone imap-to-local-html.sample.yml to imap-to-local-html.yml and edit appropriately:

settings:
  domain: imap-domain-name
  username: login-username
  # password is optional, if not provided, it will be requested during execution
  # password: my-secret-password
  folders:
    # list of folders
    # one folder per line
    # or one regular expression per line
    - INBOX
    # to select all
    - --all
  ssl: true
  # default is true
  prettify: true

If you want to use SSL to connect to IMAP, enable or disable the options.

**If you want to backup all folders, enter --all as a selected folder

If you do not know all your folder names, execute python script and checkout the list of folders

If you use gmail and want to backup all your email, use the "[Gmail]/All Mail" folder. It might be named different if you use another locale, for me with a Dutch gmail account it is named "[Gmail]/Alle Berichten".

  1. Create a virtual environment and install dependences. It is always better to use a virtual environment

    1. Create one with python 3.x, for example python3 -m venv env
    2. Get into it, for example . env/bin/activate
    3. Install dependencies from requirements.txt, for example pip install -r requirements.txt
    4. Execute main program, for example python imap-to-local-html.py
    5. Get out from the virtual environment, for example deactivate
  2. Execute the script:

    python ./imap-to-local-html.py

  3. Browse the generated backup:

Open the file index.html in your browser. There are all your folders and emails.

If you only have a console, it works just fine in Links2 (see above screenshot):

`links2 ./index.html`

Requirements

Python 3

Tested with: Python 3.8

Known issues

  • No search function (across diffrent folders or within mail body).

Info on restoring

Script creates a Maildir folder, which houses all your email. You can restore this maildir folder to an IMAP account either by using the script linked at the top on this page, or use a mail client like Mutt or Evolution and transport it to an imap account via there.

About

A python script to backup any IMAP capable email account to a HTML archive, nicely browsable, instead of weird folders (Maildir), one huge file (mbox), only needing a web browser to view (thunderbird) and no propritary code, so you can make sure I don't steal your password.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published