chore: rubocop

chore: fix api test conventions

chore: rubocop -A spec/

chore: more rubocop -A

fix failing test

rubocop fixes

removes helper methods that are in my opinion dead code

more rubocop fixes

rubocop -a --auto-gen-config
This commit is contained in:
Philipp Rothmann 2023-05-12 13:01:12 +02:00 committed by Philipp Rothmann
parent f6fb804bbe
commit fb2b4d8a8a
331 changed files with 4263 additions and 4507 deletions

View file

@ -1,4 +1,4 @@
require "email_reply_trimmer"
require 'email_reply_trimmer'
class MessagesMailReceiver
def self.regexp
@ -9,29 +9,25 @@ class MessagesMailReceiver
@message = Message.find_by_id(match[:message_id])
@user = User.find_by_id(match[:user_id])
raise "Message could not be found" if @message.nil?
raise "User could not be found" if @user.nil?
raise 'Message could not be found' if @message.nil?
raise 'User could not be found' if @user.nil?
hash = @message.mail_hash_for_user(@user)
raise "Hash does not match expectations" unless hash.casecmp(match[:hash]) == 0
raise 'Hash does not match expectations' unless hash.casecmp(match[:hash]) == 0
end
def received(data)
mail = Mail.new data
mail_part = get_mail_part(mail)
raise "No valid content could be found" if mail_part.nil?
raise 'No valid content could be found' if mail_part.nil?
body = mail_part.body.decoded
unless mail_part.content_type_parameters.nil?
body = body.force_encoding mail_part.content_type_parameters[:charset]
end
body = body.force_encoding mail_part.content_type_parameters[:charset] unless mail_part.content_type_parameters.nil?
if MIME::Type.simplified(mail_part.content_type) == "text/html"
body = Nokogiri::HTML(body).text
end
body = Nokogiri::HTML(body).text if MIME::Type.simplified(mail_part.content_type) == 'text/html'
body.encode!(Encoding::default_internal)
body.encode!(Encoding.default_internal)
body = EmailReplyTrimmer.trim(body)
raise BlankBodyException if body.empty?
@ -39,16 +35,16 @@ class MessagesMailReceiver
group: @message.group,
private: @message.private,
received_email: data
if @message.reply_to
message.reply_to_message = @message.reply_to_message
else
message.reply_to_message = @message
end
if mail.subject
message.subject = mail.subject.gsub("[#{FoodsoftConfig[:name]}] ", "")
else
message.subject = I18n.t('messages.model.reply_subject', subject: message.reply_to_message.subject)
end
message.reply_to_message = if @message.reply_to
@message.reply_to_message
else
@message
end
message.subject = if mail.subject
mail.subject.gsub("[#{FoodsoftConfig[:name]}] ", '')
else
I18n.t('messages.model.reply_subject', subject: message.reply_to_message.subject)
end
message.add_recipients [@message.sender_id]
message.save!
@ -64,9 +60,7 @@ class MessagesMailReceiver
for part in mail.parts
part = get_mail_part(part)
content_type = MIME::Type.simplified(part.content_type)
if content_type == "text/plain" || !mail_part && content_type == "text/html"
mail_part = part
end
mail_part = part if content_type == 'text/plain' || (!mail_part && content_type == 'text/html')
end
mail_part
end