How to Make Mime Recognize Mail Files?


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
>0=#! rnews
Forward to
>0=	N#! rnews
>0=Pipe to
>0=	Received:
>0=Return-Path:
>0=Return-path:
>0=	Subject:

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
From: someaddress
To: someotheraddress
Date: Fri, 29 Oct 2021 11:58:03 +0200
Message-Id: <someid>

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

Let’s say that this content is put into ipfs, available via this link .

mimetype 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.


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 message/rfc822

Much better.