mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-01-04 07:02:45 +08:00
Use buffers for BIMI docs
This commit is contained in:
parent
a1a77d2414
commit
f7d9c75cfb
1 changed files with 33 additions and 1 deletions
|
@ -5,6 +5,7 @@ const https = require('https');
|
|||
const { validateSvg } = require('mailauth/lib/bimi/validate-svg');
|
||||
const { vmc } = require('@postalsys/vmc');
|
||||
const { formatDomain, getAlignment } = require('mailauth/lib/tools');
|
||||
const crypto = require('crypto');
|
||||
|
||||
class BimiHandler {
|
||||
static create(options = {}) {
|
||||
|
@ -115,6 +116,10 @@ class BimiHandler {
|
|||
throw error;
|
||||
}
|
||||
|
||||
if (bimiDocument?.content?.buffer) {
|
||||
bimiDocument.content = bimiDocument.content.buffer;
|
||||
}
|
||||
|
||||
return bimiDocument;
|
||||
}
|
||||
|
||||
|
@ -283,6 +288,12 @@ class BimiHandler {
|
|||
{ upsert: true, returnDocument: 'after' }
|
||||
);
|
||||
|
||||
bimiDocument = r?.value;
|
||||
|
||||
if (bimiDocument?.content?.buffer) {
|
||||
bimiDocument.content = bimiDocument.content.buffer;
|
||||
}
|
||||
|
||||
return r && r.value;
|
||||
}
|
||||
|
||||
|
@ -337,6 +348,28 @@ class BimiHandler {
|
|||
throw error;
|
||||
}
|
||||
|
||||
if (locationStatus === 'fulfilled' && locationValue?.content && authorityValue.vmc?.hashAlgo && authorityValue.vmc?.validHash) {
|
||||
console.log(locationValue.content);
|
||||
let hash = crypto
|
||||
.createHash(authorityValue.vmc.hashAlgo)
|
||||
//sss
|
||||
.update(locationValue.content)
|
||||
.digest('hex');
|
||||
if (hash === authorityValue.vmc.hashValue) {
|
||||
// logo files match, so location URL is safe to use
|
||||
authorityValue.locationUrl = bimiData.location;
|
||||
} else {
|
||||
let error = new Error('Logo files from l= and a= do not match');
|
||||
error.details = {
|
||||
locationHash: hash,
|
||||
authorityHash: authorityValue.vmc.hashValue,
|
||||
hashAlgo: authorityValue.vmc.hashAlgo
|
||||
};
|
||||
error.code = 'LOGO_HASH_MISMATCH';
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return authorityValue;
|
||||
}
|
||||
|
||||
|
@ -348,7 +381,6 @@ module.exports = BimiHandler;
|
|||
|
||||
/*
|
||||
const db = require('./db');
|
||||
|
||||
db.connect(() => {
|
||||
let bimi = BimiHandler.create({
|
||||
database: db.database
|
||||
|
|
Loading…
Reference in a new issue