1
0
مراية لـ https://github.com/postalserver/postal.git تم المزامنة 2025-12-01 05:43:04 +00:00

style(rubocop): fix all safe auto correctable offenses

هذا الالتزام موجود في:
Charlie Smurthwaite
2023-03-16 15:50:53 +00:00
الأصل 02c93a4850
التزام fd289c46fd
204 ملفات معدلة مع 2611 إضافات و2486 حذوفات

عرض الملف

@@ -1,37 +1,38 @@
require 'mail'
require "mail"
module Mail
module Encodings
# Handle windows-1258 as windows-1252 when decoding
def Encodings.q_value_decode(str)
str = str.sub(/\=\?windows-?1258\?/i, '\=?windows-1252?')
def self.q_value_decode(str)
str = str.sub(/=\?windows-?1258\?/i, '\=?windows-1252?')
RubyVer.q_value_decode(str)
end
def Encodings.b_value_decode(str)
str = str.sub(/\=\?windows-?1258\?/i, '\=?windows-1252?')
def self.b_value_decode(str)
str = str.sub(/=\?windows-?1258\?/i, '\=?windows-1252?')
RubyVer.b_value_decode(str)
end
end
class Message
## Extract plain text body of message
def plain_body
if self.multipart? and self.text_part
self.text_part.decoded
elsif self.mime_type == 'text/plain' || self.mime_type.nil?
self.decoded
else
nil
if multipart? and text_part
text_part.decoded
elsif mime_type == "text/plain" || mime_type.nil?
decoded
end
end
## Extract HTML text body of message
def html_body
if self.multipart? and self.html_part
self.html_part.decoded
elsif self.mime_type == 'text/html'
self.decoded
else
nil
if multipart? and html_part
html_part.decoded
elsif mime_type == "text/html"
decoded
end
end
@@ -46,9 +47,21 @@ module Mail
# Returns the filename of the attachment (if it exists) or returns nil
# Make up a filename for rfc822 attachments if it isn't specified
def find_attachment
content_type_name = header[:content_type].filename rescue nil
content_disp_name = header[:content_disposition].filename rescue nil
content_loc_name = header[:content_location].location rescue nil
content_type_name = begin
header[:content_type].filename
rescue StandardError
nil
end
content_disp_name = begin
header[:content_disposition].filename
rescue StandardError
nil
end
content_loc_name = begin
header[:content_location].location
rescue StandardError
nil
end
if content_type && content_type_name
filename = content_type_name
@@ -56,56 +69,73 @@ module Mail
filename = content_disp_name
elsif content_location && content_loc_name
filename = content_loc_name
elsif self.mime_type == "message/rfc822"
filename = "#{rand(100000000)}.eml"
elsif mime_type == "message/rfc822"
filename = "#{rand(100_000_000)}.eml"
else
filename = nil
end
if filename
# Normal decode
filename = Mail::Encodings.decode_encode(filename, :decode) rescue filename
filename = begin
Mail::Encodings.decode_encode(filename, :decode)
rescue StandardError
filename
end
end
filename
end
def decode_body_as_text
body_text = decode_body
charset_tmp = Encoding.find(Ruby19.pick_encoding(charset)) rescue 'ASCII'
charset_tmp = 'Windows-1252' if charset_tmp.to_s =~ /windows-?1258/i
if charset_tmp == Encoding.find('UTF-7')
body_text.force_encoding('UTF-8')
decoded = body_text.gsub(/\+.*?\-/m) {|n|Base64.decode64(n[1..-2]+'===').force_encoding('UTF-16BE').encode('UTF-8')}
charset_tmp = begin
Encoding.find(Ruby19.pick_encoding(charset))
rescue StandardError
"ASCII"
end
charset_tmp = "Windows-1252" if charset_tmp.to_s =~ /windows-?1258/i
if charset_tmp == Encoding.find("UTF-7")
body_text.force_encoding("UTF-8")
decoded = body_text.gsub(/\+.*?-/m) { |n| Base64.decode64(n[1..-2] + "===").force_encoding("UTF-16BE").encode("UTF-8") }
else
body_text.force_encoding(charset_tmp)
decoded = body_text.encode("utf-8", :invalid => :replace, :undef => :replace)
decoded = body_text.encode("utf-8", invalid: :replace, undef: :replace)
end
decoded.valid_encoding? ? decoded : decoded.encode("utf-16le", :invalid => :replace, :undef => :replace).encode("utf-8")
decoded.valid_encoding? ? decoded : decoded.encode("utf-16le", invalid: :replace, undef: :replace).encode("utf-8")
end
end
# Handle attached emails as attachments
class AttachmentsList < Array
def initialize(parts_list)
@parts_list = parts_list
@content_disposition_type = 'attachment'
parts_list.map { |p|
@content_disposition_type = "attachment"
parts_list.map do |p|
(p.parts.empty? and p.attachment?) ? p : p.attachments
}.flatten.compact.each { |a| self << a }
end.flatten.compact.each { |a| self << a }
self
end
end
end
class Array
def decoded
return nil if self.empty?
return self.first.decoded
return nil if empty?
first.decoded
end
end
class NilClass
def decoded
nil
end
end