sms delete: only a message index reaches the modem

`sms delete ARG` put ARG into AT+CMGD unchecked: anything after the index
(a comma flag that deletes more, or another command) went to the modem as it
was. Found while the Ubuntu web panel's SMS page was written (#138).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DqKKtBQZCfxYnHuBCuDqqn
This commit is contained in:
Abdurrahman Kaan DikeçandClaude Opus 5.5 committed 2026-10-11 18:01:42 +03:00
1 parent 7a2a5eff84
commit bbb11aeb8b
2 files changed
+28

No files matched your search

+2
View File
@@ -133,6 +133,8 @@ delete)
case $what in
all) at 'AT+CMGD=1,4' 30 >/dev/null; echo "deleted every message in $store" ;;
read) at 'AT+CMGD=1,1' 30 >/dev/null; echo "deleted the messages already read in $store" ;;
# only a message index reaches the AT command (anything else would be sent to the modem as it is)
*[!0-9]*) echo "sms: not a message index: $what (sms delete INDEX | read | all)" >&2; exit 2 ;;
*) at "AT+CMGD=$what" 20 >/dev/null; echo "deleted #$what" ;;
esac
;;
+26
View File
@@ -713,6 +713,32 @@ class Pool(ShellTest):
self.assertEqual((self.tmp / 'fwd.log').read_text().splitlines(), ['enqueue 000001 000002', 'kick'])
class Delete(ShellTest):
"""`sms delete` (every system): only a message index, read or all reach the modem."""
def setUp(self):
super().setUp()
self.stub('mu300-at', AT_STUB)
(self.tmp / 'at').mkdir()
(self.tmp / 'at' / 'CPMS').write_text('+CPMS: 2,50,2,50,2,50\nOK\n')
def test_anything_but_an_index_is_refused_before_the_modem(self):
for shell in self.each_shell():
for bad in ('1;AT+CFUN=0', '1,4', '-1', '1 2', 'x', '1\rAT'):
(self.tmp / 'at.log').unlink(missing_ok=True)
r = subprocess.run(shell + [str(TOP / 'rootfs/overlay/opt/mu300/bin/sms'), 'delete', bad],
capture_output=True, text=True, timeout=30,
env=self.env(MU300_SMS_AWK=AWK, MU300_SMS_STATE=self.tmp / 'state'))
self.assertEqual(r.returncode, 2, (bad, r.stderr))
log = (self.tmp / 'at.log').read_text() if (self.tmp / 'at.log').exists() else ''
self.assertNotIn('CMGD', log, bad)
r = subprocess.run(shell + [str(TOP / 'rootfs/overlay/opt/mu300/bin/sms'), 'delete', '7'],
capture_output=True, text=True, timeout=30,
env=self.env(MU300_SMS_AWK=AWK, MU300_SMS_STATE=self.tmp / 'state'))
self.assertEqual(r.returncode, 0, r.stderr)
self.assertIn('AT+CMGD=7', (self.tmp / 'at.log').read_text())
class Watch(ShellTest):
"""`sms watch` (every system): a long message waits for its other parts, MU300_SMS_PARTIAL_WAIT at most."""