Now it is, and while testing the code, I’ve found that it was another case where an SQL query quickly solved a practical selection problem. The Face header is indeed not so widely used, so getting a significant sample of different pictures to show is not obvious. Ideally I wanted to extract from my mail archive a gallery of pictures that would be all different. That is, if someone had posted 1000 messages with the same Face header, I wasn’t interested in getting all those messages, only one of them, let’s say the first by it’s ID, and I wanted the next mail in the list to be with a different, non-empty Face, and so on for every message that I wanted to look at. It turns out, that in SQL, it can be expressed with:
SELECT min(mail_id) FROM header WHERE position(E'\nFace: ' in lines)>0 GROUP BY split_part(substr(lines, position(E'\nFace: ' in lines)+7, 1300), E'\n', 1)
position(…) indicates where the Face header field begins, substr(…) extracts a sufficient length of it, and split_part(…) cuts exactly the value at the first newline which marks the end of this header’s value (they’re unfolded in the header table precisely to be able to perform that kind of extraction).
Finally the GROUP BY ensures that each row in the result represents a distinct value of the Face header.
This query can be directly input into the SQL statement field of the Query Selection dialog, after which all there is to do is wait for the database engine to run it to completion.
On my sample database of about 800,000 messages from various mailing lists, it turned out that the result was a list of 176 messages. Here is a collage of a selection of the pictures (public messages only).
Here is how one particular message looks with its Face header:
Right now this is just about displaying, sometime in the future I’ll try to add Face headers to outgoing mail, and also I’d like to associate pictures to sender addresses so that messages from people who don’t use a Face header (the majority) still can be shown with a dedicated picture. I feel like even tags or sender domains (which means companies and organizations), could benefit from that kind of visual representation in certain cases.