Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用libpst将outlookpst转换为json_Python_Ruby_Json_Email_Pst - Fatal编程技术网

Python 使用libpst将outlookpst转换为json

Python 使用libpst将outlookpst转换为json,python,ruby,json,email,pst,Python,Ruby,Json,Email,Pst,我有一个OutlookPST文件,我想得到电子邮件的json,例如 {"emails": [ {"from": "alice@example.com", "to": "bob@example.com", "bcc": "eve@example.com", "subject": "mitm", "content": "be careful!" }, ...]} 我想使用readpst转换成MH格式,然后用ruby/python/bash脚本扫描,有没有更好的方法 不幸的是,ruby-ms

我有一个OutlookPST文件,我想得到电子邮件的json,例如

{"emails": [
{"from": "alice@example.com",
 "to": "bob@example.com",
 "bcc": "eve@example.com",
 "subject": "mitm",
 "content": "be careful!"
}, ...]}
我想使用
readpst
转换成MH格式,然后用ruby/python/bash脚本扫描,有没有更好的方法


不幸的是,
ruby-msg
gem在我的PST文件上不起作用(而且似乎从2014年起就没有更新过)。

我找到了一种分两个阶段完成的方法,首先转换为mbox,然后转换为json:

# requires installing libpst
pst2json my.pst
# or you can specify a custom output dir and an outlook mail folder,
# e.g. Inbox, Sent, etc.
pst2json -o email/ -f Inbox my.pst
其中,
pst2json
是我的脚本,
mbox2json
是从

pst2json

#!/usr/bin/env bash

usage(){
    echo "usage: $(basename $0) [-o <output-dir>] [-f <folder>] <pst-file>"
    echo "default output-dir: email/mbox-all/<pst-file>"
    echo "default folder: Inbox"
    exit 1
}

which readpst || { echo "Error: libpst not installed"; exit 1; }
folder=Inbox

while (( $# > 0 )); do
    [[ -n "$pst_file" ]] && usage
    case "$1" in
        -o)
            if [[ -n "$2" ]]; then
                out_dir="$2"
                shift 2
            else
                usage
            fi
            ;;
        -f)
            if [[ -n "$2" ]]; then
                folder="$2"
                shift 2
            else
                usage
            fi
            ;;
        *)
            pst_file="$1"
            shift
    esac
done

default_out_dir="email/mbox-all/$(basename $pst_file)"
out_dir=${out_dir:-"$default_out_dir"}
mkdir -p "$out_dir"
readpst -o "$out_dir" "$pst_file"
[[ -f "$out_dir/$folder" ]] || { echo "Error: folder $folder is missing or empty."; exit 1; }
res="$out_dir"/"$folder".json
mbox2json "$out_dir/$folder" "$res" && echo "Success: result saved to $res"
现在,可以轻松地处理该文件。例如,仅获取电子邮件的内容:

jq '.emails[] | .parts[] | .content' < out/Inbox.json
jq'.emails[]|.parts[]|.content'
您能告诉我如何在mac中安装
libpst
,最好使用
pip
?我搜索了谷歌,但没有找到任何方法。谢谢。@mnis@mnis
brew安装libpst
jq '.emails[] | .parts[] | .content' < out/Inbox.json