nextcloud / mail

💌 Mail app for Nextcloud
https://apps.nextcloud.com/apps/mail
GNU Affero General Public License v3.0
828 stars 256 forks source link

Support for loading avatars via BIMI #5782

Open MeiKatz opened 2 years ago

MeiKatz commented 2 years ago

Feature Request

I like to request to add BIMI support for loading avatars in Nextcloud mail. Currently its supported to load the avatars either from an image in the address book, from the favicon of the website or via Gravatar. Adding support for BIMI (partial or complete) is easy, because we only have to check the DNS entries of the corresponding domain and search for the BIMI entry. There we can read the location of the avatar image.

We don't need to implement VMC or DMARC, but we could. Maybe as an option that we can enable/disable if needed.

Example code

Code could look something like this:

function get_bimi_record() {
  $records = dns_get_record( $domain, DNS_TXT );

  foreach ( $records as $record ) {
    if ( strpos( $record['txt'], 'v=BIMI1;' ) === 0 ) {
      return $record['txt'];
    }
  }

  return null;
}

function get_dns_tags( $value ) {
  $tags = explode( ';', $entry );
  $params = [];

  foreach ( $tags as $tag ) {
    list( $name, $value ) = explode( '=', $tag, 2 );
    $name = trim( $name );

    if ( $value ) {
      $params[ $name ] = trim( $value );
    }
  }

  return $params;
}

$dns_record = get_bimi_record();

if ( $dns_record ) {
  $tags = get_dns_tags( $dns_record );
  return $tags['l']; // there is the location
}

Is this feature wanted?

I would create a pull request for this feature request; the question is: do you want it?

References

ChristophWurst commented 2 years ago

Sounds reasonable. This could be added as a new avatar source in https://github.com/nextcloud/mail/tree/master/lib/Service/Avatar.

MeiKatz commented 2 years ago

Right, that's what I was thinking about. I can try to create a pull request for this.

ChristophWurst commented 2 years ago

Awesome :)

MeiKatz commented 2 years ago

Can you give me a hint how I can access the mail headers in the AvatarService? It seems to me that only the e-mail address is passed to the service.

MeiKatz commented 2 years ago

Here you go: https://github.com/nextcloud/mail/pull/5784