Skip to content

Commit

Permalink
Reorder loops
Browse files Browse the repository at this point in the history
  • Loading branch information
mp4096 committed Dec 24, 2017
1 parent 662f300 commit ca53ce1
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,36 @@ func mergeMaps(primary map[string]string, secondary map[string]string) {
}

func ProcessFile(templateFilename string, send bool, c *Config) error {
// FIXME: Disentangle this mess

data, err := ioutil.ReadFile(templateFilename)
if err != nil {
return err
}
data_s := string(data)

ap := new(authPair)
if send {
fmt.Printf("Please enter your credentials for \"%s\"\n", c.EmailServer.Hostname)
ap := new(authPair)
ap.prompt()
}

for recipient, context := range c.Recipients {
mergeMaps(context, c.GlobalContext)
for recipient, localContext := range c.Recipients {
// Add global context to local context
mergeMaps(localContext, c.GlobalContext)

email := NewEmail().AddAuthor(&c.Author).AddRecipient(recipient).AddContent(data_s).Build(context)
email := NewEmail().AddAuthor(&c.Author).AddRecipient(recipient).AddContent(data_s).Build(localContext)

if send {
fmt.Printf("Will send to %v\n", email.GetRecipients())
if err := email.Send(&c.EmailServer, ap); err != nil {
return err
}
}
} else {
for recipient, context := range c.Recipients {
mergeMaps(context, c.GlobalContext)

email := NewEmail().AddAuthor(&c.Author).AddRecipient(recipient).AddContent(data_s).Build(context)

} else {
fmt.Printf("Send flag not set: opening preview in \"%s\"\n", c.Author.Browser)
if err := email.OpenInBrowser(c.Author.Browser); err != nil {
return err
}
}
}

return nil
}

0 comments on commit ca53ce1

Please sign in to comment.