diff --git a/src/message.js b/src/message.js index b40a11c6..5bdff7ca 100644 --- a/src/message.js +++ b/src/message.js @@ -244,7 +244,8 @@ Message.prototype.decryptSessionKeys = async function(privateKeys, passwords) { * @returns {(Uint8Array|null)} literal body of the message as Uint8Array */ Message.prototype.getLiteralData = function() { - const literal = this.packets.findPacket(enums.packet.literal); + const msg = this.unwrapCompressed(); + const literal = msg.packets.findPacket(enums.packet.literal); return (literal && literal.getBytes()) || null; }; @@ -253,7 +254,8 @@ Message.prototype.getLiteralData = function() { * @returns {(String|null)} filename of literal data packet as string */ Message.prototype.getFilename = function() { - const literal = this.packets.findPacket(enums.packet.literal); + const msg = this.unwrapCompressed(); + const literal = msg.packets.findPacket(enums.packet.literal); return (literal && literal.getFilename()) || null; }; @@ -262,7 +264,8 @@ Message.prototype.getFilename = function() { * @returns {(String|null)} literal body of the message interpreted as text */ Message.prototype.getText = function() { - const literal = this.packets.findPacket(enums.packet.literal); + const msg = this.unwrapCompressed(); + const literal = msg.packets.findPacket(enums.packet.literal); if (literal) { return literal.getText(); } diff --git a/src/packet/packetlist.js b/src/packet/packetlist.js index b56c2cd2..03f8c7da 100644 --- a/src/packet/packetlist.js +++ b/src/packet/packetlist.js @@ -168,24 +168,10 @@ List.prototype.filterByTag = function (...args) { /** * Traverses packet tree and returns first matching packet * @param {module:enums.packet} type The packet type - * @returns {module:packet/packet|null} + * @returns {module:packet/packet|undefined} */ List.prototype.findPacket = function (type) { - const packetlist = this.filterByTag(type); - if (packetlist.length) { - return packetlist[0]; - } - let found = null; - for (let i = 0; i < this.length; i++) { - if (this[i].packets.length) { - found = this[i].packets.findPacket(type); - if (found) { - return found; - } - } - } - - return null; + return this.find(packet => packet.tag === type); }; /**