Skip to content

MBox file importer to MongoDB

Notifications You must be signed in to change notification settings

Rpsl/mboximporter

 
 

Repository files navigation

Mbox Importer

Parse your "gmail takeout file" or any another .mbox file and indexing mail messages into MongoDB.

After that you can use some aggregation functions for insights or analytics your inbox

Prerequisites

  1. Go here and download your Gmail mailbox, depending on the amount of emails you have accumulated this might take a while. The downloaded archive is in the mbox format.
  2. Build importer from source or download release

Build

$ git clone git@github.com:Rpsl/mboximporter.git && cd ./mboximporter
$ go mod download
$ go build -o mbox-importer ./

Usage

Run MongoDB, you can use docker-compose for starting mongodb and web-view panel:

docker-compose up

Parse the messages:

mbox-importer -init -filename ~/path/to/your/mail.mbox

Connection to the MongoDB instance:

mongo -u root -p example --authenticationDatabase admin

> use mbox-importer
switched to db mbox-importer

And exec aggregation functions.

> db.mails.aggregate([
    { $match: { labels: { $in: ['inbox'] } } },
    { $unwind: "$sender" },
    { $group: {_id: "$sender", total: {$sum : 1} } },
    { $sort: {"total": -1 } }
]);

Usage

Usage of ./mbox-importer:
  -body
    	Parse and insert body of the emails
  -database string
    	The Database name to use in MongoDB (default "mbox-importer")
  -filename string
    	Name of the filename to import
  -headers
    	Parse and insert all headers of the emails
  -init
    	Drop if exist collection and create fresh
  -mongo string
    	The Mongo URI to connect to MongoDB (default "root:example@127.0.0.1")

Todo

  • Repair parse body
  • Extract examples (aggregate functions) to the personal classes and execute from cli
  • Add --report option for executing the aggregates and generate report files

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%