From f34f2a23b355f020759f714eb8fb567871de587c Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 5 Oct 2013 13:58:14 +0100 Subject: Output each name/addr only once with mutt-query --- clab | 10 ++++++++-- clab.yarn | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/clab b/clab index d47700a..33307a7 100755 --- a/clab +++ b/clab @@ -147,12 +147,18 @@ class CommandLineAddressBook(cliapp.Application): self.output.write('No matches\n') sys.exit(1) self.output.write('clab found matches:\n') + + name_addr_pairs = set() for entry in entries: name = entry.get_single('name', '') emails = entry.get_subdict('email') for email in emails: - n = name.encode('utf-8') - self.output.write('%s\t%s\n' % (emails[email], n)) + name_addr_pairs.add((name, emails[email])) + + for name, addr in sorted(name_addr_pairs): + n = name.encode('utf-8') + a = addr.encode('utf-8') + self.output.write('%s\t%s\n' % (a, n)) CommandLineAddressBook().run() diff --git a/clab.yarn b/clab.yarn index 234777c..745eb09 100644 --- a/clab.yarn +++ b/clab.yarn @@ -60,6 +60,15 @@ Put several records in one file. AND Bob is not found AND bob@example.com is not found +Sometimes the same person is in the database multiple times +(e.g., different records for home and work personas, where the +work persona is automatically generated from LDAP or something). +In this case, only find each person once. + + GIVEN another record for Alice (alice@example.com) + WHEN mutt-querying for example + THEN Alice is found only once + Implementation -------------- @@ -82,6 +91,12 @@ These implement the various steps. email: $MATCH_4 EOF + IMPLEMENTS GIVEN another record for (\S+) \((\S+)\) + cat << EOF >> "$DATADIR/db/foo.yaml" + - name: $MATCH_1 + email: $MATCH_2 + EOF + IMPLEMENTS WHEN listing all records ./clab --no-default-config --db "$DATADIR/db" list > "$DATADIR/output" @@ -106,5 +121,13 @@ These implement the various steps. set -x grep -F "$MATCH_1" "$DATADIR/output" + IMPLEMENTS THEN (.*) is found only once + n=$(grep -cF "$MATCH_1" "$DATADIR/output") + if [ "$n" != 1 ] + then + echo "$MATCH_1 was found $n times, expected 1" 1>&2 + exit 1 + fi + IMPLEMENTS THEN (.*) is not found ! grep -F "$MATCH_1" "$DATADIR/output" -- cgit v1.2.1