diff --git a/sgx-bwmsgsv2.rb b/sgx-bwmsgsv2.rb index cb2e2ae4850c153c26a961d63868cc5008515bd8..d2fdf8e0dccdcb890cec4dbbf0c79b4cc9d90dc9 100755 --- a/sgx-bwmsgsv2.rb +++ b/sgx-bwmsgsv2.rb @@ -40,6 +40,54 @@ require_relative 'lib/registration_repo' Sentry.init +MMS_MIME_TYPES = [ + "application/json", + "application/ogg", + "application/pdf", + "application/rtf", + "application/zip", + "application/x-tar", + "application/xml", + "application/gzip", + "application/x-bzip2", + "application/x-gzip", + "application/smil", + "application/javascript", + "audio/mp4", + "audio/mpeg", + "audio/ogg", + "audio/flac", + "audio/webm", + "audio/wav", + "audio/amr", + "audio/3gpp", + "image/bmp", + "image/gif", + "image/jpeg", + "image/pjpeg", + "image/png", + "image/svg+xml", + "image/tiff", + "image/webp", + "image/x-icon", + "text/css", + "text/csv", + "text/calendar", + "text/plain", + "text/javascript", + "text/vcard", + "text/vnd.wap.wml", + "text/xml", + "video/avi", + "video/mp4", + "video/mpeg", + "video/ogg", + "video/quicktime", + "video/webm", + "video/x-ms-wmv", + "video/x-flv" +] + def panic(e) Sentry.capture_exception(e) puts "Shutting down gateway due to exception: #{e.message}" @@ -252,17 +300,25 @@ module SGXbwmsgsv2 end puts "MMSOOB: found a url node - checking if to make MMS..." - # TODO: check size of file at un.text and shrink if need - body = s.respond_to?(:body) ? s.body : '' - # some clients send URI in both body & so delete - s.body = body.sub(/\s*#{Regexp.escape(un.text)}\s*$/, '') + EM::HttpRequest.new(un.text, tls: { verify_peer: true }).head.then { |http| + if http.response_header["CONTENT_LENGTH"].to_i > 3500000 || + !MMS_MIME_TYPES.include?(http.response_header["CONTENT_TYPE"]) + unless body.include?(un.text) + s.body = body.empty? ? un.text : "#{body}\n#{un.text}" + end + to_catapult(s, nil, num_dest, user_id, token, secret, usern) + else + # some clients send URI in both body & so delete + s.body = body.sub(/\s*#{Regexp.escape(un.text)}\s*$/, '') - puts "MMSOOB: url text is '#{un.text}'" - puts "MMSOOB: the body is '#{body.to_s.strip}'" + puts "MMSOOB: url text is '#{un.text}'" + puts "MMSOOB: the body is '#{body.to_s.strip}'" - puts "MMSOOB: sending MMS since found OOB & user asked" - to_catapult(s, un.text, num_dest, user_id, token, secret, usern) + puts "MMSOOB: sending MMS since found OOB & user asked" + to_catapult(s, un.text, num_dest, user_id, token, secret, usern) + end + } end def self.to_catapult(s, murl, num_dest, user_id, token, secret, usern)