mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Work in Progress: Reply By Email:
- Add support classes and settings to enable reply by email - Split out Email builder to be more OO, add many specs
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
<th>{{i18n user.title}}</th>
|
||||
<th>{{i18n admin.email.to_address}}</th>
|
||||
<th>{{i18n admin.email.email_type}}</th>
|
||||
<th>{{i18n admin.email.reply_key}}</th>
|
||||
</tr>
|
||||
|
||||
{{#if model.length}}
|
||||
@@ -20,6 +21,7 @@
|
||||
</td>
|
||||
<td><a href='mailto:{{unbound to_address}}'>{{to_address}}</a></td>
|
||||
<td>{{email_type}}</td>
|
||||
<td>{{reply_key}}</td>
|
||||
{{/collection}}
|
||||
{{/group}}
|
||||
{{/if}}
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
require_dependency 'email/builder'
|
||||
require_dependency 'email/message_builder'
|
||||
|
||||
class InviteMailer < ActionMailer::Base
|
||||
default charset: 'UTF-8'
|
||||
include Email::Builder
|
||||
include Email::BuildEmailHelper
|
||||
|
||||
def send_invite(invite)
|
||||
|
||||
# Find the first topic they were invited to
|
||||
first_topic = invite.topics.order(:created_at).first
|
||||
|
||||
# If they were invited to a topic
|
||||
build_email invite.email,
|
||||
'invite_mailer',
|
||||
invitee_name: invite.invited_by.username,
|
||||
invite_link: "#{Discourse.base_url}/invites/#{invite.invite_key}",
|
||||
topic_title: first_topic.try(:title)
|
||||
|
||||
build_email(invite.email,
|
||||
template: 'invite_mailer',
|
||||
invitee_name: invite.invited_by.username,
|
||||
invite_link: "#{Discourse.base_url}/invites/#{invite.invite_key}",
|
||||
topic_title: first_topic.try(:title))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
require_dependency 'email/builder'
|
||||
require_dependency 'email/message_builder'
|
||||
|
||||
class TestMailer < ActionMailer::Base
|
||||
default charset: 'UTF-8'
|
||||
include Email::Builder
|
||||
include Email::BuildEmailHelper
|
||||
|
||||
def send_test(to_address)
|
||||
build_email to_address, 'test_mailer'
|
||||
build_email(to_address, template: 'test_mailer')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
require_dependency 'markdown_linker'
|
||||
require_dependency 'email/builder'
|
||||
require_dependency 'email/message_builder'
|
||||
|
||||
class UserNotifications < ActionMailer::Base
|
||||
default charset: 'UTF-8'
|
||||
|
||||
include Email::Builder
|
||||
include Email::BuildEmailHelper
|
||||
|
||||
def signup(user, opts={})
|
||||
build_email(user.email, "user_notifications.signup", email_token: opts[:email_token])
|
||||
build_email(user.email,
|
||||
template: "user_notifications.signup",
|
||||
email_token: opts[:email_token])
|
||||
end
|
||||
|
||||
def signup_after_approval(user, opts={})
|
||||
build_email(
|
||||
user.email,
|
||||
'user_notifications.signup_after_approval',
|
||||
email_token: opts[:email_token],
|
||||
new_user_tips: SiteContent.content_for(:usage_tips)
|
||||
)
|
||||
build_email(user.email,
|
||||
template: 'user_notifications.signup_after_approval',
|
||||
email_token: opts[:email_token],
|
||||
new_user_tips: SiteContent.content_for(:usage_tips))
|
||||
end
|
||||
|
||||
def authorize_email(user, opts={})
|
||||
build_email(user.email, "user_notifications.authorize_email", email_token: opts[:email_token])
|
||||
build_email(user.email, template: "user_notifications.authorize_email", email_token: opts[:email_token])
|
||||
end
|
||||
|
||||
def forgot_password(user, opts={})
|
||||
build_email(user.email, "user_notifications.forgot_password", email_token: opts[:email_token])
|
||||
build_email(user.email, template: "user_notifications.forgot_password", email_token: opts[:email_token])
|
||||
end
|
||||
|
||||
def private_message(user, opts={})
|
||||
post = opts[:post]
|
||||
|
||||
build_email user.email,
|
||||
"user_notifications.private_message",
|
||||
message: post.raw,
|
||||
url: post.url,
|
||||
subject_prefix: "[#{I18n.t('private_message_abbrev')}] #{post.post_number != 1 ? 're: ' : ''}",
|
||||
topic_title: post.topic.title,
|
||||
private_message_from: post.user.name,
|
||||
from: "#{I18n.t(:via, username: post.user.name, site_name: SiteSetting.title)} <#{SiteSetting.notification_email}>",
|
||||
add_unsubscribe_link: true
|
||||
template: "user_notifications.private_message",
|
||||
message: post.raw,
|
||||
url: post.url,
|
||||
subject_prefix: "[#{I18n.t('private_message_abbrev')}] #{post.post_number != 1 ? 're: ' : ''}",
|
||||
topic_title: post.topic.title,
|
||||
private_message_from: post.user.name,
|
||||
from_alias: I18n.t(:via, username: post.user.name, site_name: SiteSetting.title),
|
||||
add_unsubscribe_link: true
|
||||
end
|
||||
|
||||
def digest(user, opts={})
|
||||
@@ -57,11 +57,11 @@ class UserNotifications < ActionMailer::Base
|
||||
|
||||
# Don't send email unless there is content in it
|
||||
if @new_topics.present?
|
||||
mail to: user.email,
|
||||
from: "#{I18n.t('user_notifications.digest.from', site_name: SiteSetting.title)} <#{SiteSetting.notification_email}>",
|
||||
subject: I18n.t('user_notifications.digest.subject_template',
|
||||
site_name: @site_name,
|
||||
date: I18n.l(Time.now, format: :short))
|
||||
build_email user.email,
|
||||
from_alias: I18n.t('user_notifications.digest.from', site_name: SiteSetting.title),
|
||||
subject: I18n.t('user_notifications.digest.subject_template',
|
||||
site_name: @site_name,
|
||||
date: I18n.l(Time.now, format: :short))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -80,16 +80,16 @@ class UserNotifications < ActionMailer::Base
|
||||
message: @post.raw,
|
||||
url: @post.url,
|
||||
username: username,
|
||||
add_unsubscribe_link: true
|
||||
add_unsubscribe_link: true,
|
||||
template: "user_notifications.user_#{notification_type}"
|
||||
}
|
||||
|
||||
# If we have a display name, change the from address
|
||||
if username.present?
|
||||
aliased = I18n.t(:via, username: username, site_name: SiteSetting.title)
|
||||
email_opts[:from] = "#{aliased} <#{SiteSetting.notification_email}>"
|
||||
email_opts[:from_alias] = I18n.t(:via, username: username, site_name: SiteSetting.title)
|
||||
end
|
||||
|
||||
email = build_email user.email, "user_notifications.user_#{notification_type}", email_opts
|
||||
build_email(user.email, email_opts)
|
||||
end
|
||||
|
||||
alias :user_invited_to_private_message :notification_template
|
||||
|
||||
@@ -3,6 +3,13 @@ class EmailLog < ActiveRecord::Base
|
||||
validates_presence_of :email_type
|
||||
validates_presence_of :to_address
|
||||
|
||||
before_create do
|
||||
# We only generate a reply
|
||||
if SiteSetting.reply_by_email_enabled?
|
||||
self.reply_key = SecureRandom.hex(16)
|
||||
end
|
||||
end
|
||||
|
||||
after_create do
|
||||
# Update last_emailed_at if the user_id is present
|
||||
User.update_all("last_emailed_at = CURRENT_TIMESTAMP", id: user_id) if user_id.present?
|
||||
|
||||
@@ -188,6 +188,10 @@ class SiteSetting < ActiveRecord::Base
|
||||
setting(:regular_requires_likes_given, 1)
|
||||
setting(:regular_requires_topic_reply_count, 3)
|
||||
|
||||
# Reply by Email Settings
|
||||
setting(:reply_by_email_enabled, false)
|
||||
setting(:reply_by_email_address, nil)
|
||||
|
||||
# Entropy checks
|
||||
setting(:title_min_entropy, 10)
|
||||
setting(:body_min_entropy, 7)
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
class EmailLogSerializer < ApplicationSerializer
|
||||
|
||||
attributes :id, :to_address, :email_type, :user_id, :created_at
|
||||
attributes :id,
|
||||
:reply_key,
|
||||
:to_address,
|
||||
:email_type,
|
||||
:user_id,
|
||||
:created_at
|
||||
|
||||
has_one :user, serializer: BasicUserSerializer, embed: :objects
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user