)
const (
- MailAuthActivate base.TplName = "auth/activate"
- MailAuthActivateEmail base.TplName = "auth/activate_email"
- MailAuthResetPassword base.TplName = "auth/reset_passwd"
- MailAuthRegisterNotify base.TplName = "auth/register_notify"
+ mailAuthActivate base.TplName = "auth/activate"
+ mailAuthActivateEmail base.TplName = "auth/activate_email"
+ mailAuthResetPassword base.TplName = "auth/reset_passwd"
+ mailAuthRegisterNotify base.TplName = "auth/register_notify"
- MailIssueComment base.TplName = "issue/comment"
- MailIssueMention base.TplName = "issue/mention"
+ mailIssueComment base.TplName = "issue/comment"
+ mailIssueMention base.TplName = "issue/mention"
- MailNotifyCollaborator base.TplName = "notify/collaborator"
+ mailNotifyCollaborator base.TplName = "notify/collaborator"
)
-type MailRender interface {
+type mailRenderInterface interface {
HTMLString(string, interface{}, ...macaron.HTMLOptions) (string, error)
}
-var mailRender MailRender
+var mailRender mailRenderInterface
+// InitMailRender initializes the macaron mail renderer
func InitMailRender(dir, appendDir string, funcMap []template.FuncMap) {
opt := &macaron.RenderOptions{
Directory: dir,
}
}
+// SendTestMail sends a test mail
func SendTestMail(email string) error {
return gomail.Send(&mailer.Sender{}, mailer.NewMessage([]string{email}, "Gogs Test Email!", "Gogs Test Email!").Message)
}
+// SendUserMail sends a mail to the user
func SendUserMail(c *macaron.Context, u *User, tpl base.TplName, code, subject, info string) {
data := map[string]interface{}{
"Username": u.DisplayName(),
mailer.SendAsync(msg)
}
+// SendActivateAccountMail sends an activation mail to the user
func SendActivateAccountMail(c *macaron.Context, u *User) {
- SendUserMail(c, u, MailAuthActivate, u.GenerateActivateCode(), c.Tr("mail.activate_account"), "activate account")
+ SendUserMail(c, u, mailAuthActivate, u.GenerateActivateCode(), c.Tr("mail.activate_account"), "activate account")
}
+// SendResetPasswordMail sends a password reset mail to the user
func SendResetPasswordMail(c *macaron.Context, u *User) {
- SendUserMail(c, u, MailAuthResetPassword, u.GenerateActivateCode(), c.Tr("mail.reset_password"), "reset password")
+ SendUserMail(c, u, mailAuthResetPassword, u.GenerateActivateCode(), c.Tr("mail.reset_password"), "reset password")
}
-// SendActivateAccountMail sends confirmation email.
+// SendActivateEmailMail sends confirmation email.
func SendActivateEmailMail(c *macaron.Context, u *User, email *EmailAddress) {
data := map[string]interface{}{
"Username": u.DisplayName(),
"Code": u.GenerateEmailActivateCode(email.Email),
"Email": email.Email,
}
- body, err := mailRender.HTMLString(string(MailAuthActivateEmail), data)
+ body, err := mailRender.HTMLString(string(mailAuthActivateEmail), data)
if err != nil {
log.Error(3, "HTMLString: %v", err)
return
data := map[string]interface{}{
"Username": u.DisplayName(),
}
- body, err := mailRender.HTMLString(string(MailAuthRegisterNotify), data)
+ body, err := mailRender.HTMLString(string(mailAuthRegisterNotify), data)
if err != nil {
log.Error(3, "HTMLString: %v", err)
return
"RepoName": repoName,
"Link": repo.HTMLURL(),
}
- body, err := mailRender.HTMLString(string(MailNotifyCollaborator), data)
+ body, err := mailRender.HTMLString(string(mailNotifyCollaborator), data)
if err != nil {
log.Error(3, "HTMLString: %v", err)
return
}
func composeIssueMessage(issue *Issue, doer *User, tplName base.TplName, tos []string, info string) *mailer.Message {
- subject := issue.MailSubject()
+ subject := issue.mailSubject()
body := string(markdown.RenderSpecialLink([]byte(issue.Content), issue.Repo.HTMLURL(), issue.Repo.ComposeMetas()))
data := composeTplData(subject, body, issue.HTMLURL())
data["Doer"] = doer
return
}
- mailer.SendAsync(composeIssueMessage(issue, doer, MailIssueComment, tos, "issue comment"))
+ mailer.SendAsync(composeIssueMessage(issue, doer, mailIssueComment, tos, "issue comment"))
}
// SendIssueMentionMail composes and sends issue mention emails to target receivers.
if len(tos) == 0 {
return
}
- mailer.SendAsync(composeIssueMessage(issue, doer, MailIssueMention, tos, "issue mention"))
+ mailer.SendAsync(composeIssueMessage(issue, doer, mailIssueMention, tos, "issue mention"))
}
CreatedUnix int64
}
+// BeforeInsert is invoked from XORM before inserting an object of this type.
func (r *Release) BeforeInsert() {
if r.CreatedUnix == 0 {
r.CreatedUnix = time.Now().Unix()
}
}
+// AfterSet is invoked from XORM after setting the value of a field of this object.
func (r *Release) AfterSet(colName string, _ xorm.Cell) {
switch colName {
case "created_unix":
return rels, err
}
-type ReleaseSorter struct {
+type releaseSorter struct {
rels []*Release
}
-func (rs *ReleaseSorter) Len() int {
+func (rs *releaseSorter) Len() int {
return len(rs.rels)
}
-func (rs *ReleaseSorter) Less(i, j int) bool {
+func (rs *releaseSorter) Less(i, j int) bool {
diffNum := rs.rels[i].NumCommits - rs.rels[j].NumCommits
if diffNum != 0 {
return diffNum > 0
return rs.rels[i].Created.After(rs.rels[j].Created)
}
-func (rs *ReleaseSorter) Swap(i, j int) {
+func (rs *releaseSorter) Swap(i, j int) {
rs.rels[i], rs.rels[j] = rs.rels[j], rs.rels[i]
}
// SortReleases sorts releases by number of commits and created time.
func SortReleases(rels []*Release) {
- sorter := &ReleaseSorter{rels: rels}
+ sorter := &releaseSorter{rels: rels}
sort.Sort(sorter)
}