'Parse a list of lines (the output of GsmModem._wait), to extract any
incoming SMS and append them to GsmModem.incoming_queue. Returns the
same lines with the incoming SMS removed. Other unsolicited data may
remain, which must be cropped separately.'

def _parse_incoming_sms(self, lines):

    output_lines = []
    n = 0
    while (n < len(lines)):
        if (lines[n][0:5] != '+CMT:'):
            output_lines.append(lines[n])
            n += 1
            continue
        msg_line = lines[(n + 1)].strip()
        try:
            self.command('AT+CNMA')
        except errors.GsmError:
            pass
        msg = self.smshandler.parse_incoming_message(lines[n], msg_line)
        if (msg is not None):
            self.incoming_queue.append(msg)
        n += 2
    return output_lines
