feat: edit HTML templates and freeze sender account signatures

This commit is contained in:
abaishu0730 committed 2026-10-23 18:19:34 +08:00
1 parent 61f561a842
commit 97e06328c3
24 files changed
+215 -29

No files matched your search

+1 -1
View File
@@ -21,7 +21,7 @@ class OrderRuleDispatcher{
constructor({store,mail,settings,calendar=()=>[],clock=()=>new Date(),providersReady=()=>false,attachmentReader,templateResolver}){
this.store=store;this.mail=mail;this.settings=settings;this.calendar=calendar;this.clock=clock;this.providersReady=providersReady;
this.running=null;this.stopped=false;this.schedule=null;this.timer=null;
this.attachmentReader=attachmentReader;if(templateResolver)store.templateResolver=templateResolver;
this.attachmentReader=attachmentReader;if(templateResolver)store.templateResolver=templateResolver;if(mail?.store?.signature)store.signatureResolver=id=>mail.store.signature(id);
}
ready(){
const config=this.store.settings(),cap=this.store.snapshot().capabilities;
+3 -3
View File
@@ -2,7 +2,7 @@
const path=require('node:path');
const {publicationIssues}=require('./validation.cjs');
const {archiveFilename}=require('../storage/order-filename.cjs');
const {buildBatch}=require('./batch.cjs'),{applyBodyTemplate}=require('./template.cjs');
const {composeBatch}=require('./template.cjs');
const {initialNotification,ordersForMode}=require('./huizhou.cjs');
function previewEffects(rule,event,store){
const hui=initialNotification(rule,event);
@@ -19,8 +19,8 @@ function previewEffects(rule,event,store){
for(const mode of ['normal','huizhou']){
if(mode==='huizhou'&&hui.status!=='pending')continue;
try{
const orders=ordersForMode([order],mode),snapshot=applyBodyTemplate(buildBatch(rule,orders,cutoff,{maxMessageBytes:store.settings().maxMessageBytes,notificationMode:mode}),store.templateResolver?.(rule.categoryId,rule,mode),orders,store.settings().maxMessageBytes);
const mail={subject:snapshot.subject,text:snapshot.text,to:snapshot.to,cc:snapshot.cc,attachments:snapshot.attachments.map(f=>f.name),template:snapshot.template||null};
const orders=ordersForMode([order],mode),snapshot=composeBatch(rule,orders,cutoff,store,{notificationMode:mode,simulation:true});
const mail={subject:snapshot.subject,text:snapshot.text,to:snapshot.to,cc:snapshot.cc,attachments:snapshot.attachments.map(f=>f.name),template:snapshot.template||null,signature:snapshot.signature||null};
result.notifications[mode]={...result.notifications[mode],status:'ready',mail};if(mode==='normal')result.mail=mail;
}catch(error){result.notifications[mode].status='blocked';result.notifications[mode].issues.push(error.message);if(mode==='normal')result.issues.push(error.message);}
}
+3 -3
View File
@@ -2,8 +2,8 @@
const fs=require('node:fs');const path=require('node:path');const crypto=require('node:crypto');
const {DatabaseSync}=require('node:sqlite');const {BpmVault}=require('../../platform/security/vault.cjs');
const {seedRules}=require('./catalog.cjs');const registry=require('./registry.cjs');const {previewMatch,describeRule}=require('./matching.cjs');
const {buildBatch}=require('./batch.cjs');const {transition}=require('./state.cjs');
const {applyBodyTemplate}=require('./template.cjs');
const {transition}=require('./state.cjs');
const {composeBatch}=require('./template.cjs');
const {fail,validateRule,publicationIssues}=require('./validation.cjs');
const {windowForCutoff,upcomingWindow,inWindow}=require('./window.cjs');
const {matchesScope,scopesOverlap}=require('./scopes.cjs');
@@ -284,7 +284,7 @@ class RuleStore{
if(!error&&mode==='huizhou'&&orders.some(o=>delivery(o,mode).issues?.length))error=orders.flatMap(o=>delivery(o,mode).issues||[]).join(';');
if(!error&&orders.some(o=>mode==='normal'?o.status!=='pending':!o.archive||!['pending','batched','sent','unknown'].includes(o.status)))error='本类别存在字段、文件或归档尚未准备完成的订单。';
let snapshot;
if(!error)try{for(const order of orders)require('./restricted-test.cjs').assertOrder(this,order);const selected=ordersForMode(orders,mode);snapshot=buildBatch(rule,selected,cutoff,{store:this,maxMessageBytes:this.settings().maxMessageBytes,window,notificationMode:mode});snapshot=applyBodyTemplate(snapshot,this.templateResolver?.(rule.categoryId,rule,mode),selected,this.settings().maxMessageBytes);}catch(cause){error=cause.message;}
if(!error)try{for(const order of orders)require('./restricted-test.cjs').assertOrder(this,order);snapshot=composeBatch(rule,ordersForMode(orders,mode),cutoff,this,{window,notificationMode:mode});}catch(cause){error=cause.message;}
const key=resultId(rule.categoryId,mode);
if(error){this.put('window-results',{id:key,categoryId:rule.categoryId,notificationMode:mode,cutoff,status:'blocked',error,updatedAt:this.now()});this.recordIssue('build:'+key,{component:'rules',notificationMode:mode,error,cutoff,categoryId:rule.categoryId,orderIds:orders.map(o=>o.id)});for(const original of orders){const order=this.get('orders',original.id);updateDelivery(order,mode,{error,...(mode==='huizhou'?{status:'blocked'}:{})});this.put('orders',order);}continue;}
const batch={...snapshot,id:crypto.randomUUID(),version:1,status:'prepared',createdAt:this.now(),ruleSnapshot:copy(rule),channelId:this.settings().channelId,error:null};
+7 -1
View File
@@ -52,4 +52,10 @@ function applyHuizhouTemplate(snapshot,template,orders,maxMessageBytes){
if(bytes>maxMessageBytes)fail('关联模板展开后超过邮件容量限制。');
return {...snapshot,subject,text,html,template:{id:template.id,version:template.version,bindingVersion:template.bindingVersion,notificationMode:'huizhou'}};
}
module.exports={applyBodyTemplate};
function composeBatch(rule,orders,cutoff,store,{window,notificationMode='normal',simulation=false}={}){
const settings=store.settings(),signature=settings.channelId?store.signatureResolver?.(settings.channelId):null;
const snapshot=require('./batch.cjs').buildBatch(signature?.enabled?{...rule,signature:''}:rule,orders,cutoff,{...(!simulation?{store}:{}),maxMessageBytes:settings.maxMessageBytes,window,notificationMode});
const rendered=applyBodyTemplate(snapshot,store.templateResolver?.(rule.categoryId,rule,notificationMode),orders,settings.maxMessageBytes);
return require('../mail/content.cjs').appendSignature(rendered,signature,settings.maxMessageBytes);
}
module.exports={applyBodyTemplate,composeBatch};