Skip to content

Commit

Permalink
Implement encrypted & unsigned eml
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmaske-psd committed Jan 21, 2025
1 parent e418396 commit ff39bf9
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions lib/mail-drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class MailDrop {
encryptedEnvelope,
encryptedUnsignedStream,
recipientsUnsignedEncryptedValid,
encryptedUnsignedEnvelope
unsignedEncryptedEnvelope
} = await envelope.signEML(raw);

//#region - Regular Recipients
Expand Down Expand Up @@ -651,8 +651,8 @@ class MailDrop {
//#region - Encrypted Unsigned Recipients
if (recipientsUnsignedEncryptedValid && recipientsUnsignedEncryptedValid.length > 0) {
// Create Encrypted Envelope
encryptedUnsignedEnvelope.id = encryptedId;
encryptedUnsignedEnvelope.to = recipientsUnsignedEncryptedValid;
unsignedEncryptedEnvelope.id = encryptedId;
unsignedEncryptedEnvelope.to = recipientsUnsignedEncryptedValid;

// Create Encrypted MessageInfo
let encryptedMessageInfo = _.cloneDeep(messageInfo);
Expand All @@ -663,16 +663,16 @@ class MailDrop {
});

// Create a new BodyHashStream and pipe the signed/encrypted Stream
let encryptedBodyHash = new BodyHashStream('relaxed/relaxed', encryptedUnsignedEnvelope.dkim.hashAlgo);
let encryptedBodyHash = new BodyHashStream('relaxed/relaxed', unsignedEncryptedEnvelope.dkim.hashAlgo);
encryptedBodyHash.on('hash', bodyHash => {
// store relaxed body hash for signing
encryptedUnsignedEnvelope.dkim.bodyHash = bodyHash;
encryptedUnsignedEnvelope.bodySize = encryptedBodyHash.byteLength;
unsignedEncryptedEnvelope.dkim.bodyHash = bodyHash;
unsignedEncryptedEnvelope.bodySize = encryptedBodyHash.byteLength;
// re-write values for encryptedMessageInfo after signing/encrypting
// BODY SIZE
encryptedMessageInfo.body = encryptedUnsignedEnvelope.bodySize || 0;
encryptedMessageInfo.body = unsignedEncryptedEnvelope.bodySize || 0;
// SUBJECT
let subjectUpdated = encryptedUnsignedEnvelope.headers.getFirst('subject');
let subjectUpdated = unsignedEncryptedEnvelope.headers.getFirst('subject');
try {
subjectUpdated = libmime.decodeWords(subjectUpdated);
} catch (E) {
Expand All @@ -695,7 +695,7 @@ class MailDrop {
});

encryptedMessageHashStream.on('hash', data => {
encryptedUnsignedEnvelope.sourceMd5 = data.hash;
unsignedEncryptedEnvelope.sourceMd5 = data.hash;
encryptedMessageInfo.md5 = (data.hash || '?').substr(0, 12);
});

Expand All @@ -706,11 +706,11 @@ class MailDrop {
source.resume(); // let the original stream to end normally before displaying the error message
}
if (/Error$/.test(err.name)) {
log.error('Queue/' + process.pid, 'id=%s %s NOQUEUE store "%s" (%s)', encryptedUnsignedEnvelope.sessionId, encryptedId, err.message, encryptedMessageInfo.format());
log.error('Queue/' + process.pid, 'id=%s %s NOQUEUE store "%s" (%s)', unsignedEncryptedEnvelope.sessionId, encryptedId, err.message, encryptedMessageInfo.format());
let keys = encryptedMessageInfo.keys();
['interface', 'originhost', 'transhost', 'transtype', 'user'].forEach(key => {
if (encryptedUnsignedEnvelope[key] && !(key in keys)) {
keys[key] = encryptedUnsignedEnvelope[key];
if (unsignedEncryptedEnvelope[key] && !(key in keys)) {
keys[key] = unsignedEncryptedEnvelope[key];
}
});
keys.error = err.message;
Expand All @@ -720,28 +720,28 @@ class MailDrop {
return callback(err);
}

plugins.handler.runHooks('message:queue', [encryptedUnsignedEnvelope, encryptedMessageInfo], err => {
plugins.handler.runHooks('message:queue', [unsignedEncryptedEnvelope, encryptedMessageInfo], err => {
if (err) {
return setImmediate(() => this.queue.removeMessage(encryptedId, () => callback(err)));
}

let headerFrom = encryptedUnsignedEnvelope.headers
let headerFrom = unsignedEncryptedEnvelope.headers
.getDecoded('from')
.reverse()
.map(entry => entry.value)
.join(' ');

// convert headers object to a serialized array
encryptedUnsignedEnvelope.headers = encryptedUnsignedEnvelope.headers ? encryptedUnsignedEnvelope.headers.getList() : [];
unsignedEncryptedEnvelope.headers = unsignedEncryptedEnvelope.headers ? unsignedEncryptedEnvelope.headers.getList() : [];

// inject message headers to the stored stream
this.queue.setMeta(encryptedId, encryptedUnsignedEnvelope, err => {
this.queue.setMeta(encryptedId, unsignedEncryptedEnvelope, err => {
if (err) {
log.error('Queue/' + process.pid, 'id=%s %s NOQUEUE meta "%s" (%s)', encryptedUnsignedEnvelope.sessionId, encryptedId, err.message, encryptedMessageInfo.format());
log.error('Queue/' + process.pid, 'id=%s %s NOQUEUE meta "%s" (%s)', unsignedEncryptedEnvelope.sessionId, encryptedId, err.message, encryptedMessageInfo.format());
let keys = encryptedMessageInfo.keys();
['interface', 'originhost', 'transhost', 'transtype', 'user'].forEach(key => {
if (encryptedUnsignedEnvelope[key] && !(key in keys)) {
keys[key] = encryptedUnsignedEnvelope[key];
if (unsignedEncryptedEnvelope[key] && !(key in keys)) {
keys[key] = unsignedEncryptedEnvelope[key];
}
});
keys.headerFrom = headerFrom;
Expand All @@ -751,22 +751,22 @@ class MailDrop {
}

// push delivery data
this.queue.push(encryptedId, encryptedUnsignedEnvelope, err => {
this.queue.push(encryptedId, unsignedEncryptedEnvelope, err => {
let keys = encryptedMessageInfo.keys();
['interface', 'originhost', 'transhost', 'transtype', 'user'].forEach(key => {
if (encryptedUnsignedEnvelope[key] && !(key in keys)) {
keys[key] = encryptedUnsignedEnvelope[key];
if (unsignedEncryptedEnvelope[key] && !(key in keys)) {
keys[key] = unsignedEncryptedEnvelope[key];
}
});
keys.headerFrom = headerFrom;
if (err) {
log.error('Queue/' + process.pid, 'id=%s %s NOQUEUE push "%s" (%s)', encryptedUnsignedEnvelope.sessionId, encryptedId, err.message, encryptedMessageInfo.format());
log.error('Queue/' + process.pid, 'id=%s %s NOQUEUE push "%s" (%s)', unsignedEncryptedEnvelope.sessionId, encryptedId, err.message, encryptedMessageInfo.format());
keys.error = err.message;
plugins.handler.remotelog(encryptedId, false, 'NOQUEUE', keys);
return this.queue.removeMessage(encryptedId, () => callback(err));
}

log.info('Queue/' + process.pid, 'id=%s %s QUEUED (%s)', encryptedUnsignedEnvelope.sessionId, encryptedId, encryptedMessageInfo.format());
log.info('Queue/' + process.pid, 'id=%s %s QUEUED (%s)', unsignedEncryptedEnvelope.sessionId, encryptedId, encryptedMessageInfo.format());
plugins.handler.remotelog(encryptedId, false, 'QUEUED', keys);
return setImmediate(() => callback(null, 'Message queued as ' + encryptedId));
});
Expand Down

0 comments on commit ff39bf9

Please sign in to comment.