Skip to content

Commit 6e4b701

Browse files
authored
fix(imap-append): ZMS-276: imap append improve logging add new fields to logging (#884)
message-handler addAsync return prepared too
1 parent 168e4cc commit 6e4b701

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

imap-core/lib/commands/append.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,33 @@ module.exports = {
141141
};
142142

143143
this._server.onAppend(path, flags, internaldate, raw, this.session, (err, success, info) => {
144-
Object.keys(info || {}).forEach(key => {
145-
let vkey = '_' + key.replace(/[A-Z]+/g, c => '_' + c.toLowerCase());
146-
if (['_id', '_status'].includes(vkey)) {
147-
vkey = '_append' + vkey;
144+
Object.keys(info || {})
145+
.filter(key => key !== 'prepared')
146+
.forEach(key => {
147+
let vkey = '_' + key.replace(/[A-Z]+/g, c => '_' + c.toLowerCase());
148+
if (['_id', '_status'].includes(vkey)) {
149+
vkey = '_append' + vkey;
150+
}
151+
logdata[vkey] = info[key];
152+
});
153+
154+
if (info && info.prepared) {
155+
const { headers } = info.prepared;
156+
157+
const from = headers.find(header => header.key === 'from');
158+
const parsedFrom = info.prepared.mimeTree.parsedHeader.from[0];
159+
if (from && parsedFrom) {
160+
logdata._append_header_from = parsedFrom.address;
161+
logdata._append_header_from_name = parsedFrom.name;
162+
logdata._append_header_from_value = from.value;
148163
}
149-
logdata[vkey] = info[key];
150-
});
164+
165+
const { msgid } = info.prepared;
166+
logdata._append_message_id = msgid;
167+
168+
const { subject } = info.prepared;
169+
logdata._append_subject = subject;
170+
}
151171

152172
if (err) {
153173
logdata._error = err.message;

lib/message-handler.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,8 @@ class MessageHandler {
690690
mailbox: mailboxData._id.toString(),
691691
mailboxPath: mailboxData.path,
692692
size,
693-
status: 'new'
693+
status: 'new',
694+
prepared
694695
});
695696

696697
// do not use more suitable finally as it is not supported in Node v8

lib/user-handler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ class UserHandler {
761761
// clear rate limit counter on success
762762
try {
763763
await this.rateLimitReleaseUser(userData._id);
764-
} catch (err) {
764+
} catch {
765765
//ignore
766766
}
767767

0 commit comments

Comments
 (0)