@@ -24,11 +24,11 @@ def initialize(data=nil)
24
24
self . header . parse ( head )
25
25
ctype = self . header . find ( 'Content-Type' )
26
26
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 ]+)"?/
28
28
self . bound = $1
29
29
chunks = body . to_s . split ( /--#{ self . bound } (--)?\r ?\n / )
30
30
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?
32
32
33
33
chunks . each do |chunk |
34
34
break if chunk == "--"
@@ -88,15 +88,13 @@ def mime_defaults
88
88
def add_part ( data = '' , content_type = 'text/plain' , transfer_encoding = "8bit" , content_disposition = nil )
89
89
part = Rex ::MIME ::Part . new
90
90
91
- if ( content_disposition )
91
+ if content_disposition
92
92
part . header . set ( "Content-Disposition" , content_disposition )
93
93
end
94
94
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
98
96
99
- if ( transfer_encoding )
97
+ if transfer_encoding
100
98
part . header . set ( "Content-Transfer-Encoding" , transfer_encoding )
101
99
end
102
100
@@ -127,24 +125,15 @@ def add_part_inline_attachment(data, name)
127
125
def to_s
128
126
header_string = self . header . to_s
129
127
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?
139
130
140
131
self . parts . each do |part |
141
132
msg << force_crlf ( "--" + self . bound + "\r \n " )
142
133
msg << part . to_s
143
134
end
144
135
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
148
137
149
138
msg
150
139
end
0 commit comments