addr-book-combine
jasoncarloscox.com/creations/addr-book-combine
Combine multiple aerc-style address books into a single address book, with de-duplication and smart sorting.
Works well with maildir-rank-addr.
Usage
addr-book-combine (-f <file> | -c <command>) ...
<file>
is the path to a file containing address book entries.
<command>
is a command (to be run with sh -c
) that outputs address book entries on stdout.
Each argument (-f <file>
or -c <command>
) is considered a separate address book. Each book contains entries, each on their own line. Entries have tab-separated fields (address<tab>name<tab>rank
). Here's an example address book:
[email protected] Andy Apple 5
[email protected] Bart Berry 2
[email protected] Chad Cherry 4
[email protected]
(Names and ranks are optional.)
Sorting
When comparing two addresses, a and b, which appear in books numbered i and j, respectively, the following procedure is applied:
-
First, if the addresses are not from the same book, the address from the earlier book appears first.
-
Next, each book is checked to compare the addresses:
- If neither address is ranked within the book, check in the next book.
- If only one address is ranked within the book, the ranked address appears first.
- If both addresses have the same rank, check in the next book.
- If the addresses have different ranks, the address with the lowest rank appears first.
-
Finally, if no address has been chosen to appear first, preserve the original order of the addresses.
Check out the test code to see some examples.
Building & Running
go build
./addr-book-combine
Testing
go test
Contributing
Contributions are welcome! You can send questions, bug reports, patches, etc. by email to ~jcc/[email protected]. (Don't know how to contribute via email? Check out the interactive tutorial at git-send-email.io, or email me for help.)