Modify Subject, Body after message_from_string in Python -


i trying modify email2sms script smstools 3.

a sample incoming sms file:

$ cat /var/spool/sms/incoming/gsm1.ateo8g from: 950 from_toa: d0 alphanumeric, unknown from_smsc: 421950900050 sent: 17-09-13 17:41:17 received: 17-09-13 17:48:21 subject: gsm1 modem: gsm1 imsi: 231030011459971 report: no alphabet: iso length: 5  test1 

the script using following code format message:

if (statuscode == 'received'):     smsfile = open(smsfilename)     msg = email.message_from_string(smsfile.read())     msg['original-from'] = msg['from']     msg['to'] = forwardto 

the problem: want modify subject field in code above. tried msg['subject '] = 'example' (after msg['to']), subject field not overwrited, doubled. knows how modify after email.message_from_string() function?

you want replace subject header message.

msg.replace_header('subject', 'example subject') 

assigning index adds new header. use when header doesn't exist.

msg['subject'] = 'example subject' # add new subject header print(msg.items)  >> [('from', '950'), ('from_toa', 'd0 alphanumeric, unknown'),      ('from_smsc', '421950900050'), ('sent', '17-09-13 17:41:17'),      ('received', '17-09-13 17:48:21'), ('subject', 'gsm 1'),     ('modem', 'gsm1'), ('imsi', '231030011459971'),      ('report', 'no'), ('alphabet', 'iso'),     ('length', '5'), ('original-from', '950'),     ('subject', 'example subject')] 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -