wiki:Import SMS from SIM

Import SMS from SIM card

This script is a first version that imports messages from your SIM card into opimd.

Missing stuff:

  • concatinating split messages
  • setting correct timestamp for the messages
#!/usr/bin/python

import dbus

bus = dbus.SystemBus()

gsm_device_obj = bus.get_object("org.freesmartphone.ogsmd", "/org/freesmartphone/GSM/Device")
simObject = dbus.Interface(gsm_device_obj,'org.freesmartphone.GSM.SIM')

opimd_device_obj = bus.get_object("org.freesmartphone.opimd", "/org/freesmartphone/PIM/Messages")
opimdObject = dbus.Interface(opimd_device_obj, dbus_interface="org.freesmartphone.PIM.Messages")
fieldsObject = dbus.Interface(opimd_device_obj, dbus_interface="org.freesmartphone.PIM.Fields")

if fieldsObject.GetType("Direction") == "generic":
	fieldsObject.AddField("Direction","text")
if fieldsObject.GetType("Content") == "generic":
	fieldsObject.AddField("Content","text")
if fieldsObject.GetType("Peer") == "generic":
	fieldsObject.AddField("Peer","phonenumber")

#if fieldsObject.GetType("New") == "generic":
#	fieldsObject.AddField("New","boolean")
#if fieldsObject.GetType("Timestamp") == "generic":
#	fieldsObject.AddField("Timestamp","date")
#if fieldsObject.GetType("Timezone") == "generic":
#	fieldsObject.AddField("Timezone","timezone")
#if fieldsObject.GetType("Source") == "generic":
#	fieldsObject.AddField("Source","text")

for i in range(0, 255):
	try:
		m = simObject.RetrieveMessage(i)
	except dbus.exceptions.DBusException:
		continue

	if len(m[2]) == 0:
		continue
	
	if m[0] == "sent":
		opimdObject.Add({"Direction":"out", "Peer":m[1], "Content":m[2]})
	else
		opimdObject.AddIncoming({"Direction":"in", "Peer":m[1], "Content":m[2]})