Cleaning up
This commit is contained in:
@ -3,12 +3,11 @@ package main
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
import "io/ioutil"
|
import "io/ioutil"
|
||||||
import "net/smtp"
|
import "net/smtp"
|
||||||
|
import "samhofi.us/x/keybase"
|
||||||
|
|
||||||
func send(e Email) {
|
func send(e Email, api keybase.ChatAPI) {
|
||||||
e.Body = appendSignature(e.Body)
|
e.Body = appendSignature(e.Body)
|
||||||
|
|
||||||
//e.Body = signMessage(e.Body)
|
|
||||||
|
|
||||||
message := fmt.Sprintf("From: %s\n", conf.MyEmail)
|
message := fmt.Sprintf("From: %s\n", conf.MyEmail)
|
||||||
for _, recipient := range e.Recipients {
|
for _, recipient := range e.Recipients {
|
||||||
message += fmt.Sprintf("To: %s\n", recipient)
|
message += fmt.Sprintf("To: %s\n", recipient)
|
||||||
@ -24,12 +23,15 @@ func send(e Email) {
|
|||||||
log.LogInfo("Message created")
|
log.LogInfo("Message created")
|
||||||
log.LogDebug(message)
|
log.LogDebug(message)
|
||||||
log.LogInfo("Sending message")
|
log.LogInfo("Sending message")
|
||||||
|
chat.React(api.Msg.ID, ":mailbox_with_no_mail:")
|
||||||
err := smtp.SendMail(conf.SmtpServer,
|
err := smtp.SendMail(conf.SmtpServer,
|
||||||
smtp.PlainAuth("", conf.MyEmail, conf.EmailPass, conf.AuthServer),
|
smtp.PlainAuth("", conf.MyEmail, conf.EmailPass, conf.AuthServer),
|
||||||
conf.MyEmail, e.Recipients, []byte(message))
|
conf.MyEmail, e.Recipients, []byte(message))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.LogErrorType(err)
|
log.LogErrorType(err)
|
||||||
}
|
}
|
||||||
|
chat.React(api.Msg.ID, ":mailbox_with_no_mail:")
|
||||||
|
chat.React(api.Msg.ID, ":mailbox_with_mail:")
|
||||||
log.LogInfo("Email Sent")
|
log.LogInfo("Email Sent")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,6 +40,6 @@ func appendSignature(body string) string {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.LogErrorType(err)
|
log.LogErrorType(err)
|
||||||
}
|
}
|
||||||
return signMessage(fmt.Sprintf("%s\n\n%s", body, string(bytes)))
|
return signMessage(fmt.Sprintf("%s\n\n%s\n", body, string(bytes)))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
43
main.go
43
main.go
@ -16,14 +16,20 @@ var (
|
|||||||
k = keybase.NewKeybase()
|
k = keybase.NewKeybase()
|
||||||
|
|
||||||
logOpts = loggy.LogOpts{
|
logOpts = loggy.LogOpts{
|
||||||
//OutFile: "Keybase-Email.log",
|
OutFile: "Keybase-Email.log",
|
||||||
//KBTeam: "nightmarehaus.logs",
|
KBTeam: "nightmarehaus.logs",
|
||||||
//KBChann: "general",
|
KBChann: "general",
|
||||||
//ProgName: "KB-Email",
|
ProgName: "KB-Email",
|
||||||
Level: 5,
|
Level: 4,
|
||||||
UseStdout: true,
|
UseStdout: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chann = keybase.Channel{
|
||||||
|
Name: "rudi9719",
|
||||||
|
MembersType: keybase.USER,
|
||||||
|
}
|
||||||
|
chat keybase.Chat
|
||||||
|
|
||||||
log = loggy.NewLogger(logOpts)
|
log = loggy.NewLogger(logOpts)
|
||||||
conf = Config{}
|
conf = Config{}
|
||||||
)
|
)
|
||||||
@ -36,6 +42,7 @@ func main() {
|
|||||||
conf = loadConfig()
|
conf = loadConfig()
|
||||||
setupCredentials()
|
setupCredentials()
|
||||||
log.LogInfo("Starting keybase")
|
log.LogInfo("Starting keybase")
|
||||||
|
chat = k.NewChat(chann)
|
||||||
k.Run(func(api keybase.ChatAPI) {
|
k.Run(func(api keybase.ChatAPI) {
|
||||||
handleMessage(api)
|
handleMessage(api)
|
||||||
})
|
})
|
||||||
@ -43,27 +50,29 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleMessage(api keybase.ChatAPI) {
|
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" {
|
if api.Msg.Content.Type != "text" {
|
||||||
log.LogInfo("Wrong message type detected.")
|
log.LogDebug("Wrong message type detected.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
parts := strings.Split(api.Msg.Content.Text.Body, " ")
|
parts := strings.Split(api.Msg.Content.Text.Body, " ")
|
||||||
if parts[0] != "!email" {
|
if parts[0] != "!email" {
|
||||||
log.LogInfo("Wrong command detected")
|
log.LogDebug("Wrong command detected")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if api.Msg.Sender.Username != k.Username {
|
||||||
|
log.LogDebug("Wrong username detected.")
|
||||||
|
chat = k.NewChat(api.Msg.Channel)
|
||||||
|
chat.Reply(api.Msg.ID, "[EMBot] No thanks!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if len(parts) < 4 {
|
if len(parts) < 4 {
|
||||||
log.LogInfo("Wrong length of parts detected.")
|
log.LogDebug("Wrong length of parts detected.")
|
||||||
|
chat.Send("[KB-Email] Not enough components to send email.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
chann = api.Msg.Channel
|
||||||
|
chat = k.NewChat(chann)
|
||||||
var e Email
|
var e Email
|
||||||
partCounter := 1
|
partCounter := 1
|
||||||
for _, subj := range parts[1:] {
|
for _, subj := range parts[1:] {
|
||||||
@ -101,7 +110,7 @@ func handleMessage(api keybase.ChatAPI) {
|
|||||||
e.Body += fmt.Sprintf("%s ", word)
|
e.Body += fmt.Sprintf("%s ", word)
|
||||||
}
|
}
|
||||||
log.LogDebug(fmt.Sprintf("%+v", e))
|
log.LogDebug(fmt.Sprintf("%+v", e))
|
||||||
go send(e)
|
go send(e, api)
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadConfig() Config {
|
func loadConfig() Config {
|
||||||
|
|||||||
11
pgpHelper.go
11
pgpHelper.go
@ -12,18 +12,18 @@ import (
|
|||||||
func getPrivateKey() *openpgp.Entity {
|
func getPrivateKey() *openpgp.Entity {
|
||||||
pp := conf.KeyPass
|
pp := conf.KeyPass
|
||||||
ppb := []byte(pp)
|
ppb := []byte(pp)
|
||||||
log.LogInfo("Getting entityList")
|
log.LogDebug("Getting entityList")
|
||||||
entitylist, err := openpgp.ReadArmoredKeyRing(strings.NewReader(conf.PrivateKey))
|
entitylist, err := openpgp.ReadArmoredKeyRing(strings.NewReader(conf.PrivateKey))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.LogErrorType(err)
|
log.LogErrorType(err)
|
||||||
}
|
}
|
||||||
log.LogInfo(fmt.Sprintf("Getting entity 0 ```%+v```", entitylist))
|
log.LogDebug(fmt.Sprintf("Getting entity 0 ```%+v```", entitylist))
|
||||||
entity := entitylist[0]
|
entity := entitylist[0]
|
||||||
log.LogInfo("if PrivateKey != nil")
|
log.LogDebug("if PrivateKey != nil")
|
||||||
if entity.PrivateKey != nil && entity.PrivateKey.Encrypted {
|
if entity.PrivateKey != nil && entity.PrivateKey.Encrypted {
|
||||||
err := entity.PrivateKey.Decrypt(ppb)
|
err := entity.PrivateKey.Decrypt(ppb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Failed to decrypt key")
|
log.LogErrorType(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ func getPrivateKey() *openpgp.Entity {
|
|||||||
if subkey.PrivateKey != nil && subkey.PrivateKey.Encrypted {
|
if subkey.PrivateKey != nil && subkey.PrivateKey.Encrypted {
|
||||||
err := subkey.PrivateKey.Decrypt(ppb)
|
err := subkey.PrivateKey.Decrypt(ppb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Failed to decrypt subkey")
|
log.LogErrorType(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -42,7 +42,6 @@ func signMessage(m string) string {
|
|||||||
pk := getPrivateKey()
|
pk := getPrivateKey()
|
||||||
out := new(bytes.Buffer)
|
out := new(bytes.Buffer)
|
||||||
in, err := clearsign.Encode(out, pk.PrivateKey, nil)
|
in, err := clearsign.Encode(out, pk.PrivateKey, nil)
|
||||||
//in, err := openpgp.Sign(out, pk, nil, nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.LogErrorType(err)
|
log.LogErrorType(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user