Class: RMail::Message
Class Method Summary collapse
- .make_attachment(payload, mime_type, encoding, filename) ⇒ Object
- .make_file_attachment(fn) ⇒ Object
Instance Method Summary collapse
Class Method Details
.make_attachment(payload, mime_type, encoding, filename) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/sup/util.rb', line 99 def self. payload, mime_type, encoding, filename a = Message.new a.header.add "Content-Disposition", "attachment; filename=#{filename.inspect}" a.header.add "Content-Type", "#{mime_type}; name=#{filename.inspect}" a.header.add "Content-Transfer-Encoding", encoding if encoding a.body = case encoding when "base64" [payload].pack "m" when "quoted-printable" [payload].pack "M" when "7bit", "8bit", nil payload else raise EncodingUnsupportedError, encoding.inspect end a end |
.make_file_attachment(fn) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/sup/util.rb', line 80 def self. fn bfn = File.basename fn t = MIME::Types.type_for(bfn).first || MIME::Types.type_for("exe").first payload = IO.read fn ## Need to encode as base64 or quoted-printable if any lines are longer than 998 chars. encoding = if t.encoding != t.default_encoding and payload.each_line.any? { |l| l.length > 998 } t.default_encoding else t.encoding end payload, t.content_type, encoding, bfn.to_s end |
Instance Method Details
#charset ⇒ Object
93 94 95 96 97 |
# File 'lib/sup/util.rb', line 93 def charset if header.field?("content-type") && header.fetch("content-type") =~ /charset\s*=\s*"?(.*?)"?(;|$)/i $1 end end |