- Add @git.zone/tsrust with linux_amd64/linux_arm64 cross-compilation - Scaffold Rust workspace with 5 crates: mailer-core, mailer-smtp, mailer-security, mailer-napi, mailer-bin - Fix all TypeScript compilation errors for upgraded dependencies (smartfile v13, mailauth v4.13, smartproxy v23) - Replace smartfile.fs/memory with @push.rocks/smartfs throughout codebase - Fix .ts import extensions to .js for NodeNext module resolution - Update DKIMSignOptions usage to match mailauth v4.13 API - Add MTA error classes with permissive signatures for legacy SMTP client - Replace removed DcRouter/StorageManager/deliverability imports with local interfaces
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import * as plugins from '../../plugins.js';
|
|
import type { UnifiedEmailServer } from '../routing/classes.unified.email.server.js';
|
|
|
|
interface Headers {
|
|
[key: string]: string;
|
|
}
|
|
|
|
interface IEmailSignJobOptions {
|
|
domain: string;
|
|
selector: string;
|
|
headers: Headers;
|
|
body: string;
|
|
}
|
|
|
|
export class EmailSignJob {
|
|
emailServerRef: UnifiedEmailServer;
|
|
jobOptions: IEmailSignJobOptions;
|
|
|
|
constructor(emailServerRef: UnifiedEmailServer, options: IEmailSignJobOptions) {
|
|
this.emailServerRef = emailServerRef;
|
|
this.jobOptions = options;
|
|
}
|
|
|
|
async loadPrivateKey(): Promise<string> {
|
|
const keyInfo = await this.emailServerRef.dkimCreator.readDKIMKeys(this.jobOptions.domain);
|
|
return keyInfo.privateKey;
|
|
}
|
|
|
|
public async getSignatureHeader(emailMessage: string): Promise<string> {
|
|
const privateKey = await this.loadPrivateKey();
|
|
const signResult = await plugins.dkimSign(emailMessage, {
|
|
signingDomain: this.jobOptions.domain,
|
|
selector: this.jobOptions.selector,
|
|
privateKey,
|
|
canonicalization: 'relaxed/relaxed',
|
|
algorithm: 'rsa-sha256',
|
|
signTime: new Date(),
|
|
signatureData: [
|
|
{
|
|
signingDomain: this.jobOptions.domain,
|
|
selector: this.jobOptions.selector,
|
|
privateKey,
|
|
algorithm: 'rsa-sha256',
|
|
canonicalization: 'relaxed/relaxed',
|
|
},
|
|
],
|
|
});
|
|
const signature = signResult.signatures;
|
|
return signature;
|
|
}
|
|
}
|