Hi all, attached you'll find two patches ment to be applied together (*) The first one introduces From: auto completion in edit-message mode (plus key shortcut "f"), the second adds a From: question when composing messages (config ask_for_from, again with auto completion) and improves the auto completion to be "Name <address>" instead of just "address".
Motivation: I have to send mail from different accounts, and am tired of typing in the full sender each time. (*) Sorry, I can't quite get git to export them as one right now :( Also, I'll bear any comments on my code - this is the first ruby I've ever written. So long, Tyberius Prime
>From d20e3d2d66e671d18efec3d6210e8f22ef5409af Mon Sep 17 00:00:00 2001 From: Tyberius Prime [EMAIL PROTECTED] <[EMAIL PROTECTED]> Date: Thu, 1 May 2008 20:37:20 +0200 Subject: [PATCH] add autocomplete editing for from in edit-message-mode and a key shortcut(f) for it --- lib/sup/buffer.rb | 2 +- lib/sup/modes/edit-message-mode.rb | 11 ++++++++++ 2 files changed, 11 insertions(+), 1 deletions(-) diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb index ebc3587..e68c001 100644 --- a/lib/sup/buffer.rb +++ b/lib/sup/buffer.rb @@ -406,7 +406,7 @@ EOS end end - def ask_with_completions domain, question, completions, default=nil + def ask_with_completions domain, question, completions, default=nil #questions are a space seperated list, I believe. ask domain, question, default do |s| completions.select { |x| x =~ /^#{Regexp::escape s}/i }.map { |x| [x, x] } end diff --git a/lib/sup/modes/edit-message-mode.rb b/lib/sup/modes/edit-message-mode.rb index 8bb7756..aa582d4 100644 --- a/lib/sup/modes/edit-message-mode.rb +++ b/lib/sup/modes/edit-message-mode.rb @@ -45,6 +45,7 @@ EOS k.add :edit_message_or_field, "Edit selected field", 'e' k.add :edit_to, "Edit To:", 't' k.add :edit_cc, "Edit Cc:", 'c' + k.add :edit_from, "Edit From:", 'f' k.add :edit_subject, "Edit Subject", 's' k.add :edit_message, "Edit message", :enter k.add :save_as_draft, "Save as draft", 'P' @@ -117,6 +118,7 @@ EOS def edit_to; edit_field "To" end def edit_cc; edit_field "Cc" end def edit_subject; edit_field "Subject" end + def edit_from; edit_field "From" end def edit_message @file = Tempfile.new "sup.#{self.class.name.gsub(/.*::/, '').camel_to_hyphy}" @@ -379,6 +381,14 @@ protected update field end + when "From" + completions = AccountManager.user_emails + text = BufferManager.ask_with_completions :from, "From: ", completions, @header[field] + if text + @header[field] = parse_header field, text + update + field + end else default = case field -- 1.4.4.4
>From e293e2d66d4bfe4f342d03151baea9181a1d7b38 Mon Sep 17 00:00:00 2001 From: Tyberius Prime <[EMAIL PROTECTED]> Date: Fri, 2 May 2008 19:29:28 +0200 Subject: [PATCH] add from query on compose, configuration option, autocomplete --- lib/sup/account.rb | 6 ++++++ lib/sup/modes/compose-mode.rb | 6 ++++-- lib/sup/modes/edit-message-mode.rb | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/sup/account.rb b/lib/sup/account.rb index f8ac0fc..664debd 100644 --- a/lib/sup/account.rb +++ b/lib/sup/account.rb @@ -31,6 +31,12 @@ class AccountManager def user_accounts; @accounts.keys; end def user_emails; @email_map.keys.select { |e| String === e }; end + def user_accounts_autocompletion; + completion = [] + completion.push ( @default_account.name + " <" + default_account.email + ">" ) #make sure default account is [0] + @accounts.each { |account, dummy| if account != @default_account then completion.push (account.name + " <" + account.email + ">") end } + return completion + end ## must be called first with the default account. fills in missing ## values from the default account. diff --git a/lib/sup/modes/compose-mode.rb b/lib/sup/modes/compose-mode.rb index 7674d7b..ce8ea8e 100644 --- a/lib/sup/modes/compose-mode.rb +++ b/lib/sup/modes/compose-mode.rb @@ -3,7 +3,7 @@ module Redwood class ComposeMode < EditMessageMode def initialize opts={} header = {} - header["From"] = (opts[:from] || AccountManager.default_account).full_address + header["From"] = (opts[:from] || AccountManager.default_account.full_address) header["To"] = opts[:to].map { |p| p.full_address }.join(", ") if opts[:to] 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] @@ -24,8 +24,10 @@ class ComposeMode < EditMessageMode 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]) subj = opts[:subj] || (BufferManager.ask(:subject, "Subject: ") or return if $config[:ask_for_subject]) + completion = AccountManager.user_accounts_autocompletion; + from = opts[:from] || (BufferManager.ask_with_completions :from, "From: ", completion, completion[0]) or return if $config[:ask_for_from] - mode = ComposeMode.new :from => opts[:from], :to => to, :cc => cc, :bcc => bcc, :subj => subj + mode = ComposeMode.new :from => from, :to => to, :cc => cc, :bcc => bcc, :subj => subj BufferManager.spawn "New Message", mode mode.edit_message end diff --git a/lib/sup/modes/edit-message-mode.rb b/lib/sup/modes/edit-message-mode.rb index aa582d4..d66d261 100644 --- a/lib/sup/modes/edit-message-mode.rb +++ b/lib/sup/modes/edit-message-mode.rb @@ -382,7 +382,7 @@ protected field end when "From" - completions = AccountManager.user_emails + completions = AccountManager.user_accounts_autocompletion; text = BufferManager.ask_with_completions :from, "From: ", completions, @header[field] if text @header[field] = parse_header field, text -- 1.4.4.4
_______________________________________________ sup-talk mailing list sup-talk@rubyforge.org http://rubyforge.org/mailman/listinfo/sup-talk