Module System
SirrChat adopts a modular architecture that allows you to customize and extend functionality according to your needs.
Module Types
Auth Modules
Handle user authentication.
go
type AuthModule interface {
Name() string
Authenticate(username, credential string) (bool, error)
Supports(method string) bool
}Storage Modules
Manage email and data storage.
go
type StorageModule interface {
Save(mailbox string, message *Message) error
Load(mailbox string, uid uint32) (*Message, error)
Delete(mailbox string, uid uint32) error
}Filter Modules
Email content filtering and processing.
go
type FilterModule interface {
Filter(ctx *Context, msg *Message) (Action, error)
}Built-in Modules
blockchain-auth
Blockchain wallet authentication module.
Configuration:
toml
[[modules.auth]]
name = "blockchain-auth"
enabled = true
[modules.auth.config]
networks = ["ethereum", "bsc"]ldap-auth
LDAP directory service authentication.
Configuration:
toml
[[modules.auth]]
name = "ldap-auth"
enabled = true
[modules.auth.config]
server = "ldap://ldap.example.com"spam-filter
Spam filtering module.
Configuration:
toml
[[modules.filter]]
name = "spam-filter"
enabled = true
[modules.filter.config]
threshold = 5.0
quarantine = truedkim-signer
DKIM email signing module.
Configuration:
toml
[[modules.modify]]
name = "dkim-signer"
enabled = true
[modules.modify.config]
selector = "default"
private_key = "/etc/sirrchatd/dkim/private.key"Custom Modules
Creating a Module
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 {
// Initialize configuration
return nil
}
func (f *MyFilter) Filter(ctx *module.Context, msg *module.Message) (module.Action, error) {
// Implement filtering logic
if someCondition(msg) {
return module.ActionReject, nil
}
return module.ActionAccept, nil
}Register Module
go
func init() {
module.Register("my-filter", &MyFilter{})
}Configure Module
toml
[[modules.filter]]
name = "my-filter"
enabled = true
[modules.filter.config]
custom_option = "value"Module Management
List Modules
bash
sirrchatd module listOutput:
Auth Modules:
- blockchain-auth (enabled)
- ldap-auth (disabled)
- pam-auth (enabled)
Filter Modules:
- spam-filter (enabled)
- virus-scanner (enabled)
Storage Modules:
- maildir (enabled)
- s3 (disabled)Enable/Disable Modules
bash
# Enable module
sirrchatd module enable spam-filter
# Disable module
sirrchatd module disable spam-filterReload Module
bash
sirrchatd module reload --name spam-filterModule Configuration
Global Configuration
toml
[modules]
# Module loading path
load_path = "/usr/lib/sirrchatd/modules"
# Auto load
auto_load = true
# Module timeout
timeout = "30s"Module Priority
toml
[[modules.filter]]
name = "spam-filter"
priority = 100 # Lower number = higher priority
[[modules.filter]]
name = "virus-scanner"
priority = 50Module Hooks
Available Hooks
pre_auth: Before authenticationpost_auth: After authenticationpre_receive: Before receiving emailpost_receive: After receiving emailpre_send: Before sending emailpost_send: After sending email
Hook Example
go
func (m *MyModule) PreReceive(ctx *Context, msg *Message) error {
// Execute before receiving email
log.Printf("Receiving email from %s", msg.From)
return nil
}Module Development
Development Environment Setup
bash
# Clone module template
git clone https://github.com/mail-chat-chain/module-template.git my-module
cd my-module
# Install dependencies
go mod download
# Build module
go build -buildmode=plugin -o my-module.soTest Module
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)
}
// Test logic
}Package and Release
bash
# Build release version
go build -ldflags="-s -w" -buildmode=plugin
# Install to system
sudo cp my-module.so /usr/lib/sirrchatd/modules/Common Modules
rate-limiter
Rate limiting module.
toml
[[modules.filter]]
name = "rate-limiter"
[modules.filter.config]
max_per_hour = 100
max_per_minute = 10auto-reply
Auto-reply module.
toml
[[modules.modify]]
name = "auto-reply"
[modules.modify.config]
enabled_users = ["[email protected]"]
message = "I'm out of office"archive
Email archiving module.
toml
[[modules.storage]]
name = "archive"
[modules.storage.config]
retention_days = 365
compress = trueModule Performance
Performance Monitoring
bash
sirrchatd module statsOutput:
Module Calls Avg Time Max Time
spam-filter 1,234 45ms 250ms
dkim-signer 1,234 12ms 45ms
virus-scanner 1,234 123ms 890msPerformance Optimization
toml
[modules.performance]
# Concurrent processing
parallel = true
max_goroutines = 10
# Caching
enable_cache = true
cache_size_mb = 64Troubleshooting
Debug Mode
toml
[modules.debug]
enabled = true
log_level = "debug"
trace_calls = trueModule Logs
bash
# View module logs
sirrchatd module logs --name spam-filter
# Real-time logs
sirrchatd module logs --name spam-filter --followRelated documentation: