@ -73,6 +73,8 @@ func (sm *SMTP) send(address, fromName, fromAddr string, email *Email) error {
// Emailer contains the email sender, email content, and methods to construct message content.
// Emailer contains the email sender, email content, and methods to construct message content.
type Emailer struct {
type Emailer struct {
fromAddr , fromName string
fromAddr , fromName string
lang * EmailLang
cLang string
sender emailClient
sender emailClient
}
}
@ -108,6 +110,8 @@ func NewEmailer(app *appContext) *Emailer {
emailer := & Emailer {
emailer := & Emailer {
fromAddr : app . config . Section ( "email" ) . Key ( "address" ) . String ( ) ,
fromAddr : app . config . Section ( "email" ) . Key ( "address" ) . String ( ) ,
fromName : app . config . Section ( "email" ) . Key ( "from" ) . String ( ) ,
fromName : app . config . Section ( "email" ) . Key ( "from" ) . String ( ) ,
lang : & ( app . storage . lang . Email ) ,
cLang : app . storage . lang . chosenEmailLang ,
}
}
method := app . config . Section ( "email" ) . Key ( "method" ) . String ( )
method := app . config . Section ( "email" ) . Key ( "method" ) . String ( )
if method == "smtp" {
if method == "smtp" {
@ -153,8 +157,9 @@ func (emailer *Emailer) NewSMTP(server string, port int, username, password stri
}
}
func ( emailer * Emailer ) constructInvite ( code string , invite Invite , app * appContext ) ( * Email , error ) {
func ( emailer * Emailer ) constructInvite ( code string , invite Invite , app * appContext ) ( * Email , error ) {
lang := emailer . cLang
email := & Email {
email := & Email {
subject : app . config . Section ( "invite_emails" ) . Key ( "subject" ) . String( ) ,
subject : app . config . Section ( "invite_emails" ) . Key ( "subject" ) . Must String( emailer . lang . get ( lang , "inviteEmail" , "title" ) ) ,
}
}
expiry := invite . ValidTill
expiry := invite . ValidTill
d , t , expiresIn := emailer . formatExpiry ( expiry , false , app . datePattern , app . timePattern )
d , t , expiresIn := emailer . formatExpiry ( expiry , false , app . datePattern , app . timePattern )
@ -170,11 +175,13 @@ func (emailer *Emailer) constructInvite(code string, invite Invite, app *appCont
}
}
var tplData bytes . Buffer
var tplData bytes . Buffer
err = tpl . Execute ( & tplData , map [ string ] string {
err = tpl . Execute ( & tplData , map [ string ] string {
"expiry_date" : d ,
"hello" : emailer . lang . get ( lang , "inviteEmail" , "hello" ) ,
"expiry_time" : t ,
"youHaveBeenInvited" : emailer . lang . get ( lang , "inviteEmail" , "youHaveBeenInvited" ) ,
"expires_in" : expiresIn ,
"toJoin" : emailer . lang . get ( lang , "inviteEmail" , "toJoin" ) ,
"invite_link" : inviteLink ,
"inviteExpiry" : emailer . lang . format ( lang , "inviteEmail" , "inviteExpiry" , d , t , expiresIn ) ,
"message" : message ,
"linkButton" : emailer . lang . get ( lang , "inviteEmail" , "linkButton" ) ,
"invite_link" : inviteLink ,
"message" : message ,
} )
} )
if err != nil {
if err != nil {
return nil , err
return nil , err
@ -189,8 +196,9 @@ func (emailer *Emailer) constructInvite(code string, invite Invite, app *appCont
}
}
func ( emailer * Emailer ) constructExpiry ( code string , invite Invite , app * appContext ) ( * Email , error ) {
func ( emailer * Emailer ) constructExpiry ( code string , invite Invite , app * appContext ) ( * Email , error ) {
lang := emailer . cLang
email := & Email {
email := & Email {
subject : "Notice: Invite expired" ,
subject : emailer . lang . get ( lang , "inviteExpiry" , "title" ) ,
}
}
expiry := app . formatDatetime ( invite . ValidTill )
expiry := app . formatDatetime ( invite . ValidTill )
for _ , key := range [ ] string { "html" , "text" } {
for _ , key := range [ ] string { "html" , "text" } {
@ -201,8 +209,9 @@ func (emailer *Emailer) constructExpiry(code string, invite Invite, app *appCont
}
}
var tplData bytes . Buffer
var tplData bytes . Buffer
err = tpl . Execute ( & tplData , map [ string ] string {
err = tpl . Execute ( & tplData , map [ string ] string {
"code" : code ,
"inviteExpired" : emailer . lang . get ( lang , "inviteExpiry" , "inviteExpired" ) ,
"expiry" : expiry ,
"expiredAt" : emailer . lang . format ( lang , "inviteExpiry" , "expiredAt" , "\"" + code + "\"" , expiry ) ,
"notificationNotice" : emailer . lang . get ( lang , "inviteExpiry" , "notificationNotice" ) ,
} )
} )
if err != nil {
if err != nil {
return nil , err
return nil , err
@ -217,8 +226,9 @@ func (emailer *Emailer) constructExpiry(code string, invite Invite, app *appCont
}
}
func ( emailer * Emailer ) constructCreated ( code , username , address string , invite Invite , app * appContext ) ( * Email , error ) {
func ( emailer * Emailer ) constructCreated ( code , username , address string , invite Invite , app * appContext ) ( * Email , error ) {
lang := emailer . cLang
email := & Email {
email := & Email {
subject : "Notice: User created" ,
subject : emailer . lang . get ( lang , "userCreated" , "title" ) ,
}
}
created := app . formatDatetime ( invite . Created )
created := app . formatDatetime ( invite . Created )
var tplAddress string
var tplAddress string
@ -235,10 +245,14 @@ func (emailer *Emailer) constructCreated(code, username, address string, invite
}
}
var tplData bytes . Buffer
var tplData bytes . Buffer
err = tpl . Execute ( & tplData , map [ string ] string {
err = tpl . Execute ( & tplData , map [ string ] string {
"code" : code ,
"aUserWasCreated" : emailer . lang . format ( lang , "userCreated" , "aUserWasCreated" , "\"" + code + "\"" ) ,
"username" : username ,
"name" : emailer . lang . get ( lang , "userCreated" , "name" ) ,
"address" : tplAddress ,
"address" : emailer . lang . get ( lang , "userCreated" , "emailAddress" ) ,
"time" : created ,
"time" : emailer . lang . get ( lang , "userCreated" , "time" ) ,
"nameVal" : username ,
"addressVal" : tplAddress ,
"timeVal" : created ,
"notificationNotice" : emailer . lang . get ( lang , "userCreated" , "notificationNotice" ) ,
} )
} )
if err != nil {
if err != nil {
return nil , err
return nil , err
@ -253,8 +267,9 @@ func (emailer *Emailer) constructCreated(code, username, address string, invite
}
}
func ( emailer * Emailer ) constructReset ( pwr PasswordReset , app * appContext ) ( * Email , error ) {
func ( emailer * Emailer ) constructReset ( pwr PasswordReset , app * appContext ) ( * Email , error ) {
lang := emailer . cLang
email := & Email {
email := & Email {
subject : app. config . Section ( "password_resets" ) . Key ( "subject" ) . MustString ( "Password reset - Jellyfin ") ,
subject : emailer. lang . get ( lang , "passwordReset" , "title ") ,
}
}
d , t , expiresIn := emailer . formatExpiry ( pwr . Expiry , true , app . datePattern , app . timePattern )
d , t , expiresIn := emailer . formatExpiry ( pwr . Expiry , true , app . datePattern , app . timePattern )
message := app . config . Section ( "email" ) . Key ( "message" ) . String ( )
message := app . config . Section ( "email" ) . Key ( "message" ) . String ( )
@ -266,12 +281,14 @@ func (emailer *Emailer) constructReset(pwr PasswordReset, app *appContext) (*Ema
}
}
var tplData bytes . Buffer
var tplData bytes . Buffer
err = tpl . Execute ( & tplData , map [ string ] string {
err = tpl . Execute ( & tplData , map [ string ] string {
"username" : pwr . Username ,
"helloUser" : emailer . lang . format ( lang , "passwordReset" , "helloUser" , pwr . Username ) ,
"expiry_date" : d ,
"someoneHasRequestedReset" : emailer . lang . get ( lang , "passwordReset" , "someoneHasRequestedReset" ) ,
"expiry_time" : t ,
"ifItWasYou" : emailer . lang . get ( lang , "passwordReset" , "ifItWasYou" ) ,
"expires_in" : expiresIn ,
"codeExpiry" : emailer . lang . format ( lang , "passwordReset" , "codeExpiry" , d , t , expiresIn ) ,
"pin" : pwr . Pin ,
"ifItWasNotYou" : emailer . lang . get ( lang , "passwordReset" , "ifItWasNotYou" ) ,
"message" : message ,
"pin" : emailer . lang . get ( lang , "passwordReset" , "pin" ) ,
"pinVal" : pwr . Pin ,
"message" : message ,
} )
} )
if err != nil {
if err != nil {
return nil , err
return nil , err
@ -286,8 +303,9 @@ func (emailer *Emailer) constructReset(pwr PasswordReset, app *appContext) (*Ema
}
}
func ( emailer * Emailer ) constructDeleted ( reason string , app * appContext ) ( * Email , error ) {
func ( emailer * Emailer ) constructDeleted ( reason string , app * appContext ) ( * Email , error ) {
lang := emailer . cLang
email := & Email {
email := & Email {
subject : app. config . Section ( "deletion" ) . Key ( "subject" ) . MustString ( "Your account was deleted - Jellyfin ") ,
subject : emailer. lang . get ( lang , "userDeleted" , "title ") ,
}
}
for _ , key := range [ ] string { "html" , "text" } {
for _ , key := range [ ] string { "html" , "text" } {
fpath := app . config . Section ( "deletion" ) . Key ( "email_" + key ) . String ( )
fpath := app . config . Section ( "deletion" ) . Key ( "email_" + key ) . String ( )
@ -297,7 +315,9 @@ func (emailer *Emailer) constructDeleted(reason string, app *appContext) (*Email
}
}
var tplData bytes . Buffer
var tplData bytes . Buffer
err = tpl . Execute ( & tplData , map [ string ] string {
err = tpl . Execute ( & tplData , map [ string ] string {
"reason" : reason ,
"yourAccountWasDeleted" : emailer . lang . get ( lang , "userDeleted" , "yourAccountWasDeleted" ) ,
"reason" : emailer . lang . get ( lang , "userDeleted" , "reason" ) ,
"reasonVal" : reason ,
} )
} )
if err != nil {
if err != nil {
return nil , err
return nil , err