commit 6b583f0cbc93bbb327dab5cbbc0a379e1059b76d
parent 18c45ac3671183245f8efac9b5806afe7d9cbce1
Author: Peter Kosyh <p.kosyh@gmail.com>
Date: Fri, 5 Feb 2021 09:40:13 +0000
Merge branch 'master' of https://github.com/gl00my/ii-go
Diffstat:
3 files changed, 42 insertions(+), 23 deletions(-)
diff --git a/README.md b/README.md
@@ -86,6 +86,9 @@ slice is the start:limit. For example:
Options are:
```
+-from <user> -- from user
+-to <user> -- to user
+-t -- only topics (w/o repto)
-db <database> -- db by default (db.idx - genetated index)
-v -- show message text, not only MsgId
```
@@ -108,10 +111,12 @@ Where options are:
-db <database> -- db by default (db.idx - genetated index)
-v -- show message text, not only MsgId
```
-To show messages adressed to selected user, try:
+You can sort ids by date with sort command.
+
+To show last 5 messages adressed to selected user, try:
```
-./ii-tool [options] cc <user> [slice]
+./ii-tool [options] -to <user> select "" | ./ii-tool sort | tail -n5 | ./ii-tool -v sort
```
For example:
diff --git a/ii-tool/main.go b/ii-tool/main.go
@@ -8,6 +8,7 @@ import (
"io"
"io/ioutil"
"os"
+ "sort"
"strings"
)
@@ -60,7 +61,8 @@ func main() {
users_opt := flag.String("u", "points.txt", "Users database")
conns_opt := flag.Int("j", 6, "Maximum parallel jobs")
topics_opt := flag.Bool("t", false, "Select topics only")
-
+ from_opt := flag.String("from", "", "Select from")
+ to_opt := flag.String("to", "", "Select to")
flag.Parse()
ii.MaxConnections = *conns_opt
if *verbose_opt {
@@ -77,8 +79,7 @@ Commands:
fetch <url> [echofile|-] - fetch
store <bundle|-> - import bundle to database
get <msgid> - show message from database
- select <echo> [[start]:lim] - get slice from echo
- cc <name> [[start]:lim] - get msgs to name
+ select [[start]:lim] - get slice from echo
index - recreate index
blacklist <msgid> - blacklist msg
useradd <name> <e-mail> <password> - adduser
@@ -87,6 +88,9 @@ Options:
-lim=<lim> - fetch lim last messages
-u=<path> - points account file
-t - topics only (select,get)
+ -from=<user> - select from
+ -to=<user> - select to
+ -echo=echo - select echo
`, os.Args[0])
os.Exit(1)
}
@@ -358,13 +362,23 @@ Options:
if m != nil {
fmt.Println(m)
}
- case "cc":
+ case "select":
if len(args) < 2 {
fmt.Printf("No echo supplied\n")
os.Exit(1)
}
db := open_db(*db_opt)
- req := ii.Query{To: args[1]}
+ req := ii.Query{ Echo: args[1] }
+ if *from_opt != "" {
+ req.From = *from_opt
+ }
+ if *to_opt != "" {
+ req.To = *to_opt
+ }
+
+ if *topics_opt {
+ req.Repto = "!"
+ }
if len(args) > 2 {
fmt.Sscanf(args[2], "%d:%d", &req.Start, &req.Lim)
}
@@ -376,25 +390,25 @@ Options:
fmt.Println(v)
}
}
- case "select":
- if len(args) < 2 {
- fmt.Printf("No echo supplied\n")
- os.Exit(1)
- }
+ case "sort":
db := open_db(*db_opt)
- req := ii.Query{Echo: args[1]}
- if *topics_opt {
- req.Repto = "!"
- }
- if len(args) > 2 {
- fmt.Sscanf(args[2], "%d:%d", &req.Start, &req.Lim)
+ db.LoadIndex()
+ scanner := bufio.NewScanner(os.Stdin)
+ var mm []*ii.Msg
+ for scanner.Scan() {
+ mi := db.LookupFast(scanner.Text(), false)
+ if mi != nil {
+ mm = append(mm, db.Get(mi.Id))
+ }
}
- resp := db.SelectIDS(req)
- for _, v := range resp {
+ sort.SliceStable(mm, func(i, j int) bool {
+ return mm[i].Date < mm[j].Date
+ })
+ for _, v := range mm {
if *verbose_opt {
- fmt.Println(db.Get(v))
- } else {
fmt.Println(v)
+ } else {
+ fmt.Println(v.MsgId)
}
}
case "index":
diff --git a/ii/db.go b/ii/db.go
@@ -775,7 +775,7 @@ func (db *DB) _Store(m *Msg, edit bool) error {
}
if repto != "" {
if _, ok := db.Idx.Hash[repto]; !ok { // repto is absent, we should avoid loops!
- return errors.New("Wrong repto")
+ return errors.New("Wrong repto: " + repto)
}
}
fi, err := os.Stat(db.BundlePath())