I set out to quickly add support for cid: links in the shr renderer and wound up making our charset handling more robust and rewriting our content-ID handling. The test introduced in patch 2 passes in all but one really obscure case, but only because of many unwritten and potentially fragile assumptions that Emacs and the CLI make about each other. The first three patches could reasonably go in to 0.18. The rest of this series is certainly post-0.18, but I didn't want to lose track of it. This series comes in three stages. Each depends on the earlier ones, but each prefix makes sense on its own and could be pushed without the later stages. Patch 1 is a simple clean up patch. Patches 2 through 7 robust-ify our charset handling in Emacs, mostly by splitting the broken `notmuch-get-bodypart-content' API into `notmuch-get-bodypart-binary' and `notmuch-get-bodypart-text' so a caller can explicitly convey their requirements. The remaining patches improve our content-ID handling and add support for cid: links for shr.