- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 Outlook PST 文件,我想获取电子邮件的 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
是从 Mining the Social Web 稍作修改的。 .
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"
mbox2json
(python 2.7):
# -*- coding: utf-8 -*-
import sys
import mailbox
import email
import quopri
import json
from BeautifulSoup import BeautifulSoup
MBOX = sys.argv[1]
OUT_FILE = sys.argv[2]
SKIP_HTML=True
def cleanContent(msg):
# Decode message from "quoted printable" format
msg = quopri.decodestring(msg)
# Strip out HTML tags, if any are present
soup = BeautifulSoup(msg)
return ''.join(soup.findAll(text=True))
def jsonifyMessage(msg):
json_msg = {'parts': []}
for (k, v) in msg.items():
json_msg[k] = v.decode('utf-8', 'ignore')
# The To, CC, and Bcc fields, if present, could have multiple items
# Note that not all of these fields are necessarily defined
for k in ['To', 'Cc', 'Bcc']:
if not json_msg.get(k):
continue
json_msg[k] = json_msg[k].replace('\n', '').replace('\t', '').replace('\r'
, '').replace(' ', '').decode('utf-8', 'ignore').split(',')
try:
for part in msg.walk():
json_part = {}
if part.get_content_maintype() == 'multipart':
continue
type = part.get_content_type()
if SKIP_HTML and type == 'text/html':
continue
json_part['contentType'] = type
content = part.get_payload(decode=False).decode('utf-8', 'ignore')
json_part['content'] = cleanContent(content)
json_msg['parts'].append(json_part)
except Exception, e:
sys.stderr.write('Skipping message - error encountered (%s)\n' % (str(e), ))
finally:
return json_msg
# There's a lot of data to process, so use a generator to do it. See http://wiki.python.org/moin/Generators
# Using a generator requires a trivial custom encoder be passed to json for serialization of objects
class Encoder(json.JSONEncoder):
def default(self, o):
return {'emails': list(o)}
# The generator itself...
def gen_json_msgs(mb):
while 1:
msg = mb.next()
if msg is None:
break
yield jsonifyMessage(msg)
mbox = mailbox.UnixMailbox(open(MBOX, 'rb'), email.message_from_file)
json.dump(gen_json_msgs(mbox),open(OUT_FILE, 'wb'), indent=4, cls=Encoder)
现在,可以轻松处理该文件了。例如。仅获取电子邮件的内容:
jq '.emails[] | .parts[] | .content' < out/Inbox.json
关于python - 使用 libpst 将 Outlook PST 转换为 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38122047/
正在计算每月的最后一个工作日,合并如下 - • AI.VOUCHER_DT >= 本月最后一个工作日下午 5:00(太平洋标准时间) • AI.VOUCHER_DT <= 本月最后一个日历日太平洋标准
我想使用 C# 访问我的 Outlook 已发送文件夹,并将那里的邮件移动到我的 PST 中名为 Archive 的文件夹中。这是我正在使用的代码,但出现多个编译错误。这里有更多编码经验的人知道如何完
我正在使用 PST File Format SDK尝试从 Outlook PST 导出中提取一些约会项目数据: int main() { pst myfile(L"export.pst");
这个问题已经有答案了: How to initialize a JavaScript Date to a particular time zone (21 个回答) Convert Javascrip
我们正在研究处理 PST 的东西,所以我们正在尝试使用 java-libpst 创建示例代码。它对我来说工作正常,但我们需要显示 PST 的详细信息,例如 PST 名称、给定 PST 上配置的电子邮件
我找不到完全用 Excel VBA 操作的代码来指向一个不是 Outlook 中默认收件箱的收件箱。 想象一下第二个收件箱,其中有一个用于特殊电子邮件的备用电子邮件地址。 看来Set Inbox =
它最终达到了我不得不寻求帮助的地步。 由于电子邮件服务器的空间限制,我们公司的常见做法是将邮件/日历等从 Outlook 备份到 PST 文件。 我们现在在电子邮件服务器上不再有阻止这种情况的空间限制
我想要当前的日期和时间(太平洋标准时间)。我使用了这段代码 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [date
我编辑了一个我在网上找到的脚本,将电子邮件移动到各个文件夹。 我想更进一步,将电子邮件移动到单独的 PST 文件中的文件夹。 这将在 Outlook 2007 中运行。 宏源于这个名为“更新”的宏,是
在我的一个模块中,我必须实现以下目标。 我从服务器获取 yyyy-MM-dd'T'HH:mm:ss'Z' 格式的日期。我必须转换此日期和 PST 中的当前日期,然后以小时/分钟/秒为单位显示这两者之间
我正在尝试提取 .pst 文件的内容(作为字符串/文本)。 我尝试了不同的答案,但没有找到任何相关的解决方案。 Outlook PST File Parsing in Python Read PST
在我们的应用程序服务器中,以这样的格式提供日期时间字符串“2013-01-14 T 06:33 PST” 和 “2013-01-14 T 06:33 PDT” 或 “2013-01-14 T 06:3
我需要获取从现在到“America/Los_Angeles”(太平洋标准时间)午夜之间的毫秒数。 midnightAtPST = ???; long millis = ChronoUnit.MILLI
玩弄 Calendar 和 TimeZone 我遇到了以下奇怪的行为。 Calendar pstCal = Calendar.getInstance(TimeZone.getTimeZone("PST
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭
我正在研究 javascript。我有时间以毫秒为单位。所以我必须显示 PST 时区的时间。我试过格林威治标准时间。但是是否有任何选项以 PST 格式显示时间,其中输入以毫秒为单位,如 1671673
我正在使用 java libpst 和 tika 从 pst 文件中提取元数据,我使用了以下代码: int numberOfAttachments = email.getNumberOfAtt
我正在使用java-libpst查看其中有哪些电子邮件和电子邮件附件。现在,请建议一种将所有或选定的电子邮件以及电子邮件附件从 PST 文件提取到本地文件夹的方法。 最佳答案 该库似乎没有尝试将 PS
有没有一种方法可以使用 C# 检查 Microsoft Outlook pst 文件是否受密码保护。我正在尝试使用以下代码读取 pst 文件。 Microsoft.Office.Interop.Out
有没有办法通过 API 调用或注册表项以编程方式查找当前用户的 Outlook .pst 文件的位置? 最佳答案 与 Outlook Redemption ,您可以使用 RDOStores 迭代 VB
我是一名优秀的程序员,十分优秀!