How to Extract Attachments from Corrupted PST File using Mac Terminal?
The extracting attachments from a corrupted .pst file on a Mac possess two distinct difficulties: first, Mac OS X cannot open PST files by default, and secondly, corruption frequently causes problems with normal software that would be capable of opening such a file. If you need to extract invoices, contracts, pictures, or PDFs hidden in a corrupt PST file, you may begin with command line programs in Mac Terminal, but if that is not successful, then automated solution will surely be a wise choice.
Why PST Files Corrupt and Fail to Open on macOS?
The data items of PST file such as mail folders, emails, contacts, calendar appointments, and attachments are stored within on Windows platform. The most common reason of corruption in Outlook is the occurrence of an oversized PST that exceeds its storage limit, a crash in an email client application in the middle of writing operation, an abrupt disconnection from the network drive during synchronization, or degradation of storage sectors.
In case of using Mac computers, the default email clients require .mbox files, and Outlook for Mac requires .olm archive files. If you have not corrupted your PST file, still there is no option to open it through any OS X utility.
Step 1: Back Up the Corrupted PST before Touching It
Never perform any restoration procedures or conversions directly on the one copy of a damaged PST file. If the container is damaged, then it can suffer from more writing problems due to faulty processing of the damaged sector.
Step 1. Open Terminal or Finder and make a folder which will be used for this work only, for example, ~/pst_recovery.
Step 2. Copy the damaged .pst file into this folder and do not move the original copy from your backup drive.
Step 3. Make sure that there is enough free disk space – at least twice or even three times the size of the PST file.
Step 2: Extract Attachments Using Mac Terminal (readpst)
macOS does not have any built-in PST parser; therefore, the usual command-line solution is to install the libpst package, that includes the readpst program. The readpst program is used for reading PST structures and exporting messages and attachments into standard formats.
Readpst installation through Homebrew
In case you have Homebrew installed on your machine, then use Terminal to execute:
brew install libpst
In case Homebrew is not yet installed, install it from the Homebrew website and then execute the following command:
readpst -V
Extract Separate Messages and Attachments
To extract attachments with messages and retain the folder structure, use the following procedure to produce an output directory using separate-file output:
mkdir -p ~/pst_recovery/output_separatereadpst -r -S -o ~/pst_recovery/output_separate ~/pst_recovery/corrupted_copy.pst
Important flags that will be used:
- -r: The PST file folder structure is recreated recursively within the specified output folder.
- -S: Individual messages will be written to individual files, with attachments saved in the same folder and named with the prefix <message number>-<file name> so as to prevent overwriting.
- -o <folder>: Specifies the output folder that must exist already.
However, some items have been deleted or became orphaned because of the damaged index, the following flag could also be tried out on a different test folder:
mkdir -p ~/pst_recovery/output_deletedreadpst -r -S -D -o ~/pst_recovery/output_deleted ~/pst_recovery/corrupted_copy.pst
Collect Only Attachments into One Folder
In order to view all the attached files together at once, use the find command of Terminal after extracting the attachments. Let’s assume that readpst extracts messages as numeric files such as 1, 2, 3 and attachments such as .pdf, .docx, .xlsx, .jpg, and .zip.
mkdir -p ~/pst_recovery/all_attachmentsfind ~/pst_recovery/output_separate -type f ! -regex ‘.*/[0-9]+$’ -exec cp -n {} ~/pst_recovery/all_attachments/ \;
The above command moves non-numeric message files to all_attachments but -n avoids file overwriting of files having similar names. If you want to move specific types of files only, you can modify the find command accordingly.
Step 3: Where Terminal Extraction Falls Short
Readpst extraction using the command line is efficient, automated, and cost-effective. However, its limitation lies in that it has limitations when there is extreme damage to the files.
- Serious structural damage: If the internal pointers or attachment tables have been highly damaged, a simple parser will ignore them or report errors without providing a visual look at them.
- Large or complicated archives: Multi-gigabyte PST files that contain deeply nested folders, embedded images, or different encodings become difficult to review using plain terminal logs or numbered output files.
- No visual preview: You cannot preview message context prior to deciding on what to export.
Step 4: Using Professional Technique
If you are looking for a graphical process flow in macOS or if you want to convert PST data to specific formats without facing trouble related to CLI flags, then use MacMister Mac PST Converter. It is an alternative solution that works in macOS. This program works offline on your Mac and not online by uploading your mails to a cloud server.
How to Extract and Export With Automated Method
Step 1. Download and launch software on your Mac computer.

Step 2. Click “Add File(s)” or “Add Folder(s)” and choose the necessary PST files from the system.

Step 3. Check the list of PST folder items appearing, make required selection if needed and press Next.

Step 4. Select one of the saving formats from the menu: MBOX (in case of exporting into Apple Mail or Thunderbird), EML, MSG, or PDF according to your needs.

Step 5. Choose sub-options and any other options of naming and filtering if needed and then click “Export” to see the real-time status of the process.

Epilogue
To begin with, make a backup of the corrupted PST file. You can try using the command “readpst -r -S” for a quick run through the Terminal in Mac OS if you desire to get a command line approach that will allow you to separate messages from attachments and put them in different folders. For visual interface or multiple PSTs, MacMister PST Conversion utility will come in handy.