[MlMt] Gravatar-hack for MailMate

Aslak Raanes aslakr at gmail.com
Thu Feb 28 19:35:56 EST 2019


On 21 Feb 2019, at 15:35, Benny Kjær Nielsen wrote:

> I still haven't integrated MailMate with images from Contacts, but I 
> realized that it was fairly easy to use the 
> [Gravatar](https://www.gravatar.com) service.

One alternative could be use [Libravatar](https://www.libravatar.org/) 
and its [federated api](https://wiki.libravatar.org/api/) which makes it 
possible to run your own avatar server.

Since MailMate doesn't support the federated api (yet) one could use 
Apache installed on macOS to redirect or reverse proxy to different 
avatar servers.

I.e. change `headersFormatting.plist` to something like:

```diff
--- headersFormatting-2.plist	2019-03-01 00:18:48.000000000 +0100
+++ headersFormatting.plist	2019-03-01 00:41:08.000000000 +0100
@@ -5,7 +5,7 @@
  		(
  			// Gravatar example with link
  			{
-				formatString = "<a 
href=\"https://www.gravatar.com/${from.address.#md5}\"><img 
style=\"float: left; height: 60px;\" 
src=\"https://www.gravatar.com/avatar/${from.address.#md5}\"/></a>";
+				formatString = "<img style=\"float: left; height: 60px;\" 
src=\"http://localhost/avatar/${from.address.#md5}?s=60&d=identicon\" 
srcset=\"http://localhost/avatar/${from.address.#md5}?s=60&d=identicon 
1x, http://localhost/avatar/${from.address.#md5}?s=90&d=identicon 
1.5x,http://localhost/avatar/${from.address.#md5}?s=120&d=identicon 
2x\"/>";
  			},
  			{
  				separator = { string = "\n"; };
```

and by [using Apache 
RewriteMap](https://httpd.apache.org/docs/current/rewrite/rewritemap.html), 
redirect

```apache
LoadModule ssl_module libexec/apache2/mod_ssl.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so

<VirtualHost localhost:80>

     CustomLog /var/log/apache2/avatar-rewrite-access.log combined
     ErrorLog /var/log/apache2/avatar-rewrite-error.log

     SSLProxyEngine On
     RewriteEngine On

     RewriteMap hash2avatarurl 
"txt:/Library/WebServer/hash2avatarurl.txt"
     RewriteRule "^/avatar/(.*)" 
"${hash2avatarurl:$1|https://www.gravatar.com/avatar/00000000000000000000000000000000}" 
[R,L]

</VirtualHost>
```
or reverse proxy

```apache
LoadModule proxy_module libexec/apache2/mod_proxy.so
LoadModule proxy_http_module libexec/apache2/mod_proxy_http.so
LoadModule ssl_module libexec/apache2/mod_ssl.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule cache_module libexec/apache2/mod_cache.so
LoadModule cache_socache_module libexec/apache2/mod_cache_socache.so
LoadModule socache_shmcb_module libexec/apache2/mod_socache_shmcb.so

<VirtualHost localhost:80>
     LogLevel info rewrite:trace3 socache_shmcb:debug

     CustomLog /var/log/apache2/avatar-proxy-access.log combined
     ErrorLog /var/log/apache2/avatar-proxy-error.log

     CacheSocache shmcb:/var/tmp/avatarproxyshmcbcache(512000)

     CacheQuickHandler off

     CacheStoreExpired On
     CacheIgnoreNoLastMod On
     CacheIgnoreCacheControl On
     CacheDefaultExpire 86400
     CacheMinExpire 86400
     CacheMaxExpire 604800

     CacheHeader On
     CacheDetailHeader On

     <Location "/avatar">
         CacheEnable socache
     </Location>

     SSLProxyEngine on
     RewriteEngine On

     RewriteMap hash2avatarurl 
"dbm:/Library/WebServer/hash2avatarurl.dbm"
     RewriteRule "^/avatar/(.*)" 
"${hash2avatarurl:$1|https://www.gravatar.com/avatar/00000000000000000000000000000000}" 
[P]

</VirtualHost>
```

where `hash2avatarurl.txt` looks like:

```text
54d652cfd5beed169d4d585b134c65e1 
https://secure.gravatar.com/avatar/54d652cfd5beed169d4d585b134c65e1
967b1e0903bb424fdf75fa38bcaf9af0 
https://seccdn.libravatar.org/avatar/967b1e0903bb424fdf75fa38bcaf9af0
```


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freron.com/pipermail/mailmate/attachments/20190301/82ee4a83/attachment-0001.html>


More information about the mailmate mailing list