Difference between revisions of "PyThunderbird"

From BITPlan Wiki
Jump to navigation Jump to search
 
(20 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
=OsProject=
 +
 +
{{OsProject
 +
|id=pyThunderbird
 +
|state=active
 +
|owner=WolfgangFahl
 +
|title=pyThunderbird
 +
|url=https://github.com/WolfgangFahl/pyThunderbird
 +
|version=0.2.0
 +
|date=2024-08-01
 +
|since=2020-10-24
 +
|storemode=property
 +
}}
 +
= Motivation =
 
Thunderbird uses mailbox format and an sqlite database for keeping track of the mails.
 
Thunderbird uses mailbox format and an sqlite database for keeping track of the mails.
 
How can this setup be accessed with Python?
 
How can this setup be accessed with Python?
 +
{{pip|pyThunderbird}}
 +
= Demo =
 +
* http://pythunderbird-demo.bitplan.com/
 +
 +
= Usage =
 +
<source lang='bash'>
 +
tbmail -h
 +
usage: tbmail [-h] [-a] [-c] [-d] [--debugServer DEBUGSERVER]
 +
              [--debugPort DEBUGPORT] [--debugRemotePath DEBUGREMOTEPATH]
 +
              [--debugLocalPath DEBUGLOCALPATH] [-l] [-i INPUT] [-rol]
 +
              [--host HOST] [--port PORT] [-s] [-V] [-u USER] [-m MAILID]
 +
              [-ul USER_LIST [USER_LIST ...]] [-ci] [-f] [-v]
 +
 +
python based access to Thunderbird mail
 +
 +
options:
 +
  -h, --help            show this help message and exit
 +
  -a, --about          show about info [default: False]
 +
  -c, --client          start client [default: False]
 +
  -d, --debug          show debug info [default: False]
 +
  --debugServer DEBUGSERVER
 +
                        remote debug Server
 +
  --debugPort DEBUGPORT
 +
                        remote debug Port
 +
  --debugRemotePath DEBUGREMOTEPATH
 +
                        remote debug Server path mapping - remotePath - path on
 +
                        debug server
 +
  --debugLocalPath DEBUGLOCALPATH
 +
                        remote debug Server path mapping - localPath - path on
 +
                        machine where python runs
 +
  -l, --local          run with local file system access [default: False]
 +
  -i INPUT, --input INPUT
 +
                        input file
 +
  -rol, --render_on_load
 +
                        render on load [default: False]
 +
  --host HOST          the host to serve / listen from [default: localhost]
 +
  --port PORT          the port to serve from [default: 8482]
 +
  -s, --serve          start webserver [default: False]
 +
  -V, --version        show program's version number and exit
 +
  -u USER, --user USER  id of the user
 +
  -m MAILID, --mailid MAILID
 +
                        id of the mail to retrieve
 +
  -ul USER_LIST [USER_LIST ...], --user-list USER_LIST [USER_LIST ...]
 +
  -ci, --create-index  create an alternative index for the given users's
 +
                        Thunderbird mailarchive
 +
  -f, --force          force the creation of a new index even if one already
 +
                        exists
 +
  -v, --verbose        show verbose infos e.g. on startup [default: False]
 +
</source>
 +
= Configuration =
 +
== $HOME/.thunderbird/thunderbird.yaml ==
 +
The yaml file has two entries per user
 +
* db: the path of the gloda (global-messages-sqlite)
 +
* profile: the path to the Thunderbird profile
 +
=== MacOS Example ===
 +
In this example we try to make sure that the python library doesn't interfere with the running thunderbird.
 +
<source lang='yaml'>
 +
joe:
 +
  db: /Users/joe/Library/Thunderbird/Profiles/klm97bfn.default/gloda.sqlite
 +
  profile: /Users/wf/Library/Thunderbird/Profiles/klm97bfn.default
 +
kathy:
 +
  db: /Users/kathy/Library/Thunderbird/Profiles/war97k3r.default/gloda.sqlite
 +
  profile: /Users/kathy/Library/Thunderbird/Profiles/war97k3r.default
 +
</source>
 +
==== gloda script ====
 +
If you put this in your local bin directory you can call it from the command line any time you'd like to get an updated gloda that is a copy of the global-messages-db.sqlite
 +
you need to adapt the Profile location
 +
<source lang='bash'>
 +
#!/bin/bash
 +
# WF 2021-09-22
 +
# copy the thunderbird gloda sqlite database
 +
cd /Users/joe/Library/Thunderbird/Profiles/klm97bfn.default
 +
cp -p  global-messages-db.sqlite gloda.sqlite
 +
</source>
 +
=== Linux example ===
 +
in this example the server runs from an rsync'ed backup of the thunderbird files of the different users
 +
<source>
 +
user123:
 +
  db: /hd/diskAlpha/backup/siteAlpha.com/user123/Library/Thunderbird/Profiles/randomID1.default/global-messages-db.sqlite
 +
  profile: /hd/diskAlpha/backup/siteAlpha.com/user123/Library/Thunderbird/Profiles/randomID1.default
 +
user456:
 +
  db: /hd/diskBeta/backup/siteBeta.com/user456/Library/Thunderbird/Profiles/randomID2.default/global-messages-db.sqlite
 +
  profile: /hd/diskBeta/backup/siteBeta.com/user456/Library/Thunderbird/Profiles/randomID2.default
 +
</source>
 +
 
= Relevant Libraries =
 
= Relevant Libraries =
 
* https://docs.python.org/3.8/library/mailbox.html
 
* https://docs.python.org/3.8/library/mailbox.html
Line 7: Line 106:
 
= Links =
 
= Links =
 
* https://stackoverflow.com/questions/21625906/access-thunderbird-emails-by-python
 
* https://stackoverflow.com/questions/21625906/access-thunderbird-emails-by-python
 +
* https://stackoverflow.com/questions/60938536/decoding-mail-subject-thunderbird-in-python-3-x
 
* https://medium.com/shanes-tech-tips/offlineimap-to-thunderbird-152bb02286f
 
* https://medium.com/shanes-tech-tips/offlineimap-to-thunderbird-152bb02286f
 
* https://groups.google.com/g/comp.lang.python/c/sp-3_ddmgbA?pli=1
 
* https://groups.google.com/g/comp.lang.python/c/sp-3_ddmgbA?pli=1
 
* https://wlsoft.de/?q=node/369
 
* https://wlsoft.de/?q=node/369
 +
* https://github.com/rooper/thunderbirdscraper/blob/master/run.py
 +
* https://stackoverflow.com/questions/26567843/reading-the-mail-content-of-an-mbox-file-using-python-mailbox/26567942

Latest revision as of 07:33, 1 August 2024

OsProject

OsProject
edit
id  pyThunderbird
state  active
owner  WolfgangFahl
title  pyThunderbird
url  https://github.com/WolfgangFahl/pyThunderbird
version  0.2.0
description  
date  2024-08-01
since  2020-10-24
until  

Motivation

Thunderbird uses mailbox format and an sqlite database for keeping track of the mails. How can this setup be accessed with Python?


Installation

pip install pyThunderbird
# alternatively if your pip is not a python3 pip
pip3 install pyThunderbird 
# local install from source directory of pyThunderbird 
pip install .

upgrade

pip install pyThunderbird  -U
# alternatively if your pip is not a python3 pip
pip3 install pyThunderbird -U


Demo

Usage

tbmail -h
usage: tbmail [-h] [-a] [-c] [-d] [--debugServer DEBUGSERVER]
              [--debugPort DEBUGPORT] [--debugRemotePath DEBUGREMOTEPATH]
              [--debugLocalPath DEBUGLOCALPATH] [-l] [-i INPUT] [-rol]
              [--host HOST] [--port PORT] [-s] [-V] [-u USER] [-m MAILID]
              [-ul USER_LIST [USER_LIST ...]] [-ci] [-f] [-v]

python based access to Thunderbird mail

options:
  -h, --help            show this help message and exit
  -a, --about           show about info [default: False]
  -c, --client          start client [default: False]
  -d, --debug           show debug info [default: False]
  --debugServer DEBUGSERVER
                        remote debug Server
  --debugPort DEBUGPORT
                        remote debug Port
  --debugRemotePath DEBUGREMOTEPATH
                        remote debug Server path mapping - remotePath - path on
                        debug server
  --debugLocalPath DEBUGLOCALPATH
                        remote debug Server path mapping - localPath - path on
                        machine where python runs
  -l, --local           run with local file system access [default: False]
  -i INPUT, --input INPUT
                        input file
  -rol, --render_on_load
                        render on load [default: False]
  --host HOST           the host to serve / listen from [default: localhost]
  --port PORT           the port to serve from [default: 8482]
  -s, --serve           start webserver [default: False]
  -V, --version         show program's version number and exit
  -u USER, --user USER  id of the user
  -m MAILID, --mailid MAILID
                        id of the mail to retrieve
  -ul USER_LIST [USER_LIST ...], --user-list USER_LIST [USER_LIST ...]
  -ci, --create-index   create an alternative index for the given users's
                        Thunderbird mailarchive
  -f, --force           force the creation of a new index even if one already
                        exists
  -v, --verbose         show verbose infos e.g. on startup [default: False]

Configuration

$HOME/.thunderbird/thunderbird.yaml

The yaml file has two entries per user

  • db: the path of the gloda (global-messages-sqlite)
  • profile: the path to the Thunderbird profile

MacOS Example

In this example we try to make sure that the python library doesn't interfere with the running thunderbird.

joe:
  db: /Users/joe/Library/Thunderbird/Profiles/klm97bfn.default/gloda.sqlite
  profile: /Users/wf/Library/Thunderbird/Profiles/klm97bfn.default
kathy:
  db: /Users/kathy/Library/Thunderbird/Profiles/war97k3r.default/gloda.sqlite
  profile: /Users/kathy/Library/Thunderbird/Profiles/war97k3r.default

gloda script

If you put this in your local bin directory you can call it from the command line any time you'd like to get an updated gloda that is a copy of the global-messages-db.sqlite you need to adapt the Profile location

#!/bin/bash
# WF 2021-09-22
# copy the thunderbird gloda sqlite database
cd /Users/joe/Library/Thunderbird/Profiles/klm97bfn.default
cp -p  global-messages-db.sqlite gloda.sqlite

Linux example

in this example the server runs from an rsync'ed backup of the thunderbird files of the different users

user123:
  db: /hd/diskAlpha/backup/siteAlpha.com/user123/Library/Thunderbird/Profiles/randomID1.default/global-messages-db.sqlite
  profile: /hd/diskAlpha/backup/siteAlpha.com/user123/Library/Thunderbird/Profiles/randomID1.default
user456:
  db: /hd/diskBeta/backup/siteBeta.com/user456/Library/Thunderbird/Profiles/randomID2.default/global-messages-db.sqlite
  profile: /hd/diskBeta/backup/siteBeta.com/user456/Library/Thunderbird/Profiles/randomID2.default

Relevant Libraries

Links