From 52c9a13ca00e2876e9c2873ecc7e8a39cc959b60 Mon Sep 17 00:00:00 2001 From: Guillaume DOTT Date: Mon, 10 Feb 2014 11:05:07 +0100 Subject: [PATCH] Return the exception without raising it when getting messages --- lib/biju/hayes.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/biju/hayes.rb b/lib/biju/hayes.rb index cc6a61a..c5cc9e6 100644 --- a/lib/biju/hayes.rb +++ b/lib/biju/hayes.rb @@ -91,14 +91,27 @@ module Biju at_command('+CPIN', pin)[:status] if pin_status == 'SIM PIN' 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) sms = at_command('+CMGL', which) return [] unless sms.has_key?(:sms) 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