Hi Andrew,

On Fri, Aug 21, 2009 at 9:35 PM, Andrzej Zaborowski <andrew.zaborowski@intel.com> wrote:
On modems that don't support +CMT (or for class 2 SMSes) the messages are
stored in the modem and then read and deleted from there in two separate
steps with no warranty that deletion succeeds or (more likely) power is
cut before the deletion happens.  Over time the memory may become full
and if we don't want to deal with this condition we need to check on
startup if there are messages we haven't deleted.

We can't differentiate between those messages and those the user already
had on the SIM / modem before installing ofono or switching phones, so we
might want to deliver messages with REC READ status with some kind of
indication that these are potentially old so the UI doesn't emit spurious
alerts.  We don't do this now and just deliver as usual.

So the patch isn't going to work as intended.  See below for exact reasons:

+               hexpdu = g_at_result_pdu(result);

You can't use g_at_result_pdu on messages that haven't been flagged to expect a PDU.  Right now this only works for g_at_chat_register style unsolicited notifications for which the 'expect_pdu' has been set to TRUE.
+       g_at_chat_send(at->parser, "AT+CMGL=4", cmgl_prefix,
+                       at_cmgl_cb, modem, NULL);

Again, this is actually filtering anything that doesn't start with a prefix in the list given by cmgl_prefix.  Namely anything that doesn't start with +CMGL: or is a known final response gets filtered out.

One way to go would be to use NULL for cmgl_prefix and update the parse loop in the callback accordingly.  However, this means that the entire response will be waited on and given once.

It might be worthwhile to support CMGL listings using something similar to g_at_chat_send_listing. 
       ofono_sms_manager_register(modem, &ops);
+       /* Inspect and free the incoming SMS storage */
+       if (at->sms->incoming == MT_STORE)
+               at_cmgl_set_cpms(modem, ME_STORE);
+       else
+               at_cmgl_set_cpms(modem, at->sms->incoming);

It might be worth to scan both ME & SM stores.  Especially since MT literally means combined SM + ME store.