---
title: "Inspect email files from the command line"
url: https://recursiveai.org/onemail/cookbook/inspect-email-cli/
description: "Inspect .msg, .eml, .pst, mbox and winmail.dat files from the command line with the onemail .NET tool: sender, date, subject, attachments and defects, as text or JSON, and convert them to EML or mbox. OneMail.Cli 0.3.0-preview.2."
version: "0.3.0-preview.2"
---

# Inspect email files from the command line

Install the `onemail` .NET tool and run `onemail inspect` on files or folders. Each message gets one line with its date, sender, subject, attachments and defects. Add `--json` for machine-readable output. It reads every format the library reads: `.eml`, `.msg`, `.pst`, `.ost`, mbox, Maildir, `winmail.dat`, Outlook Express `.dbx` and Outlook for Mac `.olm`. `onemail convert` writes them in another format.

```shell
dotnet tool install -g RecursiveAI.OneMail.Cli --version 0.3.0-preview.2
onemail --version
```

```text
0.3.0-preview.2
```

The tool needs the .NET 10 runtime. The examples use public test files from Apache POI and Apache Tika:

```shell
curl -LO https://raw.githubusercontent.com/apache/poi/REL_5_4_1/test-data/hsmf/attachment_test_msg.msg
curl -LO https://raw.githubusercontent.com/apache/poi/REL_5_4_1/test-data/hmef/quick-winmail.dat
curl -LO https://raw.githubusercontent.com/apache/tika/4.2.0/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-mail-module/src/test/resources/test-documents/complex.mbox
curl -LO https://raw.githubusercontent.com/apache/tika/4.2.0/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-mail-module/src/test/resources/test-documents/testRFC822_multipart_attachments.eml
```

## One file

```shell
onemail inspect attachment_test_msg.msg
```

```text
attachment_test_msg.msg: Msg
  #0  2009-04-22T14:36:33Z  from: Nicolas1 23456 <nicolas1.23456@free.fr>  subject: test pièce jointe 1  attachments: 2 (test-unicode.doc, pj1.txt)  defects: 0
inspected 1 files/stores, 1 items, 2 attachments, 0 defects (0 ambiguities), 0 not readable
```

The last line is a summary, written to standard error.

## A folder, with attachment sizes

`--sizes` adds each attachment’s decoded size in bytes. A folder is searched for every file it can read:

```shell
onemail inspect --sizes .
```

```text
./attachment_test_msg.msg: Msg
  #0  2009-04-22T14:36:33Z  from: Nicolas1 23456 <nicolas1.23456@free.fr>  subject: test pièce jointe 1  attachments: 2 (test-unicode.doc 24064B, pj1.txt 89B)  defects: 0
./complex.mbox: Mbox
  #0  2009-06-01T04:26:31Z  from: Jothi Padmanabhan <jothipn@yahoo-inc.com>  subject: Re: question about when shuffle/sort start working  attachments: 0  defects: 0
  #1  2009-06-01T05:30:49Z  from: Jianmin Woo <jianmin_woo@yahoo.com>  subject: Re: question about when shuffle/sort start working  attachments: 0  defects: 0
  #2  2009-06-01T06:03:13Z  from: Jothi Padmanabhan <jothipn@yahoo-inc.com>  subject: Re: question about when shuffle/sort start working  attachments: 0  defects: 0
./quick-winmail.dat: Tnef
  #0  -  from: -  subject: -  attachments: 5 (quick.doc 19968B, quick.html 428B, quick.pdf 18638B, quick.txt 235B, quick.xml 143B)  defects: 1
./testRFC822_multipart_attachments.eml: Eml
  #0  -  from: Bugs Bunny <Bugs.Bunny@acme.com>  subject: EML 1  attachments: 2 (Test TxtA.txt 33B, Test TxtB.txt 33B)  defects: 0
inspected 4 files/stores, 6 items, 9 attachments, 1 defects (0 ambiguities), 0 not readable
```

## Defects

`--defects` lists each repair under its message, with the byte offset where it was found:

```shell
onemail inspect --defects quick-winmail.dat
```

```text
quick-winmail.dat: Tnef
  #0  -  from: -  subject: -  attachments: 5 (quick.doc, quick.html, quick.pdf, quick.txt, quick.xml)  defects: 1
      mapi:LowerLayerDefect @40
inspected 1 files/stores, 1 items, 5 attachments, 1 defects (0 ambiguities), 0 not readable
```

## JSON

`--json` writes one JSON object per line: one for each file or store, then one for each message.

```shell
onemail inspect --json attachment_test_msg.msg
```

```text
{"type":"container","path":"attachment_test_msg.msg","format":"Msg"}
{"type":"item","index":0,"kind":"Message","provenance":{"format":"Msg","location":"attachment_test_msg.msg","folder":null,"offset":0,"length":52224},"subject":"test pi\u00E8ce jointe 1","sender":[],"from":[{"name":"Nicolas1 23456","addr":"nicolas1.23456@free.fr"}],"to":[{"name":"\u0027nicolas1.23456@free.fr\u0027","addr":"nicolas1.23456@free.fr"}],"cc":[],"bcc":[],"replyTo":[],"date":{"utc":"2009-04-22T14:36:33Z","offsetMinutes":null,"source":"ClientSubmit"},"messageId":null,"inReplyTo":[],"references":[],"conversationTopic":"test pi\u00E8ce jointe 1","attachments":[{"name":"test-unicode.doc","type":"application/msword","contentId":null,"inline":false,"embedded":false},{"name":"pj1.txt","type":"text/plain","contentId":null,"inline":false,"embedded":false}],"defects":[]}
```

## Convert

`onemail convert` writes a file or a whole store in another format and lists what didn’t carry over. `--to` takes `eml`, `mbox`, `maildir`, `emlx`, `ics`, `vcf`, `jcal`, `jcard`, `xcal`, `xcard` or `tnef`:

```shell
onemail convert --to eml attachment_test_msg.msg eml
```

```text
read 1 items, wrote 1 as Eml to eml, skipped 0, 1 with something that did not carry over
  Approximated DateSubSecondDropped (mapi) in 1 items, for example PidTagClientSubmitTime
  Approximated DefaultValueNotWritten (mapi) in 1 items, for example PidTagSensitivity
  Approximated HtmlFromRtf (mapi) in 1 items, for example PidTagRtfCompressed
  Dropped NoInternetMapping (mapi) in 1 items, for example PidTagCreationTime
  Dropped FlagsNotCarried (store) in 1 items, for example flags
```

The message is now `eml/000001-test-pi-ce-jointe-1.eml`. `onemail export` does the same for a whole store into a directory, and `--json` makes both machine-readable. The library call behind them: [Convert a PST file to mbox](https://recursiveai.org/onemail/cookbook/convert-pst-to-mbox/).

## Limits

- **A preview.** 0.3.0-preview.2: the commands and their output can change before 1.0.
- **No extract command.** To save attachments, use the library, as in [Extract attachments from email](https://recursiveai.org/onemail/cookbook/extract-attachments/).
- **Not for calendar files.** `inspect` counts `.ics` and `.vcf` files as not readable; read them with [RecursiveAI.OneMail.Calendar](https://recursiveai.org/onemail/cookbook/read-ics-file/).

The tool’s options: [Mail.Open and the read view](https://recursiveai.org/onemail/docs/shared-view/).
