mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Add rubocop to our build. (#5004)
This commit is contained in:
@@ -17,7 +17,7 @@ module Email
|
||||
class MessageBuilder
|
||||
attr_reader :template_args
|
||||
|
||||
def initialize(to, opts=nil)
|
||||
def initialize(to, opts = nil)
|
||||
@to = to
|
||||
@opts = opts || {}
|
||||
|
||||
@@ -166,7 +166,6 @@ module Email
|
||||
result
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
|
||||
def reply_key
|
||||
@@ -195,11 +194,13 @@ module Email
|
||||
|
||||
@reply_by_email_address = SiteSetting.reply_by_email_address.dup
|
||||
@reply_by_email_address.gsub!("%{reply_key}", reply_key)
|
||||
@reply_by_email_address = if private_reply?
|
||||
alias_email(@reply_by_email_address)
|
||||
else
|
||||
site_alias_email(@reply_by_email_address)
|
||||
end
|
||||
|
||||
@reply_by_email_address =
|
||||
if private_reply?
|
||||
alias_email(@reply_by_email_address)
|
||||
else
|
||||
site_alias_email(@reply_by_email_address)
|
||||
end
|
||||
end
|
||||
|
||||
def alias_email(source)
|
||||
|
||||
@@ -2,12 +2,12 @@ module Email
|
||||
|
||||
class Processor
|
||||
|
||||
def initialize(mail, retry_on_rate_limit=true)
|
||||
def initialize(mail, retry_on_rate_limit = true)
|
||||
@mail = mail
|
||||
@retry_on_rate_limit = retry_on_rate_limit
|
||||
end
|
||||
|
||||
def self.process!(mail, retry_on_rate_limit=true)
|
||||
def self.process!(mail, retry_on_rate_limit = true)
|
||||
Email::Processor.new(mail, retry_on_rate_limit).process!
|
||||
end
|
||||
|
||||
@@ -35,23 +35,23 @@ module Email
|
||||
|
||||
def handle_failure(mail_string, e, incoming_email)
|
||||
message_template = case e
|
||||
when Email::Receiver::EmptyEmailError then :email_reject_empty
|
||||
when Email::Receiver::NoBodyDetectedError then :email_reject_empty
|
||||
when Email::Receiver::UserNotFoundError then :email_reject_user_not_found
|
||||
when Email::Receiver::ScreenedEmailError then :email_reject_screened_email
|
||||
when Email::Receiver::AutoGeneratedEmailError then :email_reject_auto_generated
|
||||
when Email::Receiver::InactiveUserError then :email_reject_inactive_user
|
||||
when Email::Receiver::BlockedUserError then :email_reject_blocked_user
|
||||
when Email::Receiver::BadDestinationAddress then :email_reject_bad_destination_address
|
||||
when Email::Receiver::StrangersNotAllowedError then :email_reject_strangers_not_allowed
|
||||
when Email::Receiver::InsufficientTrustLevelError then :email_reject_insufficient_trust_level
|
||||
when Email::Receiver::ReplyUserNotMatchingError then :email_reject_reply_user_not_matching
|
||||
when Email::Receiver::TopicNotFoundError then :email_reject_topic_not_found
|
||||
when Email::Receiver::TopicClosedError then :email_reject_topic_closed
|
||||
when Email::Receiver::InvalidPost then :email_reject_invalid_post
|
||||
when ActiveRecord::Rollback then :email_reject_invalid_post
|
||||
when Email::Receiver::InvalidPostAction then :email_reject_invalid_post_action
|
||||
when Discourse::InvalidAccess then :email_reject_invalid_access
|
||||
when Email::Receiver::EmptyEmailError then :email_reject_empty
|
||||
when Email::Receiver::NoBodyDetectedError then :email_reject_empty
|
||||
when Email::Receiver::UserNotFoundError then :email_reject_user_not_found
|
||||
when Email::Receiver::ScreenedEmailError then :email_reject_screened_email
|
||||
when Email::Receiver::AutoGeneratedEmailError then :email_reject_auto_generated
|
||||
when Email::Receiver::InactiveUserError then :email_reject_inactive_user
|
||||
when Email::Receiver::BlockedUserError then :email_reject_blocked_user
|
||||
when Email::Receiver::BadDestinationAddress then :email_reject_bad_destination_address
|
||||
when Email::Receiver::StrangersNotAllowedError then :email_reject_strangers_not_allowed
|
||||
when Email::Receiver::InsufficientTrustLevelError then :email_reject_insufficient_trust_level
|
||||
when Email::Receiver::ReplyUserNotMatchingError then :email_reject_reply_user_not_matching
|
||||
when Email::Receiver::TopicNotFoundError then :email_reject_topic_not_found
|
||||
when Email::Receiver::TopicClosedError then :email_reject_topic_closed
|
||||
when Email::Receiver::InvalidPost then :email_reject_invalid_post
|
||||
when ActiveRecord::Rollback then :email_reject_invalid_post
|
||||
when Email::Receiver::InvalidPostAction then :email_reject_invalid_post_action
|
||||
when Discourse::InvalidAccess then :email_reject_invalid_access
|
||||
else :email_reject_unrecognized_error
|
||||
end
|
||||
|
||||
|
||||
@@ -166,7 +166,7 @@ module Email
|
||||
elsif bounce_score >= SiteSetting.bounce_score_threshold
|
||||
# NOTE: we check bounce_score before sending emails, nothing to do
|
||||
# here other than log it happened.
|
||||
reason = I18n.t("user.email.revoked", { email: user.email, date: user.user_stat.reset_bounce_score_after })
|
||||
reason = I18n.t("user.email.revoked", email: user.email, date: user.user_stat.reset_bounce_score_after)
|
||||
StaffActionLogger.new(Discourse.system_user).log_revoke_email(user, reason)
|
||||
end
|
||||
end
|
||||
@@ -466,7 +466,7 @@ module Email
|
||||
true
|
||||
end
|
||||
|
||||
def self.reply_by_email_address_regex(extract_reply_key=true)
|
||||
def self.reply_by_email_address_regex(extract_reply_key = true)
|
||||
reply_addresses = [SiteSetting.reply_by_email_address]
|
||||
reply_addresses << (SiteSetting.alternative_reply_by_email_addresses.presence || "").split("|")
|
||||
|
||||
@@ -538,11 +538,11 @@ module Email
|
||||
PostActionType.types[:like] if likes.include?(body.strip.downcase)
|
||||
end
|
||||
|
||||
def create_topic(options={})
|
||||
def create_topic(options = {})
|
||||
create_post_with_attachments(options)
|
||||
end
|
||||
|
||||
def create_reply(options={})
|
||||
def create_reply(options = {})
|
||||
raise TopicNotFoundError if options[:topic].nil? || options[:topic].trashed?
|
||||
|
||||
if post_action_type = post_action_for(options[:raw])
|
||||
@@ -572,7 +572,7 @@ module Email
|
||||
end
|
||||
end
|
||||
|
||||
def create_post_with_attachments(options={})
|
||||
def create_post_with_attachments(options = {})
|
||||
# deal with attachments
|
||||
attachments.each do |attachment|
|
||||
tmp = Tempfile.new(["discourse-email-attachment", File.extname(attachment.filename)])
|
||||
@@ -612,7 +612,7 @@ module Email
|
||||
end
|
||||
end
|
||||
|
||||
def create_post(options={})
|
||||
def create_post(options = {})
|
||||
options[:via_email] = true
|
||||
options[:raw_email] = @raw_email
|
||||
|
||||
@@ -622,7 +622,7 @@ module Email
|
||||
raise InvalidPost, "No post creation date found. Is the e-mail missing a Date: header?"
|
||||
end
|
||||
|
||||
options[:created_at] = DateTime.now if options[:created_at] > DateTime.now
|
||||
options[:created_at] = DateTime.now if options[:created_at] > DateTime.now
|
||||
|
||||
is_private_message = options[:archetype] == Archetype.private_message ||
|
||||
options[:topic].try(:private_message?)
|
||||
|
||||
@@ -3,7 +3,7 @@ require_dependency 'email/styles'
|
||||
module Email
|
||||
class Renderer
|
||||
|
||||
def initialize(message, opts=nil)
|
||||
def initialize(message, opts = nil)
|
||||
@message = message
|
||||
@opts = opts || {}
|
||||
end
|
||||
|
||||
@@ -15,7 +15,7 @@ SMTP_CLIENT_ERRORS = [Net::SMTPFatalError, Net::SMTPSyntaxError]
|
||||
module Email
|
||||
class Sender
|
||||
|
||||
def initialize(message, email_type, user=nil)
|
||||
def initialize(message, email_type, user = nil)
|
||||
@message = message
|
||||
@email_type = email_type
|
||||
@user = user
|
||||
@@ -55,8 +55,8 @@ module Email
|
||||
# These are the links we add when a user uploads a file or image.
|
||||
# Ideally we would parse general markdown into plain text, but that is almost an intractable problem.
|
||||
url_prefix = Discourse.base_url
|
||||
@message.parts[0].body = @message.parts[0].body.to_s.gsub(/<a class="attachment" href="(\/uploads\/default\/[^"]+)">([^<]*)<\/a>/, '[\2]('+url_prefix+'\1)')
|
||||
@message.parts[0].body = @message.parts[0].body.to_s.gsub(/<img src="(\/uploads\/default\/[^"]+)"([^>]*)>/, '')
|
||||
@message.parts[0].body = @message.parts[0].body.to_s.gsub(/<a class="attachment" href="(\/uploads\/default\/[^"]+)">([^<]*)<\/a>/, '[\2](' + url_prefix + '\1)')
|
||||
@message.parts[0].body = @message.parts[0].body.to_s.gsub(/<img src="(\/uploads\/default\/[^"]+)"([^>]*)>/, '')
|
||||
|
||||
@message.text_part.content_type = 'text/plain; charset=UTF-8'
|
||||
|
||||
@@ -88,8 +88,8 @@ module Email
|
||||
"<topic/#{topic_id}/#{post_id}@#{host}>"
|
||||
|
||||
referenced_posts = Post.includes(:incoming_email)
|
||||
.where(id: PostReply.where(reply_id: post_id).select(:post_id))
|
||||
.order(id: :desc)
|
||||
.where(id: PostReply.where(reply_id: post_id).select(:post_id))
|
||||
.order(id: :desc)
|
||||
|
||||
referenced_post_message_ids = referenced_posts.map do |post|
|
||||
if post.incoming_email&.message_id.present?
|
||||
@@ -165,9 +165,9 @@ module Email
|
||||
when /\.mailjet\.com/
|
||||
@message.header['X-MJ-CustomID'] = @message.message_id
|
||||
when "smtp.mandrillapp.com"
|
||||
merge_json_x_header('X-MC-Metadata', { message_id: @message.message_id })
|
||||
merge_json_x_header('X-MC-Metadata', message_id: @message.message_id)
|
||||
when "smtp.sparkpostmail.com"
|
||||
merge_json_x_header('X-MSYS-API', { metadata: { message_id: @message.message_id } })
|
||||
merge_json_x_header('X-MSYS-API', metadata: { message_id: @message.message_id })
|
||||
end
|
||||
|
||||
# Suppress images from short emails
|
||||
|
||||
@@ -10,7 +10,7 @@ module Email
|
||||
|
||||
delegate :css, to: :fragment
|
||||
|
||||
def initialize(html, opts=nil)
|
||||
def initialize(html, opts = nil)
|
||||
@html = html
|
||||
@opts = opts || {}
|
||||
@fragment = Nokogiri::HTML.fragment(@html)
|
||||
@@ -41,7 +41,7 @@ module Email
|
||||
img['width'] = img['height'] = 20
|
||||
else
|
||||
# use dimensions of original iPhone screen for 'too big, let device rescale'
|
||||
if img['width'].to_i > 320 or img['height'].to_i > 480
|
||||
if img['width'].to_i > (320) || img['height'].to_i > (480)
|
||||
img['width'] = img['height'] = 'auto'
|
||||
end
|
||||
end
|
||||
@@ -246,7 +246,7 @@ module Email
|
||||
linknum = 0
|
||||
element.css('a').each do |inner|
|
||||
# we want the first footer link to be specially highlighted as IMPORTANT
|
||||
if footernum == 0 and linknum == 0
|
||||
if footernum == (0) && linknum == (0)
|
||||
inner['style'] = "background-color: #006699; color:#ffffff; border-top: 4px solid #006699; border-right: 6px solid #006699; border-bottom: 4px solid #006699; border-left: 6px solid #006699; display: inline-block;"
|
||||
else
|
||||
inner['style'] = "color:#666;"
|
||||
@@ -271,7 +271,7 @@ module Email
|
||||
def style(selector, style, attribs = {})
|
||||
@fragment.css(selector).each do |element|
|
||||
add_styles(element, style) if style
|
||||
attribs.each do |k,v|
|
||||
attribs.each do |k, v|
|
||||
element[k] = v
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user