{"id":18035832,"url":"https://github.com/echo-devim/libaltspam","last_synced_at":"2025-04-04T23:25:31.620Z","repository":{"id":82335399,"uuid":"537841533","full_name":"echo-devim/libAltSpam","owner":"echo-devim","description":"Portable lightweight C++ library to block spam emails","archived":false,"fork":false,"pushed_at":"2022-10-27T08:17:40.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-10T08:12:22.990Z","etag":null,"topics":["antispam","antispam-api","email","portable"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-4-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/echo-devim.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-17T14:58:06.000Z","updated_at":"2022-09-19T15:34:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"e1b9de94-3ed5-4357-b732-3c79f647ea99","html_url":"https://github.com/echo-devim/libAltSpam","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/echo-devim%2FlibAltSpam","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/echo-devim%2FlibAltSpam/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/echo-devim%2FlibAltSpam/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/echo-devim%2FlibAltSpam/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/echo-devim","download_url":"https://codeload.github.com/echo-devim/libAltSpam/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247263966,"owners_count":20910500,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["antispam","antispam-api","email","portable"],"created_at":"2024-10-30T12:10:25.896Z","updated_at":"2025-04-04T23:25:31.598Z","avatar_url":"https://github.com/echo-devim.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AltSpam\n\nThis repository contains the source code of libAltSpam, a lightweight and portable antispam library written in C++. Included in this repo there are also a command line interface tool and a tiny API server (single client).\n\nThe idea of this project is to check if an input email is spam or not assigning it a score. The score is assigned using several (offline) checks on the headers, the charsets, url domains and \"spam words\".\nThe library **is not** based on any AI algorithm, because it must be lightweight. You can mark emails as spam in order to add the words of those email to the spam word count database.\n\nCheck [AltSpam Java App](https://github.com/echo-devim/JAltSpam) for a complete antispam service with graphical user interface based on this library.\n\n## Details\nThe source code of the library is contained in the `lib` directory of this repo. The core of the library is the word count function. Each time you give in input an email marked as spam, the library parses the email and then adds the words in the email to a global word count database called `wc.dat`.\nThis is a text file created in the program directory that simply contains a word count.\n\nExample:\n```\ntest 5\nhello 1\nclick 8\nhere 8\n```\n\nThe first column contains the words, the second column contains the count.\nEach time you add an email to spam, the library updates the word count database adding the new words or increasing the existing value. In the same way, when you mark an email as not spam, the library updates the word count database decreasing the words or removing them if the count is less than 1.\n\nAfter a first setup where you mark spam emails to populate the word count, the antispam is ready.\n\n## Code Structure\nEmails are strings that can be parsed and represented by Email class. The Email class is a basic email object representation. There is also the EnrichedEmail class that extends Email object with more details (e.g. the list of links contained in the body).\nEach Email object can contain one or more links represented by Link class.\nFinally, there is the AltSpam class that implements all the checks on a EnrichedEmail object to calculate a spam score for it.\nIn the `imap` directory there is a limited imap client implementation based on libcurl that can retrieve emails from a remote server.\nThe `misc` directory contains utility functions like cryptographic functions.\n\n## API\nThis repo contains a tiny API server implementation for AltSpam Remote Procedure Call (RPC). The default port is 22525/tcp and it listens on localhost interface. It is not recommended to expose the service on the network. \n\nThe messages accepted by the server must have the following structure:\n```\n|OPERATION|SIZE|DATA|\n```\n*  OPERATION is one byte representing the function of AltSpam to call (check `AltSpam.h` for details)\n*  SIZE is an integer representing the data length\n*  DATA is the argument of OPERATION\n\nNote: Messages are protected by a very basic XOR encryption.\n\nThe server exposes only the functions offered by the library, thus for example imap client functions are not available.\n\n## CLI\nThis repo contains a CLI tool which allows to call the library functions, use the imap client and start the server API.\n\n```\nusage: ./altspam [options] ... \noptions:\n  -l, --loadwc              load word vector from path (string [=])\n  -s, --savewc              save word vector to path (string [=])\n      --importwc            import word vector from existing file (string [=])\n  -t, --threshold           set spam threshold (float [=0.9])\n  -a, --add-to-spam         add an email to spam dataset (string [=])\n  -r, --remove-from-spam    remove an email from spam dataset (string [=])\n  -i, --is-spam             check if an email is spam or not (string [=])\n      --spam-score          get the spam score for the specified email (string [=])\n      --list                get the latest 10 email for each folder and print their subject to stdout\n      --list-score          get the latest 10 email for each folder and print their scores to stdout\n  -m, --monitor             monitor the latest 10 email and move to junk spam emails each n minutes (int [=10])\n      --spam-folder         set spam folder name where to move spam messages (string [=JUNK])\n      --imap-conf           imap configuration file (string [=])\n      --init-imap           interactive imap configuration (string [=prop.ini])\n  -v, --verbose             show debug prints\n  -d, --delete              when combined with monitor option, force spam emails deletion\n      --server              start API server\n  -?, --help                print this message\n\n```\n\n### Examples\n\nStart the (single-client) local server API:\n\n```sh\n$ ./altspam --server\n```\nNow the binary is listening on 22525/tcp ready for a client.\n\nConfigure your IMAP connection using the interactive setup:\n```sh\n$ ./altspam --init-imap\n```\n\nThis command will create a new file with connection properties such as (email, encrypted password, server, folders to monitor, etc.).\n\nList last 10 received unseen emails for each folder and print their scores:\n```sh\n$ ./altspam --imap-conf conn.dat --list-score\n```\n\nExample of output:\n```\nID\tFOLDER\tSUBJECT\tSPAM\tSCORE\n1\tINBOX\ttest\t0\t0.292308\n2\tINBOX\ttest2\t0\t0.325428\n3\tINBOX\ttest_spam123\t1\t1.341849\n...\n```\n\nNow, we can add or remove an email to/from the dataset using the ID.\nFor example let's add the test2 email to spam:\n```sh\n./altspam --imap-conf conn.dat -a 2\n```\n\nYou can monitor your inbox folders for (unread) spam messages each 10 minutes on a remote IMAP server with the following command:\n```sh\n$ ./altspam --imap-conf conn.dat --monitor 10\n```\n\nNote: if you use 0 as value for `--monitor`, the application checks for spam messages only once and then it'll exit.\n\nNow, you are ready to easily create an antispam service in your system\n\n## Compilation\n\nJust run the `compile.sh` included in this repo to cross-compile the project against many platforms or to generate the library (shared object).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecho-devim%2Flibaltspam","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fecho-devim%2Flibaltspam","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecho-devim%2Flibaltspam/lists"}