Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/proto/mms/model/message.rb
Views: 11766
# -*- coding: binary -*-1require 'rex/mime/message'23module Rex4module Proto5module Mms6module Model7class Message89# @!attribute message10# @return [String] The text message11attr_accessor :message1213# @!attribute content_type14# @return [Fixnum] The content type of the attachment15attr_accessor :content_type1617# @!attribute attachment18# @return [String] The loaded attachment converted to Base6419attr_accessor :attachment2021# @!attribute from22# @return [String] The from field in the email23attr_accessor :from2425# @!attribute to26# @return [String] The to field in the email27attr_accessor :to2829# @!attribute subject30# @return [String] The subject of the email31attr_accessor :subject3233# @!attribute attachment_name34# @return [String] The attachment base name extracted from :attachment35attr_accessor :attachment_name363738# Initializes the SMTP object.39#40# @param [Hash] opts41# @option opts [String] :from42# @option opts [String] :to43# @option opts [String] :message44# @option opts [String] :content_type45# @option opts [String] :attachment_path46#47# @return [Rex::Proto::Mms::Model::Message]48def initialize(opts={})49self.from = opts[:from]50self.to = opts[:to]51self.message = opts[:message]52self.subject = opts[:subject]53self.content_type = opts[:content_type]54if opts[:attachment_path]55self.attachment = load_file_to_base64(opts[:attachment_path])56self.attachment_name = File.basename(opts[:attachment_path])57end58end596061# Returns the raw MMS message62#63# @return [String]64def to_s65generate_mms_message66end676869private707172# Returns the loaded file in Base64 format73#74# @return [String] Base64 data75def load_file_to_base64(path)76buf = File.read(path)77(Rex::Text.encode_base64(buf).scan(/.{,76}/).flatten * "\n").strip78end798081# Returns the raw MMS message82#83# @return [String]84def generate_mms_message85text = Rex::MIME::Message.new86text.add_part(self.message, 'text/plain; charset=UTF-8', nil)87body = Rex::MIME::Message.new88body.add_part(text.to_s, "multipart/alternative; boundary=#{text.bound}", nil)89if self.attachment90body.add_part(self.attachment, "#{content_type}; name=\"#{attachment_name}\"", 'base64', "attachment; filename=\"#{attachment_name}\"")91end9293mms = "MIME-Version: 1.0\n"94mms << "From: #{self.from}\n"95mms << "To: #{self.to}\n"96mms << "Subject: #{self.subject}\n"97mms << "Content-Type: multipart/mixed; boundary=#{body.bound}\n"98mms << "\n"99mms << body.to_s.gsub(/\-\-\r\n\r\n\-\-_/, "--\n--_")100101mms102end103104end105end106end107end108end109110111