mirror of
				https://github.com/SSLMate/certspotter.git
				synced 2025-07-03 10:47:17 +02:00 
			
		
		
		
	Simplify some code
This commit is contained in:
		
							parent
							
								
									f8040df68d
								
							
						
					
					
						commit
						5fae49a971
					
				| @ -201,16 +201,11 @@ func main() { | ||||
| 		Verbose:             flags.verbose, | ||||
| 		Script:              flags.script, | ||||
| 		ScriptDir:           defaultScriptDir(), | ||||
| 		SendmailPath:        "/usr/sbin/sendmail", | ||||
| 		Email:               flags.email, | ||||
| 		Stdout:              flags.stdout, | ||||
| 		HealthCheckInterval: flags.healthcheck, | ||||
| 	} | ||||
| 
 | ||||
| 	if envVar := os.Getenv("SENDMAIL_PATH"); envVar != "" { | ||||
| 		config.SendmailPath = envVar | ||||
| 	} | ||||
| 
 | ||||
| 	emailFileExists := false | ||||
| 	if emailRecipients, err := readEmailFile(defaultEmailFile()); err == nil { | ||||
| 		emailFileExists = true | ||||
|  | ||||
| @ -20,7 +20,6 @@ type Config struct { | ||||
| 	WatchList           WatchList | ||||
| 	Verbose             bool | ||||
| 	SaveCerts           bool | ||||
| 	SendmailPath        string | ||||
| 	Script              string | ||||
| 	ScriptDir           string | ||||
| 	Email               []string | ||||
|  | ||||
| @ -36,7 +36,7 @@ func notify(ctx context.Context, config *Config, notif notification) error { | ||||
| 	} | ||||
| 
 | ||||
| 	if len(config.Email) > 0 { | ||||
| 		if err := sendEmail(ctx, config.SendmailPath, config.Email, notif); err != nil { | ||||
| 		if err := sendEmail(ctx, config.Email, notif); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	} | ||||
| @ -62,10 +62,15 @@ func writeToStdout(notif notification) { | ||||
| 	os.Stdout.WriteString(notif.Text() + "\n") | ||||
| } | ||||
| 
 | ||||
| func sendEmail(ctx context.Context, sendmailPath string, to []string, notif notification) error { | ||||
| func sendEmail(ctx context.Context, to []string, notif notification) error { | ||||
| 	stdin := new(bytes.Buffer) | ||||
| 	stderr := new(bytes.Buffer) | ||||
| 
 | ||||
| 	sendmailPath := "/usr/sbin/sendmail" | ||||
| 	if envVar := os.Getenv("SENDMAIL_PATH"); envVar != "" { | ||||
| 		sendmailPath = envVar | ||||
| 	} | ||||
| 
 | ||||
| 	fmt.Fprintf(stdin, "To: %s\n", strings.Join(to, ", ")) | ||||
| 	fmt.Fprintf(stdin, "Subject: [certspotter] %s\n", notif.Summary()) | ||||
| 	fmt.Fprintf(stdin, "Mime-Version: 1.0\n") | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Andrew Ayer
						Andrew Ayer