Skip to content

Commit

Permalink
Merge branch 'release/4.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
fedelemantuano committed Nov 11, 2024
2 parents 77fe015 + e83cc38 commit fb34c0e
Show file tree
Hide file tree
Showing 36 changed files with 964 additions and 653 deletions.
106 changes: 103 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Python application
name: Python application and Docker image CI

on:
push:
Expand Down Expand Up @@ -32,13 +32,20 @@ jobs:
sudo cpan -f -i Email::Outlook::Message
- name: Run tests
env:
PYTHONPATH: src
run: |
pytest
pytest --cov=mailparser --cov-report=xml
python -m mailparser -v
python -m mailparser -h
mail-parser -f tests/mails/mail_malformed_3 -j
cat tests/mails/mail_malformed_3 | mail-parser -k -j
- name: Run pre-commit
if: matrix.python-version == '3.10'
run: |
make pre-commit
- name: Report to Coveralls
if: matrix.python-version == '3.10'
uses: coverallsapp/[email protected]
Expand All @@ -57,4 +64,97 @@ jobs:
name: build-artifacts
path: |
dist/mail-parser-*.tar.gz
dist/mail_parser-*.whl
dist/mail_parser-*.whl
- name: Publish to PyPI
if: matrix.python-version == '3.10' && startsWith(github.ref, 'refs/tags/')
uses: pypa/[email protected]
with:
user: ${{ secrets.PYPI_USERNAME }}
password: ${{ secrets.PYPI_PASSWORD }}

docker:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract branch or tag name
id: extract_ref
run: |
if [ -n "${GITHUB_HEAD_REF}" ]; then
REF_NAME=${GITHUB_HEAD_REF}
else
REF_NAME=$(git describe --tags --exact-match 2>/dev/null || git rev-parse --abbrev-ref HEAD)
fi
echo "REF_NAME=${REF_NAME,,}" >> $GITHUB_ENV
- name: Debug REF_NAME
run: echo "REF_NAME=${{ env.REF_NAME }}"

- name: Build and push Docker image on GitHub Container Registry
run: |
cd docker
IMAGE_NAME=ghcr.io/ghcr.io/spamscope/mail-parser/mailparser
if [[ $GITHUB_REF == refs/tags/* ]]; then
TAG=${GITHUB_REF#refs/tags/}
docker build \
--label "org.opencontainers.image.source=${{ github.repositoryUrl }}" \
--label "org.opencontainers.image.description=Easy way to pass from raw mail to Python object" \
--label "org.opencontainers.image.licenses=Apache-2.0" \
--build-arg BRANCH=$TAG \
-t $IMAGE_NAME:$TAG \
-t $IMAGE_NAME:latest .
docker push $IMAGE_NAME:$TAG
docker push $IMAGE_NAME:latest
else
docker build \
--label "org.opencontainers.image.source=${{ github.repositoryUrl }}" \
--label "org.opencontainers.image.description=Easy way to pass from raw mail to Python object" \
--label "org.opencontainers.image.licenses=Apache-2.0" \
--build-arg BRANCH=${{ env.REF_NAME }} \
-t $IMAGE_NAME:develop .
docker push $IMAGE_NAME:develop
fi
- name: Build and push Docker image on Docker Hub
run: |
cd docker
IMAGE_NAME=docker.io/${{ secrets.DOCKER_USERNAME }}/spamscope-mail-parser
if [[ $GITHUB_REF == refs/tags/* ]]; then
TAG=${GITHUB_REF#refs/tags/}
docker build \
--label "org.opencontainers.image.source=${{ github.repositoryUrl }}" \
--label "org.opencontainers.image.description=Easy way to pass from raw mail to Python object" \
--label "org.opencontainers.image.licenses=Apache-2.0" \
--build-arg BRANCH=$TAG \
-t $IMAGE_NAME:$TAG \
-t $IMAGE_NAME:latest .
docker push $IMAGE_NAME:$TAG
docker push $IMAGE_NAME:latest
else
docker build \
--label "org.opencontainers.image.source=${{ github.repositoryUrl }}" \
--label "org.opencontainers.image.description=Easy way to pass from raw mail to Python object" \
--label "org.opencontainers.image.licenses=Apache-2.0" \
--build-arg BRANCH=${{ env.REF_NAME }} \
-t $IMAGE_NAME:develop .
docker push $IMAGE_NAME:develop
fi
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
args: ['--maxkb=5000']
- id: check-case-conflict
- id: check-json
- id: check-merge-conflict
- id: detect-aws-credentials
args: ["--allow-missing-credentials"]
- id: detect-private-key
- id: mixed-line-ending
- id: check-ast

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.7.3
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ clean-tests: ## remove test and coverage artifacts

clean-all: clean-tests clean-build ## remove all tests and build files

test: clean-tests ## run tests quickly with the default Python
unittest: clean-tests ## run tests quickly with the default Python
pytest

pre-commit: ## run pre-commit on all files
Expand All @@ -55,4 +55,4 @@ dist: clean-all ## builds source and wheel package
python -m build

release: dist ## package and upload a release
twine upload dist/*
twine upload dist/*
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[![PyPI version](https://badge.fury.io/py/mail-parser.svg)](https://badge.fury.io/py/mail-parser)
[![PyPI - Version](https://img.shields.io/pypi/v/mail-parser)](https://pypi.org/project/mail-parser/)
[![Coverage Status](https://coveralls.io/repos/github/SpamScope/mail-parser/badge.svg?branch=develop)](https://coveralls.io/github/SpamScope/mail-parser?branch=develop)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/mail-parser?color=blue)](https://pypistats.org/packages/mail-parser)


![SpamScope](https://raw.githubusercontent.com/SpamScope/spamscope/develop/docs/logo/spamscope.png)

Expand Down Expand Up @@ -28,9 +30,16 @@ mail-parser supports Python 3.
mail-parser can be downloaded, used, and modified free of charge. It is available under the Apache 2 license.

## Support the project
If you find this project useful, you can support it by donating any amount you want. All donations are greatly appreciated and help maintain and develop the project.

[![Donate](https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif "Donate")](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VEPXYP745KJF2)

<a href="bitcoin:bc1qxhz3tghztpjqdt7atey68s344wvmugtl55tm32">
<img src="https://github.com/SpamScope/mail-parser/blob/develop/docs/images/Bitcoin%20SpamScope.jpg?raw=true" alt="Bitcoin" width="200">
</a>

Bitcoin Address: `bc1qxhz3tghztpjqdt7atey68s344wvmugtl55tm32`

# mail-parser on Web
- [Splunk app](https://splunkbase.splunk.com/app/4129/)
- [FreeBSD port](https://www.freshports.org/mail/py-mail-parser/)
Expand Down Expand Up @@ -279,7 +288,7 @@ $ pip install -e ".[dev, test]"
The second step is to run the tests:

```
$ make test
$ make unittest
```

Then you can try to run the command line tool:
Expand All @@ -288,4 +297,4 @@ Then you can try to run the command line tool:
$ mail-parser -f tests/mails/mail_malformed_3 -j
```

If all is ok, you can start to develop.
If all is ok, you can start to develop.
17 changes: 9 additions & 8 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
FROM python
FROM python:3.10-slim-bullseye
ENV MAIL_PARSER_PATH=/tmp/mailparser
ARG BRANCH=develop
RUN apt-get -yqq update; \
apt-get -yqq --no-install-recommends install libemail-outlook-message-perl; \
apt-get clean; \
rm -rf /var/lib/apt/lists/*; \
git clone -b $BRANCH --single-branch https://github.com/SpamScope/mail-parser.git $MAIL_PARSER_PATH; \
cd $MAIL_PARSER_PATH && python setup.py install
ENTRYPOINT ["mailparser"]
RUN apt-get -yqq update && \
apt-get -yqq --no-install-recommends install libemail-outlook-message-perl git && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
git clone -b ${BRANCH} --single-branch https://github.com/SpamScope/mail-parser.git ${MAIL_PARSER_PATH} && \
cd ${MAIL_PARSER_PATH} && \
python setup.py install
ENTRYPOINT ["mail-parser"]
CMD ["-h"]
20 changes: 10 additions & 10 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
[![Build Status](https://travis-ci.org/SpamScope/mail-parser.svg?branch=develop)](https://travis-ci.org/SpamScope/mail-parser)
[![](https://images.microbadger.com/badges/image/fmantuano/spamscope-mail-parser.svg)](https://microbadger.com/images/fmantuano/spamscope-mail-parser "Get your own image badge on microbadger.com")
[![PyPI - Version](https://img.shields.io/pypi/v/mail-parser)](https://pypi.org/project/mail-parser/)
[![Coverage Status](https://coveralls.io/repos/github/SpamScope/mail-parser/badge.svg?branch=develop)](https://coveralls.io/github/SpamScope/mail-parser?branch=develop)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/mail-parser?color=blue)](https://pypistats.org/packages/mail-parser)

![SpamScope](https://raw.githubusercontent.com/SpamScope/spamscope/develop/docs/logo/spamscope.png)

# fmantuano/spamscope-mail-parser

This Dockerfile represents a Docker image that encapsulates mail-parser. The [official image](https://hub.docker.com/r/fmantuano/spamscope-mail-parser/) is on Docker Hub.
This Dockerfile represents a Docker image that encapsulates `mail-parser`. The [official image](https://hub.docker.com/r/fmantuano/spamscope-mail-parser/) is on Docker Hub.

To run this image after installing Docker, use a command like this:

```
```shell
sudo docker run -i -t --rm -v ~/mails:/mails fmantuano/spamscope-mail-parser
```

This command runs mail-parser help as default, but you can use all others options.
This command runs `mail-parser` help as default, but you can use all others options.

To share the "mails" directory between your host and the container, create a "mails" directory on your host.

There also is an example of `docker-compose`
There also is an example of `docker-compose`

From the `docker-compose.yml` directory, run:

```
```shell
$ sudo docker-compose up
```

The provided ```docker-compose.yml``` file is configured to:
The provided `docker-compose.yml` file is configured to:

- Mount your host's `~/mails/` folder from your source tree inside the container at `/mails/` (read-only).
- A command line test example.

See the ```docker-compose.yml``` to view and tweak the launch parameters.
See the `docker-compose.yml` to view and tweak the launch parameters.
Binary file added docs/images/Bitcoin SpamScope.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[build-system]
requires = ["setuptools >= 40.6.0", "wheel"]
build-backend = "setuptools.build_meta"
build-backend = "setuptools.build_meta"
Empty file removed report/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ addopts =
--cov-report=html
--junitxml=junit.xml
--verbose
testpaths = tests
testpaths = tests
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
import setuptools

if __name__ == "__main__":
setuptools.setup()
setuptools.setup()
18 changes: 14 additions & 4 deletions src/mailparser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,23 @@
limitations under the License.
"""


from .mailparser import (
from mailparser.core import (
MailParser,
parse_from_bytes,
parse_from_file,
parse_from_file_msg,
parse_from_file_obj,
parse_from_string)
parse_from_string,
)

from mailparser.utils import get_header

from .utils import get_header
__all__ = [
"MailParser",
"parse_from_bytes",
"parse_from_file",
"parse_from_file_msg",
"parse_from_file_obj",
"parse_from_string",
"get_header",
]
Loading

0 comments on commit fb34c0e

Please sign in to comment.