| Total Complexity | 10 |
| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Changes | 6 | ||
| Bugs | 0 | Features | 2 |
| 1 | require 'mime' |
||
| 3 | module MIMEBuilder |
||
| 4 | class Text |
||
| 5 | attr_accessor :mime |
||
| 6 | attr_accessor :text |
||
| 7 | |||
| 8 | def initialize(text, opts = {}) |
||
| 9 | @text = text |
||
| 10 | |||
| 11 | if opts.key?(:content_type) && opts[:content_type].to_s.length>0 |
||
| 12 | content_type = opts[:content_type] |
||
| 13 | if content_type =~ /^text\/([^\/]+)$/i |
||
| 14 | @mime = MIME::Text.new(text, $1.downcase) |
||
| 15 | else |
||
| 16 | raise "Unknown Content Type: " + opts[:content_type].to_s |
||
| 17 | end |
||
| 18 | else |
||
| 19 | @mime = MIME::Text.new(text, 'plain') |
||
| 20 | end |
||
| 21 | |||
| 22 | @mime.headers.delete('Content-Id') \ |
||
| 23 | if opts.key?(:content_id_disable) && opts[:content_id_disable] |
||
| 24 | |||
| 25 | set_attachment_content_disposition(opts[:filename], opts[:is_attachment]) |
||
| 26 | end |
||
| 27 | |||
| 28 | def set_attachment_content_disposition(filename, is_attachment) |
||
| 29 | @mime.headers.set( |
||
| 30 | 'Content-Disposition', |
||
| 31 | get_attachment_content_disposition(filename) |
||
| 32 | ) if is_attachment |
||
| 33 | end |
||
| 34 | |||
| 35 | def get_attachment_content_disposition(filename = nil) |
||
| 36 | cd = filename.to_s.length > 0 \ |
||
| 37 | ? "attachment; filename=\"#{filename}\"" \ |
||
| 38 | : 'attachment' |
||
| 39 | end |
||
| 40 | end |
||
| 42 |