【问题标题】:AppleScript - Get information of .eml fileAppleScript - 获取 .eml 文件的信息
【发布时间】:2011-10-16 06:07:47
【问题描述】:

我编写了一个 AppleScript 来备份我所有的电子邮件。我已经将很多电子邮件保存为本地硬盘上的 .eml 文件,并将它们从服务器中删除。有没有办法使用 AppleScript 作为 message 加载 .eml 文件以获取它们的发送日期主题等?

【问题讨论】:

    标签: email backup applescript


    【解决方案1】:

    这样的事情怎么样:

    set fromField to text 7 thru -1 of (do shell script "cat /test.eml | grep From:")
    set dateField to text 7 thru -1 of (do shell script "cat test.eml | grep Date:")
    set toField to text 5 thru -1 of (do shell script "cat /test.eml | grep To:")
    set subjectField to text 10 thru -1 of (do shell script "cat /test.eml | grep Subject:")
    

    正文有点困难,因为您需要决定是只想要电子邮件正文还是嵌入到正文中的所有以前的电子邮件。以下获取我的测试电子邮件的正文。

    set temp to do shell script "cat /test.eml"
    set text item delimiters to "--"
    
    set temp2 to (text item 3 of temp)
    set text item delimiters to "
    "
    set messageField to paragraphs 6 thru -1 of temp2 as text
    

    如果您使用其他字符,请务必注意文件的编码。

    【讨论】:

    • 非常感谢。它适用于日期。但是题目有问题。我得到一个长字符串,最后有“主题:=”和一长串随机字母。我怎样才能让它工作?
    • 这个脚本适用于我的测试文件,如果你想让我让它处理更广泛的电子邮件,我可以看看它失败的那个。只需执行(执行 shell 脚本“cat /test.eml | grep Subject:”),看看它给了你什么。
    猜你喜欢
    • 2016-06-26
    • 1970-01-01
    • 1970-01-01
    • 2014-11-15
    • 2020-07-21
    • 2015-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多