1

This is an example from the mmcli manpage:

mmcli -m 0 --messaging-create-sms="text='Hello world',number='+1234567890'"

The details how it is parsed are unclear, the description says only --messaging-create-sms=['KEY1=VALUE1,...'] and lists known keys. The value for the text key is an UTF-8 message text.

So this is the corresponding line from my script:

mmcli -m $modem --messaging-create-sms="text='$msg',number='$num'"

The probem is that the message must not contain a single quote. The error is:

'GDBus.Error:org.freedesktop.ModemManager1.Error.Message.InvalidPduParameter: Failed to convert message text to GSM'

Currently I'm replacing it by a double qoute. I tried backslash escaping, but it did not work. Could you please help?

VPfB
  • 801

2 Answers2

1

Perhaps the code doing the parsing is here:

/* Expecting input as:
 *   key1=string,key2=true,key3=false...
 * Strings may also be passed enclosed between double or single quotes, like:
 *   key1="this is a string", key2='and so is this' */
gboolean mm_common_parse_key_value_string(...)

So, providing you don't have both double and single quotes in your text you can use the opposite quote in the argument, for example:

case "$msg" in
*\'*\"*|*\"*\'*) echo oops; exit 1 ;;
*\'*)   q=\" ;;
*\"*)   q=\' ;;
esac

... --messaging-create-sms="text=$q$msg$q,number='$num'"
meuh
  • 51,383
1

It's a little late, but I recently ran into the same problem. I needed support for messages that can contain both single and double quotes, which is not possible with the current string parsing. I figured I'd fix it myself and forked the repository here and added a command line option, --messaging-create-sms-with-text, that allows you to read the message text from a file (which could be stdin). The option works similar to --messaging-create-sms-with-data.

I've done a pull request, but the project seems not to be very active (last commit was Nov 4, 2021). We'll see.

EDIT: The project was hosted on FreeDesktop's own gitlab. I just assumed it was on GitHub. My bad :)

My changes have since been accepted.