Metadata-Version: 2.4
Name: lite-email-parser
Version: 2.2.5
Summary: Parse email to get signature, replies, attachments and inline images
Author-email: Henrique Teixeira Silva <henriqueteixeirasilva16@gmail.com>, Philipe Dutra Cunha <philipedtc@gmail.com>
License: MIT
Project-URL: Homepage, https://github.com/philipedc/lite-email-parser
Project-URL: Repository, https://github.com/philipedc/lite-email-parser
Project-URL: Issues, https://github.com/philipedc/lite-email-parser/issues
Keywords: email,parser,email-parser,extract-attachments,remove-signature,remove-replies,inline-images,lite-email-parser,email-to-html,signature-remover
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: C++
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Communications :: Email
Classifier: Topic :: Text Processing :: Markup :: HTML
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# Lite email parser (Python)

Simple library to remove signature and replies and extract attachments and inline attachments from an email. Built using a C++ lib [Core](https://github.com/philipedc/lite-email-parser) for maximum performance. There's also bindings for [Node.js](https://www.npmjs.com/package/lite-email-parser)

If you stumble upon an email that is not parsed correctly, please create an issue and attach the raw .eml file.

## Installation

```bash
pip install lite-email-parser
```

## Python usage

### Import

`from lite_email_parser import parse_email`

### Usage

#### No file upload

```python
from lite_email_parser import parse_email

# Load your email (bytes or str accepted here)
with open('email.eml', 'rb') as f:
    email = f.read()

result = parse_email(email)

print(result)
```
[See sample](https://github.com/philipedc/lite-email-parser/blob/main/python/samples/simple.py)

#### File upload

```python
from lite_email_parser import parse_email, replace_src

# Load your email (bytes or str accepted here)
with open('email.eml', 'rb') as f:
    email = f.read()

result = parse_email(email)

uploaded_inline = []

for file in result['inline_attachments']:
    url = upload_to_s3('my-bucket', file['name'], file['buffer'])
    uploaded_inline.append({ 'original_src': file['original_src'], 'src': url })

final_html = replace_src(result['last_message'], uploaded_inline)
```
[See sample](https://github.com/philipedc/lite-email-parser/blob/main/python/samples/upload.py)

## Methods and Interfaces

### `parse_email(email: Union[bytes, str]) -> dict`
Parses the raw `.eml` file content and extracts the clean HTML message along with attachments.

**Returns:**
A dictionary with the following keys:
- `last_message` (`str`): The pure HTML content with replies and signatures stripped.
- `attachments` (`list` of `dict`): A list of standard attachments.
- `inline_attachments` (`list` of `dict`): A list of inline attachments embedded in the email.

Each file dictionary contains:
- `name` (`str`): File name.
- `type` (`str`): MIME type.
- `size` (`int`): File size in bytes.
- `buffer` (`bytes`): File binary data.
- `src` (`str`, optional): Replaced source URL (if modified).
- `original_src` (`str`, optional): The original `cid:` or source URL found in the HTML.

### `replace_src(html: str, files: list[dict]) -> str`
Replaces the `original_src` of inline attachments in the HTML with a new `src` URL.

### Other Methods
The following utilities are also exposed for individual operations on HTML:
- `clean_html(html: str) -> str`
- `remove_signature(html: str) -> str`
- `remove_replies(html: str) -> str`
- `remove_dividers(html: str) -> str`

## License

This project is licensed under the [MIT License](https://github.com/philipedc/lite-email-parser/blob/main/LICENSE)
