【问题标题】:Applescript: Parse from MailApplescript:从邮件中解析
【发布时间】:2017-05-08 21:40:04
【问题描述】:

我正在寻找一个通过我的邮件获取所需结果的 applescript:

邮件主题:Registrierung fuer die Badener Hochzeitstage - 2587(这里我需要号码)

我需要的电子邮件的内容是“Frau/Herr/Firma”之后的名称,直到下一个“空格”

我的 php/mysql 代码有一个错误,因此我的数据库中没有这个,所以我需要解析大约 400 封电子邮件。

tell application "Mail"

set theMessages to message 1 of mailbox "INBOX" of account "Die Badenerhochzeitstage" whose subject begins with "Registrierung fuer"
set theContent to content of theMessages

set someData to paragraphs of theContent
repeat with someData in theContent

    if someData begins with "Firma" then
        set theURL to paragraph of someData
    else
        set theURL to paragraph 10 of theContent -- this works but this line can change weekly
    end if
end repeat

end tell

我在这里尝试过,但结果只是得到了一些线条,而不是我想要的。

【问题讨论】:

    标签: applescript


    【解决方案1】:

    试试这个...

    set theAccount to "Die Badenerhochzeitstage"
    set subjectText to "Registrierung fuer"
    set subjectSearch to "-"
    set contentSearch to "Frau/Herr/Firma"
    set theResults to {}
    
    tell application "Mail"
        try
            set theMessages to messages of mailbox "INBOX" of account theAccount whose subject begins with subjectText
            if theMessages is {} then
                display dialog "No Messages were found which begins with:" & return & subjectText buttons {"OK"} default button 1
                return
            end if
    
            repeat with aMessage in theMessages
                tell aMessage
                    set theSubject to subject
                    set theContent to content
                end tell
                set theNumber to my getFirstWordAfterSearchText(subjectSearch, theSubject)
                set theWord to my getFirstWordAfterSearchText(contentSearch, theContent)
                set end of theResults to {theNumber, theWord}
            end repeat
        on error theError
            display dialog theError buttons {"OK"} default button 1
            return
        end try
    end tell
    return theResults
    
    (*============== SUBROUTINES =================*)
    on getFirstWordAfterSearchText(searchString, theText)
        try
            set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, searchString}
            set textItems to text items of theText
            set AppleScript's text item delimiters to tids
            return (first word of (item 2 of textItems))
        on error theError
            return ""
        end try
    end getFirstWordAfterSearchText
    

    【讨论】:

    • 伟大的思想相通 ;) macscripter.net/viewtopic.php?id=39630 我不确定这个名字是不是 1 个字或更多。
    • 这很有趣。他确实说过up-to-the-space,所以这对我来说是1。无论如何,我很高兴他能得到帮助。
    【解决方案2】:

    试试这个:

       set TID to text item delimiters
    set myRecords to {}
    
    set outputFile to quoted form of (POSIX path of ((path to desktop as text) & "LaunchAgent_Alert.txt")) -- represents "MacHD:Users:david:Desktop:result.txt"
    
    tell application "Mail" to set theMessages to every message of mailbox "INBOX" of account "Badener Hochzeitstage" whose subject begins with "Registrierung fuer"
    
    repeat with aMessage in theMessages
       tell application "Mail" to set {mSubject, mContent} to {subject, content} of aMessage
       set AppleScript's text item delimiters to "-"
       set mSubject to text item 2 of mSubject
    
       set AppleScript's text item delimiters to "Herr/Frau/Firma "
       set mContent to first word of (text item 2 of mContent)
    
       set end of myRecords to {mSubject & return & mContent & return & return}
    
    end repeat
    
    set myRecords to myRecords as text
    do shell script "echo " & myRecords & " > " & outputFile
    
    set text item delimiters to TID
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多