forked from 4ov/go-termux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sms-list.go
58 lines (53 loc) · 1.22 KB
/
sms-list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package termux
import (
"encoding/json"
"fmt"
)
const (
SmsTypeAll = iota
SmsTypeInbox
SmsTypeSent
SmsTypeDrafts
SmsTypeOutbox
)
type Sms struct {
ThreadId int `json:"threadid"`
Type string `json:"type"`
Read bool `json:"read"`
Number string `json:"number"`
Recived string `json:"received"`
Body string `json:"body"`
Id int `json:"_id"`
}
type SmsOptions struct {
// offset in sms list (default: 10)
Limit int `arg:"-l"`
// offset in sms list (default: 0)
Offset int `arg:"-o"`
// the type of messages to list (default: all):
// all|inbox|sent|draft|outbox
Type int `arg:"-t"`
// (unique item per conversation)
ConversationList bool `arg:"-c"`
// the number for locate messages
From string `arg:"-f"`
// (obsolete) show phone numbers
ShowNumbers bool `arg:"-n"`
// (obsolete) show dates when messages were created
ShowDates bool `arg:"-d"`
}
func SmsList(options SmsOptions) ([]Sms, error) {
args := ReadyArgs(options)
output, err := CallCommand("termux-sms-list", args...)
if err != nil {
fmt.Println(err)
return ([]Sms{}), err
}
result := []Sms{}
err = json.Unmarshal(output, &result)
if err != nil {
fmt.Println(err)
return ([]Sms{}), err
}
return result, nil
}