* [PATCH] VIM: Better reply handling with multiple emails
@ 2014-10-02 23:50 Ian Main
2014-10-27 20:33 ` [PATCH v2] " Ian Main
2014-10-27 20:35 ` [PATCH v3] " Ian Main
0 siblings, 2 replies; 3+ messages in thread
From: Ian Main @ 2014-10-02 23:50 UTC (permalink / raw)
To: notmuch
This patch fixes reply handling when using multiple emails. This adds a
config check for other_email and uses that information when formulating
reply headers. It will strip out your own email addresses from the
reply and set the From: to be an email of yours found in the original
message.
Note that this is built on top of the config change patch.
Ian
---
vim/notmuch.vim | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 52 insertions(+), 5 deletions(-)
diff --git a/vim/notmuch.vim b/vim/notmuch.vim
index b251af6..fbd0e21 100644
--- a/vim/notmuch.vim
+++ b/vim/notmuch.vim
@@ -467,6 +467,7 @@ ruby << EOF
end
$db_name = nil
+ $all_emails = []
$email = $email_name = $email_address = nil
$searches = []
$threads = []
@@ -485,8 +486,14 @@ ruby << EOF
$db_name = get_config_item('database.path')
$email_name = get_config_item('user.name')
$email_address = get_config_item('user.primary_email')
+ $secondary_email_addresses = get_config_item('user.primary_email')
$email_name = get_config_item('user.name')
$email = "%s <%s>" % [$email_name, $email_address]
+ other_emails = get_config_item('user.other_email')
+ $all_emails = other_emails.split("\n")
+ # Add the primary to this too as we use it for checking
+ # addresses when doing a reply
+ $all_emails.unshift($email_address)
end
def vim_puts(s)
@@ -562,14 +569,54 @@ ruby << EOF
end
end
+ def is_our_address(address)
+ $all_emails.each do |addy|
+ if address.to_s.index(addy) != nil
+ return addy
+ end
+ end
+ return nil
+ end
+
def open_reply(orig)
reply = orig.reply do |m|
- # fix headers
- if not m[:reply_to]
- m.to = [orig[:from].to_s, orig[:to].to_s]
+ m.cc = []
+ email_addr = $email_address
+ # Append addresses to the new to: from the original from:
+ # so long as they are not ours.
+ if orig[:from]
+ orig[:from].each do |o|
+ if not is_our_address(o)
+ m.to << o
+ end
+ end
+ end
+ # This copies the cc list to the new email while
+ # stripping out our own addresses and sets the from:
+ # address to ours if it finds one.
+ if orig[:cc]
+ orig[:cc].each do |o|
+ if is_our_address(o)
+ email_addr = is_our_address(o)
+ else
+ m.cc << o
+ end
+ end
+ end
+ # This copies the to list to the new email while
+ # stripping out our own addresses and sets the from:
+ # address to ours if it finds one.
+ if orig[:to]
+ orig[:to].each do |o|
+ if is_our_address(o)
+ email_addr = is_our_address(o)
+ else
+ m.to << o
+ end
+ end
end
- m.cc = orig[:cc]
- m.from = $email
+ m.to = m[:reply_to] if m[:reply_to]
+ m.from = "#{$email_name} <#{email_addr}>"
m.charset = 'utf-8'
end
--
1.9.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v2] VIM: Better reply handling with multiple emails
2014-10-02 23:50 [PATCH] VIM: Better reply handling with multiple emails Ian Main
@ 2014-10-27 20:33 ` Ian Main
2014-10-27 20:35 ` [PATCH v3] " Ian Main
1 sibling, 0 replies; 3+ messages in thread
From: Ian Main @ 2014-10-27 20:33 UTC (permalink / raw)
To: notmuch
This patch fixes reply handling when using multiple emails. This adds a
config check for other_email and uses that information when formulating
reply headers. It will strip out your own email addresses from the
reply and set the From: to be an email of yours found in the original
message.
Note that this is built on top of the config change patch.
Ian
---
This update uses hashes to ensure no duplicate emails are inserted into
the to/cc lists. It's also just a little easier to read.
vim/notmuch.vim | 53 ++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 48 insertions(+), 5 deletions(-)
diff --git a/vim/notmuch.vim b/vim/notmuch.vim
index cad9517..b480277 100644
--- a/vim/notmuch.vim
+++ b/vim/notmuch.vim
@@ -476,6 +476,7 @@ ruby << EOF
end
$db_name = nil
+ $all_emails = []
$email = $email_name = $email_address = nil
$searches = []
$threads = []
@@ -494,8 +495,14 @@ ruby << EOF
$db_name = get_config_item('database.path')
$email_name = get_config_item('user.name')
$email_address = get_config_item('user.primary_email')
+ $secondary_email_addresses = get_config_item('user.primary_email')
$email_name = get_config_item('user.name')
$email = "%s <%s>" % [$email_name, $email_address]
+ other_emails = get_config_item('user.other_email')
+ $all_emails = other_emails.split("\n")
+ # Add the primary to this too as we use it for checking
+ # addresses when doing a reply
+ $all_emails.unshift($email_address)
end
def vim_puts(s)
@@ -571,14 +578,50 @@ ruby << EOF
end
end
+ def is_our_address(address)
+ $all_emails.each do |addy|
+ if address.to_s.index(addy) != nil
+ return addy
+ end
+ end
+ return nil
+ end
+
def open_reply(orig)
reply = orig.reply do |m|
- # fix headers
- if not m[:reply_to]
- m.to = [orig[:from].to_s, orig[:to].to_s]
+ m.cc = []
+ m.to = []
+ email_addr = $email_address
+ # Use hashes for email addresses so we can eliminate duplicates.
+ to = Hash.new
+ cc = Hash.new
+ if orig[:from]
+ orig[:from].each do |o|
+ to[o.address] = o
+ end
+ end
+ if orig[:cc]
+ orig[:cc].each do |o|
+ cc[o.address] = o
+ end
+ end
+ if orig[:to]
+ orig[:to].each do |o|
+ cc[o.address] = o
+ end
+ end
+ to.each do |e_addr, addr|
+ m.to << addr
+ end
+ cc.each do |e_addr, addr|
+ if is_our_address(e_addr)
+ email_addr = is_our_address(e_addr)
+ else
+ m.cc << addr
+ end
end
- m.cc = orig[:cc]
- m.from = $email
+ m.to = m[:reply_to] if m[:reply_to]
+ m.from = "#{$email_name} <#{email_addr}>"
m.charset = 'utf-8'
end
--
1.9.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v3] VIM: Better reply handling with multiple emails
2014-10-02 23:50 [PATCH] VIM: Better reply handling with multiple emails Ian Main
2014-10-27 20:33 ` [PATCH v2] " Ian Main
@ 2014-10-27 20:35 ` Ian Main
1 sibling, 0 replies; 3+ messages in thread
From: Ian Main @ 2014-10-27 20:35 UTC (permalink / raw)
To: notmuch
Fix reply handling when using multiple emails. This adds a config
check for other_email and uses that information when formulating reply
headers. It will strip out your own email addresses from the reply and
set the From: to be an email of yours found in the original message.
Ian
---
Fix commit message.
vim/notmuch.vim | 53 ++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 48 insertions(+), 5 deletions(-)
diff --git a/vim/notmuch.vim b/vim/notmuch.vim
index cad9517..b480277 100644
--- a/vim/notmuch.vim
+++ b/vim/notmuch.vim
@@ -476,6 +476,7 @@ ruby << EOF
end
$db_name = nil
+ $all_emails = []
$email = $email_name = $email_address = nil
$searches = []
$threads = []
@@ -494,8 +495,14 @@ ruby << EOF
$db_name = get_config_item('database.path')
$email_name = get_config_item('user.name')
$email_address = get_config_item('user.primary_email')
+ $secondary_email_addresses = get_config_item('user.primary_email')
$email_name = get_config_item('user.name')
$email = "%s <%s>" % [$email_name, $email_address]
+ other_emails = get_config_item('user.other_email')
+ $all_emails = other_emails.split("\n")
+ # Add the primary to this too as we use it for checking
+ # addresses when doing a reply
+ $all_emails.unshift($email_address)
end
def vim_puts(s)
@@ -571,14 +578,50 @@ ruby << EOF
end
end
+ def is_our_address(address)
+ $all_emails.each do |addy|
+ if address.to_s.index(addy) != nil
+ return addy
+ end
+ end
+ return nil
+ end
+
def open_reply(orig)
reply = orig.reply do |m|
- # fix headers
- if not m[:reply_to]
- m.to = [orig[:from].to_s, orig[:to].to_s]
+ m.cc = []
+ m.to = []
+ email_addr = $email_address
+ # Use hashes for email addresses so we can eliminate duplicates.
+ to = Hash.new
+ cc = Hash.new
+ if orig[:from]
+ orig[:from].each do |o|
+ to[o.address] = o
+ end
+ end
+ if orig[:cc]
+ orig[:cc].each do |o|
+ cc[o.address] = o
+ end
+ end
+ if orig[:to]
+ orig[:to].each do |o|
+ cc[o.address] = o
+ end
+ end
+ to.each do |e_addr, addr|
+ m.to << addr
+ end
+ cc.each do |e_addr, addr|
+ if is_our_address(e_addr)
+ email_addr = is_our_address(e_addr)
+ else
+ m.cc << addr
+ end
end
- m.cc = orig[:cc]
- m.from = $email
+ m.to = m[:reply_to] if m[:reply_to]
+ m.from = "#{$email_name} <#{email_addr}>"
m.charset = 'utf-8'
end
--
1.9.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-10-27 20:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-02 23:50 [PATCH] VIM: Better reply handling with multiple emails Ian Main
2014-10-27 20:33 ` [PATCH v2] " Ian Main
2014-10-27 20:35 ` [PATCH v3] " Ian Main
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).