# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # # Translators: msgid "" msgstr "" "Project-Id-Version: ownCloud\n" "Report-Msgid-Bugs-To: http://bugs.owncloud.org/\n" "POT-Creation-Date: 2012-08-29 02:01+0200\n" "PO-Revision-Date: 2012-08-29 00:03+0000\n" "Last-Translator: I Robot \n" "Language-Team: Arabic (Saudi Arabia) (http://www.transifex.com/projects/p/owncloud/language/ar_SA/)\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Language: ar_SA\n" "Plural-Forms: nplurals=2; plural=(n != 1)\n" #: templates/settings.php:8 msgid "Host" msgstr "" #: templates/settings.php:8 msgid "" "You can omit the protocol, except you require SSL. Then start with ldaps://" msgstr "" #: templates/settings.php:9 msgid "Base DN" msgstr "" #: templates/settings.php:9 msgid "You can specify Base DN for users and groups in the Advanced tab" msgstr "" #: templates/settings.php:10 msgid "User DN" msgstr "" #: templates/settings.php:10 msgid "" "The DN of the client user with which the bind shall be done, e.g. " "uid=agent,dc=example,dc=com. For anonymous access, leave DN and Password " "empty." msgstr "" #: templates/settings.php:11 msgid "Password" msgstr "" #: templates/settings.php:11 msgid "For anonymous access, leave DN and Password empty." msgstr "" #: templates/settings.php:12 msgid "User Login Filter" msgstr "" #: templates/settings.php:12 #, php-format msgid "" "Defines the filter to apply, when login is attempted. %%uid replaces the " "username in the login action." msgstr "" #: templates/settings.php:12 #, php-format msgid "use %%uid placeholder, e.g. \"uid=%%uid\"" msgstr "" #: templates/settings.php:13 msgid "User List Filter" msgstr "" #: templates/settings.php:13 msgid "Defines the filter to apply, when retrieving users." msgstr "" #: templates/settings.php:13 msgid "without any placeholder, e.g. \"objectClass=person\"." msgstr "" #: templates/settings.php:14 msgid "Group Filter" msgstr "" #: templates/settings.php:14 msgid "Defines the filter to apply, when retrieving groups." msgstr "" #: templates/settings.php:14 msgid "without any placeholder, e.g. \"objectClass=posixGroup\"." msgstr "" #: templates/settings.php:17 msgid "Port" msgstr "" #: templates/settings.php:18 msgid "Base User Tree" msgstr "" #: templates/settings.php:19 msgid "Base Group Tree" msgstr "" #: templates/settings.php:20 msgid "Group-Member association" msgstr "" #: templates/settings.php:21 msgid "Use TLS" msgstr "" #: templates/settings.php:21 msgid "Do not use it for SSL connections, it will fail." msgstr "" #: templates/settings.php:22 msgid "Case insensitve LDAP server (Windows)" msgstr "" #: templates/settings.php:23 msgid "Turn off SSL certificate validation." msgstr "" #: templates/settings.php:23 msgid "" "If connection only works with this option, import the LDAP server's SSL " "certificate in your ownCloud server." msgstr "" #: templates/settings.php:23 msgid "Not recommended, use for testing only." msgstr "" #: templates/settings.php:24 msgid "User Display Name Field" msgstr "" #: templates/settings.php:24 msgid "The LDAP attribute to use to generate the user`s ownCloud name." msgstr "" #: templates/settings.php:25 msgid "Group Display Name Field" msgstr "" #: templates/settings.php:25 msgid "The LDAP attribute to use to generate the groups`s ownCloud name." msgstr "" #: templates/settings.php:27 msgid "in bytes" msgstr "" #: templates/settings.php:29 msgid "in seconds. A change empties the cache." msgstr "" #: templates/settings.php:30 msgid "" "Leave empty for user name (default). Otherwise, specify an LDAP/AD " "attribute." msgstr "" #: templates/settings.php:32 msgid "Help" msgstr "" ' href='#n1'>1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
// Copyright 2016 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package models

import (
	"fmt"
	"html/template"
	"path"

	"gopkg.in/gomail.v2"
	"gopkg.in/macaron.v1"

	"github.com/gogits/gogs/modules/base"
	"github.com/gogits/gogs/modules/log"
	"github.com/gogits/gogs/modules/mailer"
	"github.com/gogits/gogs/modules/markdown"
	"github.com/gogits/gogs/modules/setting"
)

const (
	MAIL_AUTH_ACTIVATE        base.TplName = "auth/activate"
	MAIL_AUTH_ACTIVATE_EMAIL  base.TplName = "auth/activate_email"
	MAIL_AUTH_RESET_PASSWORD  base.TplName = "auth/reset_passwd"
	MAIL_AUTH_REGISTER_NOTIFY base.TplName = "auth/register_notify"

	MAIL_ISSUE_COMMENT base.TplName = "issue/comment"
	MAIL_ISSUE_MENTION base.TplName = "issue/mention"

	MAIL_NOTIFY_COLLABORATOR base.TplName = "notify/collaborator"
)

type MailRender interface {
	HTMLString(string, interface{}, ...macaron.HTMLOptions) (string, error)
}

var mailRender MailRender

func InitMailRender(dir, appendDir string, funcMap []template.FuncMap) {
	opt := &macaron.RenderOptions{
		Directory:         dir,
		AppendDirectories: []string{appendDir},
		Funcs:             funcMap,
		Extensions:        []string{".tmpl", ".html"},
	}
	ts := macaron.NewTemplateSet()
	ts.Set(macaron.DEFAULT_TPL_SET_NAME, opt)

	mailRender = &macaron.TplRender{
		TemplateSet: ts,
		Opt:         opt,
	}
}

func SendTestMail(email string) error {
	return gomail.Send(&mailer.Sender{}, mailer.NewMessage([]string{email}, "Gogs Test Email!", "Gogs Test Email!").Message)
}

func SendUserMail(c *macaron.Context, u *User, tpl base.TplName, code, subject, info string) {
	data := map[string]interface{}{
		"Username":          u.DisplayName(),
		"ActiveCodeLives":   setting.Service.ActiveCodeLives / 60,
		"ResetPwdCodeLives": setting.Service.ResetPwdCodeLives / 60,
		"Code":              code,
	}
	body, err := mailRender.HTMLString(string(tpl), data)
	if err != nil {
		log.Error(3, "HTMLString: %v", err)
		return
	}

	msg := mailer.NewMessage([]string{u.Email}, subject, body)
	msg.Info = fmt.Sprintf("UID: %d, %s", u.ID, info)

	mailer.SendAsync(msg)
}

func SendActivateAccountMail(c *macaron.Context, u *User) {
	SendUserMail(c, u, MAIL_AUTH_ACTIVATE, u.GenerateActivateCode(), c.Tr("mail.activate_account"), "activate account")
}

func SendResetPasswordMail(c *macaron.Context, u *User) {
	SendUserMail(c, u, MAIL_AUTH_RESET_PASSWORD, u.GenerateActivateCode(), c.Tr("mail.reset_password"), "reset password")
}

// SendActivateAccountMail sends confirmation email.
func SendActivateEmailMail(c *macaron.Context, u *User, email *EmailAddress) {
	data := map[string]interface{}{
		"Username":        u.DisplayName(),
		"ActiveCodeLives": setting.Service.ActiveCodeLives / 60,
		"Code":            u.GenerateEmailActivateCode(email.Email),
		"Email":           email.Email,
	}
	body, err := mailRender.HTMLString(string(MAIL_AUTH_ACTIVATE_EMAIL), data)
	if err != nil {
		log.Error(3, "HTMLString: %v", err)
		return
	}

	msg := mailer.NewMessage([]string{email.Email}, c.Tr("mail.activate_email"), body)
	msg.Info = fmt.Sprintf("UID: %d, activate email", u.ID)

	mailer.SendAsync(msg)
}

// SendRegisterNotifyMail triggers a notify e-mail by admin created a account.
func SendRegisterNotifyMail(c *macaron.Context, u *User) {
	data := map[string]interface{}{
		"Username": u.DisplayName(),
	}
	body, err := mailRender.HTMLString(string(MAIL_AUTH_REGISTER_NOTIFY), data)
	if err != nil {
		log.Error(3, "HTMLString: %v", err)
		return
	}

	msg := mailer.NewMessage([]string{u.Email}, c.Tr("mail.register_notify"), body)
	msg.Info = fmt.Sprintf("UID: %d, registration notify", u.ID)

	mailer.SendAsync(msg)
}

// SendCollaboratorMail sends mail notification to new collaborator.
func SendCollaboratorMail(u, doer *User, repo *Repository) {
	repoName := path.Join(repo.Owner.Name, repo.Name)
	subject := fmt.Sprintf("%s added you to %s", doer.DisplayName(), repoName)

	data := map[string]interface{}{
		"Subject":  subject,
		"RepoName": repoName,
		"Link":     repo.HTMLURL(),
	}
	body, err := mailRender.HTMLString(string(MAIL_NOTIFY_COLLABORATOR), data)
	if err != nil {
		log.Error(3, "HTMLString: %v", err)
		return
	}

	msg := mailer.NewMessage([]string{u.Email}, subject, body)
	msg.Info = fmt.Sprintf("UID: %d, add collaborator", u.ID)

	mailer.SendAsync(msg)
}

func composeTplData(subject, body, link string) map[string]interface{} {
	data := make(map[string]interface{}, 10)
	data["Subject"] = subject
	data["Body"] = body
	data["Link"] = link
	return data
}

func composeIssueMessage(issue *Issue, doer *User, tplName base.TplName, tos []string, info string) *mailer.Message {
	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
	content, err := mailRender.HTMLString(string(tplName), data)
	if err != nil {
		log.Error(3, "HTMLString (%s): %v", tplName, err)
	}
	msg := mailer.NewMessageFrom(tos, fmt.Sprintf(`"%s" <%s>`, doer.DisplayName(), setting.MailService.FromEmail), subject, content)
	msg.Info = fmt.Sprintf("Subject: %s, %s", subject, info)
	return msg
}

// SendIssueCommentMail composes and sends issue comment emails to target receivers.
func SendIssueCommentMail(issue *Issue, doer *User, tos []string) {
	if len(tos) == 0 {
		return
	}

	mailer.SendAsync(composeIssueMessage(issue, doer, MAIL_ISSUE_COMMENT, tos, "issue comment"))
}

// SendIssueMentionMail composes and sends issue mention emails to target receivers.
func SendIssueMentionMail(issue *Issue, doer *User, tos []string) {
	if len(tos) == 0 {
		return
	}
	mailer.SendAsync(composeIssueMessage(issue, doer, MAIL_ISSUE_MENTION, tos, "issue mention"))
}