commit 003a28032593275a04fa07a65d4438ff221dd6b2
parent 263e56f5a2a91787b0e64cf95948fdb9232a808c
Author: Hamish Downer <dmishd@gmail.com>
Date: Sun, 19 Jun 2011 22:36:41 +0100
resolved merge conflict
Diffstat:
4 files changed, 60 insertions(+), 5 deletions(-)
diff --git a/lib/sup.rb b/lib/sup.rb
@@ -297,6 +297,7 @@ EOS
:ask_for_cc => true,
:ask_for_bcc => false,
:ask_for_subject => true,
+ :account_selector => true,
:confirm_no_attachments => true,
:confirm_top_posting => true,
:jump_to_open_message => true,
diff --git a/lib/sup/account.rb b/lib/sup/account.rb
@@ -80,6 +80,10 @@ class AccountManager
@regexen.argfind { |re, a| re =~ email && a }
end
end
+ def full_address_for email
+ a = account_for email
+ Person.full_address a.name, email
+ end
end
end
diff --git a/lib/sup/modes/edit-message-mode.rb b/lib/sup/modes/edit-message-mode.rb
@@ -116,6 +116,28 @@ EOS
@selector_label_width = 0
@async_mode = nil
+ # only show account selector if there is more than one email address
+ if $config[:account_selector] && AccountManager.user_emails.length > 1
+ ## Duplicate e-mail strings to prevent a "can't modify frozen
+ ## object" crash triggered by the String::display_length()
+ ## method in util.rb
+ user_emails_copy = []
+ AccountManager.user_emails.each { |e| user_emails_copy.push e.dup }
+
+ @account_selector =
+ HorizontalSelector.new "Account:", AccountManager.user_emails + [nil], user_emails_copy + ["Customized"]
+
+ if @header["From"] =~ /<?(\S+@(\S+?))>?$/
+ @account_selector.set_to $1
+ @account_user = ""
+ else
+ @account_selector.set_to nil
+ @account_user = @header["From"]
+ end
+
+ add_selector @account_selector
+ end
+
@crypto_selector =
if CryptoManager.have_crypto?
HorizontalSelector.new "Crypto:", [:none] + CryptoManager::OUTGOING_MESSAGE_OPERATIONS.keys, ["None"] + CryptoManager::OUTGOING_MESSAGE_OPERATIONS.values
@@ -164,6 +186,8 @@ EOS
def edit_subject; edit_field "Subject" end
def edit_message
+ old_from = @header["From"] if @account_selector
+
@file = Tempfile.new "sup.#{self.class.name.gsub(/.*::/, '').camel_to_hyphy}"
@file.puts format_headers(@header - NON_EDITABLE_HEADERS).first
@file.puts
@@ -180,6 +204,12 @@ EOS
header, @body = parse_file @file.path
@header = header - NON_EDITABLE_HEADERS
+
+ if @account_selector and @header["From"] != old_from
+ @account_user = @header["From"]
+ @account_selector.set_to nil
+ end
+
handle_new_text @header, @body
rerun_crypto_selector_hook
update
@@ -295,6 +325,7 @@ protected
if curpos < @selectors.length
@selectors[curpos].roll_left
buffer.mark_dirty
+ update if @account_selector
else
col_left
end
@@ -304,6 +335,7 @@ protected
if curpos < @selectors.length
@selectors[curpos].roll_right
buffer.mark_dirty
+ update if @account_selector
else
col_right
end
@@ -315,6 +347,14 @@ protected
end
def update
+ if @account_selector
+ if @account_selector.val.nil?
+ @header["From"] = @account_user
+ else
+ @header["From"] = AccountManager.full_address_for @account_selector.val
+ end
+ end
+
regen_text
buffer.mark_dirty if buffer
end
@@ -532,6 +572,12 @@ protected
if contacts
text = contacts.map { |s| s.full_address }.join(", ")
@header[field] = parse_header field, text
+
+ if @account_selector and field == "From"
+ @account_user = @header["From"]
+ @account_selector.set_to nil
+ end
+
rerun_crypto_selector_hook
update
end
diff --git a/lib/sup/person.rb b/lib/sup/person.rb
@@ -43,18 +43,22 @@ class Person
def mediumname; @name || @email; end
- def full_address
- if @name && @email
- if @name =~ /[",@]/
- "#{@name.inspect} <#{@email}>" # escape quotes
+ def Person.full_address name, email
+ if name && email
+ if name =~ /[",@]/
+ "#{name.inspect} <#{email}>" # escape quotes
else
- "#{@name} <#{@email}>"
+ "#{name} <#{email}>"
end
else
email
end
end
+ def full_address
+ Person.full_address @name, @email
+ end
+
## when sorting addresses, sort by this
def sort_by_me
case @name