zone-webmail/wildduck-php-client 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

zone-webmail/wildduck-php-client

Composer 安装命令:

composer require zone-webmail/wildduck-php-client

包简介

PHP client for Wildduck email server API

README 文档

README

A modern PHP client for the Wildduck email server API with full type safety and DTO support.

PHP Version License

Features

  • 🔒 Type-Safe: Full PHP 8.3+ type hints with strict types
  • 📦 DTOs: Request and response Data Transfer Objects for IDE autocomplete
  • 🎯 Modern PHP: Readonly properties, named parameters, union types
  • 🔄 EventSource: Real-time updates via server-sent events
  • 📚 Comprehensive: All 17 WildDuck API services covered

Requirements

  • PHP 8.3 or newer
  • Composer

Installation

composer require zone-eu/wildduck-php-client

Quick Start

use Zone\Wildduck\WildduckClient;
use Zone\Wildduck\Dto\User\CreateUserDto;

// Initialize client
$client = new WildduckClient([
    'accessToken' => 'your-api-token',
    'apiUrl' => 'https://api.wildduck.email',
]);

// Create a user
$createDto = new CreateUserDto(
    username: 'john.doe',
    password: 'SecurePass123!',
    address: 'john.doe@example.com',
    name: 'John Doe'
);

$result = $client->users()->create($createDto);
echo "User created with ID: {$result->id}\n";

// Get user details
$user = $client->users()->get($result->id);
echo "Username: {$user->username}\n";
echo "Email: {$user->address}\n";

// Update user
$updateDto = new UpdateUserDto(
    name: 'John Updated Doe'
);
$client->users()->update($result->id, $updateDto);

// Delete user
$client->users()->delete($result->id);

Available Services

All services are accessed via the WildduckClient instance:

  • $client->users() - User management
  • $client->addresses() - Email address management
  • $client->mailboxes() - Mailbox operations
  • $client->messages() - Message handling
  • $client->filters() - Email filters
  • $client->autoreply() - Auto-reply settings
  • $client->applicationPasswords() - App-specific passwords
  • $client->authentication() - Authentication endpoints
  • $client->twoFactorAuthentication() - 2FA management
  • $client->archive() - Message archiving
  • $client->audit() - Audit logs
  • $client->dkim() - DKIM key management
  • $client->domainAliases() - Domain alias operations
  • $client->events() - Event streaming
  • $client->storage() - File storage
  • $client->submission() - Message submission
  • $client->webhooks() - Webhook management

See MIGRATION.md for complete migration guide from v1.x.

Examples

Managing Messages

use Zone\Wildduck\Dto\Message\UploadMessageDto;

// Upload a message
$uploadDto = new UploadMessageDto(
    raw: base64_encode($emailSource),
    mailbox: $mailboxId
);

$result = $client->messages()->upload($userId, $mailboxId, $uploadDto);

// Search messages
$messages = $client->messages()->search($userId, [
    'q' => 'from:sender@example.com',
    'limit' => 10
]);

foreach ($messages->results as $message) {
    echo "Subject: {$message->subject}\n";
}

Working with Filters

use Zone\Wildduck\Dto\Filter\CreateFilterDto;
use Zone\Wildduck\Dto\Shared\FilterQueryDto;
use Zone\Wildduck\Dto\Shared\FilterActionDto;

$createDto = new CreateFilterDto(
    name: 'Spam Filter',
    query: new FilterQueryDto(from: 'spam@example.com'),
    action: new FilterActionDto(delete: true)
);

$client->filters()->create($userId, $createDto);

Event Streaming

// Stream user mailbox updates
$response = $client->events()->forUser($userId);
// Returns StreamedResponse that can be processed with EventSource

Testing

The library includes comprehensive structure tests. See TESTING.md for:

  • Running tests
  • Writing integration tests
  • Test coverage information
# Run structure tests
vendor/bin/phpunit tests/Unit/Service/ServiceStructureTest.php

Configuration

Environment Variables

  • WDPC_REQUEST_LOGGING (true/false) - Enable request logging
  • WDPC_REQUEST_LOGGING_FOLDER_PERMISSIONS (0755) - Log folder permissions
  • WDPC_REQUEST_LOGGING_PATTERN - RegEx for requests to log
  • WDPC_REQUEST_LOGGING_DIRECTORY - Base directory for logs

Client Options

$client = new WildduckClient([
    'accessToken' => 'your-token',       // Required
    'apiUrl' => 'https://api.example.com', // Optional
    'apiVersion' => 'v1',                 // Optional
    'httpClient' => $customClient,        // Optional custom HTTP client
]);

Architecture

DTOs (Data Transfer Objects)

All requests and responses use strongly-typed DTOs:

// Request DTOs
use Zone\Wildduck\Dto\User\CreateUserDto;
use Zone\Wildduck\Dto\User\UpdateUserDto;

// Response DTOs
use Zone\Wildduck\Dto\User\UserDto;
use Zone\Wildduck\Dto\User\UserInfoDto;
use Zone\Wildduck\Dto\PaginatedResultDto;

DTOs provide:

  • ✅ IDE autocomplete
  • ✅ Type safety at compile time
  • ✅ Clear API contracts
  • ✅ Validation support

Service Layer

Services extend AbstractService and provide typed methods:

class UserService extends AbstractService
{
    public function create(CreateUserDto|null $params = null): UserInfoDto
    {
        return $this->requestDto('post', '/users', $params, UserInfoDto::class);
    }

    public function get(string $id): UserDto
    {
        return $this->requestDto('get', "/users/{$id}", null, UserDto::class);
    }
}

Upgrading from v1.x

See MIGRATION.md for detailed upgrade instructions. Key changes:

  1. DTOs instead of arrays: All requests now use DTOs
  2. Service access: $client->users() instead of $client->users
  3. Return types: Typed DTOs instead of generic arrays
  4. PHP 8.3+: Modern PHP features throughout

Contributing

Contributions are welcome! Please see our contributing guidelines:

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new features
  4. Ensure all tests pass
  5. Submit a pull request

License

EUPL-1.2 - European Union Public License

Resources

Credits

Heavily inspired by stripe/stripe-php.

Made with ❤️ by Zone Media OÜ

zone-webmail/wildduck-php-client 适用场景与选型建议

zone-webmail/wildduck-php-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.74k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2021 年 06 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 zone-webmail/wildduck-php-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 zone-webmail/wildduck-php-client 我们能提供哪些服务?
定制开发 / 二次开发

基于 zone-webmail/wildduck-php-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5.74k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 20
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 3
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: EUPL-1.1
  • 更新时间: 2021-06-16