Skip to content

Commit

Permalink
Added CI and updated Bash script.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdulcet committed Dec 30, 2023
1 parent f4d56ed commit 8fb261f
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 17 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: CI

on:
push:
pull_request:
schedule:
- cron: '0 0 1 * *'

jobs:
Linux:
name: Linux Bash

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Script
run: |
bash -e -o pipefail -- sendmsg.sh -h
- name: ShellCheck
run: shopt -s globstar; shellcheck -o avoid-nullary-conditions,check-extra-masked-returns,check-set-e-suppressed,deprecate-which,quote-safe-variables,require-double-brackets -s bash **/*.sh
continue-on-error: true

Pylint:
name: Pylint

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install pylint
- name: Script
run: pylint -f colorized --py-version 3.7 -d design,C0103,W0311,C0301,C0302,C0209 --load-plugins pylint.extensions.code_style,pylint.extensions.comparison_placement,pylint.extensions.for_any_all,pylint.extensions.consider_refactoring_into_while_condition,pylint.extensions.consider_ternary_expression,pylint.extensions.dict_init_mutate,pylint.extensions.docstyle,pylint.extensions.check_elif,pylint.extensions.set_membership,pylint.extensions.typing -e R6104,C1804,C1805 -r y python-port/
continue-on-error: true

Ruff:
name: Ruff

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install ruff
- name: Script
run: ruff --output-format=github --target-version py37 --select F,E4,E7,E9,W,I,D,UP,YTT,ANN,S,BLE,B,A,COM819,C4,T10,EM,EXE,ISC,ICN,G,PIE,PYI,Q,RSE,RET,SLF,SLOT,SIM,TID,TCH,ARG,PGH,PL,TRY,FLY,PERF,FURB,LOG,RUF --preview --ignore W191,D211,D213,D401,PLR09,PLR2004,RUF001,RUF002,RUF003 .
continue-on-error: true

Python:
name: Linux Python

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "pypy3.7", "pypy3.8", "pypy3.9", "pypy3.10"]
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Script
run: |
python -X dev python-port/sendpy/ --help
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ Send [e-mail](https://en.wikipedia.org/wiki/Email) (and [text messages](https://

Useful to know when a cron job failed, when a long running job (LRP) has finished, to quickly backup/share a file or to send notifications as part of a larger script.

❤️ Please visit [tealdulcet.com](https://www.tealdulcet.com/) to support these script and my other software development.
❤️ Please visit [tealdulcet.com](https://www.tealdulcet.com/) to support these scripts and my other software development.

## Usage

Requires Bash 4.4 and the curl and netcat commands, which are included on most Linux distributions.
Requires at least Bash 4.4 and the curl and netcat commands, which are included on most Linux distributions.

Optional [S/MIME](https://en.wikipedia.org/wiki/S/MIME) digital signatures require the openssl command.\
Optional [PGP/MIME](https://en.wikipedia.org/wiki/Pretty_Good_Privacy#OpenPGP) digital signatures require the gpg command.
Expand Down Expand Up @@ -170,7 +170,7 @@ You will also need to either create an [App Password](https://support.google.com
</tr>
<tr>
<th colspan="2">Supports International email addresses</th>
<td>✔^</td>
<td>✔</td>
<td>✔</td>
<td>✔</td>
<td></td>
Expand Down Expand Up @@ -242,8 +242,7 @@ You will also need to either create an [App Password](https://support.google.com
</table>

\* Optional\
^ Only supported in Internationalizing Domain Names in Applications (IDNA) encoding\
^^ Does not work with all mobile providers
† Only supported in Internationalizing Domain Names in Applications (IDNA) encoding

This is not a comprehensive list of the Send E-mail Script’s functionality.

Expand Down
37 changes: 25 additions & 12 deletions sendmsg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set -e
SEND=1

# To e-mail addresses
# Send SMSs by using your mobile providers e-mail to SMS or MMS gateway (https://en.wikipedia.org/wiki/SMS_gateway#Email_clients)
# Send text messages by using your mobile providers e-mail to SMS or MMS gateway (https://en.wikipedia.org/wiki/SMS_gateway#Email_clients)
TOEMAILS=(

)
Expand Down Expand Up @@ -148,34 +148,34 @@ Options:
Examples:
Send e-mail
$ $1 -s \"Example\" -t \"Example <example@example.com>\"
$ $1 -s \"Example\" -t \"User <user@example.com>\"
Send e-mail with message
$ $1 -s \"Example\" -m \"This is an example"'!'"\" -t \"Example <example@example.com>\"
$ $1 -s \"Example\" -m \"This is an example"'!'"\" -t \"User <user@example.com>\"
Send e-mail with message and single attachment
$ $1 -s \"Example\" -m \"This is an example"'!'"\" -a example.txt -t \"Example <example@example.com>\"
$ $1 -s \"Example\" -m \"This is an example"'!'"\" -a example.txt -t \"User <user@example.com>\"
Send e-mail with message and multiple attachments
$ $1 -s \"Example\" -m \"This is an example"'!'"\" -a example1.txt -a example2.txt -t \"Example <example@example.com>\"
$ $1 -s \"Example\" -m \"This is an example"'!'"\" -a example1.txt -a example2.txt -t \"User <user@example.com>\"
Send e-mail to a CC address
$ $1 -s \"Example\" -t \"Example 1 <example1@example.com>\" -c \"Example 2 <example2@example.com>\"
$ $1 -s \"Example\" -t \"User 1 <user1@example.com>\" -c \"User 2 <user2@example.com>\"
Send e-mail with a From address
$ $1 -s \"Example\" -f \"Example <[email protected]>\" -t \"Example <example@example.com>\"
$ $1 -s \"Example\" -f \"Example <[email protected]>\" -t \"User <user@example.com>\"
Send e-mail with an external SMTP server
$ $1 -s \"Example\" -f \"Example <[email protected]>\" -S \"smtps://mail.example.com\" -u \"example\" -p \"password\" -t \"Example <example@example.com>\"
$ $1 -s \"Example\" -f \"Example <[email protected]>\" -S \"smtps://mail.example.com\" -u \"example\" -p \"password\" -t \"User <user@example.com>\"
Send high priority e-mail
$ $1 -s \"Example\" -f \"Example <[email protected]>\" -S \"smtps://mail.example.com\" -u \"example\" -p \"password\" -P \"1 (Highest)\" -t \"Example <example@example.com>\"
$ $1 -s \"Example\" -f \"Example <[email protected]>\" -S \"smtps://mail.example.com\" -u \"example\" -p \"password\" -P \"1 (Highest)\" -t \"User <user@example.com>\"
Send e-mail digitally signed with an S/MIME Certificate
$ $1 -s \"Example\" -f \"Example <[email protected]>\" -S \"smtps://mail.example.com\" -u \"example\" -p \"password\" -C \"cert.p12\" -t \"Example <example@example.com>\"
$ $1 -s \"Example\" -f \"Example <[email protected]>\" -S \"smtps://mail.example.com\" -u \"example\" -p \"password\" -C \"cert.p12\" -t \"User <user@example.com>\"
Send e-mail digitally signed with PGP/MIME
$ $1 -s \"Example\" -f \"Example <[email protected]>\" -S \"smtps://mail.example.com\" -u \"example\" -p \"password\" -k \"passphrase\" -t \"Example <example@example.com>\"
$ $1 -s \"Example\" -f \"Example <[email protected]>\" -S \"smtps://mail.example.com\" -u \"example\" -p \"password\" -k \"passphrase\" -t \"User <user@example.com>\"
" >&2
}

Expand Down Expand Up @@ -414,6 +414,11 @@ if [[ -n "$FROMADDRESS" ]] && ! [[ $FROMADDRESS =~ $RE1 && $FROMADDRESS =~ $RE2
fi

if [[ -n "$CERT" ]]; then
if ! command -v openssl >/dev/null; then
echo "Error: OpenSSL is not installed." >&2
exit 1
fi

if [[ ! -r "$CERT" && ! -f "$CLIENTCERT" ]]; then
echo "Error: '$CERT' certificate file does not exist." >&2
exit 1
Expand All @@ -422,7 +427,10 @@ if [[ -n "$CERT" ]]; then
if [[ ! -s "$CLIENTCERT" ]]; then
echo -e "Saving the client certificate from '$CERT' to '$CLIENTCERT'"
echo -e "Please enter the password when prompted.\n"
openssl pkcs12 -in "$CERT" -out "$CLIENTCERT" -clcerts -nodes
if ! openssl pkcs12 -in "$CERT" -out "$CLIENTCERT" -clcerts -nodes; then
echo "Error saving the client certificate. Trying again in legacy mode." >&2
openssl pkcs12 -in "$CERT" -out "$CLIENTCERT" -clcerts -nodes -legacy
fi
fi

# if ! output=$(openssl verify -verify_email "$FROMADDRESS" "$CLIENTCERT" 2>/dev/null); then
Expand Down Expand Up @@ -451,6 +459,11 @@ if [[ -n "$CERT" ]]; then
fi

if [[ -n "$PASSPHRASE" ]]; then
if ! command -v gpg >/dev/null; then
echo "Error: GNU Privacy Guard is not installed." >&2
exit 1
fi

if ! echo "$PASSPHRASE" | gpg --pinentry-mode loopback --batch -o /dev/null -ab -u "$FROMADDRESS" --passphrase-fd 0 <(echo); then
echo "Error: A PGP key pair does not yet exist for '$FROMADDRESS' or the passphrase was incorrect." >&2
exit 1
Expand Down

0 comments on commit 8fb261f

Please sign in to comment.