docs: def listStoredSms(self, status=Sms.STATUS_ALL, memory=None, delete=False):
          """ Returns SMS messages currently stored on the device/SIM card.
          
          The messages are read from the memory set by the "memory" parameter.
          
          :param status: Filter messages based on this read status; must be 0-4 (see Sms class)
          :type status: int
          :param memory: The memory type to read from. If None, use the current default SMS read memory
          :type memory: str or None
          :param delete: If True, delete returned messages from the device/SIM card
          :type delete: bool
          
          :return: A list of Sms objects containing the messages read
          :rtype: list
          """
          self._setSmsMemory(readDelete=memory)
          messages = []
          delMessages = set()
          if self._smsTextMode:
              cmglRegex= re.compile(r'^\+CMGL: (\d+),"([^"]+)","([^"]+)",[^,]*,"([^"]+)"$')
              for key, val in dictItemsIter(Sms.TEXT_MODE_STATUS_MAP):
                  if status == val:
                      statusStr = key
                      break
              else:
                  raise ValueError('Invalid status value: {0}'.format(status))
              result = self.write('AT+CMGL="{0}"'.format(statusStr))
              msgLines = []
              msgIndex = msgStatus = number = msgTime = None
              for line in result:
                  cmglMatch = cmglRegex.match(line)                
                  if cmglMatch:
                      # New message; save old one if applicable
                      if msgIndex != None and len(msgLines) > 0:
                          msgText = '\n'.join(msgLines)
                          msgLines = []
                          messages.append(ReceivedSms(self, Sms.TEXT_MODE_STATUS_MAP[msgStatus], number, parseTextModeTimeStr(msgTime), msgText))
                          delMessages.add(int(msgIndex))
                      msgIndex, msgStatus, number, msgTime = cmglMatch.groups()
                      msgLines = []
                  else:
                      if line != 'OK':
                          msgLines.append(line)
              if msgIndex != None and len(msgLines) > 0:
                  msgText = '\n'.join(msgLines)
                  msgLines = []
                  messages.append(ReceivedSms(self, Sms.TEXT_MODE_STATUS_MAP[msgStatus], number, parseTextModeTimeStr(msgTime), msgText))
                  delMessages.add(int(msgIndex))
          else:
              cmglRegex = re.compile(r'^\+CMGL:\s*(\d+),\s*(\d+),.*$')
              readPdu = False
              result = self.write('AT+CMGL={0}'.format(status))
              for line in result:
                  if not readPdu:
                      cmglMatch = cmglRegex.match(line)
                      if cmglMatch:
                          msgIndex = int(cmglMatch.group(1))
                          msgStat = int(cmglMatch.group(2))
                          readPdu = True
                  else:
                      try:
                          smsDict = decodeSmsPdu(line)
                      except EncodingError:
                          self.log.debug('Discarding line from +CMGL response: %s', line)
                      else:
                          if smsDict['type'] == 'SMS-DELIVER':
                              sms = ReceivedSms(self, int(msgStat), smsDict['number'], smsDict['time'], smsDict['text'], smsDict['smsc'])
                          elif smsDict['type'] == 'SMS-STATUS-REPORT':
                              sms = StatusReport(self, int(msgStat), smsDict['reference'], smsDict['number'], smsDict['time'], smsDict['discharge'], smsDict['status'])
                          else:
                              raise CommandError('Invalid PDU type for readStoredSms(): {0}'.format(smsDict['type']))
                          messages.append(sms)
                          delMessages.add(msgIndex)
                          readPdu = False
          if delete:
              if status == Sms.STATUS_ALL:
                  # Delete all messages
                  self.deleteMultipleStoredSms()
              else:
                  for msgIndex in delMessages:
                      self.deleteStoredSms(msgIndex)
          return messages