Return the exception without raising it when getting messages

develop
Guillaume DOTT 2014-02-10 11:05:07 +01:00
parent e34a881ab7
commit 52c9a13ca0
1 changed files with 15 additions and 2 deletions

View File

@ -91,14 +91,27 @@ module Biju
at_command('+CPIN', pin)[:status] if pin_status == 'SIM PIN' at_command('+CPIN', pin)[:status] if pin_status == 'SIM PIN'
end end
def messages(which = :all) def messages!(which = :all)
messages(which, true)
end
def messages(which = :all, exceptions = false)
which = MESSAGE_STATUS[which][text_mode? ? 1 : 0] if which.is_a?(Symbol) which = MESSAGE_STATUS[which][text_mode? ? 1 : 0] if which.is_a?(Symbol)
sms = at_command('+CMGL', which) sms = at_command('+CMGL', which)
return [] unless sms.has_key?(:sms) return [] unless sms.has_key?(:sms)
sms[:sms].map do |msg| sms[:sms].map do |msg|
Biju::Sms.from_pdu(msg[:message].chomp, msg[:infos][0]) begin
Biju::Sms.from_pdu(msg[:message].chomp, msg[:infos][0])
rescue Biju::PDU::Errors::PDUError => e
malformed = Biju::PDU::Errors::MalformedSms.new(msg[:message].chomp, e)
if exceptions
raise malformed
else
malformed
end
end
end end
end end