/// <summary> /// Returns List Messages. /// </summary> /// <param name="status">Select status of the message</param> public List<BaseResult<SMSReadResult>> Read(SMSStatus status) { List<BaseResult<SMSReadResult>> listReads = new List<BaseResult<SMSReadResult>>(); System.Diagnostics.Stopwatch sp = new System.Diagnostics.Stopwatch(); BaseResult<GenericTypeResult<PhoneActivityStatus>> activityStatus = Connection.GetActivityStatus(); if (activityStatus.Response.Result != PhoneActivityStatus.Ready) { return listReads; } SetMessageFormat(Connection.PDUMode); string readValue = "ALL"; string response; Regex regexReadPattern; if (Connection.PDUMode) { regexReadPattern = new Regex("\\+CMGL: (\\d+),(\\d+),(?:\"(.*[A-Z0-9-_ ].*)\")?,(\\d+)\\r(\\w+)"); switch (status) { case SMSStatus.ReceivedUnreadMessage: readValue = "0"; break; case SMSStatus.ReceivedReadMessage: readValue = "1"; break; case SMSStatus.StoredUnsentMessage: readValue = "2"; break; case SMSStatus.StoredSentMessage: readValue = "3"; break; case SMSStatus.AllMessages: readValue = "4"; break; } } else { regexReadPattern = new Regex(@"\+CMGL: (\d+)," + (char)34 + "(.*[A-Z0-9-_ ].*)" + (char)34 + "," + (char)34 + "(.*[0-9-_ +].*)" + (char)34 + ",(?:\"(.*[A-Z0-9-_ ].*)\")?," + @"(.*[0-9-_ +/:].*)" + "\r([ 0-9A-Za-z#$%=@!{},`~&*()'<>?.:;_|^/+\t\r\n\\[\\]\"-]([^(CMGL)]+)*)"); switch (status) { case SMSStatus.ReceivedUnreadMessage: readValue = "\"REC UNREAD\""; break; case SMSStatus.ReceivedReadMessage: readValue = "\"REC READ\""; break; case SMSStatus.StoredUnsentMessage: readValue = "\"STO UNSENT\""; break; case SMSStatus.StoredSentMessage: readValue = "\"STO SENT\""; break; case SMSStatus.AllMessages: readValue = "\"ALL\""; break; } } Connection.Connector.DiscardBuffer(); sp.Start(); response = Connection.Connector.Execute(Command.Set(Commands.CMGL, readValue)); sp.Stop(); int index = 1; BaseResult<SMSReadResult> smp; for (Match match = regexReadPattern.Match(response); match.Success; match = match.NextMatch()) { IncomingSmsPdu sms = IncomingSmsPdu.Decode(match.Groups[5].Value, true); if (!string.IsNullOrEmpty(match.Groups[1].Value)) { index = int.Parse(match.Groups[1].Value); } SMSReadResult read = new SMSReadResult(index, ((GSMCommunication.PDUDecoder.SmsDeliverPdu)(sms)).OriginatingAddress, ((GSMCommunication.PDUDecoder.SmsDeliverPdu)(sms)).UserDataText, ((GSMCommunication.PDUDecoder.SmsDeliverPdu)(sms)).SCTimestamp.ToDateTime(), match.Groups[2].Value, Connection.Operator); smp = new BaseResult<SMSReadResult>(); smp.Response = read; smp.ExecutionTime = sp.Elapsed; listReads.Add(smp); } return listReads; }
/// <summary> /// Returns List Messages. /// </summary> /// <param name="status">Select status of the message</param> public List <BaseResult <SMSReadResult> > Read(SMSStatus status) { List <BaseResult <SMSReadResult> > listReads = new List <BaseResult <SMSReadResult> >(); System.Diagnostics.Stopwatch sp = new System.Diagnostics.Stopwatch(); BaseResult <GenericTypeResult <PhoneActivityStatus> > activityStatus = Connection.GetActivityStatus(); if (activityStatus.Response.Result != PhoneActivityStatus.Ready) { return(listReads); } SetMessageFormat(Connection.PDUMode); string readValue = "ALL"; string response; Regex regexReadPattern; if (Connection.PDUMode) { regexReadPattern = new Regex("\\+CMGL: (\\d+),(\\d+),(?:\"(.*[A-Z0-9-_ ].*)\")?,(\\d+)\\r(\\w+)"); switch (status) { case SMSStatus.ReceivedUnreadMessage: readValue = "0"; break; case SMSStatus.ReceivedReadMessage: readValue = "1"; break; case SMSStatus.StoredUnsentMessage: readValue = "2"; break; case SMSStatus.StoredSentMessage: readValue = "3"; break; case SMSStatus.AllMessages: readValue = "4"; break; } } else { regexReadPattern = new Regex(@"\+CMGL: (\d+)," + (char)34 + "(.*[A-Z0-9-_ ].*)" + (char)34 + "," + (char)34 + "(.*[0-9-_ +].*)" + (char)34 + ",(?:\"(.*[A-Z0-9-_ ].*)\")?," + @"(.*[0-9-_ +/:].*)" + "\r([ 0-9A-Za-z#$%=@!{},`~&*()'<>?.:;_|^/+\t\r\n\\[\\]\"-]([^(CMGL)]+)*)"); switch (status) { case SMSStatus.ReceivedUnreadMessage: readValue = "\"REC UNREAD\""; break; case SMSStatus.ReceivedReadMessage: readValue = "\"REC READ\""; break; case SMSStatus.StoredUnsentMessage: readValue = "\"STO UNSENT\""; break; case SMSStatus.StoredSentMessage: readValue = "\"STO SENT\""; break; case SMSStatus.AllMessages: readValue = "\"ALL\""; break; } } Connection.Connector.DiscardBuffer(); sp.Start(); response = Connection.Connector.Execute(Command.Set(Commands.CMGL, readValue)); sp.Stop(); int index = 1; BaseResult <SMSReadResult> smp; for (Match match = regexReadPattern.Match(response); match.Success; match = match.NextMatch()) { IncomingSmsPdu sms = IncomingSmsPdu.Decode(match.Groups[5].Value, true); if (!string.IsNullOrEmpty(match.Groups[1].Value)) { index = int.Parse(match.Groups[1].Value); } SMSReadResult read = new SMSReadResult(index, ((GSMCommunication.PDUDecoder.SmsDeliverPdu)(sms)).OriginatingAddress, ((GSMCommunication.PDUDecoder.SmsDeliverPdu)(sms)).UserDataText, ((GSMCommunication.PDUDecoder.SmsDeliverPdu)(sms)).SCTimestamp.ToDateTime(), match.Groups[2].Value, Connection.Operator); smp = new BaseResult <SMSReadResult>(); smp.Response = read; smp.ExecutionTime = sp.Elapsed; listReads.Add(smp); } return(listReads); }