Email signing with signature
This commit is contained in:
@ -1,10 +1,13 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import "io/ioutil"
|
||||
import "net/smtp"
|
||||
|
||||
func send(e Email) {
|
||||
e.Body = signMessage(e.Body)
|
||||
e.Body = appendSignature(e.Body)
|
||||
|
||||
//e.Body = signMessage(e.Body)
|
||||
|
||||
message := fmt.Sprintf("From: %s\n", conf.MyEmail)
|
||||
for _, recipient := range e.Recipients {
|
||||
@ -29,3 +32,12 @@ func send(e Email) {
|
||||
}
|
||||
log.LogInfo("Email Sent")
|
||||
}
|
||||
|
||||
func appendSignature(body string) string {
|
||||
bytes, err := ioutil.ReadFile("default.sig")
|
||||
if err != nil {
|
||||
log.LogErrorType(err)
|
||||
}
|
||||
return signMessage(fmt.Sprintf("%s\n\n%s", body, string(bytes)))
|
||||
|
||||
}
|
||||
|
||||
75
main.go
75
main.go
@ -6,7 +6,6 @@ import (
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/rudi9719/loggy"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
@ -36,15 +35,75 @@ func main() {
|
||||
log.LogInfo(fmt.Sprintf("Bot started using account %s", k.Username))
|
||||
conf = loadConfig()
|
||||
setupCredentials()
|
||||
em := Email{
|
||||
Recipients: []string{"rudi@nmare.net"},
|
||||
Subject: "Test Email",
|
||||
Body: "Hello, world!",
|
||||
}
|
||||
send(em)
|
||||
time.Sleep(2 * time.Second)
|
||||
log.LogInfo("Starting keybase")
|
||||
k.Run(func(api keybase.ChatAPI) {
|
||||
handleMessage(api)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
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 {
|
||||
var c Config
|
||||
bytes, err := ioutil.ReadFile("conf.json")
|
||||
|
||||
Reference in New Issue
Block a user