Skip to content

Commit 709ff1b

Browse files
committed
touch up lib/rex/mime/message.rb
1 parent c833888 commit 709ff1b

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

lib/rex/mime/message.rb

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ def initialize(data=nil)
2424
self.header.parse(head)
2525
ctype = self.header.find('Content-Type')
2626

27-
if ctype and ctype[1] and ctype[1] =~ /multipart\/mixed;\s*boundary="?([A-Za-z0-9'\(\)\+\_,\-\.\/:=\?^\s]+)"?/
27+
if ctype && ctype[1] && ctype[1] =~ /multipart\/mixed;\s*boundary="?([A-Za-z0-9'\(\)\+\_,\-\.\/:=\?^\s]+)"?/
2828
self.bound = $1
2929
chunks = body.to_s.split(/--#{self.bound}(--)?\r?\n/)
3030
self.content = chunks.shift.to_s.gsub(/\s+$/, '')
31-
self.content << "\r\n" if not self.content.empty?
31+
self.content << "\r\n" unless self.content.empty?
3232

3333
chunks.each do |chunk|
3434
break if chunk == "--"
@@ -88,15 +88,13 @@ def mime_defaults
8888
def add_part(data='', content_type='text/plain', transfer_encoding="8bit", content_disposition=nil)
8989
part = Rex::MIME::Part.new
9090

91-
if (content_disposition)
91+
if content_disposition
9292
part.header.set("Content-Disposition", content_disposition)
9393
end
9494

95-
if (content_type)
96-
part.header.set("Content-Type", content_type)
97-
end
95+
part.header.set("Content-Type", content_type) if content_type
9896

99-
if (transfer_encoding)
97+
if transfer_encoding
10098
part.header.set("Content-Transfer-Encoding", transfer_encoding)
10199
end
102100

@@ -127,24 +125,15 @@ def add_part_inline_attachment(data, name)
127125
def to_s
128126
header_string = self.header.to_s
129127

130-
if header_string.empty?
131-
msg = ''
132-
else
133-
msg = force_crlf(self.header.to_s + "\r\n")
134-
end
135-
136-
unless self.content.blank?
137-
msg << force_crlf(self.content + "\r\n")
138-
end
128+
msg = header_string.empty? ? '' : force_crlf(self.header.to_s + "\r\n")
129+
msg << force_crlf(self.content + "\r\n") unless self.content.blank?
139130

140131
self.parts.each do |part|
141132
msg << force_crlf("--" + self.bound + "\r\n")
142133
msg << part.to_s
143134
end
144135

145-
if self.parts.length > 0
146-
msg << force_crlf("--" + self.bound + "--\r\n")
147-
end
136+
msg << force_crlf("--" + self.bound + "--\r\n") if self.parts.length > 0
148137

149138
msg
150139
end

0 commit comments

Comments
 (0)