Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add recursive option, db-to-html option for msg-db files. #1

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions .github/workflows/python-app.yml

This file was deleted.

34 changes: 0 additions & 34 deletions .github/workflows/python-publish.yml

This file was deleted.

5 changes: 0 additions & 5 deletions .gitignore

This file was deleted.

27 changes: 25 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2021 Jeroen Overschie
Original Copyright (c) 2021 Jeroen Overschie

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,27 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.


Later Portions Copyright (c) 2024 Jordan Haisley

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
64 changes: 33 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,58 @@
# eml-to-html
[![build status](https://github.com/dunnkers/eml-to-html/actions/workflows/python-app.yml/badge.svg)](https://github.com/dunnkers/eml-to-html/actions/workflows/python-app.yml) [![pypi badge](https://img.shields.io/pypi/v/eml-to-html.svg?maxAge=3600)](https://pypi.org/project/eml-to-html/) [![Black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![Downloads](https://pepy.tech/badge/eml-to-html/month)](https://pepy.tech/project/eml-to-html) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/eml-to-html) ![PyPI - License](https://img.shields.io/pypi/l/hydra-core)
# Enhanced EML to HTML Converter

Tiny CLI tool that converts `.eml` email files to `.html` files.
A comprehensive CLI tool that transforms `.eml` email files into readable `.html` files, now featuring recursive directory processing and database conversion for complete email account preservation.

## Installation
```
pip install eml-to-html
```
## Features
- **EML to HTML Conversion**: Quickly convert single or multiple `.eml` files to `.html`.
- **Recursive Directory Processing**: Use the `-r` flag to process all `.eml` files within a directory, including nested directories.
- **DB to HTML Conversion**: Specifically catered for email backups (e.g., from GYB) stored in a `msg-db.sqlite` database, allowing direct conversion to `.html`.

## Usage
Basic usage:
```
eml-to-html [EML FILE]...
```

Feel free to pass a _glob_. For example:

For multiple files or using a _glob_:
```
eml-to-html some_email_file_1.eml some_email_file_2.eml
eml-to-html example1.eml example2.eml
eml-to-html *.eml
```

and

To recursively process directories:
```
eml-to-html *.eml
eml-to-html -r [DIRECTORY]
```
This option intelligently skips existing files, facilitating incremental conversions.

are both valid calls to the command. Cheers!

### DB to HTML Conversion
For converting email databases:
```
db-to-html [DB FILE]
```
Optionally, specify an output file:
```
db-to-html [DB FILE] [OUTPUT FILE]
```

## Example

Running `eml-to-html` on the [`test_emails`](https://github.com/dunnkers/eml-to-html/tree/master/test_emails) folder:

### EML to HTML
```
$ eml-to-html test_emails/*.eml
🟢 Written `test_email_1.html`
🟢 Written `test_email_2.html`
Written: `test_email_1.html`
Written: `test_email_2.html`
```

File tree is now:

### DB to HTML
```
$ tree test_emails
test_emails
├── test_email_1.eml
├── test_email_1.html
├── test_email_2.eml
└── test_email_2.html

0 directories, 4 files
$ db-to-html msg-db.sqlite
Processed: `msg-db.sqlite` into HTML files.
```

## About
This micro module was written by [Jeroen Overschie](https://jeroenoverschie.nl/) in 2022.
The Enhanced EML to HTML Converter is developed by Jordan Haisley, building upon the original micro module crafted by [Jeroen Overschie](https://jeroenoverschie.nl/) in 2022. This version introduces advanced functionalities—recursive directory processing and database conversion—to meet the evolving needs for comprehensive email data processing and preservation.

For more information, updates, or to contribute, please visit the [GitHub repository](https://github.com/jhaisley/eml-to-html).

Your feedback and contributions are always welcomed as we aim to make email data management easier and more accessible for everyone.
18 changes: 18 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Security Policy

## Supported Versions

Upon release, major revisions are provided with security updates.

The most recent alpha or pre-release version is also provided with security updates, but may experience breaking changes.


| Version | Supported |
| ------- | ------------------ |
| v2.0.0 | :white_check_mark: |
| v2a | :white_check_mark: |
| <v2a | :x: |

## Reporting a Vulnerability

Report vulnerabilities on github to this project.
41 changes: 41 additions & 0 deletions db-to-html.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import sqlite3
import pandas as pd
import sys

def db_to_html(db_path: str, html_path: str):
# Connect to the SQLite database
conn = sqlite3.connect(db_path)

# Get a cursor object
cursor = conn.cursor()

# Get the list of all tables in the database
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables = cursor.fetchall()

# For each table, read it into a pandas DataFrame and write it to the HTML file
with open(html_path, 'w') as f:
for table in tables:
df = pd.read_sql_query(f"SELECT * from {table[0]}", conn)
f.write(df.to_html())
f.write("\n")

# Close the connection to the SQLite database
conn.close()

def main():
if len(sys.argv) < 2:
print("Usage: db_to_html.py <database_path> [<html_output_path>]")
sys.exit(1)

db_path = sys.argv[1]

if len(sys.argv) == 3:
html_path = sys.argv[2]
else:
html_path = db_path.rsplit('.', 1)[0] + '.html'

db_to_html(db_path, html_path)

if __name__ == "__main__":
main()
17 changes: 14 additions & 3 deletions eml_to_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from email.message import Message
from pathlib import Path
import sys
import argparse
from typing import Any, List, Union


Expand Down Expand Up @@ -45,11 +46,21 @@ def eml_to_html(eml_path_str: Union[str, Path]) -> Path:
return html_path



def main():
file_paths: List[str] = sys.argv[1:]
parser = argparse.ArgumentParser()
parser.add_argument('-r', '--recursive', action='store_true', help='Recursively process directories')
parser.add_argument('paths', nargs='*', help='Paths to process')
args = parser.parse_args()

for path_str in args.paths:
path = Path(path_str)
if path.is_file():
eml_to_html(path)
elif path.is_dir() and args.recursive:
for eml_path in path.rglob('*.eml'):
eml_to_html(eml_path)

for file_path in file_paths:
eml_to_html(file_path)


if __name__ == "__main__":
Expand Down
9 changes: 7 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
LONG_DESC = fh.read()
setup(
name="eml-to-html",
version="0.0.2",
version="0.0.3",
py_modules=["eml_to_html"],
scripts=["eml_to_html.py"],
entry_points={"console_scripts": ["eml-to-html = eml_to_html:main"]},
entry_points={
"console_scripts": [
"eml-to-html = eml_to_html:main",
"db-to-html = db_to_html:main"
]
},
description="Converts `.eml` files to HTML.",
keywords="",
long_description=LONG_DESC,
Expand Down