mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-11-04 08:21:11 +00:00 
			
		
		
		
	Fix validity of the FROM email address not being checked (#29347)
Fixes #27188. Introduces a check on the installation that tries to parse the FROM address. If it fails, shows a new error message to the user. --------- Co-authored-by: KN4CK3R <admin@oldschoolhack.me> (cherry picked from commit 6f6120dfa8d549d0b866eeb9317054fea831c844) Conflicts: options/locale/locale_en-US.ini context
This commit is contained in:
		
					parent
					
						
							
								7143f8fcdd
							
						
					
				
			
			
				commit
				
					
						fc384e494e
					
				
			
		
					 2 changed files with 7 additions and 0 deletions
				
			
		| 
						 | 
					@ -248,6 +248,7 @@ email_title = Email Settings
 | 
				
			||||||
smtp_addr = SMTP Host
 | 
					smtp_addr = SMTP Host
 | 
				
			||||||
smtp_port = SMTP Port
 | 
					smtp_port = SMTP Port
 | 
				
			||||||
smtp_from = Send Email As
 | 
					smtp_from = Send Email As
 | 
				
			||||||
 | 
					smtp_from_invalid = The "Send Email As" address is invalid
 | 
				
			||||||
smtp_from_helper = Email address Forgejo will use. Enter a plain email address or use the "Name" <email@example.com> format.
 | 
					smtp_from_helper = Email address Forgejo will use. Enter a plain email address or use the "Name" <email@example.com> format.
 | 
				
			||||||
mailer_user = SMTP Username
 | 
					mailer_user = SMTP Username
 | 
				
			||||||
mailer_password = SMTP Password
 | 
					mailer_password = SMTP Password
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,6 +7,7 @@ package install
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
 | 
						"net/mail"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"os/exec"
 | 
						"os/exec"
 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
| 
						 | 
					@ -423,6 +424,11 @@ func SubmitInstall(ctx *context.Context) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if len(strings.TrimSpace(form.SMTPAddr)) > 0 {
 | 
						if len(strings.TrimSpace(form.SMTPAddr)) > 0 {
 | 
				
			||||||
 | 
							if _, err := mail.ParseAddress(form.SMTPFrom); err != nil {
 | 
				
			||||||
 | 
								ctx.RenderWithErr(ctx.Tr("install.smtp_from_invalid"), tplInstall, &form)
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		cfg.Section("mailer").Key("ENABLED").SetValue("true")
 | 
							cfg.Section("mailer").Key("ENABLED").SetValue("true")
 | 
				
			||||||
		cfg.Section("mailer").Key("SMTP_ADDR").SetValue(form.SMTPAddr)
 | 
							cfg.Section("mailer").Key("SMTP_ADDR").SetValue(form.SMTPAddr)
 | 
				
			||||||
		cfg.Section("mailer").Key("SMTP_PORT").SetValue(form.SMTPPort)
 | 
							cfg.Section("mailer").Key("SMTP_PORT").SetValue(form.SMTPPort)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue