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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
package main
import (
"bytes"
"fmt"
"os"
"io/ioutil"
"strconv"
"github.com/BurntSushi/toml"
)
type Config struct {
Mailacc MailAccount `toml:"MailAccount"`
Massmail MassMail `toml:"MassMail"`
}
type MailAccount struct {
Address string //`toml:"address"`
Name string //`toml:"name"`
Smtpurl string //`toml:"smtpurl"`
Port int //`toml:"port"`
Accountname string //`toml:"accountname"`
Accountpwd string //`toml:"accountpwd"`
}
type MassMail struct {
Listfile string //`toml:"listfile"`
Mailfile string //`toml:"mailfile"`
Bannerfile string //`toml:"bannerfile"`
Anrede []string //`toml:"anrede"`
Subject string //`toml:"subject"`
}
var config Config
func initConf() {
goodconf := false
for !goodconf {
if _, err := toml.DecodeFile("myconfig.toml", &config); err != nil {
fmt.Println(err)
makeNewTOML(false)
}else{
showConfig()
//fmt.Println("Loaded Config:\n",config)
if isSure("Is this Configuration Correct?") {
goodconf = true
}else{
if isSure("Enter new Configuration?"){
makeNewTOML(true)
}else{
fmt.Println("I Really Dont think I can Help You then...! Goodbye.")
os.Exit(0)
}
}
}
}
}
func makeNewTOML(gibts bool) {
if gibts {
fmt.Println("Editing Configuration File\nPress [Enter] to keep the Current setting")
}else{
fmt.Println("Making new Configuration File")
arr := []string{"", "", ""}
ma0 := MailAccount{"","","",0,"",""}
mm0 := MassMail{"","","",arr,""}
config = Config{ma0,mm0}
}
fmt.Println("Enter properties of the Send-account\n")
email := getNewInput("Email Account to send from: ",config.Mailacc.Address)
mailname := getNewInput("Name for this Account: ",config.Mailacc.Name)
smtpurl := getNewInput("URL of the SMTP server: ",config.Mailacc.Smtpurl)
port := 0
var err error
if gibts {
fmt.Println("Current:",config.Mailacc.Port)
}
for{
strport := getInput("Port of the SMTP Server: ")
port,err = strconv.Atoi(strport)
if err != nil {
fmt.Println(" Please insert a valid Port number!!!")
}else {break}
}
logname := getNewInput("Login name of the Account: ",config.Mailacc.Accountname)
logpwd := Encrypt(getInput("Password of the Account: "))
ma := MailAccount{email,mailname,smtpurl,port,logname,logpwd}
fmt.Println("\nEnter properties of the Mass Mail\n")
listfile := getNewInput("Which .csv file should be used?: ",config.Massmail.Listfile)
mailfile := getNewInput("What .html template to use?: ",config.Massmail.Mailfile)
bannerfile := getNewInput("Name of the banner image: ",config.Massmail.Bannerfile)
subject := getNewInput("Subject of the Mass Mail: ",config.Massmail.Subject)
if gibts {
fmt.Println("Current Salutations:",config.Massmail.Anrede)
}
anredemale := getInput("Salutation for a Male recipient: ")
anredeneut := getInput("Salutation for a unknown recipient: ")
anredefemale := getInput("Salutation for a Female recipient: ")
strarr := []string{anredemale, anredeneut, anredefemale}
mm := MassMail{listfile, mailfile, bannerfile, strarr, subject}
conf := Config{ma,mm}
buf := new(bytes.Buffer)
err = toml.NewEncoder(buf).Encode(conf)
if err != nil {
panic(err)
}else{
//fmt.Println("Conffile:\n",buf.String())
fmt.Println("Writing Configuration File")
err = ioutil.WriteFile("myconfig.toml", buf.Bytes(), 0644)
checkErr(err)
}
}
func showConfig() {
buf := new(bytes.Buffer)
err := toml.NewEncoder(buf).Encode(config)
if err != nil {
panic(err)
}else{
fmt.Println("Configuration:\n",buf.String())
}
}
|