1 |
torben |
143 |
|
2 |
|
|
#include "SmsHelper.h" |
3 |
|
|
|
4 |
|
|
#include <string> |
5 |
|
|
#include <vector> |
6 |
|
|
|
7 |
|
|
|
8 |
|
|
#include "Sms.h" |
9 |
torben |
158 |
#include "Util.h" |
10 |
torben |
143 |
#include "SmsPdu.h" |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
namespace SmsHelper |
15 |
|
|
{ |
16 |
|
|
|
17 |
|
|
SMS FromRawString(const std::string& input) |
18 |
|
|
{ |
19 |
|
|
std::string smsline = input.substr(7, input.length() -7); //strip "+CMGL: " |
20 |
|
|
|
21 |
|
|
std::vector<std::string> lines = Util::str_split(smsline, "\r\n"); |
22 |
|
|
std::vector<std::string> fields = Util::str_split(lines[0],","); |
23 |
|
|
|
24 |
|
|
std::string body; |
25 |
|
|
for (unsigned i=1; i<lines.size(); ++i) |
26 |
|
|
{ |
27 |
|
|
std::string body_line = lines[i]; |
28 |
|
|
|
29 |
|
|
|
30 |
|
|
if (body_line != "") |
31 |
|
|
{ |
32 |
|
|
if (body.length() > 0) |
33 |
|
|
body += "\r\n"; |
34 |
|
|
body += body_line; |
35 |
|
|
} |
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
body = Util::str_trim(body); |
39 |
|
|
|
40 |
|
|
SMS sms; |
41 |
|
|
|
42 |
|
|
sms.SetIndex( fields[0] ); |
43 |
|
|
|
44 |
|
|
|
45 |
|
|
std::string sender = fields[2]; |
46 |
|
|
sender = Util::str_replace(sender, "\""); |
47 |
|
|
sms.SetSender(sender); |
48 |
|
|
|
49 |
|
|
std::string timestamp = fields[4] + std::string(",") + fields[5]; |
50 |
|
|
timestamp = Util::str_replace(timestamp, "\""); |
51 |
|
|
sms.SetTimestamp(timestamp); |
52 |
|
|
|
53 |
|
|
sms.SetMessage( body ); |
54 |
|
|
|
55 |
|
|
return sms; |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
SMS FromPduString(const std::string& input) |
59 |
|
|
{ |
60 |
|
|
std::string smsline = input.substr(7, input.length() -7); //strip "+CMGL: " |
61 |
|
|
|
62 |
|
|
std::vector<std::string> lines = Util::str_split(smsline, "\r\n"); |
63 |
|
|
std::vector<std::string> fields = Util::str_split(lines[0],","); |
64 |
|
|
|
65 |
|
|
SMS sms = SmsPdu::ParseSmsPdu(lines[1]); |
66 |
|
|
|
67 |
|
|
sms.SetIndex(fields[0]); |
68 |
|
|
|
69 |
|
|
return sms; |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
} |