From e83d6e4de9153d69634619ed2fb4ef57f9738fb8 Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Fri, 14 Oct 2022 11:59:57 +0200 Subject: [PATCH] Initial commit. --- LICENSE | 21 +++++++++++++++++++++ README.md | 12 ++++++++++++ pyproject.toml | 32 ++++++++++++++++++++++++++++++++ signalspam.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 pyproject.toml create mode 100644 signalspam.py diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2373a2d --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2022 Julien Palard + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..83cdf1a --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Report to signal-spam.fr + +## Install + +To install signal-spam CLI, use: + + python -m pip install signal-spam + + +## Usage + + signal-spam BuyMyDogFood.eml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..f1ab245 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,32 @@ +[build-system] +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "signal-spam" +description = "Report an eml file to signal-spam.fr" +readme = "README.md" +license = {text = "MIT License"} +authors = [ + {name = "Julien Palard", email = "julien@palard.fr"}, +] +requires-python = ">= 3.7" +dependencies = [ + "requests" +] +dynamic = ["version"] + +[project.urls] +homepage = "https://git.afpy.org/mdk/signal-spam" + +[project.scripts] +signal-spam = "signalspam:main" + +[tool.setuptools] +py-modules = [ + "signalspam", +] +include-package-data = false + +[tool.setuptools.dynamic.version] +attr = "signalspam.__version__" diff --git a/signalspam.py b/signalspam.py new file mode 100644 index 0000000..85832f4 --- /dev/null +++ b/signalspam.py @@ -0,0 +1,42 @@ +"""Send .eml files to signal-spam.fr.""" + +from base64 import b64encode +from pathlib import Path +from getpass import getpass +import argparse + +import requests + +__version__ = "0.1" + + +CONF = Path("~/.signal-spam").expanduser() + + +def parse_args(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("eml", type=Path, help="An email file to report as spam.") + return parser.parse_args() + + +def main(): + args = parse_args() + try: + username, password = CONF.read_text(encoding="UTF-8").splitlines() + except FileNotFoundError: + username = input("signal spam username: ") + password = getpass("signal spam password: ") + CONF.write_text(f"{username}\n{password}\n", encoding='UTF-8') + CONF.chmod(0o600) + payload = {"dossier": 0, "message": b64encode(args.eml.read_text(encoding="UTF-8").encode("UTF-8"))} + response = requests.post( + "https://www.signal-spam.fr/api/signaler", + auth=(username, password), + timeout=10, + data=payload) + print("Sent") + print(response.text) + + +if __name__ == '__main__': + main()