X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=lib%2Fsup%2Fmodes%2Fforward-mode.rb;h=b71be482d99cf29574d6bb12191acb959aa0e0cd;hb=81ee8d587ed713ebef29c1e450f5bc2557119c07;hp=34551b34ce53ca921c01df74d96942c8db3f1823;hpb=ce88631cead32ea9011ee32d0d34b627c4fd19e6;p=sup diff --git a/lib/sup/modes/forward-mode.rb b/lib/sup/modes/forward-mode.rb index 34551b3..b71be48 100644 --- a/lib/sup/modes/forward-mode.rb +++ b/lib/sup/modes/forward-mode.rb @@ -1,19 +1,71 @@ module Redwood class ForwardMode < EditMessageMode - def initialize m - super :header => { + ## TODO: share some of this with reply-mode + def initialize opts={} + header = { "From" => AccountManager.default_account.full_address, - "Subject" => "Fwd: #{m.subj}", - }, - :body => forward_body_lines(m) + } + + header["Subject"] = + if opts[:message] + "Fwd: " + opts[:message].subj + elsif opts[:attachments] + "Fwd: " + opts[:attachments].keys.join(", ") + end + + header["To"] = opts[:to].map { |p| p.full_address }.join(", ") if opts[:to] + header["Cc"] = opts[:cc].map { |p| p.full_address }.join(", ") if opts[:cc] + header["Bcc"] = opts[:bcc].map { |p| p.full_address }.join(", ") if opts[:bcc] + + body = + if opts[:message] + forward_body_lines(opts[:message]) + elsif opts[:attachments] + ["Note: #{opts[:attachments].size.pluralize 'attachment'}."] + end + + super :header => header, :body => body, :attachments => opts[:attachments] + end + + def self.spawn_nicely opts={} + to = opts[:to] || BufferManager.ask_for_contacts(:people, "To: ") or return + cc = opts[:cc] || BufferManager.ask_for_contacts(:people, "Cc: ") or return if $config[:ask_for_cc] + bcc = opts[:bcc] || BufferManager.ask_for_contacts(:people, "Bcc: ") or return if $config[:ask_for_bcc] + + attachment_hash = {} + attachments = opts[:attachments] || [] + + if(m = opts[:message]) + m.load_from_source! # read the full message in. you know, maybe i should just make Message#chunks do this.... + attachments += m.chunks.select { |c| c.is_a?(Chunk::Attachment) && !c.quotable? } + end + + attachments.each do |c| + mime_type = MIME::Types[c.content_type].first || MIME::Types["application/octet-stream"].first + attachment_hash[c.filename] = RMail::Message.make_attachment c.raw_content, mime_type.content_type, mime_type.encoding, c.filename + end + + mode = ForwardMode.new :message => opts[:message], :to => to, :cc => cc, :bcc => bcc, :attachments => attachment_hash + + title = "Forwarding " + + if opts[:message] + opts[:message].subj + elsif attachments + attachment_hash.keys.join(", ") + else + "something" + end + + BufferManager.spawn title, mode + mode.edit_message end protected def forward_body_lines m ["--- Begin forwarded message from #{m.from.mediumname} ---"] + - m.basic_header_lines + [""] + m.basic_body_lines + + m.quotable_header_lines + [""] + m.quotable_body_lines + ["--- End forwarded message ---"] end end