You can use OfflineIMAP to download a
specified folder from the remote IMAP server. You could for example
.offlineimaprc.gmail that looks something like this:
# allow offlineimap access at https://myaccount.google.com/lesssecureapps
# List of accounts to be synced, separated by a comma.
accounts = main
# Identifier for the local repository; e.g. the maildir to be synced via IMAP.
localrepository = main-local
# Identifier for the remote repository; i.e. the actual IMAP, usually non-local.
remoterepository = main-remote
# Status cache. Default is plain, which eventually becomes huge and slow.
status_backend = sqlite
# Remote repos can be IMAP or Gmail, the latter being a preconfigured IMAP.
type = Gmail
remoteuser = firstname.lastname@example.org
remotepass = GMAIL_PASS
sslcacertfile = /etc/ssl/certs/ca-certificates.crt
# Currently, offlineimap only supports maildir and IMAP for local repositories.
type = Maildir
# Where should the mail be placed?
localfolders = ~/.gmail-emails
folderfilter = lambda folder: folder in ['[Gmail].Starred']
Replace values of
remotepass fields with your
correct username and password respectively and change
to the name of the folder you want to sync. Run
offlineimap -c .offlineimaprc.gmail
Downloaded mail will be put in
~/.gmail-emails/<FOLDER_NAME>. Each e-mail will be put in a separate file.
As for the HTML part, I use this Python
to display HTML in Firefox from mutt. It takes HTML formatted e-mail
on its standard input like this:
viewhtmlmail.py < 1567104704_1.12841.comp,U=4,FMD5=2af771a9578089448f7740e324bfbe89:2,F
The good thing about
viewhtmlmail.py is that it can combine all
parts of an HTML formatted e-mail together and show it in its original form
with all images embedded.