|
@@ -2,6 +2,7 @@ package main
|
|
|
|
|
|
import (
|
|
|
"bufio"
|
|
|
+ "errors"
|
|
|
"flag"
|
|
|
"fmt"
|
|
|
"os"
|
|
@@ -12,6 +13,27 @@ import (
|
|
|
var noVersion = "dev"
|
|
|
var version string
|
|
|
|
|
|
+type attachmentList []string
|
|
|
+
|
|
|
+func (a *attachmentList) String() string {
|
|
|
+ var str string
|
|
|
+ for _, attachment := range *a {
|
|
|
+ str += fmt.Sprintf("%s\n", attachment)
|
|
|
+ }
|
|
|
+ return str
|
|
|
+}
|
|
|
+
|
|
|
+func (a *attachmentList) Set(file string) error {
|
|
|
+ if _, err := os.Lstat(file); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if file == "" {
|
|
|
+ return errors.New("no file provided")
|
|
|
+ }
|
|
|
+ *a = append(*a, file)
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
func readFromConsole(result chan string) {
|
|
|
var text, line string
|
|
|
var err error
|
|
@@ -73,6 +95,7 @@ func main() {
|
|
|
var encryption, dbg, versionFlag, interactive bool
|
|
|
var serverPortAux int
|
|
|
var serverPort int64
|
|
|
+ var attachments attachmentList
|
|
|
|
|
|
flag.BoolVar(&versionFlag, "version", false, "Prints the version and exits")
|
|
|
flag.StringVar(&configPath, "conf", "", "Path to a config file (defaults to /etc/sendmail.toml)")
|
|
@@ -89,6 +112,7 @@ func main() {
|
|
|
flag.StringVar(&bcc, "bcc", "", "Comma-separated list of blind carbon-copy recipient(s)")
|
|
|
flag.StringVar(&from, "from", "", "Sender of the mail (used as default account user to log in on the SMTP server)")
|
|
|
flag.StringVar(&subject, "sub", "", "Subject of the mail")
|
|
|
+ flag.Var(&attachments, "attach", "Attachment to the mail (may be repeated)")
|
|
|
flag.Parse()
|
|
|
|
|
|
LogInit(dbg)
|
|
@@ -136,7 +160,8 @@ parameters:
|
|
|
password: %s
|
|
|
to: %s
|
|
|
from: %s
|
|
|
- subject: %s`,
|
|
|
+ subject: %s
|
|
|
+ attachments: %s`,
|
|
|
configPath,
|
|
|
dbg,
|
|
|
serverAddress,
|
|
@@ -147,6 +172,7 @@ parameters:
|
|
|
to,
|
|
|
from,
|
|
|
subject,
|
|
|
+ attachments,
|
|
|
)
|
|
|
|
|
|
config := initializeConfig(configPath, section)
|
|
@@ -161,6 +187,7 @@ parameters:
|
|
|
config.Merge("Bcc", toList(bcc))
|
|
|
config.Merge("Subject", subject)
|
|
|
config.Merge("Text", text)
|
|
|
+ config.Merge("Attachments", attachments)
|
|
|
|
|
|
Debug.F("---\nPre-validation config\n%s", config)
|
|
|
err = config.Validate()
|