The email duplicates test in the t1900-mail.sh test script could fail sporadically due to `stg email` arbitrarily ordering email addresses.
The root cause was __update_header() iterating a dict. The solution is to modify __update_header() to collect email addresses in a list instead of a dict to ensure deterministic ordering. t1900-mail.sh is updated to expect the new deterministic ordering. Signed-off-by: Peter Grayson <[email protected]> --- stgit/commands/mail.py | 20 +++++++++----------- t/t1900-mail.sh | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/stgit/commands/mail.py b/stgit/commands/mail.py index 2dc3dba6..4a18dba1 100644 --- a/stgit/commands/mail.py +++ b/stgit/commands/mail.py @@ -324,19 +324,17 @@ def __send_message(type, tmpl, options, *args): return msg_id def __update_header(msg, header, addr = '', ignore = ()): - def __addr_pairs(msg, header, extra): - pairs = email.Utils.getaddresses(msg.get_all(header, []) + extra) - # remove pairs without an address and resolve the aliases - return [address_or_alias(p) for p in pairs if p[1]] - - addr_pairs = __addr_pairs(msg, header, [addr]) + addr_pairs = email.Utils.getaddresses(msg.get_all(header, []) + [addr]) del msg[header] + # remove pairs without an address and resolve the aliases + addr_pairs = [address_or_alias(name_addr) for name_addr in addr_pairs + if name_addr[1]] # remove the duplicates and filter the addresses - addr_dict = dict((addr, email.Utils.formataddr((name, addr))) - for name, addr in addr_pairs if addr not in ignore) - if addr_dict: - msg[header] = ', '.join(addr_dict.itervalues()) - return set(addr_dict.iterkeys()) + addr_pairs = [name_addr for name_addr in addr_pairs + if name_addr[1] not in ignore] + if addr_pairs: + 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 = []): """Build the address headers and check existing headers in the diff --git a/t/t1900-mail.sh b/t/t1900-mail.sh index 10cb7f9d..987beaef 100755 --- a/t/t1900-mail.sh +++ b/t/t1900-mail.sh @@ -75,7 +75,7 @@ test_expect_success \ stg mail --to="a@a, b b <b@b>" --cc="b@b, c@c" \ --bcc="c@c, d@d, [email protected]" --auto $(stg top) -m \ -t $STG_ROOT/templates/patchmail.tmpl > mbox && - test "$(cat mbox | grep -e "^To:")" = "To: b b <b@b>, a@a" && + test "$(cat mbox | grep -e "^To:")" = "To: a@a, b b <b@b>" && test "$(cat mbox | grep -e "^Cc:")" = \ "Cc: C O Mitter <[email protected]>, c@c" && test "$(cat mbox | grep -e "^Bcc:")" = "Bcc: d@d" _______________________________________________ stgit-users mailing list [email protected] https://mail.gna.org/listinfo/stgit-users
