|
|
@ -6,7 +6,6 @@ import ( |
|
|
|
"io/ioutil" |
|
|
|
"io/ioutil" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
"syscall" |
|
|
|
"syscall" |
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/rudi9719/loggy" |
|
|
|
"github.com/rudi9719/loggy" |
|
|
|
"golang.org/x/crypto/ssh/terminal" |
|
|
|
"golang.org/x/crypto/ssh/terminal" |
|
|
@ -36,15 +35,75 @@ func main() { |
|
|
|
log.LogInfo(fmt.Sprintf("Bot started using account %s", k.Username)) |
|
|
|
log.LogInfo(fmt.Sprintf("Bot started using account %s", k.Username)) |
|
|
|
conf = loadConfig() |
|
|
|
conf = loadConfig() |
|
|
|
setupCredentials() |
|
|
|
setupCredentials() |
|
|
|
em := Email{ |
|
|
|
log.LogInfo("Starting keybase") |
|
|
|
Recipients: []string{"rudi@nmare.net"}, |
|
|
|
k.Run(func(api keybase.ChatAPI) { |
|
|
|
Subject: "Test Email", |
|
|
|
handleMessage(api) |
|
|
|
Body: "Hello, world!", |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
send(em) |
|
|
|
|
|
|
|
time.Sleep(2 * time.Second) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func handleMessage(api keybase.ChatAPI) { |
|
|
|
|
|
|
|
if api.Msg.Channel.Name != k.Username { |
|
|
|
|
|
|
|
log.LogInfo("Wrong channel detected.") |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if api.Msg.Sender.Username != k.Username { |
|
|
|
|
|
|
|
log.LogInfo("Wrong username detected.") |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if api.Msg.Content.Type != "text" { |
|
|
|
|
|
|
|
log.LogInfo("Wrong message type detected.") |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
parts := strings.Split(api.Msg.Content.Text.Body, " ") |
|
|
|
|
|
|
|
if parts[0] != "!email" { |
|
|
|
|
|
|
|
log.LogInfo("Wrong command detected") |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if len(parts) < 4 { |
|
|
|
|
|
|
|
log.LogInfo("Wrong length of parts detected.") |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var e Email |
|
|
|
|
|
|
|
partCounter := 1 |
|
|
|
|
|
|
|
for _, subj := range parts[1:] { |
|
|
|
|
|
|
|
if strings.Contains(subj, "@") { |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
partCounter++ |
|
|
|
|
|
|
|
e.Subject += fmt.Sprintf("%s ", subj) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for _, to := range parts { |
|
|
|
|
|
|
|
if strings.HasPrefix(to, "to:") { |
|
|
|
|
|
|
|
if strings.Contains(to, "@") { |
|
|
|
|
|
|
|
e.Recipients = append(e.Recipients, strings.Replace(to, "to:", "", -1)) |
|
|
|
|
|
|
|
partCounter++ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for _, cc := range parts { |
|
|
|
|
|
|
|
if strings.HasPrefix(cc, "cc:") { |
|
|
|
|
|
|
|
if strings.Contains(cc, "@") { |
|
|
|
|
|
|
|
e.Cc = append(e.Cc, strings.Replace(cc, "cc:", "", -1)) |
|
|
|
|
|
|
|
partCounter++ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for _, bcc := range parts { |
|
|
|
|
|
|
|
if strings.HasPrefix(bcc, "bcc:") { |
|
|
|
|
|
|
|
if strings.Contains(bcc, "@") { |
|
|
|
|
|
|
|
e.Bcc = append(e.Bcc, strings.Replace(bcc, "bcc:", "", -1)) |
|
|
|
|
|
|
|
partCounter++ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for _, word := range parts[partCounter:] { |
|
|
|
|
|
|
|
e.Body += fmt.Sprintf("%s ", word) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
log.LogDebug(fmt.Sprintf("%+v", e)) |
|
|
|
|
|
|
|
go send(e) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func loadConfig() Config { |
|
|
|
func loadConfig() Config { |
|
|
|
var c Config |
|
|
|
var c Config |
|
|
|
bytes, err := ioutil.ReadFile("conf.json") |
|
|
|
bytes, err := ioutil.ReadFile("conf.json") |
|
|
|