Beispiel #1
0
 def parse_incoming(self, msgs, access):
     lineas = self.prerare_list(msgs)
     for linea in lineas:
         phone, received, text, msg_id  = linea.split('$')
         date = datetime.datetime.strptime(received, '%Y-%m-%d %H:%M:%S')
         if msg_id:
             try:
                 m = SMSHistory.objects.filter(remote_id = msg_id)[0].message
             except IndexError:
                 log.error("Incoming message %s external to this platform (phone %s, id = %s)", text, phone, msg_id)
                 item = ResponseMessage.create_one(None, text, date, msg_id)
                 continue
             item = ResponseMessage.create_one(m, text, date, msg_id)
             log.debug("Incoming message to %s received: %s", m, item)
             args = m.account.args()
             if 'to' in args:
                 to_reply = [p.strip() for p in args['to'].split(',')]
                 from_reply = args['from'] if 'from' in args else '*****@*****.**'
                 subject = u"Reply message received from %s" % phone
                 mail = "Received on: %s\nMobile: %s\nText: %s" % (date, phone, text)
                 log.debug("Sending mail %s to %s", mail, to_reply)
                 send_mail(subject, mail, from_reply, to_reply, fail_silently=False)
         else:
             item = IncomingMessage.create_one(phone, text, date, access.account_set.all()[0], None)
             log.info("Received %s msg on %s from %s mobile to %s access.", text, received, phone, access)
             if self.process:
                 self.encode(item)