モジュールシステム
SirrChat は、ニーズに応じて機能をカスタマイズおよび拡張できるモジュラーアーキテクチャを採用しています。
モジュールタイプ
認証モジュール
ユーザー認証を処理。
go
type AuthModule interface {
Name() string
Authenticate(username, credential string) (bool, error)
Supports(method string) bool
}ストレージモジュール
メールとデータストレージを管理。
go
type StorageModule interface {
Save(mailbox string, message *Message) error
Load(mailbox string, uid uint32) (*Message, error)
Delete(mailbox string, uid uint32) error
}フィルターモジュール
メールコンテンツのフィルタリングと処理。
go
type FilterModule interface {
Filter(ctx *Context, msg *Message) (Action, error)
}組み込みモジュール
blockchain-auth
ブロックチェーンウォレット認証モジュール。
設定:
toml
[[modules.auth]]
name = "blockchain-auth"
enabled = true
[modules.auth.config]
networks = ["ethereum", "bsc"]ldap-auth
LDAP ディレクトリサービス認証。
設定:
toml
[[modules.auth]]
name = "ldap-auth"
enabled = true
[modules.auth.config]
server = "ldap://ldap.example.com"spam-filter
スパムフィルタリングモジュール。
設定:
toml
[[modules.filter]]
name = "spam-filter"
enabled = true
[modules.filter.config]
threshold = 5.0
quarantine = truedkim-signer
DKIM メール署名モジュール。
設定:
toml
[[modules.modify]]
name = "dkim-signer"
enabled = true
[modules.modify.config]
selector = "default"
private_key = "/etc/sirrchatd/dkim/private.key"カスタムモジュール
モジュールの作成
go
package mymodule
import "github.com/mail-chat-chain/mailchatd/module"
type MyFilter struct {
config Config
}
func (f *MyFilter) Name() string {
return "my-filter"
}
func (f *MyFilter) Init(cfg map[string]interface{}) error {
// 設定を初期化
return nil
}
func (f *MyFilter) Filter(ctx *module.Context, msg *module.Message) (module.Action, error) {
// フィルタリングロジックを実装
if someCondition(msg) {
return module.ActionReject, nil
}
return module.ActionAccept, nil
}モジュールを登録
go
func init() {
module.Register("my-filter", &MyFilter{})
}モジュールを設定
toml
[[modules.filter]]
name = "my-filter"
enabled = true
[modules.filter.config]
custom_option = "value"モジュール管理
モジュールをリスト
bash
sirrchatd module list出力:
認証モジュール:
- blockchain-auth (有効)
- ldap-auth (無効)
- pam-auth (有効)
フィルターモジュール:
- spam-filter (有効)
- virus-scanner (有効)
ストレージモジュール:
- maildir (有効)
- s3 (無効)モジュールを有効化/無効化
bash
# モジュールを有効化
sirrchatd module enable spam-filter
# モジュールを無効化
sirrchatd module disable spam-filterモジュールをリロード
bash
sirrchatd module reload --name spam-filterモジュール設定
グローバル設定
toml
[modules]
# モジュールロードパス
load_path = "/usr/lib/sirrchatd/modules"
# 自動ロード
auto_load = true
# モジュールタイムアウト
timeout = "30s"モジュール優先度
toml
[[modules.filter]]
name = "spam-filter"
priority = 100 # 数字が小さいほど優先度が高い
[[modules.filter]]
name = "virus-scanner"
priority = 50モジュールフック
利用可能なフック
pre_auth: 認証前post_auth: 認証後pre_receive: メール受信前post_receive: メール受信後pre_send: メール送信前post_send: メール送信後
フックの例
go
func (m *MyModule) PreReceive(ctx *Context, msg *Message) error {
// メール受信前に実行
log.Printf("Receiving email from %s", msg.From)
return nil
}モジュール開発
開発環境セットアップ
bash
# モジュールテンプレートをクローン
git clone https://github.com/mail-chat-chain/module-template.git my-module
cd my-module
# 依存関係をインストール
go mod download
# モジュールをビルド
go build -buildmode=plugin -o my-module.soモジュールをテスト
go
package mymodule_test
import (
"testing"
"github.com/mail-chat-chain/mailchatd/module"
)
func TestMyModule(t *testing.T) {
m := &MyModule{}
err := m.Init(map[string]interface{}{})
if err != nil {
t.Fatal(err)
}
// テストロジック
}パッケージとリリース
bash
# リリースバージョンをビルド
go build -ldflags="-s -w" -buildmode=plugin
# システムにインストール
sudo cp my-module.so /usr/lib/sirrchatd/modules/一般的なモジュール
rate-limiter
レート制限モジュール。
toml
[[modules.filter]]
name = "rate-limiter"
[modules.filter.config]
max_per_hour = 100
max_per_minute = 10auto-reply
自動返信モジュール。
toml
[[modules.modify]]
name = "auto-reply"
[modules.modify.config]
enabled_users = ["user@example.com"]
message = "I'm out of office"archive
メールアーカイブモジュール。
toml
[[modules.storage]]
name = "archive"
[modules.storage.config]
retention_days = 365
compress = trueモジュールパフォーマンス
パフォーマンス監視
bash
sirrchatd module stats出力:
モジュール 呼び出し 平均時間 最大時間
spam-filter 1,234 45ms 250ms
dkim-signer 1,234 12ms 45ms
virus-scanner 1,234 123ms 890msパフォーマンス最適化
toml
[modules.performance]
# 並行処理
parallel = true
max_goroutines = 10
# キャッシング
enable_cache = true
cache_size_mb = 64トラブルシューティング
デバッグモード
toml
[modules.debug]
enabled = true
log_level = "debug"
trace_calls = trueモジュールログ
bash
# モジュールログを表示
sirrchatd module logs --name spam-filter
# リアルタイムログ
sirrchatd module logs --name spam-filter --follow関連ドキュメント: