定制 palpalani/laravel-spamassassin-score 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

palpalani/laravel-spamassassin-score

Composer 安装命令:

composer require palpalani/laravel-spamassassin-score

包简介

Check the spam score of emails before sending them.

README 文档

README

Latest Version on Packagist Total Downloads License

GitHub Tests Code Style PHPStan

PHP Version Support Laravel Version Support

A Laravel package to check the spam score of email contents before sending them using the SpamAssassin filter API.

Features

  • ✅ Check email spam scores using SpamAssassin API
  • ✅ Simple and intuitive API
  • ✅ Facade support for easy access
  • ✅ Fully configurable
  • ✅ Supports both "short" and "long" report formats
  • ✅ Works with Laravel 11 and 12
  • ✅ Well tested
  • ✅ PHP 8.3+ support

Requirements

  • PHP >= 8.3
  • Laravel ^11.0 | ^12.0

Installation

You can install the package via Composer:

composer require palpalani/laravel-spamassassin-score

The package will automatically register its service provider and facade.

Configuration

You can publish the config file with:

php artisan vendor:publish --tag="laravel-spamassassin-score-config"

This is the contents of the published config file:

return [
    'api' => 'https://spamcheck.postmarkapp.com/filter',

    // Default "long". Must either be "long" for a full report of processing rules, or "short" for a score request.
    'option' => 'long'
];

Configuration Options

  • api: The SpamAssassin API endpoint URL
  • option: The report format - either "long" for a full report of processing rules, or "short" for a score request only

Usage

Using the Facade

use palPalani\SpamassassinScore\Facades\SpamassassinScore;

// Get spam score with default configuration
$result = SpamassassinScore::getScore($emailContent);

// The result will contain:
// - 'score': The spam score
// - 'success': Whether the check was successful
// Additional fields when using 'long' option format

Using Dependency Injection

use palPalani\SpamassassinScore\SpamassassinScore;

class EmailController extends Controller
{
    public function __construct(
        private SpamassassinScore $spamassassinScore
    ) {}

    public function checkEmail(Request $request)
    {
        $result = $this->spamassassinScore->getScore($request->input('email'));
        
        if ($result['score'] > 5.0) {
            return response()->json(['message' => 'Email may be spam'], 400);
        }
        
        // Proceed with sending email
    }
}

Using Direct Instantiation

use palPalani\SpamassassinScore\SpamassassinScore;

$spamassassinScore = new SpamassassinScore();
$result = $spamassassinScore->getScore($emailContent);

// Access the score
$score = $result['score'] ?? null;

Example Response

When using the default "long" option, the response includes:

[
    'success' => true,
    'score' => 2.5,
    'rules' => [
        // Full list of rules that matched
    ],
    'description' => '...'
]

When using "short" option, the response is:

[
    'success' => true,
    'score' => 2.5
]

Testing

Run the tests with:

composer test

For test coverage:

composer test-coverage

Code Quality Tools

This package uses several code quality tools:

  • PHPUnit - Testing framework
  • Pest - Testing framework (alternative)
  • Laravel Pint - Code style fixing (powered by PHP CS Fixer)
  • PHPStan - Static analysis
  • Larastan - Laravel-specific static analysis (PHPStan extension)

Run static analysis:

composer analyse  # PHPStan

Run code formatting:

composer format  # Laravel Pint

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details on our code of conduct, and the process for submitting pull requests.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 2.94k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-02-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固