# How to Make Mime Recognize Mail Files?

evergreen

how to make mime recognize mail files

I store important mails inside ipfs, see my ideal file system.

Unfortunately, most of those I save are not recognized when they don’t have an extension.

My debian system already has a bit of mime magic to find out rfc822 files.

sed -n '/^$50:message\/rfc822$/,/^\[/ p' /usr/share/mime/magic

[50:message/rfc822]
>0=#! rnews
>0=
Forward to
>0=From:
>0=	N#! rnews
>0=Pipe to
>0=Relay-Version:
>0=Return-Path:
>0=Return-path:
>0=	Subject:
[50:model/iges]


Somehow, it expects the metadata to be prefixed by a tabulation character, whereas my mails don’t have. They look like this

Content-Type: multipart/alternative; boundary="===============3140710037221646522=="
MIME-Version: 1.0
Subject: some subject
Date: Fri, 29 Oct 2021 11:58:03 +0200
Message-Id: <someid>

--===============3140710037221646522==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
...
--===============3140710037221646522==--


Let’s say that this content is put into ipfs, available via this link https://konubinix.eu/ipfs/bafkreih4ah2ymy7buqsxzqakpej4ou5edihfc6cfcg3vue2ikevnw5alei .

mimetype https://konubinix.eu/ipfs/bafkreih4ah2ymy7buqsxzqakpej4ou5edihfc6cfcg3vue2ikevnw5alei

https://konubinix.eu/ipfs/bafkreih4ah2ymy7buqsxzqakpej4ou5edihfc6cfcg3vue2ikevnw5alei: text/plain


Let’s try to put some more magic to recognize this one

Let’s put the following content in one of my XDG_DATA_DIRS/mime/magic files.

[50:message/rfc822]
>0=From:+257
>0=Subject:+257
>0=To:+257


To be noted that the data before Subject, To and From are the size of the data. I also added a range value to avoid parsing the whole file.

Now, let’s try again.

mimetype https://konubinix.eu/ipfs/bafkreih4ah2ymy7buqsxzqakpej4ou5edihfc6cfcg3vue2ikevnw5alei

https://konubinix.eu/ipfs/bafkreih4ah2ymy7buqsxzqakpej4ou5edihfc6cfcg3vue2ikevnw5alei: message/rfc822


Much better.