In preparation for 'stg mail --auto' growing the capability to send all
patches in a series to a designated address, 'addressX', if any patch in
series has 'addressX' in the Cc:, make 'extra_cc' a parameter
__send_message().
Cc: Dave Chinner <
da...@fromorbit.com>
Signed-off-by: Dan Williams <
dan.j.w...@intel.com>
---
stgit/commands/mail.py | 45 ++++++++++++++++++++++++++-------------------
1 file changed, 26 insertions(+), 19 deletions(-)
diff --git a/stgit/commands/mail.py b/stgit/commands/mail.py
index 4a18dba1e4a8..e238bb6f397a 100644
--- a/stgit/commands/mail.py
+++ b/stgit/commands/mail.py
@@ -336,7 +336,7 @@ def __update_header(msg, header, addr = '', ignore = ()):
msg[header] = ', '.join(map(email.Utils.formataddr, addr_pairs))
return set(addr for _, addr in addr_pairs)
-def __build_address_headers(msg, options, extra_cc = []):
+def __build_address_headers(msg, options, extra_cc):
"""Build the address headers and check existing headers in the
template.
"""
@@ -459,7 +459,7 @@ def __edit_message(msg):
return msg
-def __build_cover(tmpl, msg_id, options, patches):
+def __build_cover(tmpl, msg_id, options, patches, extra_cc):
"""Build the cover message (series description) to be sent via SMTP
"""
sender = __get_sender()
@@ -531,16 +531,6 @@ def __build_cover(tmpl, msg_id, options, patches):
except Exception, ex:
raise CmdException, 'template parsing error: %s' % str(ex)
- extra_cc = []
- if options.auto:
- for patch in patches:
- p = crt_series.get_patch(patch)
- if p.get_description():
- descr = p.get_description().strip()
- extra_cc.extend(__get_signers_list(descr))
- extra_cc = list(set(extra_cc))
-
-
if not options.git:
__build_address_headers(msg, options, extra_cc)
__build_extra_headers(msg, msg_id, options.in_reply_to)
@@ -548,7 +538,8 @@ def __build_cover(tmpl, msg_id, options, patches):
return msg
-def __build_message(tmpl, msg_id, options, patch, patch_nr, total_nr, ref_id):
+def __build_message(tmpl, msg_id, options, patch, patch_nr, total_nr, ref_id,
+ extra_cc):
"""Build the message to be sent via SMTP
"""
p = crt_series.get_patch(patch)
@@ -656,13 +647,17 @@ def __build_message(tmpl, msg_id, options, patch, patch_nr, total_nr, ref_id):
except Exception, ex:
raise CmdException, 'template parsing error: %s' % str(ex)
+ cc = []
+ # merge the series addresses with local signers
if options.auto:
- extra_cc = __get_signers_list(descr)
- else:
- extra_cc = []
+ cc = __get_signers_list(descr)
+ signer_addrs = [email.Utils.parseaddr(a)[1] for a in cc]
+ extra_addrs = [email.Utils.parseaddr(a)[1] for a in extra_cc]
+ extra_addrs = list(set(extra_addrs).difference(set(signer_addrs)))
+ cc.extend(extra_addrs)
if not options.git:
- __build_address_headers(msg, options, extra_cc)
+ __build_address_headers(msg, options, cc)
__build_extra_headers(msg, msg_id, ref_id)
__encode_message(msg)
@@ -706,6 +701,17 @@ def func(parser, options, args):
# get username/password if sending by SMTP
__set_smtp_credentials(options)
+ # generate unified cc list for cover letter and "series" designated
+ # addresses
+ extra_cc = []
+ if options.auto:
+ for patch in patches:
+ p = crt_series.get_patch(patch)
+ if p.get_description():
+ descr = p.get_description().strip()
+ extra_cc.extend(__get_signers_list(descr))
+ extra_cc = list(set(extra_cc))
+
# send the cover message (if any)
if options.cover or options.edit_cover:
if options.unrelated:
@@ -719,7 +725,7 @@ def func(parser, options, args):
if not tmpl:
raise CmdException, 'No cover message template file found'
- msg_id = __send_message('cover', tmpl, options, patches)
+ msg_id = __send_message('cover', tmpl, options, patches, extra_cc)
# subsequent e-mails are seen as replies to the first one
if not options.no_thread:
@@ -739,7 +745,8 @@ def func(parser, options, args):
raise CmdException, 'No e-mail template file found'
for (p, n) in zip(patches, range(1, total_nr + 1)):
- msg_id = __send_message('patch', tmpl, options, p, n, total_nr, ref_id)
+ msg_id = __send_message('patch', tmpl, options, p, n, total_nr,
+ ref_id, [])
# subsequent e-mails are seen as replies to the first one
if not options.no_thread and not options.unrelated and not ref_id: