Skip to content

Commit acb135d

Browse files
committed
chore: initial commit
0 parents  commit acb135d

20 files changed

Lines changed: 1282 additions & 0 deletions
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
name: Issue report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
## Description of the problem, including code snippet
11+
12+
13+
## Expected Behavior
14+
15+
16+
## Actual Behavior
17+
18+
19+
## Specifications
20+
21+
* python-smime-email version:
22+
* OS name:
23+
* OS version:

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!-- Please make sure your commit messages follow Conventional Commits
2+
(https://www.conventionalcommits.org) with a commit type (e.g. feat, fix, refactor, chore):
3+
4+
Bad: Added support for release links
5+
Good: feat(api): add support for release links
6+
7+
Bad: Update documentation for projects
8+
Good: docs(projects): update example for saving project attributes-->
9+
10+
## Changes
11+
12+
<!-- Remove this comment and describe your changes here. -->
13+
14+
### Documentation and testing
15+
16+
Please consider whether this PR needs documentation and tests. **This is not required**, but highly appreciated:
17+
18+
* [ ] Documentation in the README
19+
* [ ] Unit tests

.github/workflows/publish.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
id-token: write
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-python@v5
16+
with:
17+
python-version: "3.12"
18+
- name: Install poetry
19+
run: python3 -m pip install --user poetry==1.8.3
20+
- name: Build wheel
21+
run: poetry build
22+
- name: Publish package to PyPI
23+
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/test.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Test
2+
3+
# If a pull-request is pushed then cancel all previously running jobs related
4+
# to that pull-request
5+
concurrency:
6+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
7+
cancel-in-progress: true
8+
9+
on:
10+
push:
11+
branches:
12+
- main
13+
pull_request:
14+
branches:
15+
- main
16+
17+
env:
18+
PY_COLORS: 1
19+
20+
jobs:
21+
unit:
22+
runs-on: ${{ matrix.os }}
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
os: [ubuntu-latest]
27+
python:
28+
- version: "3.10"
29+
- version: "3.11"
30+
- version: "3.12"
31+
- version: '3.13.0-alpha - 3.13' # SemVer's version range syntax
32+
steps:
33+
- uses: actions/checkout@v4
34+
- name: Set up Python ${{ matrix.python.version }}
35+
uses: actions/setup-python@v5.2.0
36+
with:
37+
python-version: ${{ matrix.python.version }}
38+
- run: |
39+
python3 -m pip install --user -r requirements-poetry.txt
40+
sudo apt-get update && sudo apt-get -y install openssl
41+
poetry install -n
42+
poetry run poe lint
43+
poetry run poe test

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
__pycache__
2+
.env
3+
dist
4+
.pytest_cache
5+
htmlcov
6+
.mypy_cache
7+
.coverage
8+
coverage.xml
9+
junit.xml
10+
.ruff_cache

CODE-OF-CONDUCT.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
We as members, contributors, and leaders pledge to make participation in our
6+
community a harassment-free experience for everyone, regardless of age, body
7+
size, visible or invisible disability, ethnicity, sex characteristics, gender
8+
identity and expression, level of experience, education, socio-economic status,
9+
nationality, personal appearance, race, caste, color, religion, or sexual
10+
identity and orientation.
11+
12+
We pledge to act and interact in ways that contribute to an open, welcoming,
13+
diverse, inclusive, and healthy community.
14+
15+
## Our Standards
16+
17+
Examples of behavior that contributes to a positive environment for our
18+
community include:
19+
20+
* Demonstrating empathy and kindness toward other people
21+
* Being respectful of differing opinions, viewpoints, and experiences
22+
* Giving and gracefully accepting constructive feedback
23+
* Accepting responsibility and apologizing to those affected by our mistakes,
24+
and learning from the experience
25+
* Focusing on what is best not just for us as individuals, but for the overall
26+
community
27+
28+
Examples of unacceptable behavior include:
29+
30+
* The use of sexualized language or imagery, and sexual attention or advances of
31+
any kind
32+
* Trolling, insulting or derogatory comments, and personal or political attacks
33+
* Public or private harassment
34+
* Publishing others' private information, such as a physical or email address,
35+
without their explicit permission
36+
* Other conduct which could reasonably be considered inappropriate in a
37+
professional setting
38+
39+
## Enforcement Responsibilities
40+
41+
Community leaders are responsible for clarifying and enforcing our standards of
42+
acceptable behavior and will take appropriate and fair corrective action in
43+
response to any behavior that they deem inappropriate, threatening, offensive,
44+
or harmful.
45+
46+
Community leaders have the right and responsibility to remove, edit, or reject
47+
comments, commits, code, wiki edits, issues, and other contributions that are
48+
not aligned to this Code of Conduct, and will communicate reasons for moderation
49+
decisions when appropriate.
50+
51+
## Enforcement
52+
53+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
54+
reported to the community leaders responsible for enforcement at
55+
opensource@siemens.com.
56+
All complaints will be reviewed and investigated promptly and fairly.
57+
58+
All community leaders are obligated to respect the privacy and security of the
59+
reporter of any incident.
60+
61+
## Enforcement Guidelines
62+
63+
Community leaders will follow these Community Impact Guidelines in determining
64+
the consequences for any action they deem in violation of this Code of Conduct:
65+
66+
### 1. Correction
67+
68+
**Community Impact**: Use of inappropriate language or other behavior deemed
69+
unprofessional or unwelcome in the community.
70+
71+
**Consequence**: A private, written warning from community leaders, providing
72+
clarity around the nature of the violation and an explanation of why the
73+
behavior was inappropriate. A public apology may be requested.
74+
75+
### 2. Warning
76+
77+
**Community Impact**: A violation through a single incident or series of
78+
actions.
79+
80+
**Consequence**: A warning with consequences for continued behavior. No
81+
interaction with the people involved, including unsolicited interaction with
82+
those enforcing the Code of Conduct, for a specified period of time. This
83+
includes avoiding interactions in community spaces as well as external channels
84+
like social media. Violating these terms may lead to a temporary or permanent
85+
ban.
86+
87+
### 3. Temporary Ban
88+
89+
**Community Impact**: A serious violation of community standards, including
90+
sustained inappropriate behavior.
91+
92+
**Consequence**: A temporary ban from any sort of interaction or public
93+
communication with the community for a specified period of time. No public or
94+
private interaction with the people involved, including unsolicited interaction
95+
with those enforcing the Code of Conduct, is allowed during this period.
96+
Violating these terms may lead to a permanent ban.
97+
98+
### 4. Permanent Ban
99+
100+
**Community Impact**: Demonstrating a pattern of violation of community
101+
standards, including sustained inappropriate behavior, harassment of an
102+
individual, or aggression toward or disparagement of classes of individuals.
103+
104+
**Consequence**: A permanent ban from any sort of public interaction within the
105+
community.
106+
107+
## Attribution
108+
109+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
110+
version 2.1, available at
111+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
112+
113+
Community Impact Guidelines were inspired by
114+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
115+
116+
For answers to common questions about this code of conduct, see the FAQ at
117+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
118+
[https://www.contributor-covenant.org/translations][translations].
119+
120+
[homepage]: https://www.contributor-covenant.org
121+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
122+
[Mozilla CoC]: https://github.com/mozilla/diversity
123+
[FAQ]: https://www.contributor-covenant.org/faq
124+
[translations]: https://www.contributor-covenant.org/translations

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./** @siemens/python-maintainers

CONTRIBUTING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Contributing to python-smime-email
2+
3+
Contributions are always welcome. This document explains the
4+
general requirements on contributions and the recommended preparation
5+
steps.
6+
7+
## Contribution Checklist
8+
9+
- try to cover new features or fixes with accompanying tests
10+
- follow Python coding style outlined in ruff [**required**]

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Siemens AG, 2024
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# python-smime-email
2+
3+
<a href="https://pypi.org/project/smime-email/"><img alt="PyPI" src="https://img.shields.io/pypi/v/smime-email"></a>
4+
<a href="https://pepy.tech/project/smime-email"><img alt="Downloads" src="https://pepy.tech/badge/smime-email"></a>
5+
6+
Generate x509 SMIME signed emails with ease!
7+
8+
## Usage
9+
10+
1. Generate the email raw content
11+
12+
```python
13+
import smime_email
14+
15+
data = b"Hello!"
16+
SMIME_KEY = smime_email.load_key("key_path.pem")
17+
SMIME_INTERMEDIATE = smime_email.load_certificates("intermediate_path.pem")
18+
SMIME_CERT = smime_email.load_certificates("cert_path.pem")[0]
19+
email_raw_bytes = smime_email.get_smime_attachment_content(data, SMIME_KEY, SMIME_INTERMEDIATE, SMIME_CERT)
20+
```
21+
22+
1. Send it using any email library you like. Here is an example as Django email backend
23+
24+
```python
25+
email_raw_bytes = smime_email.get_smime_attachment_content(data, SMIME_KEY, SMIME_INTERMEDIATE, SMIME_CERT)
26+
# ...
27+
class EmailBackend(BaseEmailBackend):
28+
def send_messages(self, message) -> int:
29+
with smtplib.SMTP(settings.EMAIL_HOST, settings.EMAIL_PORT) as server:
30+
server.sendmail(message.from_email, message.to, email_raw_bytes)
31+
return 1
32+
```
33+
34+
## Development
35+
36+
The code is formatted with **ruff** and checked with various linters.
37+
To run the whole linting and formatting process, run `poetry run poe all`.
38+
39+
## License
40+
41+
Code and documentation copyright 2024 Siemens AG.
42+
43+
See [LICENSE.md](LICENSE.md).

0 commit comments

Comments
 (0)