Read a delivery receipt's body as the octets that arrived (#81)

* Regression tests for a receipt body read under a data_coding it is not written in

* Read a delivery receipt's body as the octets that arrived, not by its data_coding

* Assert SMPPSim's UCS2 receipt body parses like every other segment's

* Record the receipt-body defect as fixed

* Retain a multipart segment's octets once, not twice

* Sort the new type import into its file's order
This commit is contained in:
2026-09-05 22:37:05 +02:00
committed by GitHub
parent ea42bc6d20
commit 45d2f5548e
19 changed files with 300 additions and 162 deletions
+11 -10
View File
@@ -2,10 +2,11 @@ import type { MessageState } from './defs/constants.ts';
import type { ParamValue } from './defs/types.ts';
import type { PduObject } from './pdu.ts';
import type { SmsIdFormat } from './sms-id.ts';
import { consts, constsById, messageTypeOf } from './defs/constants.ts';
import { decodeMessage } from './message.ts';
import { consts, constsById, hasUdh, messageTypeOf } from './defs/constants.ts';
import { encodings } from './defs/encodings.ts';
import { normaliseSmsId } from './sms-id.ts';
import { paramNumber, paramText } from './defs/types.ts';
import { udhLength } from './udh.ts';
/**
* The seven-character status codes carried in a receipt's `stat:` field, mapped to the
@@ -154,17 +155,17 @@ function messageType(pduObj: PduObject): MessageType {
return nonEmptyText(pduObj.tlvs.receipted_message_id?.tagValue) === undefined ? 'unmarked' : 'receipt';
}
/** A UDH-carrying short_message reaches here as a buffer, header and all. */
/** SMPP 3.4 Appendix B makes a receipt fixed text, so its octets are read as octets, not decoded. */
function receiptBody(pduObj: PduObject): string {
const message = pduObj.params.short_message;
const octets = pduObj.shortMessageOctets;
if (!Buffer.isBuffer(message)) return paramText(message);
if (octets === undefined) return paramText(pduObj.params.short_message);
return decodeMessage(
message,
paramNumber(pduObj.params.data_coding, 0),
paramNumber(pduObj.params.esm_class, 0),
).message;
const body = hasUdh(paramNumber(pduObj.params.esm_class, 0))
? octets.subarray(udhLength(octets))
: octets;
return encodings.LATIN1.decode(body);
}
function receiptId(