[Jmap] I made a tool to convert email to JMAP compatible JSON

Seph Gentle <me@josephg.com> Sat, 13 June 2020 06:23 UTC

Return-Path: <me@josephg.com>
X-Original-To: jmap@ietfa.amsl.com
Delivered-To: jmap@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id BE3C23A092D for <jmap@ietfa.amsl.com>; Fri, 12 Jun 2020 23:23:31 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.098
X-Spam-Level:
X-Spam-Status: No, score=-2.098 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (1024-bit key) header.d=josephg.com header.b=MTuBFLFD; dkim=pass (2048-bit key) header.d=messagingengine.com header.b=XDwXGg0R
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jhjJZaBM7b6h for <jmap@ietfa.amsl.com>; Fri, 12 Jun 2020 23:23:29 -0700 (PDT)
Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 7FEA93A092F for <jmap@ietf.org>; Fri, 12 Jun 2020 23:23:29 -0700 (PDT)
Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 1133F407 for <jmap@ietf.org>; Sat, 13 Jun 2020 02:23:28 -0400 (EDT)
Received: from imap35 ([10.202.2.85]) by compute1.internal (MEProxy); Sat, 13 Jun 2020 02:23:28 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=josephg.com; h= mime-version:message-id:date:from:to:subject:content-type; s= mesmtp; bh=3z/65/30Mhn/2R95GfHpzYL6VbJUdx3AvNHiIU6hp0Q=; b=MTuBF LFDqZCZxh6i8yEh4xu1Uoda6sg/BHSn49n0gfC4IRFIQYtgHQ2X6Zk/xXJ/ZZ+3l yPZ+QVZ/uZOMbYLE9xARvl1Io36bG7vTYn6ICef+ICRE3ZcE5vIY5bwZPdHNA+qO D/CzHRjgTO22a4R1yMrE7/3GIrtlSZO1qhkJj4=
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=3z/65/30Mhn/2R95GfHpzYL6VbJUd x3AvNHiIU6hp0Q=; b=XDwXGg0RYmRJQ6fIXCHaB06K5/h7OyDby59cMChss68Pw qebsxNQ5QnfwdihXNcC4bmY4T9378EhEKItrl1l9cHNZCEyqVPyxTLs0lTkIAxbU NlFASKLsf4Z7Kz6BnCYhPMu3tpuJarIGVLC3kGw70qQPLeSnP2RcW3CAqCAP8Tvq QClh3lc9XhHSrOwruvAqTyFhrhhKNXMCoJ2SuSGzC9RFeFs35C89zWw2SUhGyLIO wOUWMCFXf5p84rwWDXvxqZd+scDYC6/42l73woEkTXEbLWII3MsnCVKbB81VQQ0A 5rBolWe1hQCIYXXwxLaVK2/I1dtNTiJ0ZoJY9kCiQ==
X-ME-Sender: <xms:33DkXu-2eTCB30dc1PY8gI1SndeEOaoOXdkhQE4S_SlO80-i8YVkXA>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrudeivddguddtjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepofgfggfkfffhvffutgesthdtre dtreertdenucfhrhhomhepfdfuvghphhcuifgvnhhtlhgvfdcuoehmvgesjhhoshgvphhh ghdrtghomheqnecuggftrfgrthhtvghrnhepudfhieduiedvtedtudekjedvkeeiueevke eileehjeetiefhteekhefgudegtdfhnecuffhomhgrihhnpehjohhsvghphhhgrdgtohhm pdhgihhthhhusgdrtghomhdpnhhpmhhjshdrtghomhenucevlhhushhtvghrufhiiigvpe dtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmvgesjhhoshgvphhhghdrtghomh
X-ME-Proxy: <xmx:33DkXuu5dyx17FsoZLNPKcD1mHI8pLEiiAScQkZLlPXxCRND4LNiRQ> <xmx:33DkXkCjB6b_gulkb2WwcOsm5xXkCzUFVDpGzmiBhtGu1hw8mA0hjQ> <xmx:33DkXmduz9HCuZWVy5-xN9DVQoHqntGIi-bPiRpXCUmIWi9xrfH4ew> <xmx:33DkXp0_ieoNZMVgQ0-eGXb-y3EBXekO1apnwFxlynEFmqiO_xkffw>
Received: by mailuser.nyi.internal (Postfix, from userid 501) id 70A9214C00B1; Sat, 13 Jun 2020 02:23:27 -0400 (EDT)
X-Mailer: MessagingEngine.com Webmail Interface
User-Agent: Cyrus-JMAP/3.3.0-dev0-525-ge8fa799-fm-20200609.001-ge8fa7990
Mime-Version: 1.0
Message-Id: <4cf2591e-e2d6-4149-a604-e0f6dbd8be71@www.fastmail.com>
Date: Sat, 13 Jun 2020 06:23:06 +0000
From: Seph Gentle <me@josephg.com>
To: jmap@ietf.org
Content-Type: text/plain
Archived-At: <https://mailarchive.ietf.org/arch/msg/jmap/ekUHgWr9O12cZqCFe-QHbEhe59Y>
Subject: [Jmap] I made a tool to convert email to JMAP compatible JSON
X-BeenThere: jmap@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: JSON Message Access Protocol <jmap.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/jmap>, <mailto:jmap-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/jmap/>
List-Post: <mailto:jmap@ietf.org>
List-Help: <mailto:jmap-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/jmap>, <mailto:jmap-request@ietf.org?subject=subscribe>
X-List-Received-Date: Sat, 13 Jun 2020 06:23:32 -0000

Hi everyone!

At the hackathon in Singapore last year Neil Jenkins and I tried to make a JMAP wrapper around gmail's API. But we ran into a problem converting RFC822 message envelopes into JMAP objects.

So with a bit of help from Bron (brong) I extracted the email-to-JMAP codepath out of cyrus-imapd. (Cyrus underpins Fastmail). Anyway the end result is now we have a spec compliant, standalone C library / tool to convert email objects to JMAP-compatible json. It gives nice, clean, usable HTML from any email, extracts attachments, and all the other good stuff.

I'd love to see some alternate implementations in other languages. The extracted C code isn't particularly maintainable, but I figure this would provide a great basis for spec conformance testing. And its definitely usable on its own.

I also compiled the code to WASM and wrapped it in a nodejs library so you can convert emails to jmap json from nodejs or directly from the browser.

If you have some emails kicking around, have a play! This is a browser-only email viewer which internally loads and displays emails via jmap's format:

https://josephg.com/mail-viewer/

Code:
https://github.com/josephg/mime-to-jmap

NPM package (containing pre-compiled wasm bundle. Building it yourself is a huge pain because of libicu):
https://www.npmjs.com/package/mime-to-jmap

Hope someone finds it useful!
-Seph