Debian Codegraph @

test/send-message

raw
1 #!/usr/bin/python
2
3 import sys
4 import dbus
5 import csv
6
7 if (len(sys.argv) < 4):
8 print("Usage: {}"\
9 " <recipient>,..."\
10 " <smil-file-path>"\
11 " <<content-id>,<content-type>,<file-path>>,..."\
12 .format(sys.argv[0]))
13 print("Sample(Related): {}"\
14 " \"+33611111111,+33622222222\""\
15 " \"smil.txt\""\
16 " \"cid-1,text/plain,text.txt\""\
17 " \"cid-2,image/jpeg,image.jpg\""\
18 .format(sys.argv[0]))
19 print("Sample(Mixed): {}"\
20 " \"+33611111111,+33622222222\""\
21 " \"\""\
22 " \"cid-1,text/plain,text.txt\""\
23 " \"cid-2,image/jpeg,image.jpg\""\
24 .format(sys.argv[0]))
25 sys.exit(1)
26
27 bus = dbus.SessionBus()
28
29 manager = dbus.Interface(bus.get_object('org.ofono.mms', '/org/ofono/mms'),
30 'org.ofono.mms.Manager')
31
32 services = manager.GetServices()
33 path = services[0][0]
34
35 service = dbus.Interface(bus.get_object('org.ofono.mms', path),
36 'org.ofono.mms.Service')
37
38 recipients = dbus.Array([],signature=dbus.Signature('s'))
39 reader = csv.reader([sys.argv[1]])
40 for r in reader:
41 print("Recipient list: {}".format(r))
42 for i in r:
43 recipients.append(dbus.String(i))
44
45
46 if sys.argv[2] == "":
47 print("Send MMS as Mixed")
48 smil = ""
49 else:
50 print("Send MMS as Related")
51 print("Smil path: {}".format(sys.argv[2]))
52 file = open(sys.argv[2],"r")
53 smil = dbus.String(file.read())
54
55 attachments = dbus.Array([],signature=dbus.Signature('(sss)'))
56 for a in sys.argv[3:]:
57 print("Attachment: ({})".format(a))
58 reader = csv.reader([a])
59 for r in reader:
60 attachments.append(dbus.Struct((dbus.String(r[0]),
61 dbus.String(r[1]),
62 dbus.String(r[2])
63 ), signature=None))
64
65 path = service.SendMessage(recipients, smil, attachments)
66
67 print(path)